Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp568462lqr; Wed, 5 Jun 2024 14:24:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWZ32rkuOCDBdvEt7YEWAQ6KP9DkSUZGZJhOyMOaB4r+hh0CeY9J0rGi/VIf9O1St4RFj8lnK7A9Q1ax8RTD1gAEzGNaIrxM5D/IkKMaA== X-Google-Smtp-Source: AGHT+IF6sMg1xbd1flC9EmS/ZjMOutnBxEtwsUQxYU0wAmy2eA+NyGADt2nsepevPGZadT2zeKUq X-Received: by 2002:a05:622a:20d:b0:43a:bda4:dd62 with SMTP id d75a77b69052e-4402b5f6ac0mr45854621cf.8.1717622646206; Wed, 05 Jun 2024 14:24:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717622646; cv=pass; d=google.com; s=arc-20160816; b=meWmrz0IrPYc9gQiCS+Owt2dT6Kkj0UOzjsnTFZtAX/cA4vbLj06Q0GsxYcD9Ac5nN KnnoQpCqKzziAorCgceQBl59YITrTt6KdlL54huR3sxH+N65oRcqQbf0UycmZzonscC+ UWobeKkoHTXWtZqcY+VQQhggaIAHOGek3D6cB+o4VkLnlbqUPzoMkPtBH4cXxbM78trY REAR7FE7PtbDBKk+wyK5ME7G8gD8I+VTtVcQjBlIxuMZY6cx/P5crx3fER9ORrpvnsf9 +SKiasdEPR1lMkRijD8mu4Qba3MX8MO4CHbwet4SYNv/ZWpzMhq0MnG0e3BrjWR4JFzw nOPw== 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=Y98dRxrLBHldvjnywSLtVO9jA7MBr6bUSzYUwxA+r8w=; fh=F5i+rNW4hjf57QJHDx14Nq4Eso4Z4OyY/LhC2i40VT4=; b=y5P9SWNOVUgAeObrZQw5KctHpjjuUuv43nXnaCiboCMxlnTgN+UfKtsQzb+tlnDspe 6jggu8yUjZcBhQjLWLwqhVS0gcm1/Nr4DOBhqzEHJ+pVuBd1JoxhEt/S8TeU4QgXZcsT 2a/O44eu+az+LL02KUK3yJWY2f5PXfbachdMw7TDpmG0E772mYFRsJDCAm/VHGUGynfz x7f412AxCokoaBA+QHGaqK4cZsMg80+f/s5tn5NKK5lwxw9+A2fYmBXLHzxR7QI7zIdk DM+hq3GdDyRF5UQqub3NnaCAu1QcG6D3DWxjovBeRjs5Gz8cflcB73UyLrzVtYMoZCzT xhLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lY3oaZv6; 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-203253-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203253-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-4401a691af8si10153221cf.762.2024.06.05.14.24.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-203253-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=lY3oaZv6; 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-203253-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-203253-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D96DA1C21C1A for ; Wed, 5 Jun 2024 21:24:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF25416078F; Wed, 5 Jun 2024 21:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="lY3oaZv6" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 3BEA11586D7; Wed, 5 Jun 2024 21:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717622617; cv=none; b=DiK5HqZfyooA6JDu9soLOl8DOx/or1BUEjtD2Di++cUB3TvY5TitTDVI41KA85ZGa19UcEugbAWLBWRM5MD6wNObVJUHHEc6jznVDJ2ibjUBe/m7t1073WVygKJSoPV6LLtY8DY4Yd3NLueXBLvt6L/RH/LESW+AOc5ead7maBA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717622617; c=relaxed/simple; bh=++qxSg8ePVCHBlUfgcxd7PUReZScqf/xPWbBoudBCnE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hymLRFu3pYBiEGWFzDpF2WBnMfecgaJ3bgGJGh2vJgBWoRlqryqnsXl+BZfJDe4XrHHs9fgwlGK1/sCzqG6jsI2TsDAyX5zhBfMpcKx/t5FeUUQX5Fjcs5pCOQHrkiWaTnW+08QZH+n6zTMs7og/nXhTF4lqh4ZfbFrRcg6K1Nc= 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=lY3oaZv6; arc=none smtp.client-ip=148.163.156.1 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 (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 455L0OGr020141; Wed, 5 Jun 2024 21:23:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc : content-transfer-encoding : date : from : in-reply-to : message-id : mime-version : references : subject : to; s=pp1; bh=Y98dRxrLBHldvjnywSLtVO9jA7MBr6bUSzYUwxA+r8w=; b=lY3oaZv6PK4mfWkBx4bhr+mES/YcHQQDHq8kb/sGTmkrwDhSDcmO7pgPr/fCPYtoKaf7 B4V8XYuPtTiTLLwDJ3MKh8HIQ6NjZkz5ToQzRaoV/9JB6cpPzZV9rvRQEZcdPA/dTqwI +QKw5ZBaH/eSH/FjUxT8Ef02nWIGdmd8l6AK02KYB8juRS2NTmL8Sx3VroKPaWjgP18N cYHgSob1SRvD+aMmn7EAZbbdm55P9wi/d7AQUK1zlHrPHUuxMGdoxfJ0vXK7egMRUuMT +JRugMFzwRUVpXpMLSXOPekXPUpavIMOLsgeWlPnMn+J2Cq7jgwpup+dgfeC/wggOczL EA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3yjyhyr1mh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jun 2024 21:23:20 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 455L18Jx026513; Wed, 5 Jun 2024 21:23:19 GMT Received: from smtprelay05.dal12v.mail.ibm.com ([172.16.1.7]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3yggp366ee-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 05 Jun 2024 21:23:19 +0000 Received: from smtpav06.dal12v.mail.ibm.com (smtpav06.dal12v.mail.ibm.com [10.241.53.105]) by smtprelay05.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 455LNGTJ18547272 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 5 Jun 2024 21:23:18 GMT Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F23258055; Wed, 5 Jun 2024 21:23:16 +0000 (GMT) Received: from smtpav06.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3239F5806A; Wed, 5 Jun 2024 21:23:16 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.121.242]) by smtpav06.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 5 Jun 2024 21:23:16 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: eajames@linux.ibm.com, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, broonie@kernel.org, andi.shyti@kernel.org, joel@jms.id.au, alistair@popple.id.au, jk@ozlabs.org, andrew@codeconstruct.com.au, linux-aspeed@lists.ozlabs.org, ninad@linux.ibm.com, lakshmiy@us.ibm.com Subject: [PATCH v4 10/40] fsi: core: Add slave spinlock Date: Wed, 5 Jun 2024 16:22:42 -0500 Message-Id: <20240605212312.349188-11-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240605212312.349188-1-eajames@linux.ibm.com> References: <20240605212312.349188-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-ORIG-GUID: -f-zZ_WIngontr3AXPh0CWSnvzJnDmob X-Proofpoint-GUID: -f-zZ_WIngontr3AXPh0CWSnvzJnDmob X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-05_02,2024-06-05_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 mlxscore=0 suspectscore=0 malwarescore=0 impostorscore=0 phishscore=0 adultscore=0 clxscore=1015 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406050160 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 ce9762d1bd8b0..660f89b743235 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; } @@ -1007,6 +1013,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 e9fd4be6f3760..0468ec1c60db2 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 @@ -107,6 +108,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