Received: by 10.223.164.202 with SMTP id h10csp141777wrb; Thu, 16 Nov 2017 20:51:36 -0800 (PST) X-Google-Smtp-Source: AGs4zMYqWUvmTIzdcdjs9Dd96MxwhCn9I9KDw8Lh8UPsZCtsITx1uDQLYNcfHxMfTjsP+nBpiyJ4 X-Received: by 10.98.215.19 with SMTP id b19mr732328pfh.94.1510894296509; Thu, 16 Nov 2017 20:51:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510894296; cv=none; d=google.com; s=arc-20160816; b=R5lWdC8x2pCMpEJsv4MBIt9AeK2NdCzVlTEkQP6+F7ba88AR0bGld+bZvFavAZdR4p vwZYptnEuCjVTa+xEVuzR37YxzuMjWSJrGyoh1AlwjigWaN3e9flq4Fs0nCM4XY5Nvkq 13eo3lTXeFS1cKbYzAgLxM7wAw5Ab4NdxNtoa1Ms4I7XfZ5jvxdnp1L3XHJDcR1NlNjh XOphWQwoxiatAW+mcnqB+43JVclBBQmZJDF8cw35t29qH+YrVVoZCfYYHXDETx67QfZV GXiQiNRKZy3Z7zBM9qGICXenb9As9tmeCDDKlAxnnheASXXE3ztsHOIWpnnNvHN331KS Gzsg== 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=rzWhUdQQbJtOcenPgr0eDtKCRrIl7dvF6eU2noJN/8o=; b=Vqc67wJzQLc4W1+ER1LxXbAMuCQgpO71CamBmD6rIqUERxLZQ3Y33GFYtOqpt6Ncb/ +0ZjJpzc4hCo4QFfhHH0sHjIdJN4grSSebr9tGWkiTEWYcsuMwqOnjxs4vjva7hdBX+K feCJvAlOZyf9uWGgvO+PPrA28PPtUyUk6KgpApcgiIE2uoYZv9IKVj3ZdE9Q2HBQZs4i 18ps5EnpmHeizbaw6PNiDF5h1sC56ea6bxH6BudBcRhhNnQN+HkSeEMbtJX3CDls/WzA 4ILLq6yo8gVRfMt4w3UM7NXmERzAFxAUOKBOXO+2ajZzGDgLVgpDuQVMYPUE9IZQ7sUw FULA== 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 q2si2009281pgp.701.2017.11.16.20.51.23; Thu, 16 Nov 2017 20:51:36 -0800 (PST) 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 S933830AbdKPTzs (ORCPT + 92 others); Thu, 16 Nov 2017 14:55:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58764 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932967AbdKPTyi (ORCPT ); Thu, 16 Nov 2017 14:54:38 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsYXO088259 for ; Thu, 16 Nov 2017 14:54:38 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e9es0yuu8-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:35 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:22 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:18 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJsHAF6095200; Thu, 16 Nov 2017 12:54:17 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86A3278038; Thu, 16 Nov 2017 12:54:17 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 6883378043; Thu, 16 Nov 2017 12:54:16 -0700 (MST) From: Eddie James To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org, joel@jms.id.au, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH v6 6/7] drivers/i2c: Add I2C master locking to FSI algorithm Date: Thu, 16 Nov 2017 13:53:51 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510862032-12394-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1510862032-12394-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111619-0016-0000-0000-000007D1AD35 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008076; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00946833; UDB=6.00477976; IPR=6.00727126; BA=6.00005695; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018049; XFM=3.00000015; UTC=2017-11-16 19:54:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0017-0000-0000-00003C478692 Message-Id: <1510862032-12394-7-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-16_06:,, 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" 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: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 5c312ef..1751c44 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #define FSI_ENGID_I2C 0x7 @@ -144,6 +146,8 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; struct list_head ports; + wait_queue_head_t wait; + struct semaphore lock; spinlock_t reset_lock; }; @@ -178,6 +182,29 @@ static int fsi_i2c_write_reg(struct fsi_device *fsi, unsigned int reg, return fsi_device_write(fsi, reg, &data_be, sizeof(data_be)); } +static int fsi_i2c_lock_master(struct fsi_i2c_master *i2c, int timeout) +{ + int rc; + + rc = down_trylock(&i2c->lock); + if (!rc) + return 0; + + rc = wait_event_interruptible_timeout(i2c->wait, + !down_trylock(&i2c->lock), + timeout); + if (rc > 0) + return 0; + + return -EBUSY; +} + +static void fsi_i2c_unlock_master(struct fsi_i2c_master *i2c) +{ + up(&i2c->lock); + wake_up(&i2c->wait); +} + static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) { int rc; @@ -611,25 +638,31 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, struct fsi_i2c_port *port = adap->algo_data; struct i2c_msg *msg; - rc = fsi_i2c_set_port(port); + rc = fsi_i2c_lock_master(port->master, adap->timeout); if (rc) return rc; + rc = fsi_i2c_set_port(port); + if (rc) + goto unlock; + for (i = 0; i < num; ++i) { msg = msgs + i; start_time = jiffies; 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 0; +unlock: + fsi_i2c_unlock_master(port->master); + return rc; } static u32 fsi_i2c_functionality(struct i2c_adapter *adap) @@ -655,6 +688,8 @@ static int fsi_i2c_probe(struct device *dev) if (!i2c) return -ENOMEM; + init_waitqueue_head(&i2c->wait); + sema_init(&i2c->lock, 1); spin_lock_init(&i2c->reset_lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); -- 1.8.3.1 From 1584276361712475582@xxx Fri Nov 17 01:54:36 +0000 2017 X-GM-THRID: 1584245926824090954 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread