From nobody Fri Nov 29 18:30:10 2024 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 6D6BB17C98A for ; Tue, 17 Sep 2024 17:17:01 +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=1726593423; cv=none; b=FvsZvMLE6yuvM65z/ArgdJMIPg4wBvBseNKBZmQQbzDpsF65fVf4kVOM3jxVuJalTA1BhfpJ4naH1hSrnKgiLhodDuu6VHJ9VJdQ5DYPVW56gVOW3cpxMhpOPn/sF6E1qE/K3u+e7KSDM7EOR1jvIVXPQOXTLdkQYfjJV9qZwBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726593423; c=relaxed/simple; bh=/nIB/QSSATM8hY+vOeI+bRFa7+zFuBKnc45geBoPBMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aji4/Y4Cxa4HB2LsbACxkpSCUTKGVfcinhASnTHxAF/nRiDQdRo+zWNG2WNDSWREYzivnnnu8dwqIeHhSwbCGa/1iUOkAqvpyXH0zQtyqWGSoGnzVerFjl7Dcj1anocM1DaKrhUjvUU9mWJQAqVGa4azI22uRXaDTUtYDFT81uM= 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=pXFvitiM; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="pXFvitiM" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48H8p1lv023532; Tue, 17 Sep 2024 17:16:52 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=fPZ8BVVO6vmpc HjuevIah+NTe3Dl5evEWfNVLAjy8SI=; b=pXFvitiMYjG5zAxI5LpBaCCA2QRTt +/WlW6CJ4BQnC1X0GnlFZ8Iy0OPttKt9P70M70Xou+/hbv1isAclbXh22oCHkgT3 98yU2MisDSXWfSswmBTJL+JYUzUXATh3PUlzMVF0SbO1C5zvU2votzXXct4O5frU LCc2GCeoQHdC7+k3JK8SqhYp0ufRAm1yPTwD2q/uHTu3CmWC2+lOZmizwk2g9Pdb 2LJoPXSs6wr270gvD9oB+EAoPvRNcNR99PB0Z8W0lluDsMbYaRlZBD9Zif7zkFd/ jDeJSwP2SuC6/oR3C/zOwDEMwUsKaXTp0ZV8u9vH9YH86WvgQcenRNREg== Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 41n3ud9hgk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Sep 2024 17:16:52 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 48HFhBrZ001184; Tue, 17 Sep 2024 17:16:51 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41nntq6erp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Sep 2024 17:16:50 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 48HHGncI49021326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Sep 2024 17:16:50 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D71B258057; Tue, 17 Sep 2024 17:16:49 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AAE3E58061; Tue, 17 Sep 2024 17:16:49 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.93.228]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Tue, 17 Sep 2024 17:16:49 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, alistair@popple.id.au, joel@jms.id.au, jk@ozlabs.org, andrew@codeconstruct.com.au, eajames@linux.ibm.com, ninad@linux.ibm.com Subject: [PATCH 09/15] fsi: core: Add slave spinlock Date: Tue, 17 Sep 2024 12:16:41 -0500 Message-ID: <20240917171647.1403910-10-eajames@linux.ibm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240917171647.1403910-1-eajames@linux.ibm.com> References: <20240917171647.1403910-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: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Pnwa12ELFhFQJXCw-d2TR3cctcfKhf8z X-Proofpoint-ORIG-GUID: Pnwa12ELFhFQJXCw-d2TR3cctcfKhf8z X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-17_08,2024-09-16_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 phishscore=0 impostorscore=0 spamscore=0 priorityscore=1501 suspectscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=961 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409170122 Content-Type: text/plain; charset="utf-8" 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 53d61ea46a4f..eea5bbdb00b6 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 *sla= ve, bool write, int fsi_slave_read(struct fsi_slave *slave, uint32_t addr, void *val, size_t size) { + unsigned long flags; uint8_t id =3D slave->id; int rc, err_rc, i; =20 @@ -311,6 +312,7 @@ int fsi_slave_read(struct fsi_slave *slave, uint32_t ad= dr, if (rc) return rc; =20 + spin_lock_irqsave(&slave->lock, flags); for (i =3D 0; i < slave_retries; i++) { rc =3D 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 ad= dr, if (err_rc) break; } + spin_unlock_irqrestore(&slave->lock, flags); =20 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 =3D slave->id; int rc, err_rc, i; =20 @@ -336,6 +340,7 @@ int fsi_slave_write(struct fsi_slave *slave, uint32_t a= ddr, if (rc) return rc; =20 + spin_lock_irqsave(&slave->lock, flags); for (i =3D 0; i < slave_retries; i++) { rc =3D 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 a= ddr, if (err_rc) break; } + spin_unlock_irqrestore(&slave->lock, flags); =20 return rc; } @@ -1007,6 +1013,7 @@ static int fsi_slave_init(struct fsi_master *master, = int link, uint8_t id) if (!slave) return -ENOMEM; =20 + spin_lock_init(&slave->lock); dev_set_name(&slave->dev, "slave@%02x:%02x", link, id); slave->dev.type =3D &cfam_type; slave->dev.parent =3D &master->dev; diff --git a/drivers/fsi/fsi-slave.h b/drivers/fsi/fsi-slave.h index e9fd4be6f376..0468ec1c60db 100644 --- a/drivers/fsi/fsi-slave.h +++ b/drivers/fsi/fsi-slave.h @@ -6,6 +6,7 @@ =20 #include #include +#include =20 #define FSI_SLAVE_BASE 0x800 =20 @@ -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# */ --=20 2.43.0