From patchwork Tue May 29 19:16:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 922322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40wNmT31Cbz9s08 for ; Wed, 30 May 2018 05:18:17 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40wNmT1DfkzDrCl for ; Wed, 30 May 2018 05:18:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=eajames@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com 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 lists.ozlabs.org (Postfix) with ESMTPS id 40wNks0vV7zDr7s for ; Wed, 30 May 2018 05:16:52 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TJGMMc075485 for ; Tue, 29 May 2018 15:16:49 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j9ahnp5yh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 15:16:48 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 13:16:48 -0600 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 13:16:45 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TJGisS11338028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 12:16:44 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24160C6037; Tue, 29 May 2018 13:16:44 -0600 (MDT) Received: from talon7.ibm.com (unknown [9.80.223.183]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 59F88C603E; Tue, 29 May 2018 13:16:43 -0600 (MDT) From: Eddie James To: openbmc@lists.ozlabs.org Subject: [PATCH linux dev-4.13 1/3] i2c: fsi: Don't take a lock around FSI accesses Date: Tue, 29 May 2018 14:16:36 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527621398-26526-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1527621398-26526-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052919-0020-0000-0000-00000E09C8B9 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009097; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000264; SDB=6.01039494; UDB=6.00532026; IPR=6.00818622; MB=3.00021361; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-29 19:16:46 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052919-0021-0000-0000-000061A47EE2 Message-Id: <1527621398-26526-2-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-29_08:, , 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-1805290205 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eddie James Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" That lock is incorrect as FSI can sleep and thus will trigger lockdep warnings. It is also unnecessary as it was meant to "speed up" the reset process for unspecified reasons, not to protect against anything. The the master semaphore should prevent any concurrent user from seeing the intermediate state already and the recent improvements to the FSI layer should take care of potential speed issues. Signed-off-by: Eddie James --- This is Benjamin Herrenschmidt's patch, but I also removed the reset_lock in the master structure and didn't add delay.h include; thought I would just get these in one patch set for convenience. drivers/i2c/busses/i2c-fsi.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 10f693f..3fcc14e 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #define FSI_ENGID_I2C 0x7 @@ -148,7 +147,6 @@ struct fsi_i2c_master { struct list_head ports; wait_queue_head_t wait; struct semaphore lock; - spinlock_t reset_lock; }; struct fsi_i2c_port { @@ -427,71 +425,63 @@ static int fsi_i2c_reset(struct fsi_i2c_master *i2c, u16 port) { int rc; u32 mode, stat, dummy = 0; - unsigned long flags; - - /* disable pre-emption; bus won't get left in a bad state for long */ - spin_lock_irqsave(&i2c->reset_lock, flags); /* reset engine */ rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_I2C, &dummy); if (rc) - goto done; + return rc; /* re-init engine */ rc = fsi_i2c_dev_init(i2c); if (rc) - goto done; + return rc; rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_MODE, &mode); if (rc) - goto done; + return rc; /* set port; default after reset is 0 */ if (port) { mode = SETFIELD(I2C_MODE_PORT, mode, port); rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); if (rc) - goto done; + return rc; } /* reset busy register; hw workaround */ dummy = I2C_PORT_BUSY_RESET; rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_PORT_BUSY, &dummy); if (rc) - goto done; + return rc; /* force bus reset */ rc = fsi_i2c_reset_bus(i2c); if (rc) - goto done; + return rc; /* reset errors */ dummy = 0; rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_ERR, &dummy); if (rc) - goto done; + return rc; /* wait for command complete; time from legacy driver */ - udelay(1000); + msleep(1); rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_STAT, &stat); if (rc) - goto done; + return rc; if (stat & I2C_STAT_CMD_COMP) - goto done; + return rc; /* failed to get command complete; reset engine again */ rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_I2C, &dummy); if (rc) - goto done; + return rc; /* re-init engine again */ - rc = fsi_i2c_dev_init(i2c); - -done: - spin_unlock_irqrestore(&i2c->reset_lock, flags); - return rc; + return fsi_i2c_dev_init(i2c); } static int fsi_i2c_abort(struct fsi_i2c_port *port, u32 status) @@ -711,7 +701,6 @@ static int fsi_i2c_probe(struct device *dev) 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); From patchwork Tue May 29 19:16:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 922323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40wNnQ3Gbgz9s08 for ; Wed, 30 May 2018 05:19:06 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40wNnQ1slczDr4q for ; Wed, 30 May 2018 05:19:06 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=eajames@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com 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 lists.ozlabs.org (Postfix) with ESMTPS id 40wNkt415tzDr4N for ; Wed, 30 May 2018 05:16:54 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TJECju068629 for ; Tue, 29 May 2018 15:16:51 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j9a5py5v3-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 15:16:51 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 13:16:50 -0600 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 13:16:47 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TJGkEv6685048 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 12:16:47 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DCD89C604A; Tue, 29 May 2018 13:16:46 -0600 (MDT) Received: from talon7.ibm.com (unknown [9.80.223.183]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 202ACC6037; Tue, 29 May 2018 13:16:45 -0600 (MDT) From: Eddie James To: openbmc@lists.ozlabs.org Subject: [PATCH linux dev-4.13 2/3] i2c: fsi: Use mutex lock instead of semaphore Date: Tue, 29 May 2018 14:16:37 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527621398-26526-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1527621398-26526-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052919-0004-0000-0000-0000142F9567 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009097; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000264; SDB=6.01039494; UDB=6.00532027; IPR=6.00818622; MB=3.00021361; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-29 19:16:49 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052919-0005-0000-0000-0000877265E5 Message-Id: <1527621398-26526-3-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-29_08:, , 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-1805290205 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eddie James Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Simplify the FSI I2C driver by using a mutex lock instead of a semaphore. This removes the wait until timeout on the semaphore. Signed-off-by: Eddie James --- drivers/i2c/busses/i2c-fsi.c | 46 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 3fcc14e..adc2e38 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -18,10 +18,9 @@ #include #include #include +#include #include #include -#include -#include #define FSI_ENGID_I2C 0x7 @@ -145,8 +144,7 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; struct list_head ports; - wait_queue_head_t wait; - struct semaphore lock; + struct mutex lock; }; struct fsi_i2c_port { @@ -180,29 +178,6 @@ 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; @@ -626,11 +601,10 @@ 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; - rc = fsi_i2c_lock_master(port->master, adap->timeout); - if (rc) - return rc; + mutex_lock(&master->lock); rc = fsi_i2c_set_port(port); if (rc) @@ -651,7 +625,7 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } unlock: - fsi_i2c_unlock_master(port->master); + mutex_unlock(&master->lock); return rc; } @@ -667,14 +641,11 @@ static int fsi_i2c_recover_bus(struct i2c_adapter *adap) struct fsi_i2c_port *port = adap->algo_data; struct fsi_i2c_master *master = port->master; - rc = fsi_i2c_lock_master(master, adap->timeout); - if (rc) - return rc; + mutex_lock(&master->lock); rc = fsi_i2c_reset(master, port->port); - fsi_i2c_unlock_master(master); - + mutex_unlock(&master->lock); return rc; } @@ -699,8 +670,7 @@ static int fsi_i2c_probe(struct device *dev) if (!i2c) return -ENOMEM; - init_waitqueue_head(&i2c->wait); - sema_init(&i2c->lock, 1); + mutex_init(&i2c->lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); From patchwork Tue May 29 19:16:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 922324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40wNnm1flNz9s08 for ; Wed, 30 May 2018 05:19:24 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40wNnl6S6HzDrWR for ; Wed, 30 May 2018 05:19:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com X-Original-To: openbmc@lists.ozlabs.org Delivered-To: openbmc@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=eajames@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com 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 lists.ozlabs.org (Postfix) with ESMTPS id 40wNkw22BfzDrJF for ; Wed, 30 May 2018 05:16:56 +1000 (AEST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4TJEAMP058368 for ; Tue, 29 May 2018 15:16:53 -0400 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j9c3pt0u6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 29 May 2018 15:16:53 -0400 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 May 2018 13:16:52 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 29 May 2018 13:16:50 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4TJGnQQ5702064 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 29 May 2018 12:16:49 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E670C6037; Tue, 29 May 2018 13:16:49 -0600 (MDT) Received: from talon7.ibm.com (unknown [9.80.223.183]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 93F6EC603E; Tue, 29 May 2018 13:16:48 -0600 (MDT) From: Eddie James To: openbmc@lists.ozlabs.org Subject: [PATCH linux dev-4.13 3/3] i2c: fsi: Use usleep instead of schedule calls Date: Tue, 29 May 2018 14:16:38 -0500 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1527621398-26526-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1527621398-26526-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18052919-0004-0000-0000-0000142F956C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009097; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000264; SDB=6.01039494; UDB=6.00532027; IPR=6.00818622; MB=3.00021361; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-29 19:16:51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18052919-0005-0000-0000-0000877265ED Message-Id: <1527621398-26526-4-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-29_08:, , 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-1805290205 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eddie James Errors-To: openbmc-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "openbmc" Simplify the FSI I2C driver by calling usleep_range while waiting for data to be made available instead of scheduling a timeout. The schedule overhead isn't worth it for what should be a short time. Signed-off-by: Eddie James --- drivers/i2c/busses/i2c-fsi.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index adc2e38..52a662c 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -20,7 +20,6 @@ #include #include #include -#include #define FSI_ENGID_I2C 0x7 @@ -135,7 +134,8 @@ #define I2C_PORT_BUSY_RESET 0x80000000 -#define I2C_LOCAL_WAIT_TIMEOUT 2 /* jiffies */ +#define I2C_LOCAL_SLEEP_MAX_US 500 +#define I2C_LOCAL_SLEEP_MIN_US 50 /* choose timeout length from legacy driver; it's well tested */ #define I2C_ABORT_TIMEOUT msecs_to_jiffies(100) @@ -490,10 +490,7 @@ static int fsi_i2c_abort(struct fsi_i2c_port *port, u32 status) if (status & I2C_STAT_CMD_COMP) return 0; - set_current_state(TASK_INTERRUPTIBLE); - if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0) - return -EINTR; - + usleep_range(I2C_LOCAL_SLEEP_MIN_US, I2C_LOCAL_SLEEP_MAX_US); } while (time_after(start + I2C_ABORT_TIMEOUT, jiffies)); return -ETIME; @@ -556,7 +553,7 @@ static int fsi_i2c_wait(struct fsi_i2c_port *port, struct i2c_msg *msg, unsigned long timeout) { u32 status = 0; - int rc, rc_abort; + int rc; unsigned long start = jiffies; do { @@ -578,21 +575,10 @@ static int fsi_i2c_wait(struct fsi_i2c_port *port, struct i2c_msg *msg, continue; } - set_current_state(TASK_INTERRUPTIBLE); - if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0) { - rc = -EINTR; - goto abort; - } + usleep_range(I2C_LOCAL_SLEEP_MIN_US, I2C_LOCAL_SLEEP_MAX_US); } while (time_after(start + timeout, jiffies)); - rc = -ETIME; - -abort: - rc_abort = fsi_i2c_abort(port, status); - if (rc_abort) - return rc_abort; - - return rc; + return -ETIME; } static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,