From patchwork Mon Nov 30 06:16:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939735 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 C0DCDC5519F for ; Mon, 30 Nov 2020 06:17:15 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87CC520757 for ; Mon, 30 Nov 2020 06:17:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L0TgncLT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="OFiIHvZS"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="FYJs7IWn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87CC520757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kQ7OC4PlgYo4XPvszRpHxer9S1bF7y7vweqYLUE4zIU=; b=L0TgncLTTdy+Dh6ERnwmhO2OY v2UgdUxz1pS73x4AoqDFaheAfyWzgMXH0M4Z08yQGrf2X7OszVfgbWwyGy6Wst8cLFAB9uOm4u/1v U10SgdoP8VwTmEoui0057GslvjYROPed99nRqgoxzS3UxWuFuSkuj6xaLQM8BDTwCMGVB+S8VCiCn JAd4uLzmWVVmaL7QdJ5zI2r3PMWl4aBA+3hu2yCq+/EFJ5rjDy2Sg6PXzXDboFCKGV8+zJrTfaql0 uHKbYoK8HD4ic3qFOLN7M3zwPLkIU2Xw4UwGezS9Yfet5aQuol4mEI8NwOO3QeuvNSGs9i5XZo6NF jnqTf4gsw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcUq-0008SE-Vw; Mon, 30 Nov 2020 06:17:13 +0000 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcUo-0008Rt-9H for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:17:11 +0000 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU683w3014038; Sun, 29 Nov 2020 22:17:05 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=88SHouuxN1T5NkpQIeQ9gWus3kkJctUiZ2A8oMY0QhM=; b=OFiIHvZSL6bvdpskpP6ERAVb1D4EVIO1OaR+el3fwXjAwR9kMTVVUjLUsS1onPIE3f5i 3imx++ry8i24pxhQMTF1PpXzCigbooCsbiYaw+ZbSlK4Uv7yAOYmkAyafEhiYq95ckxD szXJU1WlRioN2SA7Ej68vkx1uR+CHR/tDz06ZDHbiRtfT8uoH7ZuTwFx9DDXIdmX4Ner lsk95uxpugGV3eeZ5YGYqo0zCZB7MtopNzpN3GAdROx19YmE9sK6bhs7jBLTqbtS50iV OnizNN4XrVfOpTyNv2BffbalOxCCP1kDXsGhsYQQBchE1tj9GRFbrf5NsoEpSmOa+Kci Dg== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by mx0a-0014ca01.pphosted.com with ESMTP id 353m02v1ts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:17:05 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TfBVBH/WouWKbsXIHQI+PdGjENcYzk3l54oG1e5Qr1QpgSwnSHr1iCYSuYQ/uQqcfEaJYAx46SNKODXHuWhJlqYdK1RrVpfXAyFvAkBs8GBNECXKsD+JNXC75HcxHEz0uzymLPb7G7l/WSMY3p0KfT0ERAhxaapNsvWLkq+wr0En7e0QYkmPbutGDouTmJjVRVXKzmDVF9Ywku50MEFonX7iMVZrLPrzPraYcc7ERe5KMBHUu3MkgIGKq7fzDXn3qvZWMzhDRZPOxUMpio5DxK20zDBPphcD+Lp9wjBs2XKh5I58zQgqoFQCABvWdgxpYBfCDBV9Yry7SVOWafyx+g== 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-SenderADCheck; bh=88SHouuxN1T5NkpQIeQ9gWus3kkJctUiZ2A8oMY0QhM=; b=P9NlsOKRDy5vyyDdhOe6xQ4nu4z8o0e9t7tAWr/BVQ03u6pvKcAdHtTIrRyIjDbHXSwdvGTwcARx9ulHOQAYHM5CV/A5WUEZLgwaXfUQTuYqhEz90vBCCLwQY1l/M/BRBzAfs7lQM9SrDaqKF6qoBVM2ravtE2TmThKbbK7Y/2q2era/x7N5162Z4kzB1RbWY/gd6bC/aN0VxlbRRxK3Uyb8TyZocm2gFKU6ep0S9i/wpC1X2MOfwOFolM00zFCsUP0Q3O+mtEkd81nnwCZUhLcL6CM2vRHXujsmwILnBYmhbiaZZGnQcXfScmvHhiry4FujT+ZHKgkHhCGPWCHRAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 158.140.1.147) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=88SHouuxN1T5NkpQIeQ9gWus3kkJctUiZ2A8oMY0QhM=; b=FYJs7IWn+OEPde1EXIf0c6eccH37c58Fcf9wKk6Ob/OAdhde8Yj4CtBbIDi9bZXlkOIEDq1c82s37iRADwFlw+j+LwbGjKLwfGpkhtpV5rOIwm8jLqbMVR68fttlQpSuJp4bcBtrnR2p0G7ru2+zX+o7JoLemwsWycFpjxUVqg0= Received: from BN8PR15CA0020.namprd15.prod.outlook.com (2603:10b6:408:c0::33) by CY4PR0701MB3649.namprd07.prod.outlook.com (2603:10b6:910:90::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.26; Mon, 30 Nov 2020 06:17:03 +0000 Received: from BN8NAM12FT006.eop-nam12.prod.protection.outlook.com (2603:10b6:408:c0:cafe::6e) by BN8PR15CA0020.outlook.office365.com (2603:10b6:408:c0::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Mon, 30 Nov 2020 06:17:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 158.140.1.147) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 158.140.1.147 as permitted sender) receiver=protection.outlook.com; client-ip=158.140.1.147; helo=sjmaillnx1.cadence.com; Received: from sjmaillnx1.cadence.com (158.140.1.147) by BN8NAM12FT006.mail.protection.outlook.com (10.13.183.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.11 via Frontend Transport; Mon, 30 Nov 2020 06:17:02 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx1.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6GwdN016313 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Sun, 29 Nov 2020 22:17:00 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:16:57 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:16:57 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6GvVZ003734; Mon, 30 Nov 2020 07:16:57 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6GvTr003733; Mon, 30 Nov 2020 07:16:57 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 1/7] i3c: master: master initialization flow document Date: Mon, 30 Nov 2020 07:16:55 +0100 Message-ID: <1606717015-3697-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 82ed261c-483d-4a76-0547-08d894f78db6 X-MS-TrafficTypeDiagnostic: CY4PR0701MB3649: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:785; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lMqNtQHaeEKyuPKmbjMXP7QMfJ5SZ27fJSZCsj3IpuDEmYP7eZVzCorvqMgw6Rry2DsGMhFkdHynhTpRUQPwdo2jKufz9rSUUdZ+JWr3Ll/knnYJNVjyOgmoV1p5jMKDzN4wjji4dF1p2EmkRBuPT6bl2MaOylNFICyH91KoyapARy20S924S8q7zEr6FifVhr44IeOJ+/sllDIzeFKgcFy0F2CbE8Y9CFd2PxAm8X/42B1KGoVogMfb89PLy3fZQPuFEUlI2JmXu6fMDxg1WVRO4lxgeiVGbne97x1niYwtOJ13REiidk+yd5kfEN8nK5trcIfCJ5/NwmY2oYhwwsXNl3nifwMND7csMm0wacc4PMq4CrAEveOR+gc+rKLVN3brCZuhXZNPtLQMjCXc5kdf58ORonfqVPI7YWMGW6I= X-Forefront-Antispam-Report: CIP:158.140.1.147; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:sjmaillnx1.cadence.com; PTR:unknown.Cadence.COM; CAT:NONE; SFS:(4636009)(376002)(136003)(346002)(396003)(39860400002)(36092001)(46966005)(7636003)(356005)(86362001)(2616005)(426003)(8936002)(82310400003)(36756003)(47076004)(5660300002)(83380400001)(107886003)(336012)(42186006)(4326008)(110136005)(2906002)(54906003)(8676002)(70206006)(316002)(36906005)(26005)(478600001)(82740400003)(70586007)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:17:02.6975 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82ed261c-483d-4a76-0547-08d894f78db6 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[158.140.1.147]; Helo=[sjmaillnx1.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT006.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3649 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 spamscore=0 suspectscore=2 mlxlogscore=999 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_011710_476824_EDC5A738 X-CRM114-Status: GOOD ( 22.42 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Document describing master initialization, mastership handover and DEFSLVS handling processes. Signed-off-by: Parshuram Thombare --- Documentation/driver-api/i3c/index.rst | 1 + .../driver-api/i3c/master-initialization-flow.rst | 187 ++++++++++++++++++++ 2 files changed, 188 insertions(+), 0 deletions(-) create mode 100644 Documentation/driver-api/i3c/master-initialization-flow.rst diff --git a/Documentation/driver-api/i3c/index.rst b/Documentation/driver-api/i3c/index.rst index 783d6da..604f1c5 100644 --- a/Documentation/driver-api/i3c/index.rst +++ b/Documentation/driver-api/i3c/index.rst @@ -9,3 +9,4 @@ I3C subsystem protocol device-driver-api master-driver-api + master-initialization-flow diff --git a/Documentation/driver-api/i3c/master-initialization-flow.rst b/Documentation/driver-api/i3c/master-initialization-flow.rst new file mode 100644 index 0000000..e02b90d --- /dev/null +++ b/Documentation/driver-api/i3c/master-initialization-flow.rst @@ -0,0 +1,187 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================== +I3C Master Initialization Flow +============================== + +.. kernel-render:: DOT + :alt: I3C Master Initialization digraph + :caption: I3C Master Initialization Flow + + digraph master_init { + ranksep=.25; size="35,35"; + subgraph cluster_0 { + style=dashed + x0[shape=ellipse, label="I3C driver probe", style="filled"] + x1[shape=diamond, label="Secondary Master ?"] + a1[shape=box, label="Do I3C master controller specific initialization"] + b1[shape=box, label="Do I3C master controller specific initialization,\n + except enabling the DEFSLVS interrupt."] + a2[shape=box, label="Call i3c_primary_master_register"] + b2[shape=box, label="Call i3c_secondary_master_register"] + x0->x1; + x1->a1[label="No"]; + x1->b1[label="Yes"]; + a1->a2; b1->b2; + } + + subgraph cluster_1 { + style=dashed + label="Current Master"; + a3[shape=ellipse, label="i3c_primary_master_register", style="filled"] + a4[shape=box, label="Initialize I3C master controller object."] + a5[shape=box, label="Create I2C objects for devices in DTS and add to I2C list."] + a6[shape=box, label="Set appropriate bus mode based on I2C devices information."] + a7[shape=box, label="Create a work queue."] + a8[shape=box, label="Call i3c_primary_master_bus_init"] + a19[shape=box, label="Add I3C object representing this master to the system."] + a20[shape=box, label="Expose our I3C bus as an I2C adapter so that I2C devices\n + are exposed through the I2C subsystem."] + a21[shape=box, label="Register all I3C devices."] + a22[shape=box, label="Broadcast ENEC MR, HJ message."] + a3->a4->a5->a6->a7->a8; a19->a20->a21->a22; + a8->a19[style="invisible"]; + } + + subgraph cluster_2 { + style=dashed + label="Current Master"; + a9[shape=ellipse, label="i3c_primary_master_bus_init", style="filled"] + a10[shape=box, label="Call bus_init to do controller specific bus initialization\n + and enabling the controller."] + a11[shape=box, label="Create I3C object representing the master and add it to\n + the I3C device list."] + a12[shape=box, label="Set current master to the object created to represent I3C\n + master device."] + a13[shape=box, label="Reset all dynamic address that may have been assigned before."] + a14[shape=box, label="Disable all slave events before starting DAA."] + a15[shape=box, label="Pre-assign dynamic address and retrieve device information."] + a16[shape=box, label="Do dynamic address assignment to all I3C devices currenly\n + present on the bus."] + a17[shape=box, label="Create I3C objects representing devices found during DAA."] + a18[shape=box, label="Send DEFSVLS message containing information about all\n + known I3C and I2C devices."] + a9->a10->a11->a12->a13->a14->a15->a16->a17->a18; + } + + subgraph cluster_3 { + style=dashed + label="Current Master"; + h1[shape=ellipse, label="MR request interrupt", style="filled"] + h2[shape=box, label="Bottom half i3c_master_yield_bus"] + h1->h2; + } + + subgraph cluster_4 { + style=dashed + label="Current Master"; + i1[shape=ellipse, label="i3c_master_yield_bus", style="filled"] + i2[shape=box, label="Check if this device is still a master to handle a case of\n + multiple MR requests from different devices at a same time."] + i3[shape=box, label="Broadcast DISEC MR, HJ message.\n + New master should broadcast ENEC MR, HJ once its usage of bus is done."] + i4[shape=box, label="Get accept mastership acknowldege from requesting master."] + i5[shape=box, label="In case of failure reenable MR requests by broadcasting ENEC MR, HJ."] + i6[shape=box, label="Mastership hand over is done."] + i1->i2->i3->i4->i5->i6; + } + + subgraph cluster_5 { + style=dashed + b3[shape=ellipse, label="i3c_secondary_master_register", style="filled"] + b4[shape=box, label="Initialize I3C master controller object."] + b5[shape=box, label="Create I2C objects for devices in DTS and add to I2C list."] + b6[shape=box, label="Set appropriate bus mode based on I2C devices information."] + b7[shape=box, label="Create a work queue."] + b8[shape=box, label="Call i3c_secondary_master_bus_init."] + b12[shape=box, label="Allocate memory for defslvs_data, that will be used to pass I3C\n + device list received in DEFSLVS to the I3C core DEFSLVS processing."] + b13[shape=box, label="Add I3C object representing this master to the system."] + b14[shape=box, label="Expose our I3C bus as an I2C adapter so that I2C devices are\n + exposed through the I2C subsystem."] + b3->b4->b5->b6->b7->b8; b12->b13->b14; + b8->b12[style="invisible"] + } + + subgraph cluster_6 { + style=dashed + b9[shape=ellipse, label="i3c_secondary_master_bus_init", style="filled"] + b10[shape=box, label="Call bus_init to do controller specific bus initialization\n + and enabling the controller."] + b11[shape=box, label="Create I3C object representing the master and add it to\n + the I3C device list."] + b9->b10->b11; + } + + subgraph cluster_7 { + style=dashed + d1[shape=ellipse, label="DEFSLVS interrupt", style="filled"] + d2[shape=box, label="Controller driver can chose how to handle I2C devices received\n + in DEFSLVS."] + d3[shape=box, label="Read all I3C devices information from DEFSLVS message\n + to defslvs_data structure in the master object."] + d4[shape=box, label="Call i3c_master_process_defslvs."] + d1->d2->d3->d4; + } + + subgraph cluster_8 { + style=dashed + d5[shape=ellipse, label="i3c_master_process_defslvs", style="filled"] + d6[shape=box, label="Acquire I3C bus mastership."] + d7[shape=diamond, label="Bus acquired ?"] + d8[shape=box, label="Handle I3C device list from DEFSLVS."] + d9[shape=box, label="Call i3c_master_populate_bus"] + d10[shape=box, label="Queue defslvs processing task for retry."] + d5->d6; + d7->d8[label="Yes"]; + d8->d9; + d7->d10[label="No"]; + d6->d7[style="invisible"]; + d10->d5[style="dotted", constraint=false]; + } + + subgraph cluster_9 { + style=dashed + e1[shape=ellipse, label="i3c_master_acquire_bus", style="filled"] + e2[shape=box, label="If device is already holding the mastership,\n + just broadcast DISEC MR, HJ message and return success."] + e3[shape=box, label="Call request_mastership method"] + e1->e2->e3; + } + + subgraph cluster_10 { + style=dashed + f1[shape=ellipse, label="request_mastership", style="filled"] + f2[shape=box, label="Return success if device is already in master mode."] + f3[shape=box, label="Return error if device don't have dyn_addr."] + f4[shape=box, label="Return error if MR requests are disabled by current master."] + f5[shape=box, label="Send MR request"] + f6[shape=box, label="Wait with timeout until MR_DONE interrupt is received."] + f1->f2->f3->f4->f5->f6; + } + + subgraph cluster_11 { + style=dashed + g1[shape=ellipse, label="i3c_master_populate_bus", style="filled"] + g2[shape=box, label="Free up all I3C addresses to handle address\n + re assignment by main master."] + g3[shape=box, label="Master acquire dyn_addr received from the driver."] + g4[shape=box, label="For every I3C device in the defslvs_data\n + call i3c_master_add_i3c_dev_locked."] + g1->g2->g3->g4; + } + + a2->a3; a8->a9; a18->a19; + b2->b3; b8->b9; b11->b12; + b14->d1[style=invisible]; + a22->h1[style=invisible]; + d4->d5; + d6->e1; + e3->f1; + f6->d7[constraint=false]; + h2->i1; + d9->g1; + a18->d1[style="dotted", constraint=false]; + f5->h1[style="dotted", constraint=false]; + i4->f6[style="dotted", constraint=false]; + } From patchwork Mon Nov 30 06:17:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939737 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 38EADC63777 for ; Mon, 30 Nov 2020 06:18:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7278A20757 for ; Mon, 30 Nov 2020 06:18:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="UtQv2UU9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="oUQMNyXg"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="7UF674cL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7278A20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=//bEt4t+EfGz/ilS31h18cIZx30JvTUAkTALsAyZL80=; b=UtQv2UU9Oss0/LRdLQDasz8jU od8Pq9s5DAjSOEEHh8CQDA3d2K8QampcckpQEYEF/QBph8f5x74/EGUDuQ4lT9HMPbkw8vSlQ5Y0F 40mUHh9b2VryExMXOC+OlIV8CFFQBIfRf6h0LQrDP0hqPFf2L6Cq/8iT4a+qcvUgQTr+k9dVf+INI 4nWNm/iFqo4nrftfjEXcqww9WrgYsGlDjO9Lr/nPVqJXg+0FSTeiMeDsePWalQiLirtih+a6Le7Lf lGrz44pyYxYD3EzXuoujrjtccwE7wRJXFAf40FHpJHHVdtjjXoxKzGFTfZM7BT/DaM+Y7fW5r6U4G FKjyD0pnQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcVf-0008Tk-9n; Mon, 30 Nov 2020 06:18:03 +0000 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193] helo=mx0a-0014ca01.pphosted.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcVd-0008TO-9K for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:18:02 +0000 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU6AVZA015661; Sun, 29 Nov 2020 22:17:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=GK0qaWwFk/t+ObKCHu0hqiNOA3gYkwxzkNbeuZ+me8w=; b=oUQMNyXgm7/NZLMs5XbTWEf5OkIOm4EuXo5Hu1bh4sOkR769So3JqEcpK5vyopHUdy8F IPD+ceHESnsmYQ1HYUpewrGTBixhDGsLmzrVtcLMSPx+kqM0yc43ltQEqYFmMNw2hmek bRu+uHUai88xRth+zbCvm07bIrYbtAU38jfEW/seYT+8koAHOxCsKi1FxV1iYlStWirS IQP7mHddIkzmtZeD7RAe+2BkVKDUXhs/gBbXPaJGUakupvPnBi36qpk3XSLCPSNlfZjv 63lenfwrvSr/jQLkB4z5uqJ3Qbhwjg4V39HxBeINL7eF6CtOMlgZ0355cpXN5fOK0j28 Aw== Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2174.outbound.protection.outlook.com [104.47.57.174]) by mx0b-0014ca01.pphosted.com with ESMTP id 353k12m4tf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:17:57 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gIQHHbj/ZKb1WwXnAHELj/pQEVqzj6acfo4H8dYvBp8k5xssMim+ZH/M58BT9zIwatvSAI53trohiTzY3CVx7rDuxPdn8lretRuU/iA2bNAXdUGUVZNC+qzWz4YQeu+qZoOVawq7Op6hmlowup8y2reSJNWd/HjAZq4bf89/q4OT6ThYfU9kKuohhfhVfQPQrZCJK3bfIZjxkQq+VYIGSQbCHao2gGSvhvnK21dyfO5urtYVxsfu2FIrPfsAWb0GIa6HF4dHfv33PL9XlaiHwJrEsHJnN3tpj7vnBrn/ObsyZ2u4+Jm1Uws4Melih9T+ZU4QnkbJrO5vSzVMqG2jlw== 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-SenderADCheck; bh=GK0qaWwFk/t+ObKCHu0hqiNOA3gYkwxzkNbeuZ+me8w=; b=ZU0FhohWzWhTsgGU3z/KHsT4xPQliC8m3wkFh1MnJGMlRv2zI9dL3PvAu7X8TZPF7QXPCriL0lcoqiGP7r5xeqHO4lKfoNIQxx9n2TM+hG9JmlH+3V4BEXihw4zLZxkiU8vKN/roQaDUrqKkZn351p9n/KwrJNKGY7C9/6EaCVG3S2CqYPjzr8sW4MqenfDzarGhXVKheXU1mN2yDWVxaOfTl+NZcwH3SGDIHTHtPd2FZMiF+8mgp+PI1FfYjXOYSR7VzUPyu6fe9WH9CGeDSLXv60zQrWO9ctMjW1uoigyI6FFpktMU5dPBVXjy9bmELABmBvPb1h5qWhMlPKdLUw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 158.140.1.148) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GK0qaWwFk/t+ObKCHu0hqiNOA3gYkwxzkNbeuZ+me8w=; b=7UF674cLSXoG5vYMVYs6ncMcbDZRpYrUsFNrVbaV4DnlGcHrFQZ8RQa5DmhyuX4sX5cXmbGjSg8DG2avQkatIlQsKRKfgIpwY5R4tBZdxurCWHaGi0kKtdKPptgXj3G36Bq6qELaOpHXifzIl/ci5QazgRiCoN7QDz2lJyw1Zn0= Received: from BN6PR11CA0034.namprd11.prod.outlook.com (2603:10b6:404:4b::20) by BN8PR07MB6212.namprd07.prod.outlook.com (2603:10b6:408:b0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20; Mon, 30 Nov 2020 06:17:53 +0000 Received: from BN8NAM12FT063.eop-nam12.prod.protection.outlook.com (2603:10b6:404:4b:cafe::44) by BN6PR11CA0034.outlook.office365.com (2603:10b6:404:4b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Mon, 30 Nov 2020 06:17:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 158.140.1.148) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 158.140.1.148 as permitted sender) receiver=protection.outlook.com; client-ip=158.140.1.148; helo=sjmaillnx2.cadence.com; Received: from sjmaillnx2.cadence.com (158.140.1.148) by BN8NAM12FT063.mail.protection.outlook.com (10.13.182.194) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.11 via Frontend Transport; Mon, 30 Nov 2020 06:17:52 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6HnNh006489 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Sun, 29 Nov 2020 22:17:50 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:17:48 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:17:48 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6HmMd003822; Mon, 30 Nov 2020 07:17:48 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6HmrW003821; Mon, 30 Nov 2020 07:17:48 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 2/7] i3c: master: use i3c_master_register only for main master Date: Mon, 30 Nov 2020 07:17:46 +0100 Message-ID: <1606717066-3785-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3928b815-095d-437f-f200-08d894f7abae X-MS-TrafficTypeDiagnostic: BN8PR07MB6212: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bV0wmc2vYs2h+y6hVnX3RdoF3eACUTwQOjGKzbedn2EUbmK1f44uwcWQ3c6pw1Is/4MNX4CWV+JgAlavrQTX1U+9/hxhBLSO0i0mjhBNNxv12MoIEjFhrY4Vm8KjB0dNlX2b1errx/lJq0tFuRe4IVuNJNcRTB7y4DdDHRrVLf/CUT3qZzY1EHoJP07R0RWhJawvdBkPu1+NtENrnkC7cNGzZmc58Dn1r08V3WpP9TDOkc2sP5ffTQnuECDPzjCarL2vN5LDnm68XqBD0SIxlgmp9t58q3fZbiJYKcHnastlx97H6oFz70vResoV3mrUXNl6PaEtIKSs0lSebsq9u+DGqoi19BfDgVxx3Jv2BZtVVW6yW9Sv33d4Mv3AIoa+gcIfT2DY6MqdrCrZi+YxbQcpWVMagfvvaRXtLO0el/g= X-Forefront-Antispam-Report: CIP:158.140.1.148; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:sjmaillnx2.cadence.com; PTR:unknown.Cadence.COM; CAT:NONE; SFS:(4636009)(396003)(376002)(136003)(346002)(39860400002)(36092001)(46966005)(478600001)(186003)(70586007)(70206006)(8936002)(36756003)(336012)(82310400003)(2616005)(8676002)(426003)(54906003)(107886003)(5660300002)(110136005)(26005)(42186006)(83380400001)(36906005)(4326008)(316002)(82740400003)(47076004)(86362001)(7636003)(2906002)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:17:52.9768 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3928b815-095d-437f-f200-08d894f7abae X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[158.140.1.148]; Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT063.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR07MB6212 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=2 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_011801_461145_0135B3CC X-CRM114-Status: GOOD ( 22.91 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Removed last argument 'secondary' and restructured i3c_master_register to move code that can be common to i3c_secondary_master_register to separate function i3c_master_init. Signed-off-by: Parshuram Thombare --- drivers/i3c/master.c | 78 +++++++++++++++++++------------- drivers/i3c/master/dw-i3c-master.c | 4 +- drivers/i3c/master/i3c-master-cdns.c | 4 +- drivers/i3c/master/mipi-i3c-hci/core.c | 4 +- include/linux/i3c/master.h | 7 +-- 5 files changed, 56 insertions(+), 41 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index b61bf53..56e8fe4 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1637,7 +1637,7 @@ static void i3c_master_detach_free_devs(struct i3c_master_controller *master) } /** - * i3c_master_bus_init() - initialize an I3C bus + * i3c_primary_master_bus_init() - initialize an I3C bus * @master: main master initializing the bus * * This function is following all initialisation steps described in the I3C @@ -1668,7 +1668,7 @@ static void i3c_master_detach_free_devs(struct i3c_master_controller *master) * * Return: a 0 in case of success, an negative error code otherwise. */ -static int i3c_master_bus_init(struct i3c_master_controller *master) +static int i3c_primary_master_bus_init(struct i3c_master_controller *master) { enum i3c_addr_slot_status status; struct i2c_dev_boardinfo *i2cboardinfo; @@ -2441,31 +2441,10 @@ static int i3c_master_check_ops(const struct i3c_master_controller_ops *ops) return 0; } -/** - * i3c_master_register() - register an I3C master - * @master: master used to send frames on the bus - * @parent: the parent device (the one that provides this I3C master - * controller) - * @ops: the master controller operations - * @secondary: true if you are registering a secondary master. Will return - * -ENOTSUPP if set to true since secondary masters are not yet - * supported - * - * This function takes care of everything for you: - * - * - creates and initializes the I3C bus - * - populates the bus with static I2C devs if @parent->of_node is not - * NULL - * - registers all I3C devices added by the controller during bus - * initialization - * - registers the I2C adapter and all I2C devices - * - * Return: 0 in case of success, a negative error code otherwise. - */ -int i3c_master_register(struct i3c_master_controller *master, - struct device *parent, - const struct i3c_master_controller_ops *ops, - bool secondary) +static int i3c_master_init(struct i3c_master_controller *master, + struct device *parent, + const struct i3c_master_controller_ops *ops, + bool secondary) { unsigned long i2c_scl_rate = I3C_BUS_I2C_FM_PLUS_SCL_RATE; struct i3c_bus *i3cbus = i3c_master_get_bus(master); @@ -2535,10 +2514,49 @@ int i3c_master_register(struct i3c_master_controller *master, goto err_put_dev; } - ret = i3c_master_bus_init(master); + ret = i3c_primary_master_bus_init(master); if (ret) goto err_destroy_wq; + return 0; + +err_destroy_wq: + destroy_workqueue(master->wq); + +err_put_dev: + put_device(&master->dev); + + return ret; +} + +/** + * i3c_primary_master_register() - register an I3C master + * @master: master used to send frames on the bus + * @parent: the parent device (the one that provides this I3C master + * controller) + * @ops: the master controller operations + * + * This function takes care of everything for you: + * + * - creates and initializes the I3C bus + * - populates the bus with static I2C devs if @parent->of_node is not + * NULL + * - registers all I3C devices added by the controller during bus + * initialization + * - registers the I2C adapter and all I2C devices + * + * Return: 0 in case of success, a negative error code otherwise. + */ +int i3c_primary_master_register(struct i3c_master_controller *master, + struct device *parent, + const struct i3c_master_controller_ops *ops) +{ + int ret; + + ret = i3c_master_init(master, parent, ops, false); + if (ret) + return ret; + ret = device_add(&master->dev); if (ret) goto err_cleanup_bus; @@ -2568,15 +2586,13 @@ int i3c_master_register(struct i3c_master_controller *master, err_cleanup_bus: i3c_master_bus_cleanup(master); -err_destroy_wq: destroy_workqueue(master->wq); -err_put_dev: put_device(&master->dev); return ret; } -EXPORT_SYMBOL_GPL(i3c_master_register); +EXPORT_SYMBOL_GPL(i3c_primary_master_register); /** * i3c_master_unregister() - unregister an I3C master diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c index 8513bd3..4f4d41f 100644 --- a/drivers/i3c/master/dw-i3c-master.c +++ b/drivers/i3c/master/dw-i3c-master.c @@ -1166,8 +1166,8 @@ static int dw_i3c_probe(struct platform_device *pdev) master->maxdevs = ret >> 16; master->free_pos = GENMASK(master->maxdevs - 1, 0); - ret = i3c_master_register(&master->base, &pdev->dev, - &dw_mipi_i3c_ops, false); + ret = i3c_primary_master_register(&master->base, &pdev->dev, + &dw_mipi_i3c_ops); if (ret) goto err_assert_rst; diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c index 3f22269..f1d6d68 100644 --- a/drivers/i3c/master/i3c-master-cdns.c +++ b/drivers/i3c/master/i3c-master-cdns.c @@ -1644,8 +1644,8 @@ static int cdns_i3c_master_probe(struct platform_device *pdev) writel(MST_INT_IBIR_THR, master->regs + MST_IER); writel(DEVS_CTRL_DEV_CLR_ALL, master->regs + DEVS_CTRL); - ret = i3c_master_register(&master->base, &pdev->dev, - &cdns_i3c_master_ops, false); + ret = i3c_primary_master_register(&master->base, &pdev->dev, + &cdns_i3c_master_ops); if (ret) goto err_disable_sysclk; diff --git a/drivers/i3c/master/mipi-i3c-hci/core.c b/drivers/i3c/master/mipi-i3c-hci/core.c index 113c4c9..b288245 100644 --- a/drivers/i3c/master/mipi-i3c-hci/core.c +++ b/drivers/i3c/master/mipi-i3c-hci/core.c @@ -757,8 +757,8 @@ static int i3c_hci_probe(struct platform_device *pdev) if (ret) return ret; - ret = i3c_master_register(&hci->master, &pdev->dev, - &i3c_hci_ops, false); + ret = i3c_primary_master_register(&hci->master, &pdev->dev, + &i3c_hci_ops); if (ret) return ret; diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 9cb39d9..e543f68 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -538,10 +538,9 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, int i3c_master_set_info(struct i3c_master_controller *master, const struct i3c_device_info *info); -int i3c_master_register(struct i3c_master_controller *master, - struct device *parent, - const struct i3c_master_controller_ops *ops, - bool secondary); +int i3c_primary_master_register(struct i3c_master_controller *master, + struct device *parent, + const struct i3c_master_controller_ops *ops); int i3c_master_unregister(struct i3c_master_controller *master); /** From patchwork Mon Nov 30 06:18:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939739 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 252B7C71155 for ; Mon, 30 Nov 2020 06:18:29 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E86C20809 for ; Mon, 30 Nov 2020 06:18:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1lc7kmjD"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="pf21OGi+"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="m2u0nMM4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E86C20809 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3F7mY6BWW67pOCQNCNJlENPHG3mHfy+NM/ISkUYdlZI=; b=1lc7kmjDPQPREYlkLJUc6DQwM ar4ZmGBRLq/HNA5SLYf+aP0v5talQcbPGdvDqccJ8RgiIfp+xX6H6rJAxGw8WiQ5LooixZ/5rKKSK UoKLiwC1tRCqaWOyTI1ltgyrLT2UEaRg56hcLg7goukhh+ejs/oTQnpguVI/s9AXU5sD1xc/vV+H+ GTChxy0zQ5Dr7eEZLp1M70VeNvJB52a7zPnfJpL1MZ0SHqgrFqNY+sr27/bTzuxoWxcoez+pLG0Nj M8JfUfGPpZMIxWowISLvNLqDt14FSwjhAHNeQyL2wTOlkiZqs+4vD8Hn+UOuyBoejmViyFmlAoz9Z vEC7nTJCw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcW3-0008Ue-Mq; Mon, 30 Nov 2020 06:18:27 +0000 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcW1-0008UK-1J for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:18:26 +0000 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU68bUA014443; Sun, 29 Nov 2020 22:18:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=zAot8ZKLmBihRtXXOEijPs4fo3Dtmbdp2ADXmAaIpfw=; b=pf21OGi+1QsAoZcDaCXKi0UjSqD93lfOIlnHKCNh9L2TOQWdAIwibvs4A7m9f7GnVcyY 4Ia8L8V5cz+kfMmLOjsxbvMz60nheO+IHI6fDzOWA1zXfnBrsMGKPEC6r/YVOZCPNJ32 lBAcTsauvYZe36Av7w2Qs7DnIRWfeNttw4d6NNzoDFTLmJHR/Q347/9B3vGY1IfVPY2a OH/lTqf+OgDeFjaHM5qnn/pYU8uYZsW5i+H1SLp4Tq+bX9gq3zKV+jvdUoXgGrjYM4xD 182GenREilCvKYyFtgADIcbbwexShgTOVZNEJFev2lPDpzqIhLUkOSXBclFwWCZ2GC05 ew== Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2173.outbound.protection.outlook.com [104.47.59.173]) by mx0a-0014ca01.pphosted.com with ESMTP id 353m02v1w7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:18:21 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CZ1QLLcaQkCkXtqnAs8goeD5Rebcwn8cXmCl7WrCnYTzTl7+K6C+xlKwpduEaQJWxG6iZ2mWGmqmyyZWEV3zNKE64KzrDHIiwWNFBu12tIZBu6j88nY5q9XTojBykx3bdEXkitNKc0pF9FCWhWML54OTGTkBt2PlEw5YQokJDNWy8roDHZlpbXoOM22z6ZEMpP1Jw1eBbIjap81TcETtzoxCtpesmDrDCafujyJ8DtiR3u0xavGQSMfE2NoMrLUXuo5KTq+Zs9YqKWZcnT8d615EJly0MBkOVn490+GvP3Rbks6m6wSLPCvdP/KMuTERprsJ/LjOeA7yQN4VYUkXPA== 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-SenderADCheck; bh=zAot8ZKLmBihRtXXOEijPs4fo3Dtmbdp2ADXmAaIpfw=; b=ZrMn29J0h1u77tn0Sy2xLFPcNHgOXEfRw6EakWw7iXsnIChySQXqJNlRgDv+/5bhYGidmASqPZcUvucKrJ6y8XDnscb/t4ExnjryTxIdy8TBzjubVC6oovMFIOEhvJcT0hZnHI4HyB+7tP/fG9sbkHp94JFUvaO/UNv+zlPDZgRf/9d4bmPmFPd9hTXnRMdpdysFb5rV/c00WhdLTymnhuqv1T0tGCn2WCDxQhvxetpdyA18dcMkc6ihtnAXc0TtI+QH6p/XgfT0OZNcZ8ARixYcwWR84oECklffLbwvB34j/q/YuVD3s0FQXZjo7ObIYAgtixOdOANYzCgDdp9uDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 64.207.220.244) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zAot8ZKLmBihRtXXOEijPs4fo3Dtmbdp2ADXmAaIpfw=; b=m2u0nMM4FfM8eLJbkAtk14hvlIHyn7TBB3jsuoPlx3lCQNC0bwLPIL5/3DrMiJG7gj97rLTvBGBUQGsFglgUttjWmDn3hzD24mfEbQiE0ULsZhmhJOd1fPZEVASO3qMEwzU9GE2lhpZmbBgMh6e0/y7QptlygVyxiSa8nHkfhnE= Received: from MWHPR14CA0044.namprd14.prod.outlook.com (2603:10b6:300:12b::30) by BY5PR07MB8102.namprd07.prod.outlook.com (2603:10b6:a03:1dc::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.23; Mon, 30 Nov 2020 06:18:19 +0000 Received: from MW2NAM12FT050.eop-nam12.prod.protection.outlook.com (2603:10b6:300:12b:cafe::d1) by MWHPR14CA0044.outlook.office365.com (2603:10b6:300:12b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Mon, 30 Nov 2020 06:18:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 64.207.220.244) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 64.207.220.244 as permitted sender) receiver=protection.outlook.com; client-ip=64.207.220.244; helo=wcmailrelayl01.cadence.com; Received: from wcmailrelayl01.cadence.com (64.207.220.244) by MW2NAM12FT050.mail.protection.outlook.com (10.13.180.241) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.11 via Frontend Transport; Mon, 30 Nov 2020 06:18:16 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by wcmailrelayl01.cadence.com (8.14.7/8.14.4) with ESMTP id 0AU6IDo7027742 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=OK); Sun, 29 Nov 2020 22:18:15 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:18:13 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:18:13 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6IDNS003883; Mon, 30 Nov 2020 07:18:13 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6IDoA003882; Mon, 30 Nov 2020 07:18:13 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 3/7] i3c: master: add i3c_secondary_master_register Date: Mon, 30 Nov 2020 07:18:10 +0100 Message-ID: <1606717090-3847-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a907ae73-2f2f-40cb-afa5-08d894f7b9c9 X-MS-TrafficTypeDiagnostic: BY5PR07MB8102: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pIPXVFCNd1J/z38HrPnTkssnQHLct2X9BA0SOoneWObRJMJonaZ9gQOUV25iuaLQc2iEJIeS042M69wLg1oT5zW1n3OWvlu2KnJKekN+R3MyfDydhO5JCkmi+E4uAGMhqTVzuLt1EuwNW+MO/WK/c40DQbxI6Hn3F4Bb7GOicr4zbY+gnLINGjL5wiLcvly9r8RbJ49SX7vOHSdoRMvObo2BSmT9+KURlFrpXtmPkhx0ShiGwOSMP/TnKRIgKFA5t1NuJkowmz4RJVn5piQ3tM8LpOoPtETwOrZnNEeNofqIeKHHvesHutL2C3VfsaSx+ms20YJZIFpix47mqezKrwKEjFSRLkJ7D9lYYydekLmJF+WeJ+hiXl+R13wMm5RGk8KUo96KyQsv5BFF6syqIDNTTVM8N9EMRESHH9m/ZSE= X-Forefront-Antispam-Report: CIP:64.207.220.244; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:wcmailrelayl01.cadence.com; PTR:ErrorRetry; CAT:NONE; SFS:(4636009)(376002)(136003)(39860400002)(396003)(346002)(36092001)(46966005)(81166007)(26005)(356005)(186003)(70586007)(86362001)(2616005)(4326008)(107886003)(70206006)(82740400003)(426003)(82310400003)(47076004)(83380400001)(316002)(336012)(8676002)(42186006)(54906003)(36756003)(5660300002)(110136005)(8936002)(478600001)(2906002); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:18:16.7221 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a907ae73-2f2f-40cb-afa5-08d894f7b9c9 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[64.207.220.244]; Helo=[wcmailrelayl01.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM12FT050.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR07MB8102 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 spamscore=0 suspectscore=2 mlxlogscore=999 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_011825_235761_620EFF4B X-CRM114-Status: GOOD ( 26.22 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org add i3c_secondary_master_register which is used to register secondary masters. Signed-off-by: Parshuram Thombare --- drivers/i3c/master.c | 154 +++++++++++++++++++++++++++++++++++++++++++- include/linux/i3c/master.h | 3 + 2 files changed, 156 insertions(+), 1 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 56e8fe4..af0630a 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1797,6 +1797,90 @@ static int i3c_primary_master_bus_init(struct i3c_master_controller *master) return ret; } +/** + * i3c_secondary_master_bus_init() - initialize an I3C bus for secondary + * master + * @master: secondary master initializing the bus + * + * This function does + * + * 1. Attach I2C devs to the master + * + * 2. Call &i3c_master_controller_ops->bus_init() method to initialize + * the master controller. That's usually where the bus mode is selected + * (pure bus or mixed fast/slow bus) + * + * Once this is done, I2C devices should be usable. + * + * Return: a 0 in case of success, an negative error code otherwise. + */ +static int i3c_secondary_master_bus_init(struct i3c_master_controller *master) +{ + enum i3c_addr_slot_status status; + struct i2c_dev_boardinfo *i2cboardinfo; + struct i2c_dev_desc *i2cdev; + int ret; + + /* + * First attach all devices with static definitions provided by the + * FW. + */ + list_for_each_entry(i2cboardinfo, &master->boardinfo.i2c, node) { + status = i3c_bus_get_addr_slot_status(&master->bus, + i2cboardinfo->base.addr); + if (status != I3C_ADDR_SLOT_FREE) { + ret = -EBUSY; + goto err_detach_devs; + } + + i3c_bus_set_addr_slot_status(&master->bus, + i2cboardinfo->base.addr, + I3C_ADDR_SLOT_I2C_DEV); + + i2cdev = i3c_master_alloc_i2c_dev(master, i2cboardinfo); + if (IS_ERR(i2cdev)) { + ret = PTR_ERR(i2cdev); + goto err_detach_devs; + } + + ret = i3c_master_attach_i2c_dev(master, i2cdev); + if (ret) { + i3c_master_free_i2c_dev(i2cdev); + goto err_detach_devs; + } + } + + /* + * Now execute the controller specific ->bus_init() routine, which + * might configure its internal logic to match the bus limitations. + */ + ret = master->ops->bus_init(master); + if (ret) + goto err_detach_devs; + + /* + * The master device should have been instantiated in ->bus_init(), + * complain if this was not the case. + */ + if (!master->this) { + dev_err(&master->dev, + "master_set_info() was not called in ->bus_init()\n"); + ret = -EINVAL; + goto err_bus_cleanup; + } + + return 0; + +err_bus_cleanup: + if (master->ops->bus_cleanup) + master->ops->bus_cleanup(master); + +err_detach_devs: + i3c_master_detach_free_devs(master); + + return ret; +} + static void i3c_master_bus_cleanup(struct i3c_master_controller *master) { if (master->ops->bus_cleanup) @@ -2514,7 +2598,10 @@ static int i3c_master_init(struct i3c_master_controller *master, goto err_put_dev; } - ret = i3c_primary_master_bus_init(master); + if (secondary) + ret = i3c_secondary_master_bus_init(master); + else + ret = i3c_primary_master_bus_init(master); if (ret) goto err_destroy_wq; @@ -2595,6 +2682,71 @@ int i3c_primary_master_register(struct i3c_master_controller *master, EXPORT_SYMBOL_GPL(i3c_primary_master_register); /** + * i3c_secondary_master_register() - register an I3C secondary master + * @master: master used to send frames on the bus + * @parent: the parent device (the one that provides this I3C master + * controller) + * @ops: the master controller operations + * + * This function does minimal required initialization for secondary + * master, rest functionality like creating and registering I2C + * and I3C devices is done in defslvs processing. + * + * i3c_secondary_master_register() does following things - + * - creates and initializes the I3C bus + * - populates the bus with static I2C devs if @parent->of_node is not + * NULL + * initialization + * - allocate memory for defslvs_data.devs, which is used to receive + * defslvs list + * - create I3C device representing this master + * - registers the I2C adapter and all I2C devices + * + * Return: 0 in case of success, a negative error code otherwise. + */ +int i3c_secondary_master_register(struct i3c_master_controller *master, + struct device *parent, + const struct i3c_master_controller_ops *ops) +{ + int ret; + + ret = i3c_master_init(master, parent, ops, true); + if (ret) + return ret; + + ret = device_add(&master->dev); + if (ret) + goto err_cleanup_bus; + + /* + * Expose our I3C bus as an I2C adapter so that I2C devices are exposed + * through the I2C subsystem. + */ + ret = i3c_master_i2c_adapter_init(master); + if (ret) + goto err_del_dev; + + /* + * We're done initializing the bus and the controller, we can now + * register I3C devices from defslvs list. + */ + master->init_done = true; + + return 0; + +err_del_dev: + device_del(&master->dev); + +err_cleanup_bus: + i3c_master_bus_cleanup(master); + + put_device(&master->dev); + + return ret; +} +EXPORT_SYMBOL_GPL(i3c_secondary_master_register); + +/** * i3c_master_unregister() - unregister an I3C master * @master: master used to send frames on the bus * diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index e543f68..e186d53 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -541,6 +541,9 @@ int i3c_master_set_info(struct i3c_master_controller *master, int i3c_primary_master_register(struct i3c_master_controller *master, struct device *parent, const struct i3c_master_controller_ops *ops); +int i3c_secondary_master_register(struct i3c_master_controller *master, + struct device *parent, + const struct i3c_master_controller_ops *ops); int i3c_master_unregister(struct i3c_master_controller *master); /** From patchwork Mon Nov 30 06:18:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939741 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 45388C5519F for ; Mon, 30 Nov 2020 06:19:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A29AA20757 for ; Mon, 30 Nov 2020 06:19:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vnQEN5S7"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="TgLuS+NS"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="hsC8iL3j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A29AA20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Mulq9pJ3kxo2RVYUAyiLCMEQymdLbclIuR54Me40zFE=; b=vnQEN5S7j+bFRCIRqnsIXl7xL 4qST1LN+jZPB5Vymr0/IweBPDDdd+GB07yDaViA3keRJoqkhTOBEKaNGj0MmsUCzdoLYoZh4vaJuT CZg9gq6kJBtcDuh9dcdbIMoh+Udas76wXMEfxAoPEyhl+f59ss6lXbbWeC6+qXJl56WbXcf7GAdtp kdDl9af9UxFhWVkTqthvaGyyzvQe3m+5jIY4RPTulb8DmB/P0XfmuxsnzEyHXHmtklpyP2HK0QS5/ /aj4bjEfkj97KbG3DQYm0y+YiIv+mbzXsvu0pBH3k6IvQlBeZUVBWe1h6lTlQnhxNl8nzb+orKHOV bSUF73wdQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcWa-0008W5-Eg; Mon, 30 Nov 2020 06:19:00 +0000 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193] helo=mx0a-0014ca01.pphosted.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcWX-0008Vm-KV for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:18:58 +0000 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU6AVZG015661; Sun, 29 Nov 2020 22:18:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=K3xuo9c6g9jg2s/GancGklUt4jhLGdxsMbfrj+14mdk=; b=TgLuS+NS8K0Eegm8ujd8fCLMaxsJEqUcdj0/VC9sfArz773KWTgZyvtBea+ujyxksRhs uC2vkyK005Srr8bTZ0YNTd4uu2cUVk4QegQ+zLOI32G0OhunO+7BY1wHUNSCFi96oobl qFNnWYBIKqRlW+xpC/thfl44Q4IrhiyG69VfpbyjEwfTb5oibpJZ0I959Q7bLFj7A7YH IRKX3OkMSLVie4rEKTuT2lQGX4H+KPnvpBfdUoWX5Tti3Yn2PGmSJ+vn2ctQfDR2SlTS OHvMnRE4gYHXs/q9Inz0EP4mBdg+QIkGHA4r3XwpqSkNjyC/p/kEqdDafmZwn6aEtqlU MQ== Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by mx0b-0014ca01.pphosted.com with ESMTP id 353k12m4v7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:18:54 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Saufv8hD2KI6okuk95xZW7dAofp7widQTJ8uccVO+hrtx1F3KoyEUtQDS35290jdKCj05iN4W/eeK+ymzKMyuzH1LMpDSmdD2HPy7hknLonghcL0nMuK3xS9vgriY/SAWLn+xNf2K7qoCG/UQE6fv/Tum2JNOu6ADSKJlCvR/VOgD33NN14lomPfZqoT/zvGtlADYsIs0s3zs5XO/ba79jglwnWzrPRT6FGAh2kx2Gp8zF8OY66OVBU+lwi9Sn+A3hWD2dZXTToWUv9gjAkNNXAGJGcdyynH2xYNMBytGu0PffDZVeqv7NkNHMQC8XClPfdFIyl9vIz5Sgs4tHXQaw== 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-SenderADCheck; bh=K3xuo9c6g9jg2s/GancGklUt4jhLGdxsMbfrj+14mdk=; b=ia5Sg5zzWn++vpl80kude8rSnQ6TC02Yv3BnrfBkgKMAX087GbCiYgmbp7Sn06TsreifXiWlKzoMr10km4fF93t5FlU2JrNyD47sXY3iyFzs9rtfo6jZy9XEDwgi5KWu/2tiscvHTN49MFyy//IsI7inyuwXansvFvzJ2mDavs4TGcsU75z9QRS5M8v/jYUhgJlM2pq04mq5f59E0xudDNLuqssDN6QqfNn8/UlTA8nnqoRe7mkn8gYhw3dp153heXQv7GvWA36JDYSsfO8eQ7Pz1uTFMWbEACvDaBBGgrOCmDqS756CELW2b5sbLbohs5Owi4j+nfOGp4zi7UpZkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 199.43.4.23) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K3xuo9c6g9jg2s/GancGklUt4jhLGdxsMbfrj+14mdk=; b=hsC8iL3jz6blfSlHK2G3k4KAAT55hKZB9ZR9XtElfU12Cum6t6MwB0eEWItf5GDKL56hIoen2fhIPilUJhcblQwrHcDAIPrs1tB5LSdkuMCvXlW+Js7Kk4U28b+AfEKO1C8NAQiJ7iUepmSDOTDikGPwTo5YLAs9N2agz5gVliU= Received: from MW2PR2101CA0004.namprd21.prod.outlook.com (2603:10b6:302:1::17) by MN2PR07MB6207.namprd07.prod.outlook.com (2603:10b6:208:110::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.24; Mon, 30 Nov 2020 06:18:45 +0000 Received: from MW2NAM12FT028.eop-nam12.prod.protection.outlook.com (2603:10b6:302:1:cafe::47) by MW2PR2101CA0004.outlook.office365.com (2603:10b6:302:1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.2 via Frontend Transport; Mon, 30 Nov 2020 06:18:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 199.43.4.23) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 199.43.4.23 as permitted sender) receiver=protection.outlook.com; client-ip=199.43.4.23; helo=rmmaillnx1.cadence.com; Received: from rmmaillnx1.cadence.com (199.43.4.23) by MW2NAM12FT028.mail.protection.outlook.com (10.13.181.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.11 via Frontend Transport; Mon, 30 Nov 2020 06:18:45 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by rmmaillnx1.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6IgDT000325 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Mon, 30 Nov 2020 01:18:43 -0500 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:18:42 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:18:42 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6IgpG004094; Mon, 30 Nov 2020 07:18:42 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6IgQM004093; Mon, 30 Nov 2020 07:18:42 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 4/7] i3c: master: add mastership handover support Date: Mon, 30 Nov 2020 07:18:39 +0100 Message-ID: <1606717119-4058-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 049be4b2-1383-45b8-1b0a-08d894f7cad8 X-MS-TrafficTypeDiagnostic: MN2PR07MB6207: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d2R2ui0oFSs/bVhlpvebeS+F/PB2EAGIWZa17d+jUkNZWnkHizl+0juTO8HiZLzD1sgFP99RTwtKPUfNAV4EGqaNfxq6cfnyE4DSb07S1N604gKBLlQr9PxT92/hsukWWPhyHM4mn/2lWeacG2hycTqu814gdHsxr1jGlsPH77tgbesuo/JvLs8bOIbrsNNsYXOJHGX8hLSkWZaBSTV5Kvr2QIYtHN7Nos60BSx7F4MQim09IliEjmuUQp35jq1mB102euKhXj6En71IrbciRXHZBIAUInxOvd2oBKsYwHBs6IngUTDHjy+2t64W7kEGVwhOfC903/fcXa0ijTRPnSGDPSpzhUhx2iSaxkAzX1KUlFhATHgRK38Qn7hZh5y+gJVkxXHpOhBA3parG7040g/PDH7L5lkG1LbvQirJU8Q= X-Forefront-Antispam-Report: CIP:199.43.4.23; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:rmmaillnx1.cadence.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(4636009)(376002)(136003)(396003)(39860400002)(346002)(36092001)(46966005)(82310400003)(8936002)(81166007)(356005)(47076004)(5660300002)(6666004)(26005)(70206006)(83380400001)(2906002)(70586007)(82740400003)(2616005)(110136005)(426003)(54906003)(8676002)(36756003)(316002)(86362001)(36906005)(478600001)(336012)(42186006)(107886003)(4326008)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:18:45.2359 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 049be4b2-1383-45b8-1b0a-08d894f7cad8 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[199.43.4.23]; Helo=[rmmaillnx1.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM12FT028.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR07MB6207 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 bulkscore=0 impostorscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=2 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_011857_786551_33482AD2 X-CRM114-Status: GOOD ( 26.43 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Added mastership acquire and yield functions. Signed-off-by: Parshuram Thombare --- drivers/i3c/master.c | 183 +++++++++++++++++++++++++++++++++++++++++--- include/linux/i3c/master.h | 6 ++ 2 files changed, 177 insertions(+), 12 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index af0630a..51ef706 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -44,6 +44,16 @@ static void i3c_bus_maintenance_lock(struct i3c_bus *bus) } /** + * i3c_bus_maintenance_downgrade_lock - Downgrade maintenance lock to + * normaluse lock. + * @bus: I3C bus to take the lock on + */ +static void i3c_bus_maintenance_downgrade_lock(struct i3c_bus *bus) +{ + downgrade_write(&bus->lock); +} + +/** * i3c_bus_maintenance_unlock - Release the bus lock after a maintenance * operation * @bus: I3C bus to release the lock on @@ -451,6 +461,59 @@ static int i3c_bus_init(struct i3c_bus *i3cbus) [I3C_BUS_MODE_MIXED_SLOW] = "mixed-slow", }; +static int i3c_master_enable_mr_events(struct i3c_master_controller *master) +{ + int ret; + + master->ops->enable_mr_events(master); + i3c_bus_maintenance_lock(&master->bus); + ret = i3c_master_enec_locked(master, I3C_BROADCAST_ADDR, + I3C_CCC_EVENT_MR | I3C_CCC_EVENT_HJ); + i3c_bus_maintenance_unlock(&master->bus); + + return ret; +} + +/** + * i3c_master_acquire_bus() - acquire I3C bus mastership + * @m: I3C master object + * + * This function may sleep. + * It is expected to be called with normaluse_lock. + */ +static int i3c_master_acquire_bus(struct i3c_master_controller *m) +{ + int ret = 0; + + /* + * Request mastership needs maintenance(write) lock. So, to avoid + * deadlock, release normaluse(read) lock, which is expected to be + * held before calling this function. + * normaluse(read) lock is expected to be held before calling + * this function to avoid race with maintenance activities + * like DEFSLVS processing etc + */ + i3c_bus_normaluse_unlock(&m->bus); + i3c_bus_maintenance_lock(&m->bus); + + if (m->this && m->this == m->bus.cur_master) { + i3c_master_disec_locked(m, I3C_BROADCAST_ADDR, + I3C_CCC_EVENT_MR | + I3C_CCC_EVENT_HJ); + goto mr_req_done; + } + + ret = m->ops->request_mastership(m); + if (ret) + goto mr_req_done; + + m->bus.cur_master = m->this; + +mr_req_done: + i3c_bus_maintenance_downgrade_lock(&m->bus); + return ret; +} + static ssize_t mode_show(struct device *dev, struct device_attribute *da, char *buf) @@ -476,11 +539,12 @@ static ssize_t current_master_show(struct device *dev, char *buf) { struct i3c_bus *i3cbus = dev_to_i3cbus(dev); - ssize_t ret; + ssize_t ret = 0; i3c_bus_normaluse_lock(i3cbus); - ret = sprintf(buf, "%d-%llx\n", i3cbus->id, - i3cbus->cur_master->info.pid); + if (i3cbus->cur_master) + ret = sprintf(buf, "%d-%llx\n", i3cbus->id, + i3cbus->cur_master->info.pid); i3c_bus_normaluse_unlock(i3cbus); return ret; @@ -690,6 +754,33 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master, return 0; } +static int i3c_master_get_accmst_locked(struct i3c_master_controller *master, + u8 addr) +{ + struct i3c_ccc_getaccmst *accmst; + struct i3c_ccc_cmd_dest dest; + struct i3c_ccc_cmd cmd; + int ret; + + accmst = i3c_ccc_cmd_dest_init(&dest, addr, sizeof(*accmst)); + if (!accmst) + return -ENOMEM; + + i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETACCMST, &dest, 1); + + ret = i3c_master_send_ccc_cmd_locked(master, &cmd); + if (ret) + goto out; + + if (dest.payload.len != sizeof(*accmst)) + ret = -EIO; + +out: + i3c_ccc_cmd_dest_cleanup(&dest); + + return ret; +} + static struct i2c_dev_desc * i3c_master_find_i2c_dev_by_addr(const struct i3c_master_controller *master, u16 addr) @@ -1582,10 +1673,6 @@ int i3c_master_set_info(struct i3c_master_controller *master, if (!i3c_bus_dev_addr_is_avail(&master->bus, info->dyn_addr)) return -EINVAL; - if (I3C_BCR_DEVICE_ROLE(info->bcr) == I3C_BCR_I3C_MASTER && - master->secondary) - return -EINVAL; - if (master->this) return -EINVAL; @@ -1594,7 +1681,9 @@ int i3c_master_set_info(struct i3c_master_controller *master, return PTR_ERR(i3cdev); master->this = i3cdev; - master->bus.cur_master = master->this; + + if (!master->secondary) + master->bus.cur_master = master->this; ret = i3c_master_attach_i3c_dev(master, i3cdev); if (ret) @@ -1637,6 +1726,74 @@ static void i3c_master_detach_free_devs(struct i3c_master_controller *master) } /** + * i3c_master_yield_bus() - yield I3C bus mastership + * @m: I3C master object + * @sec_mst_dyn_addr: address of device requesting mastership + * + * This function may sleep. + * It is expected to be called with normaluse_lock. + */ +void +i3c_master_yield_bus(struct i3c_master_controller *m, u8 sec_mst_dyn_addr) +{ + struct i3c_dev_desc *i3cdev; + bool dev_found = false; + int ret = 0; + + i3c_bus_maintenance_lock(&m->bus); + if (m->this != m->bus.cur_master) + goto mr_yield_done; + + i3c_bus_for_each_i3cdev(&m->bus, i3cdev) { + if (sec_mst_dyn_addr == i3cdev->info.dyn_addr) { + dev_found = true; + break; + } + } + + /* Requesting device not found on i3c list. This should never happen. */ + if (!dev_found) + goto mr_yield_done; + + /* + * Maintenance lock and master check above is used to + * avoid race amongst devices sending MR requests + * at the same time, as soon as ENEC MST is sent by the current + * master. It ensure that only one MR request is processed, + * rest MR requests on losing devices will timeout in wait MR + * DONE state. And next MR requests are blocked due to DISEC MST + * sent by current master in yield operation. + * New master should send ENEC MST once it's work is done. + * maintainanace lock is also needed for i3c_master_get_accmst_locked. + */ + + ret = i3c_master_disec_locked(m, I3C_BROADCAST_ADDR, + I3C_CCC_EVENT_MR | + I3C_CCC_EVENT_HJ); + /* + * Once mastership is given to the new master, it is expected that + * MR is disabled prior to that and new master is responsible to + * enable it by broadcasting ENEC MR when it's work is done. + * If DISEC MR fails and we still go ahead with handover, chances + * are new master will get interrupted by unexpected MR requests. + */ + if (ret) + goto mr_yield_done; + + ret = i3c_master_get_accmst_locked(m, sec_mst_dyn_addr); + if (ret) + goto mr_yield_done; + + m->bus.cur_master = i3cdev; + +mr_yield_done: + i3c_bus_maintenance_unlock(&m->bus); + if (ret) + i3c_master_enable_mr_events(m); +} +EXPORT_SYMBOL_GPL(i3c_master_yield_bus); + +/** * i3c_primary_master_bus_init() - initialize an I3C bus * @master: main master initializing the bus * @@ -2522,6 +2679,9 @@ static int i3c_master_check_ops(const struct i3c_master_controller_ops *ops) !ops->recycle_ibi_slot)) return -EINVAL; + if (ops->request_mastership && !ops->enable_mr_events) + return -EINVAL; + return 0; } @@ -2536,10 +2696,6 @@ static int i3c_master_init(struct i3c_master_controller *master, struct i2c_dev_boardinfo *i2cbi; int ret; - /* We do not support secondary masters yet. */ - if (secondary) - return -ENOTSUPP; - ret = i3c_master_check_ops(ops); if (ret) return ret; @@ -2665,6 +2821,9 @@ int i3c_primary_master_register(struct i3c_master_controller *master, i3c_master_register_new_i3c_devs(master); i3c_bus_normaluse_unlock(&master->bus); + if (ops->request_mastership) + ret = i3c_master_enable_mr_events(master); + return 0; err_del_dev: diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index e186d53..77c0422 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -426,6 +426,8 @@ struct i3c_bus { * for a future IBI * This method is mandatory only if ->request_ibi is not * NULL. + * @request_mastership: send mastership request to the current master + * @enable_mr_events: enable mastership request handling by the controller */ struct i3c_master_controller_ops { int (*bus_init)(struct i3c_master_controller *master); @@ -452,6 +454,8 @@ struct i3c_master_controller_ops { int (*disable_ibi)(struct i3c_dev_desc *dev); void (*recycle_ibi_slot)(struct i3c_dev_desc *dev, struct i3c_ibi_slot *slot); + int (*request_mastership)(struct i3c_master_controller *master); + void (*enable_mr_events)(struct i3c_master_controller *m); }; /** @@ -517,6 +521,8 @@ struct i3c_master_controller { #define i3c_bus_for_each_i3cdev(bus, dev) \ list_for_each_entry(dev, &(bus)->devs.i3c, common.node) +void i3c_master_yield_bus(struct i3c_master_controller *m, + u8 sec_mst_dyn_addr); int i3c_master_do_i2c_xfers(struct i3c_master_controller *master, const struct i2c_msg *xfers, int nxfers); From patchwork Mon Nov 30 06:19:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939743 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 8A865C5519F for ; Mon, 30 Nov 2020 06:19:56 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D19C920757 for ; Mon, 30 Nov 2020 06:19:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QhoS7Jtc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="EZ1uO8XK"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="zgL7QOSH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D19C920757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Im2AhzZE5wvvZBnVb4kkQcV0QfWCvHRMBWhXLh5bzGU=; b=QhoS7JtcAV+X4wec/wEz/sHUC 1IWiwE0JLQC0P4XQerIY6vYb8cPUDs3KagvqXVY1VvBjd9skkLR15fMXQCrBLhONJo78VORGUi0P+ I3tAwXmav+074NL+oX5T8uFoNsFa/WcP7oXF0HawFonEhO0xSsjeIPJ+3TO1q4yJW6xLFahuupVH4 EKT6I+20pnaFcs/MxdZpvFFjhPQGoI0y4f+/YsgfYDHmnD0iyOIWWGPTSjS00mUgg/eFdtmzfLgsm dSpKU4bklkokhhFsUPhmBDpVW8t/XcI1U+6ISH2Wr6t+npdKKH5VlSYuBWxVFc+r68RiDcaEW/nxm RAZ/MzEkA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcXS-00006a-Ve; Mon, 30 Nov 2020 06:19:55 +0000 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcXP-00006B-Tn for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:19:52 +0000 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU684hw014074; Sun, 29 Nov 2020 22:19:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=QVLEsxpNGaMWv/9e6vww9tEBk/03TpXXpSZn2TUCTBo=; b=EZ1uO8XK0xu6/ABhmd5XCr9gpQT3w0QsH37WDPvkG0PgM/BjIE8yx/UP9vFK9k4C/3vs hFygpj4JnmMgq42mzZgNJtDgZ2lRv3koLrqBOIr68hy3ZB+5bOV6CdJftxfJ3IVZLs7t VCYIqNYpmujXMlo7y+HMK8V19TkvpcIyuVnOFm4tVr2rwvkzrEAfa8+KzGlZpizeBPPV /TAs11YEeoB16/XAitAZmQ4DKciUrAkYR+KunZ9IPc4KY0B6zJaX3h6mHM6VGrcZM34v /Rfp9bWSD0Mf6wcBb+fH8QVEFuPtzs4Lpk7xDQBfqd0tw+chYZpWTsevg52dyF6vcPy8 6g== Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2106.outbound.protection.outlook.com [104.47.58.106]) by mx0a-0014ca01.pphosted.com with ESMTP id 353m02v205-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:19:48 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQg5TNFuE8oHnFAU5kAxzaSEo6y1MgHdMH3qWIwtfBagkvftuHjUAUgsyObYULLyg19xxctry1S5kMzNEjCz+76HuX9u1YuF4FD4l+Pd+RVgwJPJfpGcORxbeQ9dI/bCknlHy6QdHP+7A3U352J2bs442FUEJeIULS4zUYmLMwv205zcHVBTsHFsQoOFE7Ed8a/8LjArkNNiZCvlyGALY57k+J2rcZF8skSDXbCkEQnGnrhsQcQx0gDTmqq76hFr53y/Vp0U10Rr7FcCdF+cmL98i79gT4pc+qcd8dluW4TY5B+EahUBfCqNQK7vfXe/wmoqHxW9lcwYWP8hf/yYwA== 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-SenderADCheck; bh=QVLEsxpNGaMWv/9e6vww9tEBk/03TpXXpSZn2TUCTBo=; b=Fic5rIpVYkB2N5RrGLvoC+12Da7xMGXzTzmf4Weyg2fIp5nFpp7BWv28X1MgdgD9l2SkeQo7xzlLSxIy2mj97EKqv1dChN34lRDZfVMHN3QnUVQ3AsOccQ8aHSO/PEmKax/SKXlg/1oJOAeVpYS4Ado/HpuheNluWVsI4g5/FuLvo7PaYqqpgQKz/oZfDy7bMsRHplU1OhG08HM0fFz1abI2qcE37bixoHJwNh082WX6nPBxcENjhwk97MMXkeAi/Y8te4y2n2o+QmxZVVXudp8Pd6vsrCJeKEQH+P6wjQ6hUnFw60Z9mScFhQ/XH+Ja/ypVBn4ZZfY+uNdhtYrkyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 158.140.1.147) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QVLEsxpNGaMWv/9e6vww9tEBk/03TpXXpSZn2TUCTBo=; b=zgL7QOSHkbtXlx6DXnrgWx+/S6mkq0rBWkXBeebkFoWJ2yKjjBIBiRwHHZ5OIHsOVYI7YxzcX75McnUWXkbX7l62wmlodB2EXNZBWKIYGGkCKhdqvaqIE7sVWh+DK8Z0G/ZjfqOExNQX/eTwpPiJQpyhe/3qixF+HnQitEiqZ14= Received: from BN3PR05CA0028.namprd05.prod.outlook.com (2603:10b6:400::38) by MN2PR07MB7101.namprd07.prod.outlook.com (2603:10b6:208:112::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.24; Mon, 30 Nov 2020 06:19:45 +0000 Received: from BN8NAM12FT007.eop-nam12.prod.protection.outlook.com (2603:10b6:400:0:cafe::3) by BN3PR05CA0028.outlook.office365.com (2603:10b6:400::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.7 via Frontend Transport; Mon, 30 Nov 2020 06:19:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 158.140.1.147) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 158.140.1.147 as permitted sender) receiver=protection.outlook.com; client-ip=158.140.1.147; helo=sjmaillnx1.cadence.com; Received: from sjmaillnx1.cadence.com (158.140.1.147) by BN8NAM12FT007.mail.protection.outlook.com (10.13.182.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.11 via Frontend Transport; Mon, 30 Nov 2020 06:19:43 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx1.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6Jf72016587 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Sun, 29 Nov 2020 22:19:42 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:19:40 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:19:40 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6JeMH004188; Mon, 30 Nov 2020 07:19:40 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6Je1q004187; Mon, 30 Nov 2020 07:19:40 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 5/7] i3c: master: add defslvs processing Date: Mon, 30 Nov 2020 07:19:38 +0100 Message-ID: <1606717178-4151-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e72defc-88bd-40a2-b50c-08d894f7edc6 X-MS-TrafficTypeDiagnostic: MN2PR07MB7101: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wj2LI+u6m5TLMJCQl6WXtQoCsfsCXa2Yi304Q61sdz9elLxECsLzAgY6hjnNItUqYgSA5sQqtVv55QhNZ1pjEVs14Leotl03LlxmItPtQM7e4AKMaaIIbgtJQWqHGO4/YiywYDnEvKlUFYFF/9gH79An6JMcO3H1e6KXs4WYNo93vU6y6eUJPNWDvA7Sinmxrcv/Z/DWvuSRL0zEWFIxGc9uKd4QnKH59wmTboome4Uus3CJA+ZeP0Swp5veVKIyv7VRI0hzTW1Fuobun1DGSzQmhhupvgw60odK5cqTd4VA48WRICJ8kLYere1MQgXhWMoaNljqmNBlK8iuB9VXdoex8HPPyyk4EdV2q0lTbg8F2UixviULrTdnO1DbYHm7A+V5WTrmWGnLCwJ4JLdXf80oGEAr8Z+EAs0x51zTjlA= X-Forefront-Antispam-Report: CIP:158.140.1.147; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:sjmaillnx1.cadence.com; PTR:unknown.Cadence.COM; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(396003)(376002)(36092001)(46966005)(82740400003)(82310400003)(8936002)(36756003)(107886003)(70206006)(2906002)(8676002)(356005)(5660300002)(70586007)(86362001)(47076004)(426003)(7636003)(110136005)(186003)(54906003)(2616005)(36906005)(26005)(42186006)(83380400001)(336012)(316002)(478600001)(4326008); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:19:43.8631 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0e72defc-88bd-40a2-b50c-08d894f7edc6 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[158.140.1.147]; Helo=[sjmaillnx1.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT007.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR07MB7101 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_011952_172495_D6933470 X-CRM114-Status: GOOD ( 23.78 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Added defslvs processing code to the I3C master subsystem. Signed-off-by: Parshuram Thombare --- drivers/i3c/master.c | 68 ++++++++++++++++++++++++++++++++++++++++++- include/linux/i3c/master.h | 7 ++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 51ef706..c01ba00 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2172,7 +2172,7 @@ int i3c_master_add_i3c_dev_locked(struct i3c_master_controller *master, else expected_dyn_addr = newdev->info.dyn_addr; - if (newdev->info.dyn_addr != expected_dyn_addr) { + if (!master->secondary && newdev->info.dyn_addr != expected_dyn_addr) { /* * Try to apply the expected dynamic address. If it fails, keep * the address assigned by the master. @@ -2867,12 +2867,20 @@ int i3c_secondary_master_register(struct i3c_master_controller *master, struct device *parent, const struct i3c_master_controller_ops *ops) { - int ret; + int ret, sz; ret = i3c_master_init(master, parent, ops, true); if (ret) return ret; + sz = sizeof(struct i3c_ccc_dev_desc) * I3C_BUS_MAX_DEVS; + master->defslvs_data.devs = devm_kzalloc(&master->dev, sz, + GFP_KERNEL); + if (!master->defslvs_data.devs) { + ret = -ENOMEM; + goto err_cleanup_bus; + } + ret = device_add(&master->dev); if (ret) goto err_cleanup_bus; @@ -2905,6 +2913,62 @@ int i3c_secondary_master_register(struct i3c_master_controller *master, } EXPORT_SYMBOL_GPL(i3c_secondary_master_register); +static int +i3c_master_populate_bus(struct i3c_master_controller *master, u8 dyn_addr) +{ + struct i3c_dev_desc *olddev; + struct i3c_ccc_dev_desc *desc; + int ret, slot; + + i3c_bus_for_each_i3cdev(&master->bus, olddev) + i3c_master_put_i3c_addrs(olddev); + + master->this->info.dyn_addr = dyn_addr; + i3c_master_get_i3c_addrs(master->this); + + desc = master->defslvs_data.devs; + for (slot = 1; slot < master->defslvs_data.ndevs; slot++) { + ret = i3c_master_add_i3c_dev_locked(master, + desc[slot].dyn_addr); + if (ret) + break; + } + + return ret; +} + +/** + * i3c_master_process_defslvs() - process I3C device list received in + * DEFSLVS for device plug/unplug and address change. + * @m: I3C master object + * @dyn_addr: Current dynamic address of this device + * + * This function may sleep, so should not be called in the atomic context. + */ +int i3c_master_process_defslvs(struct i3c_master_controller *m, u8 dyn_addr) +{ + int ret; + + i3c_bus_normaluse_lock(&m->bus); + ret = i3c_master_acquire_bus(m); + i3c_bus_normaluse_unlock(&m->bus); + if (ret) + return ret; + + i3c_bus_maintenance_lock(&m->bus); + ret = i3c_master_populate_bus(m, dyn_addr); + i3c_bus_maintenance_unlock(&m->bus); + if (!ret) { + i3c_bus_normaluse_lock(&m->bus); + i3c_master_register_new_i3c_devs(m); + i3c_bus_normaluse_unlock(&m->bus); + } + i3c_master_enable_mr_events(m); + + return ret; +} +EXPORT_SYMBOL_GPL(i3c_master_process_defslvs); + /** * i3c_master_unregister() - unregister an I3C master * @master: master used to send frames on the bus diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index 77c0422..835f823 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -478,6 +478,8 @@ struct i3c_master_controller_ops { * in a thread context. Typical examples are Hot Join processing which * requires taking the bus lock in maintenance, which in turn, can only * be done from a sleep-able context + * @defslvs_data: list used to pass i3c device list received in DEFSLVS message, + * from DEFSLVS controller driver to I3C core * * A &struct i3c_master_controller has to be registered to the I3C subsystem * through i3c_master_register(). None of &struct i3c_master_controller fields @@ -497,6 +499,10 @@ struct i3c_master_controller { } boardinfo; struct i3c_bus bus; struct workqueue_struct *wq; + struct { + u32 ndevs; + struct i3c_ccc_dev_desc *devs; + } defslvs_data; }; /** @@ -523,6 +529,7 @@ struct i3c_master_controller { void i3c_master_yield_bus(struct i3c_master_controller *m, u8 sec_mst_dyn_addr); +int i3c_master_process_defslvs(struct i3c_master_controller *m, u8 dyn_addr); int i3c_master_do_i2c_xfers(struct i3c_master_controller *master, const struct i2c_msg *xfers, int nxfers); From patchwork Mon Nov 30 06:20:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939745 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=-18.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 B76F4C5519F for ; Mon, 30 Nov 2020 06:20:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2329620757 for ; Mon, 30 Nov 2020 06:20:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uemUgrk5"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="DwCaWpGP"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="jV7SY4Mt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2329620757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7Oe+WF7N3V7Vc1d7oKm6OToLwDW/IcPzi+a8+2Pqmis=; b=uemUgrk5d7VsS+zD6VH/YeLoQ SpCwYBY1SF8MuI4821kPKDTxd7dbWcdy9pcg7AJSFZhpSoiBvah1LQsVwmlJzPwgjdAD2YRAgfycU Yn7jDKKIARmb1IJjShdjGxUKXEy1QRc1Ivdk4u2pLjn638+oMDBpmYTNpht8cnXgOKzGnHIrtqFRj n2+Isaxg4HtuiMLSKdUbyqQcE1opcX/11v8Q2dPpN5KydUJG5MS8ggd1F7D9NmiGFKBrPqz5XOEAv JCbJ18P2iLfKVzhW30jAtpwqs5eIsBSG4syxJ9YRwcUKid6T8A8vwFxyoXPO92j12iPHSpksUA8U4 BpZwH7R4g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcXo-00008S-B9; Mon, 30 Nov 2020 06:20:16 +0000 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcXm-00007m-Ol for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:20:15 +0000 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU68bUK014443; Sun, 29 Nov 2020 22:20:11 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=6HLJSNbqupKDA6NkIIamnWz2e6tRBqh6fhldFQb6nC8=; b=DwCaWpGPjnTqi0xheNv9eDcrBKdA65fAPckXHfOaaiLF2yGxkvwMC5iPPgXne4ufVNF2 FxDALQI4L3piNU2EpflkLk4zLMxINWvpJxPIyjZfbaokUSf+ammNX24WI+di0AwxGT3M vpzMh0C/ZZGFh+Jk907GBSGB74RAB36wGYmBQmXQZZl3tYKceJzd9Kb3pBqpm6Wm5kHw HmTYR/k3RMczMwrsAslsEfg/yvJP59YEbk5n6R51iMKKb85ObcTBM4v0T7wr7kiTkdqd nnRzrvUxrvQfzGpaVSFJSICrdvnsIIIrM3Gx3G+jnuAnqWUxjuI9r/9WWb4tH8AjYzDM 7w== Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by mx0a-0014ca01.pphosted.com with ESMTP id 353m02v211-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:20:11 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D8Gmb9W7sRYS0O2oJ4a0hqWxIkr1bgezliuF3DT97SXyrkXZoHH3E8oqHP68WuA3zCkrHNRUAJcNylehKTz8cVzEZ+o9Z0lVZ3cfZx1T5DHFMU0DigFdCU5Dqsu+L3+Vb/GTVl3kSGCg5FKL0PwGPGB1o0ThYUarJaKFEQP+ZZ9pH5yvHM3sgOVSkW8ykR9S6SssRTdFvb7aH9pYUtILEHkNIPTzU+ZZOXpYKnnWiYy9UGi8SA2A5PDmyNkpG6lz9fxSK3Nbd/miZ/zLqRamidWl/3/SHB3yo6/H3gtU6PHrKMprWxbw2wtDjUOme/ibxN4xah5EBW+s01j/bHZL6A== 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-SenderADCheck; bh=6HLJSNbqupKDA6NkIIamnWz2e6tRBqh6fhldFQb6nC8=; b=NoS1MdoBfX2uX8g5E8hzqgSu5A3auRGH8tT6AlS3lLS7c3vnlfxZpJErFt99AoMIRtbViLPeP4i0vpTy2XalOPizwSOGikrx6RkOo9qQZEHZKCSFJrWrZka2hGcW5RNLJmwvD4/c99G4c6/RnTH97CZMDVXpWudsGbxEJCgLLY4vRE00V/yqRZTHBTkRKlOHHnI8jGc0CocZtLtNrP2raJ2yozas+wOGXEzup4pkF6xCD/QLmTQmRgdFrsW7QHhO3p8XNT3/UK8PvIIXARAO55IyRezRkyobU4cTA+WllM1L20ZBWXh3aIctGW/TOPhxqYb+zNodNDFIaMOUBVHSqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 158.140.1.148) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6HLJSNbqupKDA6NkIIamnWz2e6tRBqh6fhldFQb6nC8=; b=jV7SY4MtN2qgnVxJAlPgYU6mf4+rGjePeL6FtyeqLpDvWm1ykmAESZw1P07V4hrK+CardTavbTrWn+NNNX85xxyXXKgolbDbU6+/lKCD5I+ODGSzlARhTBYzEW/fY2YEREU3+f+RZjWU3R0z8/l22VF6tIMhzAr0+fmqXJlQKnI= Received: from CO2PR04CA0135.namprd04.prod.outlook.com (2603:10b6:104::13) by DM6PR07MB4330.namprd07.prod.outlook.com (2603:10b6:5:be::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Mon, 30 Nov 2020 06:20:08 +0000 Received: from MW2NAM12FT056.eop-nam12.prod.protection.outlook.com (2603:10b6:104:0:cafe::d1) by CO2PR04CA0135.outlook.office365.com (2603:10b6:104::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22 via Frontend Transport; Mon, 30 Nov 2020 06:20:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 158.140.1.148) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 158.140.1.148 as permitted sender) receiver=protection.outlook.com; client-ip=158.140.1.148; helo=sjmaillnx2.cadence.com; Received: from sjmaillnx2.cadence.com (158.140.1.148) by MW2NAM12FT056.mail.protection.outlook.com (10.13.181.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.11 via Frontend Transport; Mon, 30 Nov 2020 06:20:07 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6K5Q7006704 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=OK); Sun, 29 Nov 2020 22:20:06 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:20:04 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:20:04 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6K4Zt004243; Mon, 30 Nov 2020 07:20:04 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6K4TE004242; Mon, 30 Nov 2020 07:20:04 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 6/7] i3c: master: sysfs key for acquire bus Date: Mon, 30 Nov 2020 07:20:02 +0100 Message-ID: <1606717202-4206-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 86f731b8-6595-4db2-d39c-08d894f7fbee X-MS-TrafficTypeDiagnostic: DM6PR07MB4330: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:510; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r03Rn3t/hhqEvbcQahm2lIsPu4VtcGXZpUdtdc0BOa6vRqbRGoLYOQGITUADAjEE7TQTi2BQetPLd9Tj+CgPK4Tnsl6IM2nehZre9UuLlSY+Hl7siCRAspszU6DXn3Kq3LCbdAcKkNp/AGclp3iPKaJcdYaW+kaeoEa0pjuVjlAyYNXvee8o4feZmS3RG9K/NZolh+dbzMBAqGPKIItsQ9BzEUD5jqWudCM1CEHAu/m96X5h8QyS6kHUDWIXgb5VwvdI/5uoS4Vq3yE62rRJfNkXxtPpSmv8PAPHmcARIj2ghuy46i2V6jHJZTOZjr4HJ8h4yNUHgfpG5wZTMxJT2IxOtxa1A/UhbA9K3KkPhVdoVnzqu9bG+4k34+UJoXVeSj/5O+xEO2msvN3PzxroJSysO+hW186rQ5G6yjYUKHc= X-Forefront-Antispam-Report: CIP:158.140.1.148; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:sjmaillnx2.cadence.com; PTR:unknown.Cadence.COM; CAT:NONE; SFS:(4636009)(39860400002)(376002)(346002)(396003)(136003)(36092001)(46966005)(336012)(82310400003)(426003)(356005)(186003)(70206006)(70586007)(82740400003)(7636003)(47076004)(83380400001)(478600001)(5660300002)(8676002)(8936002)(86362001)(26005)(2906002)(54906003)(42186006)(110136005)(36906005)(316002)(4326008)(107886003)(2616005)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:20:07.6941 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 86f731b8-6595-4db2-d39c-08d894f7fbee X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[158.140.1.148]; Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: MW2NAM12FT056.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR07MB4330 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=944 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_012014_960466_A922AE24 X-CRM114-Status: GOOD ( 16.77 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Added support to acquire I3C bus through sysfs interface. Signed-off-by: Parshuram Thombare --- drivers/i3c/master.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index c01ba00..beb7495 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -581,6 +581,23 @@ static ssize_t i2c_scl_frequency_show(struct device *dev, } static DEVICE_ATTR_RO(i2c_scl_frequency); +static ssize_t i3c_acquire_bus_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct i3c_master_controller *master = dev_to_i3cmaster(dev); + int ret; + + i3c_bus_normaluse_lock(&master->bus); + ret = i3c_master_acquire_bus(master); + i3c_bus_normaluse_unlock(&master->bus); + if (!ret) + i3c_master_enable_mr_events(master); + + return ret ?: count; +} +static DEVICE_ATTR_WO(i3c_acquire_bus); + static struct attribute *i3c_masterdev_attrs[] = { &dev_attr_mode.attr, &dev_attr_current_master.attr, @@ -591,6 +608,7 @@ static ssize_t i2c_scl_frequency_show(struct device *dev, &dev_attr_pid.attr, &dev_attr_dynamic_address.attr, &dev_attr_hdrcap.attr, + &dev_attr_i3c_acquire_bus.attr, NULL, }; ATTRIBUTE_GROUPS(i3c_masterdev); From patchwork Mon Nov 30 06:20:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Parshuram Raju Thombare X-Patchwork-Id: 11939747 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=-15.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT 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 0BB13C5519F for ; Mon, 30 Nov 2020 06:20:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FA6F20757 for ; Mon, 30 Nov 2020 06:20:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Gm2FGAsL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cadence.com header.i=@cadence.com header.b="XMbCo7mF"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=cadence.com header.i=@cadence.com header.b="XjmcbaIL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5FA6F20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cadence.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=y9zLvbg4kulFiCfO+g6cZ/3Fs76eugmNnzRgyo4poFw=; b=Gm2FGAsLMKOlAYna1BlxFUH9b PVGlGInJqs/YQyyjVFfKa/OdKNQRDmfUgGgSFsUfvLj9atGfVHGEFgIkhS9afm/k+KEFTD8aGGfn+ LmTxekrmQpEz5R2Wf/mBFLzmnFuRZOjgEXZChjylKRznlIkBIdgqmmnrXuxZ8m8fQt/dXr8jnITSB 9QYWA33X0MjmS7Zj7/Vmj+q2nI94xgTM93IJVey3eqBlS14+8uT5FqWsJ9p7Cwwltfb1DBIOOxISy x9guuG0nfE3GixF4I6tu94k+h+AAYoHhp48xAbkPU66KFzuQaULhztIWE0TiGA2syskJsY1J9fsOz tUw82wquA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcYM-00009d-KH; Mon, 30 Nov 2020 06:20:50 +0000 Received: from mx0a-0014ca01.pphosted.com ([208.84.65.235]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kjcYK-000097-KR for linux-i3c@lists.infradead.org; Mon, 30 Nov 2020 06:20:49 +0000 Received: from pps.filterd (m0042385.ppops.net [127.0.0.1]) by mx0a-0014ca01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0AU683wQ014038; Sun, 29 Nov 2020 22:20:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=HZNK9ozdIfNzKt+a1n9uxggTzwzLND7lY4nsDf/icrM=; b=XMbCo7mFdT/hq5w17TpCX338LbosgIzUa27zz9/Mh0Zqh4tTQo5KqtgcdqDovwnNOMNm 8A/voXIHc7HHtUgw2bHZzSCJFw2ZlT9J4gTk4A4wy0GOa8CXPU9ed/LdFPRAaZCK81X0 aGESCrDl+NJzaB4YIW1nqWJZLFEAt1rmt4qFA81058SWV4rKc7KOSMQR+n/LuDVXFT0k uLRpgIMAmnR1gyKQkiku81wDI9drNvW0RR0G1rRt5pBLhkvdfHnHXMsEN/E5o9C+sCTp LL4DndvLsYijQfMpsqQ4bpH7v/E8b7h8OsqH2gBaCCY11tGadb9hdBfpLVLctGUkLVNd 5g== Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by mx0a-0014ca01.pphosted.com with ESMTP id 353m02v21u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2020 22:20:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M63XfRVeH8g/FAdPp8fTqpsiNSjf4Vuj6F1VDaW1yDclwxrjzzcV9WkaDUgv6sQIon/Jzy4BIEE7hR80LV38s8kaOXKI/rORKfA/I3cdbgeuaX0xNRxrGYJIoyTY1MjCzo0xTs8ann/yrqzP9C6/moYBNA2lwb4LbZ27xORg7AD2PJr0ib9X3J5yRrUJkjUn4RURxYLIwdh48d/mQbEtdMbloobrKQNCRefNNVXgo5bkPWOaS21BfoUCqQh6Pl4AqogOEbHCXlyCkOW9ksn5PZnqcAASTOARemvimj16FsynuY5CP6TY+Gj/o7JIHw6F/X0vuWDHseUsG+74H2cWXQ== 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-SenderADCheck; bh=HZNK9ozdIfNzKt+a1n9uxggTzwzLND7lY4nsDf/icrM=; b=jvSnfQnKUX0LAQFA1I1CAn9IQi9s0VTYWCvE4jte693D9h33pGRPzX582ZJXep7oYJwk+t4THTTSjWuX1hGjQwe7+W/eP8U45I4Dr+wFziNpCAUvft+aD7vJx72wU3X4oAfcpf/8BhvD4HePxN2U3BW6XrIyPIDqjsWT+A/vtyhCcEbLRPADgHQS1Ak7gRcTetClXL0U+wmrC88Yjt0KDad3nPvc5vU7hw1dsNTeRZk6sq/xxY7cfU/Ne9LluEHAiWWePK32pFrqVgQHD/aNOtjHiqhIEMHRgkqtFV2l/ex24S1LlNSCJDZeLt44hIIw7lAuDc7gFRpJS7JEinyLHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 64.207.220.244) smtp.rcpttodomain=synopsys.com smtp.mailfrom=cadence.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=cadence.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HZNK9ozdIfNzKt+a1n9uxggTzwzLND7lY4nsDf/icrM=; b=XjmcbaILVTct7rD74d/zuOrePKw3JE4UuZpvvBIhBHb9B43plJAZwJwV4FX5T0L3gAAfMWwbc1M4z8g7HCn3fie1Yer9NwAoLrfTEgPKlnPGEmZZEUcHywPnyWKsFe+8wisyHRIcbOZRlH0Cw561SxrDy8xWbodm9gy7fiytj9g= Received: from BN6PR03CA0014.namprd03.prod.outlook.com (2603:10b6:404:23::24) by BYAPR07MB4277.namprd07.prod.outlook.com (2603:10b6:a02:ca::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.25; Mon, 30 Nov 2020 06:20:41 +0000 Received: from BN8NAM12FT052.eop-nam12.prod.protection.outlook.com (2603:10b6:404:23:cafe::14) by BN6PR03CA0014.outlook.office365.com (2603:10b6:404:23::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.20 via Frontend Transport; Mon, 30 Nov 2020 06:20:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 64.207.220.244) smtp.mailfrom=cadence.com; synopsys.com; dkim=none (message not signed) header.d=none;synopsys.com; dmarc=pass action=none header.from=cadence.com; Received-SPF: Pass (protection.outlook.com: domain of cadence.com designates 64.207.220.244 as permitted sender) receiver=protection.outlook.com; client-ip=64.207.220.244; helo=wcmailrelayl01.cadence.com; Received: from wcmailrelayl01.cadence.com (64.207.220.244) by BN8NAM12FT052.mail.protection.outlook.com (10.13.182.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.11 via Frontend Transport; Mon, 30 Nov 2020 06:20:38 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by wcmailrelayl01.cadence.com (8.14.7/8.14.4) with ESMTP id 0AU6KaJV027887 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=OK); Sun, 29 Nov 2020 22:20:37 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 30 Nov 2020 07:20:35 +0100 Received: from vleu-orange.cadence.com (10.160.88.83) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 30 Nov 2020 07:20:35 +0100 Received: from vleu-orange.cadence.com (localhost.localdomain [127.0.0.1]) by vleu-orange.cadence.com (8.14.4/8.14.4) with ESMTP id 0AU6KZwZ004295; Mon, 30 Nov 2020 07:20:35 +0100 Received: (from pthombar@localhost) by vleu-orange.cadence.com (8.14.4/8.14.4/Submit) id 0AU6KZ6t004294; Mon, 30 Nov 2020 07:20:35 +0100 From: Parshuram Thombare To: , , Subject: [PATCH v10 7/7] i3c: master: mastership handover, defslvs processing in cdns controller driver Date: Mon, 30 Nov 2020 07:20:33 +0100 Message-ID: <1606717233-4259-1-git-send-email-pthombar@cadence.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1606716983-3645-1-git-send-email-pthombar@cadence.com> References: <1606716983-3645-1-git-send-email-pthombar@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bb981c67-1474-455c-1e2b-08d894f80e8c X-MS-TrafficTypeDiagnostic: BYAPR07MB4277: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:167; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fsun7+1+ECuYEzly61PFE6UMwNDnI5qlc0LJIrtBG9/qI5VJrPzO9Jqxs/9K9sYW9DgONqNvz5MWKkQzFPSJ5qvJ3BZUPIyZfxJwWl/jGnALN3DXM8RDIeVY7NVKwnZTDz7v4FAdWRHW/8F8wJ/M8ayMk7kj2NKeaUp9oJcMKanaIwCJnnhavkRvisGLHV3gQMa7skMhOyQ+BzltS3qsYe8C/mISLsunvFZf5F8Md33cOUerJfZ/r57q2gakZCWMFCvJXVljbtkr2gVnd7Ul3hqGWLbta8fmUCv0IsXNkioI79NRpH6+dq6YDfVo6hqi+zjxlV1n9eG1WdobxSo/7t6E258rX6KS1XN9q1MSTi+BkqorwtYTBQraMvqJ2/2FhxPooQQnYLptjVFs+Xjt1nzs/WUPaStc+Z8cbtOHuYs= X-Forefront-Antispam-Report: CIP:64.207.220.244; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:wcmailrelayl01.cadence.com; PTR:ErrorRetry; CAT:NONE; SFS:(4636009)(396003)(346002)(376002)(136003)(39860400002)(36092001)(46966005)(82740400003)(47076004)(2906002)(107886003)(82310400003)(356005)(83380400001)(70206006)(70586007)(30864003)(36756003)(81166007)(5660300002)(110136005)(336012)(426003)(86362001)(478600001)(316002)(42186006)(4326008)(186003)(8676002)(2616005)(8936002)(54906003)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2020 06:20:38.7830 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb981c67-1474-455c-1e2b-08d894f80e8c X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9; Ip=[64.207.220.244]; Helo=[wcmailrelayl01.cadence.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT052.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB4277 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312, 18.0.737 definitions=2020-11-30_01:2020-11-26, 2020-11-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 mlxscore=0 malwarescore=0 bulkscore=0 priorityscore=1501 clxscore=1015 impostorscore=0 adultscore=0 spamscore=0 suspectscore=2 mlxlogscore=999 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011300041 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201130_012048_902580_90EF84E1 X-CRM114-Status: GOOD ( 23.72 ) X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: praneeth@ti.com, mparab@cadence.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org, Parshuram Thombare Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=archiver.kernel.org@lists.infradead.org Added I3C bus mastership handover and DEFSLVS message handling code to Cadence's I3C master controller driver. Signed-off-by: Parshuram Thombare --- drivers/i3c/master/i3c-master-cdns.c | 329 +++++++++++++++++++++++++++++++--- 1 files changed, 306 insertions(+), 23 deletions(-) diff --git a/drivers/i3c/master/i3c-master-cdns.c b/drivers/i3c/master/i3c-master-cdns.c index f1d6d68..ff07862 100644 --- a/drivers/i3c/master/i3c-master-cdns.c +++ b/drivers/i3c/master/i3c-master-cdns.c @@ -160,6 +160,7 @@ #define SLV_IMR 0x48 #define SLV_ICR 0x4c #define SLV_ISR 0x50 +#define SLV_INT_DEFSLVS BIT(21) #define SLV_INT_TM BIT(20) #define SLV_INT_ERROR BIT(19) #define SLV_INT_EVENT_UP BIT(18) @@ -192,7 +193,7 @@ #define SLV_STATUS1_HJ_DIS BIT(18) #define SLV_STATUS1_MR_DIS BIT(17) #define SLV_STATUS1_PROT_ERR BIT(16) -#define SLV_STATUS1_DA(x) (((s) & GENMASK(15, 9)) >> 9) +#define SLV_STATUS1_DA(s) (((s) & GENMASK(15, 9)) >> 9) #define SLV_STATUS1_HAS_DA BIT(8) #define SLV_STATUS1_DDR_RX_FULL BIT(7) #define SLV_STATUS1_DDR_TX_FULL BIT(6) @@ -397,6 +398,9 @@ struct cdns_i3c_data { struct cdns_i3c_master { struct work_struct hj_work; + struct work_struct mr_yield_work; + struct work_struct defslvs_work; + struct completion mr_done; struct i3c_master_controller base; u32 free_rr_slots; unsigned int maxdevs; @@ -416,6 +420,7 @@ struct cdns_i3c_master { struct cdns_i3c_master_caps caps; unsigned long i3c_scl_lim; const struct cdns_i3c_data *devdata; + u8 mr_addr; }; static inline struct cdns_i3c_master * @@ -1182,10 +1187,6 @@ static int cdns_i3c_master_do_daa(struct i3c_master_controller *m) cdns_i3c_master_upd_i3c_scl_lim(master); - /* Unmask Hot-Join and Mastership request interrupts. */ - i3c_master_enec_locked(m, I3C_BROADCAST_ADDR, - I3C_CCC_EVENT_HJ | I3C_CCC_EVENT_MR); - return 0; } @@ -1208,21 +1209,21 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m) struct cdns_i3c_master *master = to_cdns_i3c_master(m); unsigned long pres_step, sysclk_rate, max_i2cfreq; struct i3c_bus *bus = i3c_master_get_bus(m); - u32 ctrl, prescl0, prescl1, pres, low; + u32 ctrl, prescl0, prescl1, pres, low, bus_mode; struct i3c_device_info info = { }; int ret, ncycles; switch (bus->mode) { case I3C_BUS_MODE_PURE: - ctrl = CTRL_PURE_BUS_MODE; + bus_mode = CTRL_PURE_BUS_MODE; break; case I3C_BUS_MODE_MIXED_FAST: - ctrl = CTRL_MIXED_FAST_BUS_MODE; + bus_mode = CTRL_MIXED_FAST_BUS_MODE; break; case I3C_BUS_MODE_MIXED_SLOW: - ctrl = CTRL_MIXED_SLOW_BUS_MODE; + bus_mode = CTRL_MIXED_SLOW_BUS_MODE; break; default: @@ -1253,7 +1254,6 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m) bus->scl_rate.i2c = sysclk_rate / ((pres + 1) * 5); prescl0 |= PRESCL_CTRL0_I2C(pres); - writel(prescl0, master->regs + PRESCL_CTRL0); /* Calculate OD and PP low. */ pres_step = 1000000000 / (bus->scl_rate.i3c * 4); @@ -1261,7 +1261,6 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m) if (ncycles < 0) ncycles = 0; prescl1 = PRESCL_CTRL1_OD_LOW(ncycles); - writel(prescl1, master->regs + PRESCL_CTRL1); /* Get an address for the master. */ ret = i3c_master_get_free_addr(m, 0); @@ -1279,13 +1278,21 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m) if (ret) return ret; + ctrl = readl(master->regs + CTRL); + if (ctrl & CTRL_DEV_EN) + cdns_i3c_master_disable(master); + writel(prescl0, master->regs + PRESCL_CTRL0); + writel(prescl1, master->regs + PRESCL_CTRL1); + ctrl &= ~CTRL_BUS_MODE_MASK; + ctrl |= bus_mode | CTRL_HALT_EN | CTRL_MCS_EN; /* * Enable Hot-Join, and, when a Hot-Join request happens, disable all * events coming from this device. * * We will issue ENTDAA afterwards from the threaded IRQ handler. */ - ctrl |= CTRL_HJ_ACK | CTRL_HJ_DISEC | CTRL_HALT_EN | CTRL_MCS_EN; + if (!m->secondary) + ctrl |= CTRL_HJ_ACK | CTRL_HJ_DISEC; /* * Configure data hold delay based on device-specific data. @@ -1358,6 +1365,7 @@ static void cdns_i3c_master_handle_ibi(struct cdns_i3c_master *master, static void cnds_i3c_master_demux_ibis(struct cdns_i3c_master *master) { + struct i3c_dev_desc *dev; u32 status0; writel(MST_INT_IBIR_THR, master->regs + MST_ICR); @@ -1379,6 +1387,14 @@ static void cnds_i3c_master_demux_ibis(struct cdns_i3c_master *master) case IBIR_TYPE_MR: WARN_ON(IBIR_XFER_BYTES(ibir) || (ibir & IBIR_ERROR)); + if (ibir & IBIR_ACKED) { + dev = master->ibi.slots[IBIR_SLVID(ibir)]; + master->mr_addr = dev->info.dyn_addr; + queue_work(master->base.wq, + &master->mr_yield_work); + } + break; + default: break; } @@ -1390,16 +1406,42 @@ static irqreturn_t cdns_i3c_master_interrupt(int irq, void *data) struct cdns_i3c_master *master = data; u32 status; - status = readl(master->regs + MST_ISR); - if (!(status & readl(master->regs + MST_IMR))) - return IRQ_NONE; + if (master->base.this && + master->base.this == master->base.bus.cur_master) { + status = readl(master->regs + MST_ISR); + if (!(status & readl(master->regs + MST_IMR))) + return IRQ_NONE; + + spin_lock(&master->xferqueue.lock); + cdns_i3c_master_end_xfer_locked(master, status); + spin_unlock(&master->xferqueue.lock); + + if (status & MST_INT_IBIR_THR) + cnds_i3c_master_demux_ibis(master); + + if (status & MST_INT_MR_DONE) { + writel(FLUSH_RX_FIFO | FLUSH_TX_FIFO, + master->regs + FLUSH_CTRL); + writel(MST_INT_MR_DONE, master->regs + MST_ICR); + } + } else { + status = (readl(master->regs + SLV_ISR) & + readl(master->regs + SLV_IMR)); + + if (!status) + return IRQ_NONE; + + if (status & SLV_INT_MR_DONE) { + writel(FLUSH_RX_FIFO | FLUSH_TX_FIFO, + master->regs + FLUSH_CTRL); + complete(&master->mr_done); + } - spin_lock(&master->xferqueue.lock); - cdns_i3c_master_end_xfer_locked(master, status); - spin_unlock(&master->xferqueue.lock); + if (status & SLV_INT_DEFSLVS) + queue_work(master->base.wq, &master->defslvs_work); - if (status & MST_INT_IBIR_THR) - cnds_i3c_master_demux_ibis(master); + writel(status, master->regs + SLV_ICR); + } return IRQ_HANDLED; } @@ -1523,6 +1565,106 @@ static void cdns_i3c_master_recycle_ibi_slot(struct i3c_dev_desc *dev, i3c_generic_ibi_recycle_slot(data->ibi_pool, slot); } +static int cdns_i3c_master_find_ibi_slot(struct cdns_i3c_master *master, + struct i3c_dev_desc *dev, + s16 *slot) +{ + unsigned long flags; + unsigned int i; + int ret = -ENOENT; + + spin_lock_irqsave(&master->ibi.lock, flags); + for (i = 0; i < master->ibi.num_slots; i++) { + if (master->ibi.slots[i] == dev) { + *slot = i; + ret = 0; + break; + } + } + + if (ret) { + for (i = 0; i < master->ibi.num_slots; i++) { + if (!master->ibi.slots[i]) { + master->ibi.slots[i] = dev; + *slot = i; + ret = 0; + break; + } + } + } + spin_unlock_irqrestore(&master->ibi.lock, flags); + + return ret; +} + +static int cdns_i3c_request_mastership(struct i3c_master_controller *m) +{ + struct cdns_i3c_master *master = to_cdns_i3c_master(m); + int status; + + status = readl(master->regs + MST_STATUS0); + if (status & MST_STATUS0_MASTER_MODE) + return 0; + + status = readl(master->regs + SLV_STATUS1); + if (!(status & SLV_STATUS1_HAS_DA)) + return -EACCES; + + if (status & SLV_STATUS1_MR_DIS) + return -EACCES; + + writel(readl(master->regs + CTRL) | CTRL_MST_INIT | CTRL_MST_ACK, + master->regs + CTRL); + + init_completion(&master->mr_done); + if (!wait_for_completion_timeout(&master->mr_done, + msecs_to_jiffies(1000))) + return -ETIMEDOUT; + + return 0; +} + +static void +cdns_i3c_master_enable_mastership_events(struct i3c_master_controller *m) +{ + struct cdns_i3c_master *master = to_cdns_i3c_master(m); + struct cdns_i3c_i2c_dev_data *data; + struct i3c_dev_desc *i3cdev; + unsigned long flags; + u32 sircfg, sirmap; + int ret; + + i3c_bus_for_each_i3cdev(&m->bus, i3cdev) { + if (I3C_BCR_DEVICE_ROLE(i3cdev->info.bcr) != + I3C_BCR_I3C_MASTER || + m->this == i3cdev) + continue; + + data = i3c_dev_get_master_data(i3cdev); + if (!data) + continue; + + ret = cdns_i3c_master_find_ibi_slot(master, i3cdev, &data->ibi); + if (ret) + continue; + + spin_lock_irqsave(&master->ibi.lock, flags); + sirmap = readl(master->regs + SIR_MAP_DEV_REG(data->ibi)); + sirmap &= ~SIR_MAP_DEV_CONF_MASK(data->ibi); + sircfg = SIR_MAP_DEV_ROLE(i3cdev->info.bcr >> 6) | + SIR_MAP_DEV_DA(i3cdev->info.dyn_addr) | + SIR_MAP_DEV_PL(i3cdev->info.max_ibi_len) | + SIR_MAP_DEV_ACK; + + if (i3cdev->info.bcr & I3C_BCR_MAX_DATA_SPEED_LIM) + sircfg |= SIR_MAP_DEV_SLOW; + + sirmap |= SIR_MAP_DEV_CONF(data->ibi, sircfg); + writel(sirmap, master->regs + SIR_MAP_DEV_REG(data->ibi)); + spin_unlock_irqrestore(&master->ibi.lock, flags); + } +} + static const struct i3c_master_controller_ops cdns_i3c_master_ops = { .bus_init = cdns_i3c_master_bus_init, .bus_cleanup = cdns_i3c_master_bus_cleanup, @@ -1541,6 +1683,8 @@ static void cdns_i3c_master_recycle_ibi_slot(struct i3c_dev_desc *dev, .request_ibi = cdns_i3c_master_request_ibi, .free_ibi = cdns_i3c_master_free_ibi, .recycle_ibi_slot = cdns_i3c_master_recycle_ibi_slot, + .request_mastership = cdns_i3c_request_mastership, + .enable_mr_events = cdns_i3c_master_enable_mastership_events, }; static void cdns_i3c_master_hj(struct work_struct *work) @@ -1561,9 +1705,134 @@ static void cdns_i3c_master_hj(struct work_struct *work) { /* sentinel */ }, }; +static void cdns_i3c_master_yield(struct work_struct *work) +{ + struct cdns_i3c_master *master = container_of(work, + struct cdns_i3c_master, + mr_yield_work); + + i3c_master_yield_bus(&master->base, master->mr_addr); +} + +static void cdns_i3c_sec_master_defslvs(struct work_struct *work) +{ + struct cdns_i3c_master *master = container_of(work, + struct cdns_i3c_master, + defslvs_work); + struct i3c_master_controller *m = &master->base; + struct i3c_ccc_dev_desc *desc; + struct cdns_i3c_i2c_dev_data *data; + struct i2c_dev_desc *i2cdev; + u32 devs, val, rr, slot; + u32 r0, r1, r2; + u8 saddr; + + devs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK; + master->free_rr_slots = GENMASK(master->maxdevs, 1) & ~devs; + + /* + * We chose to ignore I2C devices received from + * main master and use I2C device info from boardinfo. + * Since I2C device from boardinfo are already + * registered during bus_init, we just use same slot + * and if any I3C device is received in DEFSLVS in that + * place, just move that I3C device to other free slot. + * If there is no free slot, then such I3C devices + * are ignored. + * Master controller driver can chose how to handle I2C + * devices in DEFSLVS and pass only I3C devices list to + * I3C core DEFSVLS processing to handle hotplug and + * I3C device address changes. + */ + for (slot = 0; slot < master->maxdevs; slot++) { + if (!(devs & BIT(slot))) + continue; + + val = readl(master->regs + DEV_ID_RR0(slot)); + if (!(val & DEV_ID_RR0_IS_I3C)) { + writel(readl(master->regs + DEVS_CTRL) | + DEVS_CTRL_DEV_CLR(slot), + master->regs + DEVS_CTRL); + master->free_rr_slots |= BIT(slot); + } + } + + val = 0; + devs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK; + i3c_bus_for_each_i2cdev(&m->bus, i2cdev) { + data = i2c_dev_get_master_data(i2cdev); + if (devs & BIT(data->id)) { + rr = readl(master->regs + DEV_ID_RR0(data->id)); + saddr = DEV_ID_RR0_GET_DEV_ADDR(rr); + if (saddr != i2cdev->boardinfo->base.addr) { + r0 = readl(master->regs + DEV_ID_RR0(data->id)); + r1 = readl(master->regs + DEV_ID_RR1(data->id)); + r2 = readl(master->regs + DEV_ID_RR2(data->id)); + slot = ffs(master->free_rr_slots) - 1; + if (slot > 0) { + writel(r0, + master->regs + DEV_ID_RR0(slot)); + writel(r1, + master->regs + DEV_ID_RR1(slot)); + writel(r2, + master->regs + DEV_ID_RR2(slot)); + writel(readl(master->regs + DEVS_CTRL) | + DEVS_CTRL_DEV_ACTIVE(slot), + master->regs + DEVS_CTRL); + master->free_rr_slots &= ~BIT(slot); + } + } else { + continue; + } + } + writel(readl(master->regs + DEVS_CTRL) | + DEVS_CTRL_DEV_CLR(data->id), + master->regs + DEVS_CTRL); + writel(readl(master->regs + DEVS_CTRL) | + DEVS_CTRL_DEV_ACTIVE(data->id), + master->regs + DEVS_CTRL); + writel(prepare_rr0_dev_address(i2cdev->boardinfo->base.addr) | + (i2cdev->boardinfo->base.flags & I2C_CLIENT_TEN ? + DEV_ID_RR0_LVR_EXT_ADDR : 0), + master->regs + DEV_ID_RR0(data->id)); + writel(i2cdev->boardinfo->lvr, + master->regs + DEV_ID_RR2(data->id)); + master->free_rr_slots &= ~BIT(data->id); + } + + master->base.defslvs_data.ndevs = 0; + desc = master->base.defslvs_data.devs; + devs = readl(master->regs + DEVS_CTRL) & DEVS_CTRL_DEVS_ACTIVE_MASK; + + for (slot = 0; slot < master->maxdevs; slot++) { + if (!(devs & BIT(slot))) + continue; + + val = readl(master->regs + DEV_ID_RR0(slot)); + if (val & DEV_ID_RR0_IS_I3C) { + memset(desc, 0, sizeof(struct i3c_ccc_dev_desc)); + rr = readl(master->regs + DEV_ID_RR0(slot)); + desc->dyn_addr = DEV_ID_RR0_GET_DEV_ADDR(rr); + rr = readl(master->regs + DEV_ID_RR2(slot)); + desc->dcr = rr; + desc->bcr = rr >> 8; + master->base.defslvs_data.ndevs++; + desc++; + } + } + + val = readl(master->regs + SLV_STATUS1); + if (!(val & SLV_STATUS1_HAS_DA) || + i3c_master_process_defslvs(m, SLV_STATUS1_DA(val))) { + queue_work(master->base.wq, work); + return; + } +} + static int cdns_i3c_master_probe(struct platform_device *pdev) { struct cdns_i3c_master *master; + bool secondary; int ret, irq; u32 val; @@ -1607,6 +1876,7 @@ static int cdns_i3c_master_probe(struct platform_device *pdev) spin_lock_init(&master->xferqueue.lock); INIT_LIST_HEAD(&master->xferqueue.list); + INIT_WORK(&master->mr_yield_work, cdns_i3c_master_yield); INIT_WORK(&master->hj_work, cdns_i3c_master_hj); writel(0xffffffff, master->regs + MST_IDR); writel(0xffffffff, master->regs + SLV_IDR); @@ -1618,6 +1888,7 @@ static int cdns_i3c_master_probe(struct platform_device *pdev) platform_set_drvdata(pdev, master); val = readl(master->regs + CONF_STATUS0); + secondary = (val & CONF_STATUS0_SEC_MASTER) ? true : false; /* Device ID0 is reserved to describe this master. */ master->maxdevs = CONF_STATUS0_DEVS_NUM(val); @@ -1640,12 +1911,24 @@ static int cdns_i3c_master_probe(struct platform_device *pdev) goto err_disable_sysclk; } + if (secondary) + INIT_WORK(&master->defslvs_work, cdns_i3c_sec_master_defslvs); + writel(IBIR_THR(1), master->regs + CMD_IBI_THR_CTRL); - writel(MST_INT_IBIR_THR, master->regs + MST_IER); + writel(MST_INT_IBIR_THR | MST_INT_MR_DONE, master->regs + MST_IER); writel(DEVS_CTRL_DEV_CLR_ALL, master->regs + DEVS_CTRL); - ret = i3c_primary_master_register(&master->base, &pdev->dev, - &cdns_i3c_master_ops); + if (secondary) { + ret = i3c_secondary_master_register(&master->base, &pdev->dev, + &cdns_i3c_master_ops); + if (!ret) + writel(SLV_INT_DEFSLVS | SLV_INT_MR_DONE, + master->regs + SLV_IER); + } else { + ret = i3c_primary_master_register(&master->base, &pdev->dev, + &cdns_i3c_master_ops); + } + if (ret) goto err_disable_sysclk;