Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp741888rdb; Thu, 15 Feb 2024 14:11:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUkylVabhSSYuQTcNoC5XOiA0FbSyX4iag3Qz26fGVNmEF1sKLNoL51+0d7EdETsOi8NxR4ZqccPXnnq6ACzQ6fzUfJ+sGoaZg7/sMY4w== X-Google-Smtp-Source: AGHT+IHimODdyvCWZIrUnh4skIFfRlurx49+blF4qTIXQUiqbghqm4sMa1Z3bbM1hxlW9UlG5q2s X-Received: by 2002:a17:906:3757:b0:a3d:9e6b:2776 with SMTP id e23-20020a170906375700b00a3d9e6b2776mr1984386ejc.17.1708035066482; Thu, 15 Feb 2024 14:11:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708035066; cv=pass; d=google.com; s=arc-20160816; b=Pf6Gy0LjHJScDd0R2QxPadLJGI4p9eKoFRhjhpCN0CL6ZPZ8lvC2/nttGpiqdGMzCT K003n+1zv3AMh4StaKWychEPXOd2GjvWbz0IdPfykFHew71LMcvxkCjd7sOCUxdyEcuk 0vRnY1j6WnNe4aRPF+l9ufEblBasq6gfr7FQuXMjVYDLiynRx5eskXyB6AKDRdp352wp 8BZRXxNb0Cv9VJXlLW0gLHMnTs+N5K2WdT5Ie4JiGDROkkSgbCa2dm3o/IpxH9uDiA3k 2LAarsQx3jqjbecfF5vg77X1tnt18gaNw+vj+FELsZlujtpuHuihZvR3cmWJpfNnzIkO UXNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=bcqBdP1smZ142CVdipR5CsJhhC56BJDRe32BgoHDJb0=; fh=Usz7XAB1EI7Q/DdLEXd449E1MLGpSzqdCCNe5XKh9R0=; b=s4+f4rkChNVdBsj6mNedrd+gCWpZpCeNoAGQhIaXI6MFtf7dEQ1dhqhT2SSx9VL+er Bm81saCteRFl9zbqtRUVjXuSx2MavlFCqlYqL28b6R2qtVc75WZ92cX3nJ/G/a5vLuMr e5Gkp1hX1dDFUVD7jpYbcMF0PiFMONh/lmbw5dNfj8lMjjAaaAyDtP9fY4yIBeBcSZ2L 7W0Oycp5RVpuh8kAQnVqb0Uuj0lkDQ7Otl8sp0nhPw3vlsIYIisnfbQ8tAI5qzLzuXHP WeI1F7WiN/d+qGAVUSqtRLDNUTHm4MXjcQUU5phFS0xi+nNFZPqbtbDt6SWp2hqmSQ7G VkXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=h2dHszgp; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-67743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qw42-20020a1709066a2a00b00a3dced5fecdsi102325ejc.552.2024.02.15.14.11.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 14:11:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=h2dHszgp; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-67743-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67743-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 119DE1F23CC2 for ; Thu, 15 Feb 2024 22:11:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08D29148FED; Thu, 15 Feb 2024 22:08:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="h2dHszgp" Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29257146010; Thu, 15 Feb 2024 22:08:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708034908; cv=none; b=VnSRIQkzVI2b9tKJRkJOHZzypqfQKrzh5CuqTTgbSXgoQS/zprOgLlJisPV05InLFxiL25kkZc6AfPSzYfBBUtJiN2o8EGgXa8nJo8ooNVyTllKPgG9O9/8JqxjnL1D4akyLnF4nwOA5SFJhOcuukjo/UUTOdFeVUNsuYFj+afY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708034908; c=relaxed/simple; bh=rnrW55EMd5WY1H/Lf4PHZ/r+oG7ZBsAslE1xLX4eUiA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j6Uxk/grEN9hMPkOAW26HIuOtE19olK3O+FAPpWPUiNDaUt2voCkbrX4xnhXkbR9wLFSalWnPIuVCIRXmZ8vpxKTqdZ9y8Rbr8GG5WsWT8oleTsPqBWDDuMAIiQDsKb0bOj8ymY1PDyl0C6jw9n6TZCBh/cJjX69kXMav3uFECI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=h2dHszgp; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41FM0XBk017924; Thu, 15 Feb 2024 22:08:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=bcqBdP1smZ142CVdipR5CsJhhC56BJDRe32BgoHDJb0=; b=h2dHszgpB5H1g7lkUbxqPswzrsfW/vrwIFlDBpbZOdP1e5+wEmpb0kLkSkznvQg4lcDo bARFQ/4+kBrvJurOt6kKivwXjk3z24HANZcau7gRQlB0QdSb4QWQFMB77+VG5cwEuHEg Iqc0HdLlT87yMJU7maCiSr7GfnLf+sH/rOxZ05mqNT7XnNza5w7Zsho/6PK1Qe8OXQ/G uv5gJYLreAS5A6+RwBuWHTg2pGsXOHvLcnp3UJs6/oCSl/Q2toITOPwGji+VJIEr4B9r qPcYpuzcsGV5Ier0CVL5htWPaRESfQ6WhXgViiY8YsNudrH39tX4j3UY9Y/1KJlu8VZS nA== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3w9u1bg69b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 22:08:10 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41FJANdP004251; Thu, 15 Feb 2024 22:08:10 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3w6kv0qtmh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Feb 2024 22:08:10 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41FM87kN9306826 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Feb 2024 22:08:09 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D031958072; Thu, 15 Feb 2024 22:08:05 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8570558086; Thu, 15 Feb 2024 22:08:05 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.14.18]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 15 Feb 2024 22:08:05 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-clk@vger.kernel.org, devicetree@vger.kernel.org, andi.shyti@kernel.org, eajames@linux.ibm.com, alistair@popple.id.au, joel@jms.id.au, jk@ozlabs.org, sboyd@kernel.org, mturquette@baylibre.com, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Subject: [PATCH 11/33] fsi: core: Add slave spinlock Date: Thu, 15 Feb 2024 16:07:37 -0600 Message-Id: <20240215220759.976998-12-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240215220759.976998-1-eajames@linux.ibm.com> References: <20240215220759.976998-1-eajames@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 1NXmfBBLW8NuuHvZgD0892lFSsN0VJSh X-Proofpoint-ORIG-GUID: 1NXmfBBLW8NuuHvZgD0892lFSsN0VJSh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-15_20,2024-02-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402150171 FSI slave operations were not locked, meaning that during slave error recovery operations, other slave accesses may take place, resulting in incorrect recovery and additional errors. Make the slave access and error recovery atomic with a spinlock. Don't use a mutex for future interrupt handling support. Signed-off-by: Eddie James --- drivers/fsi/fsi-core.c | 7 +++++++ drivers/fsi/fsi-slave.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/fsi/fsi-core.c b/drivers/fsi/fsi-core.c index e6ed2d0773b6..eb15e5f5a2ee 100644 --- a/drivers/fsi/fsi-core.c +++ b/drivers/fsi/fsi-core.c @@ -304,6 +304,7 @@ static int fsi_slave_handle_error(struct fsi_slave *slave, bool write, int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, void *val, size_t size) { + unsigned long flags; uint8_t id = slave->id; int rc, err_rc, i; @@ -311,6 +312,7 @@ int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, if (rc) return rc; + spin_lock_irqsave(&slave->lock, flags); for (i = 0; i < slave_retries; i++) { rc = fsi_master_read(slave->master, slave->link, id, addr, val, size); @@ -321,6 +323,7 @@ int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, if (err_rc) break; } + spin_unlock_irqrestore(&slave->lock, flags); return rc; } @@ -329,6 +332,7 @@ EXPORT_SYMBOL_GPL(fsi_slave_read); int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, const void *val, size_t size) { + unsigned long flags; uint8_t id = slave->id; int rc, err_rc, i; @@ -336,6 +340,7 @@ int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, if (rc) return rc; + spin_lock_irqsave(&slave->lock, flags); for (i = 0; i < slave_retries; i++) { rc = fsi_master_write(slave->master, slave->link, id, addr, val, size); @@ -346,6 +351,7 @@ int fsi_slave_write(struct fsi_slave *slave, uint32_t addr, if (err_rc) break; } + spin_unlock_irqrestore(&slave->lock, flags); return rc; } @@ -1005,6 +1011,7 @@ static int fsi_slave_init(struct fsi_master *master, int link, uint8_t id) if (!slave) return -ENOMEM; + spin_lock_init(&slave->lock); dev_set_name(&slave->dev, "slave@%02x:%02x", link, id); slave->dev.type = &cfam_type; slave->dev.parent = &master->dev; diff --git a/drivers/fsi/fsi-slave.h b/drivers/fsi/fsi-slave.h index 42af2fae0329..6f8fb97023fb 100644 --- a/drivers/fsi/fsi-slave.h +++ b/drivers/fsi/fsi-slave.h @@ -6,6 +6,7 @@ #include #include +#include #define FSI_SLAVE_BASE 0x800 @@ -100,6 +101,7 @@ struct fsi_slave { struct device dev; struct fsi_master *master; struct cdev cdev; + spinlock_t lock; /* atomic access and error recovery */ int cdev_idx; int id; /* FSI address */ int link; /* FSI link# */ -- 2.39.3