Received: by 2002:ab2:644:0:b0:1ec:cbc4:63fb with SMTP id 4csp1145222lqn; Mon, 26 Feb 2024 08:56:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXA5yAAdSIDUxgxRMocJ4MphaiJEs5+T4tyMitJ9EK7WmlphVyySBEdvP9/P+5dpnfEbqqPMBoHx21SBttKEkc1p7LNbryi9PppU7jxWw== X-Google-Smtp-Source: AGHT+IG0cYK1RvCYg18lEvJdzyjY8AzAeeBRVbZVBPqoVKsLHffpGfT+f8PwAHXzpUWQNunW3FOj X-Received: by 2002:ac8:4b5b:0:b0:42e:8986:28b9 with SMTP id e27-20020ac84b5b000000b0042e898628b9mr1562095qts.8.1708966590685; Mon, 26 Feb 2024 08:56:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708966590; cv=pass; d=google.com; s=arc-20160816; b=sT0Bizu4y4nfyM/9QtSkH8ZrGSAwMpWxiRChc+fbCjWlBStCBSunRxNsBb/ddCpF9U V5JGflaRDBstawemZDUQdO/jCQ1I82speWZXUFS24qRmWg4EWX9JCbm6y0KTmjo9A+8/ 0edyQb0ABEDC+JGUJjkFZYghu119l2rlJelICTSPvNTT+TF7Z0yq8DuoTwZXwiUGWyV7 bKvUzIyN8z73FUJqtIgvvr13qR05h7xc0Ax48FuWQA+8K0+yZdjXpNWSFJzaFUrqq/S7 0bPTceYv/eJQxOwO2SQa4CQse73/VC8TTkrVFsOluxBpIP4htSdS4oSLpDUQ7MhvZfkc jjPA== 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=hD87NRI2uXFKH7lntJG4G4naYHSrGp3lxTKSbIyEdj8=; b=k72pC9e8l4uszv86NXmwlWGksKGfDTRvuM0cLfUKeUT/fm4rQOdVkWB5oEHDdp8s6f 4SPQHXhhumpEOVph/UlrjQjVIhFL/g43AZEYKPE3yP95iXQx4cQN6YFFl71vI95oACpl M9cp0NbT7s6sRvMYjKX7Dhemr1UDBX6Z9N/J+foypOx4+qWd79baKaLP9J5NwFuYENbh aFmV8sB0d8C6fZT7yfImBCSTJYcXRtolNy/uaPx6SmXVHfxlH7qz9Mn9lpI9LBzE0h+D LusF1OImKPNwedT4Mw0/Gr1qBZhV7tjSvO1eIUopMk8B2XKufMjXzrt5yGNaQ/ktlfGS Q8fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=EzAdIi1N; 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-81960-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81960-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 t8-20020ac86a08000000b0042e3d44d71fsi5301201qtr.782.2024.02.26.08.56.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 08:56:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81960-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=EzAdIi1N; 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-81960-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81960-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 5B8B61C20CEA for ; Mon, 26 Feb 2024 16:56:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6442130E34; Mon, 26 Feb 2024 16:53:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="EzAdIi1N" 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 DF1B912F59D; Mon, 26 Feb 2024 16:53:45 +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=1708966427; cv=none; b=AS1x/0NxrRh6Lm5qjdJwLQUR2N/mJsISc1zW+iiB2t+fKYIjE+L9YW3heTfkRxJPRGFYxX+egVLZjZBZB5oj1IKHL47U4jSwtiw4aQyffCw7zHwEdc6prFrbTf59f4Iw3TxYmrFM+YcJKiVh2RIr+1eUP0wbZtv08ImKxOnpRVY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708966427; c=relaxed/simple; bh=rnrW55EMd5WY1H/Lf4PHZ/r+oG7ZBsAslE1xLX4eUiA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sSQNMxEavyzGWpnU3PYlW8OtTxgpVSLyYQWE7nqAkIWOlpVYvXdkk3L34+mZGP5lnalAfkYM9LUxG1/ZqKZqEwAP14XMtGe8F9/ROQz7HS8Y8x7ghNdByIS682CGXPFm782NWafHC1CeP7hR2h7pWe0w6WesAoj9mpf3NxJCqIY= 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=EzAdIi1N; 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 (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41QGAPmv032560; Mon, 26 Feb 2024 16:53:35 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=EzAdIi1NVXnE+z0nk7YalKHCEtL5d6Sjdwps9boCVbfwfE83eLVEBl0SkYVBgvbtwvzy LnY+59v5HQ1LAFYHTYZoRhniCeg46YfMBA1/5dchRu8DFu93heQjK8co5LLjz5X5HH6X niEE9vDS+pGqIvyFO0CcATJe3ToyclhBntTCjftpkQuzSuTpgDijT/lg1ZwCoHi/xDmp q+uelnaz0Ni/3kgdxwvecyZLUIbf2lnThFVaFF3wbjaA+eR02SCxGFO56TSINmPYlGgR jkspPGaPZd3vx5Mulyg7pib3TBacbGgNkYPkDH/z/uPCgE+rNQLggJNQ6qYgS0TIKeAU Gw== Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3wgw0k353b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 16:53:34 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 41QFTGIc024151; Mon, 26 Feb 2024 16:53:33 GMT Received: from smtprelay03.wdc07v.mail.ibm.com ([172.16.1.70]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wfw0k23f9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 26 Feb 2024 16:53:33 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay03.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41QGrUAx19858038 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 26 Feb 2024 16:53:33 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE0DE58043; Mon, 26 Feb 2024 16:53:30 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 213B658053; Mon, 26 Feb 2024 16:53:30 +0000 (GMT) Received: from slate16.aus.stglabs.ibm.com (unknown [9.61.57.130]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 26 Feb 2024 16:53:30 +0000 (GMT) From: Eddie James To: linux-fsi@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, linux-i2c@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, robh@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, lakshmiy@us.ibmcom Subject: [PATCH v2 10/31] fsi: core: Add slave spinlock Date: Mon, 26 Feb 2024 10:53:00 -0600 Message-Id: <20240226165321.91976-11-eajames@linux.ibm.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240226165321.91976-1-eajames@linux.ibm.com> References: <20240226165321.91976-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: BOQEUV3VespclJ82cBk5wG0RIE0_MtFr X-Proofpoint-ORIG-GUID: BOQEUV3VespclJ82cBk5wG0RIE0_MtFr 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-26_11,2024-02-26_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402260128 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