Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3675438imm; Tue, 17 Jul 2018 08:32:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfOhzOwXCV0T2oQjQ1OOQSLorBF/q6s4C3glveMWkWfxpszJY38Yuwk6UhrXkEoBDKR0I+x X-Received: by 2002:a62:3d86:: with SMTP id x6-v6mr1182984pfj.192.1531841548238; Tue, 17 Jul 2018 08:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531841548; cv=none; d=google.com; s=arc-20160816; b=poj1BBDKei6sLtr7fu5VXKoDgTvxBFImwgkx9YqqU2YYhWTXSU7fvvV3+vZMnRKTp1 y9ZDy8ZSS8SJ2Lk9poCZR1Kojdhjj3qYxRPzVAzOdFV87vJLwMLwFJzR+fJeIa4BID7b A1x2vMdF5H9W8bv9NLW6yv/ErO8QJIsmHbZI+jBi+K47BhaS6vrr4hRF5Xs6hSTfcrAM X7vUh3RGYiXB2wYe/05VWAj70HkJbvC7TO7plY984sYYOvlYFJLtRLRrthnsYf+86pgw VMppuVlQM1OzpbqALDIlfNO89K1B1g9D8yfHc6syaMEK2areXCyQi8NranfZtclsHZtO edmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=5w+PkrsOptW2ej9R2Fs74KYeAjmgN0GtuJyy0JygTHE=; b=sJUBGwVjjXL7oev0CorAe3mavadnHG/qxxVtZoF0OgxQLcFut7NSryN/z2AeVK67pU W6fQhVGPds/N5m6jHCevHqdTKy1CCGAnpKrRESiNVt9SMLK8sInldDngncrKD6b4sirM 1gg3VrlF40nNP1A+aRxg1JIXlv8jHR/9S4S34rB3bDejmiJ9R69yXcPUWOUmu6ch8HeD 8HrTwTM7q1okZ9ZXwyGIe92JiwgdrRtH843XrDXWjGlK/1zClcMvoknWSeZJfJ61d5iU Ui2ZBtnJxhWKQnc2p/xJDE1DFdTJj6RccTIlEABmCQpazCrh/2x5tidBwfqmj6ZGAYUp QIKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o8-v6si1213072pgo.175.2018.07.17.08.32.13; Tue, 17 Jul 2018 08:32:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730922AbeGQQEi (ORCPT + 99 others); Tue, 17 Jul 2018 12:04:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38302 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729683AbeGQQEh (ORCPT ); Tue, 17 Jul 2018 12:04:37 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w6HFTKWd056936 for ; Tue, 17 Jul 2018 11:31:26 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2k9h8hnus7-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 17 Jul 2018 11:31:26 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Jul 2018 09:31:25 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 17 Jul 2018 09:31:22 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w6HFVLd410093026 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 17 Jul 2018 08:31:21 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1535213605D; Tue, 17 Jul 2018 09:31:21 -0600 (MDT) Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CC94136053; Tue, 17 Jul 2018 09:31:20 -0600 (MDT) Received: from talon7.ibm.com (unknown [9.41.102.69]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 17 Jul 2018 09:31:20 -0600 (MDT) From: Eddie James To: linux-i2c@vger.kernel.org Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org, benh@kernel.crashing.org, joel@jms.id.au, mark.rutland@arm.com, gregkh@linuxfoundation.org, rdunlap@infradead.org, andy.shevchenko@gmail.com, peda@axentia.se, "eajames@linux.vnet.ibm.com" Subject: [PATCH v12 6/8] i2c: fsi: Add I2C master locking Date: Tue, 17 Jul 2018 10:31:04 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1531841466-9833-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1531841466-9833-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18071715-0012-0000-0000-0000168D3293 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009380; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01062145; UDB=6.00545317; IPR=6.00840002; MB=3.00022173; MTD=3.00000008; XFM=3.00000015; UTC=2018-07-17 15:31:25 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18071715-0013-0000-0000-000053B481D5 Message-Id: <1531841466-9833-7-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-17_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807170162 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "eajames@linux.vnet.ibm.com" Since there are many ports per master, each with it's own adapter and chardev, we need some locking to prevent transfers from changing the master state while other transfers are in progress. Signed-off-by: Eddie James Reviewed-by: Andy Shevchenko --- drivers/i2c/busses/i2c-fsi.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 45a6ebd..27d74a9 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -148,6 +149,7 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; struct list_head ports; + struct mutex lock; }; struct fsi_i2c_port { @@ -486,11 +488,14 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int i, rc; unsigned long start_time; struct fsi_i2c_port *port = adap->algo_data; + struct fsi_i2c_master *master = port->master; struct i2c_msg *msg; + mutex_lock(&master->lock); + rc = fsi_i2c_set_port(port); if (rc) - return rc; + goto unlock; for (i = 0; i < num; i++) { msg = msgs + i; @@ -498,15 +503,17 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, rc = fsi_i2c_start(port, msg, i == num - 1); if (rc) - return rc; + goto unlock; rc = fsi_i2c_wait(port, msg, adap->timeout - (jiffies - start_time)); if (rc) - return rc; + goto unlock; } - return num; +unlock: + mutex_unlock(&master->lock); + return rc ? : num; } static u32 fsi_i2c_functionality(struct i2c_adapter *adap) @@ -532,6 +539,7 @@ static int fsi_i2c_probe(struct device *dev) if (!i2c) return -ENOMEM; + mutex_init(&i2c->lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); -- 1.8.3.1