linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>,
	Brendan Higgins <brendanhiggins@google.com>,
	Joel Stanley <joel@jms.id.au>, Tao Ren <taoren@fb.com>,
	Wolfram Sang <wsa@the-dreams.de>, Sasha Levin <sashal@kernel.org>,
	linux-i2c@vger.kernel.org
Subject: [PATCH AUTOSEL 5.3 63/81] i2c: aspeed: fix master pending state handling
Date: Wed, 30 Oct 2019 11:49:09 -0400	[thread overview]
Message-ID: <20191030154928.9432-63-sashal@kernel.org> (raw)
In-Reply-To: <20191030154928.9432-1-sashal@kernel.org>

From: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>

[ Upstream commit 1f0d9cbeec9bb0a1c2013342836f2c9754d6502b ]

In case of master pending state, it should not trigger a master
command, otherwise data could be corrupted because this H/W shares
the same data buffer for slave and master operations. It also means
that H/W command queue handling is unreliable because of the buffer
sharing issue. To fix this issue, it clears command queue if a
master command is queued in pending state to use S/W solution
instead of H/W command queue handling. Also, it refines restarting
mechanism of the pending master command.

Fixes: 2e57b7cebb98 ("i2c: aspeed: Add multi-master use case support")
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@linux.intel.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Acked-by: Joel Stanley <joel@jms.id.au>
Tested-by: Tao Ren <taoren@fb.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/i2c/busses/i2c-aspeed.c | 54 +++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 20 deletions(-)

diff --git a/drivers/i2c/busses/i2c-aspeed.c b/drivers/i2c/busses/i2c-aspeed.c
index fa66951b05d06..7b098ff5f5dd3 100644
--- a/drivers/i2c/busses/i2c-aspeed.c
+++ b/drivers/i2c/busses/i2c-aspeed.c
@@ -108,6 +108,12 @@
 #define ASPEED_I2CD_S_TX_CMD				BIT(2)
 #define ASPEED_I2CD_M_TX_CMD				BIT(1)
 #define ASPEED_I2CD_M_START_CMD				BIT(0)
+#define ASPEED_I2CD_MASTER_CMDS_MASK					       \
+		(ASPEED_I2CD_M_STOP_CMD |				       \
+		 ASPEED_I2CD_M_S_RX_CMD_LAST |				       \
+		 ASPEED_I2CD_M_RX_CMD |					       \
+		 ASPEED_I2CD_M_TX_CMD |					       \
+		 ASPEED_I2CD_M_START_CMD)
 
 /* 0x18 : I2CD Slave Device Address Register   */
 #define ASPEED_I2CD_DEV_ADDR_MASK			GENMASK(6, 0)
@@ -336,18 +342,19 @@ static void aspeed_i2c_do_start(struct aspeed_i2c_bus *bus)
 	struct i2c_msg *msg = &bus->msgs[bus->msgs_index];
 	u8 slave_addr = i2c_8bit_addr_from_msg(msg);
 
-	bus->master_state = ASPEED_I2C_MASTER_START;
-
 #if IS_ENABLED(CONFIG_I2C_SLAVE)
 	/*
 	 * If it's requested in the middle of a slave session, set the master
 	 * state to 'pending' then H/W will continue handling this master
 	 * command when the bus comes back to the idle state.
 	 */
-	if (bus->slave_state != ASPEED_I2C_SLAVE_INACTIVE)
+	if (bus->slave_state != ASPEED_I2C_SLAVE_INACTIVE) {
 		bus->master_state = ASPEED_I2C_MASTER_PENDING;
+		return;
+	}
 #endif /* CONFIG_I2C_SLAVE */
 
+	bus->master_state = ASPEED_I2C_MASTER_START;
 	bus->buf_index = 0;
 
 	if (msg->flags & I2C_M_RD) {
@@ -422,20 +429,6 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
 		}
 	}
 
-#if IS_ENABLED(CONFIG_I2C_SLAVE)
-	/*
-	 * A pending master command will be started by H/W when the bus comes
-	 * back to idle state after completing a slave operation so change the
-	 * master state from 'pending' to 'start' at here if slave is inactive.
-	 */
-	if (bus->master_state == ASPEED_I2C_MASTER_PENDING) {
-		if (bus->slave_state != ASPEED_I2C_SLAVE_INACTIVE)
-			goto out_no_complete;
-
-		bus->master_state = ASPEED_I2C_MASTER_START;
-	}
-#endif /* CONFIG_I2C_SLAVE */
-
 	/* Master is not currently active, irq was for someone else. */
 	if (bus->master_state == ASPEED_I2C_MASTER_INACTIVE ||
 	    bus->master_state == ASPEED_I2C_MASTER_PENDING)
@@ -462,11 +455,15 @@ static u32 aspeed_i2c_master_irq(struct aspeed_i2c_bus *bus, u32 irq_status)
 #if IS_ENABLED(CONFIG_I2C_SLAVE)
 		/*
 		 * If a peer master starts a xfer immediately after it queues a
-		 * master command, change its state to 'pending' then H/W will
-		 * continue the queued master xfer just after completing the
-		 * slave mode session.
+		 * master command, clear the queued master command and change
+		 * its state to 'pending'. To simplify handling of pending
+		 * cases, it uses S/W solution instead of H/W command queue
+		 * handling.
 		 */
 		if (unlikely(irq_status & ASPEED_I2CD_INTR_SLAVE_MATCH)) {
+			writel(readl(bus->base + ASPEED_I2C_CMD_REG) &
+				~ASPEED_I2CD_MASTER_CMDS_MASK,
+			       bus->base + ASPEED_I2C_CMD_REG);
 			bus->master_state = ASPEED_I2C_MASTER_PENDING;
 			dev_dbg(bus->dev,
 				"master goes pending due to a slave start\n");
@@ -629,6 +626,14 @@ static irqreturn_t aspeed_i2c_bus_irq(int irq, void *dev_id)
 			irq_handled |= aspeed_i2c_master_irq(bus,
 							     irq_remaining);
 	}
+
+	/*
+	 * Start a pending master command at here if a slave operation is
+	 * completed.
+	 */
+	if (bus->master_state == ASPEED_I2C_MASTER_PENDING &&
+	    bus->slave_state == ASPEED_I2C_SLAVE_INACTIVE)
+		aspeed_i2c_do_start(bus);
 #else
 	irq_handled = aspeed_i2c_master_irq(bus, irq_remaining);
 #endif /* CONFIG_I2C_SLAVE */
@@ -691,6 +696,15 @@ static int aspeed_i2c_master_xfer(struct i2c_adapter *adap,
 		     ASPEED_I2CD_BUS_BUSY_STS))
 			aspeed_i2c_recover_bus(bus);
 
+		/*
+		 * If timed out and the state is still pending, drop the pending
+		 * master command.
+		 */
+		spin_lock_irqsave(&bus->lock, flags);
+		if (bus->master_state == ASPEED_I2C_MASTER_PENDING)
+			bus->master_state = ASPEED_I2C_MASTER_INACTIVE;
+		spin_unlock_irqrestore(&bus->lock, flags);
+
 		return -ETIMEDOUT;
 	}
 
-- 
2.20.1


      parent reply	other threads:[~2019-10-30 15:54 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 15:48 [PATCH AUTOSEL 5.3 01/81] regulator: of: fix suspend-min/max-voltage parsing Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 02/81] ASoC: samsung: arndale: Add missing OF node dereferencing Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 03/81] ASoC: wm8994: Do not register inapplicable controls for WM1811 Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 04/81] regulator: da9062: fix suspend_enable/disable preparation Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 05/81] ASoC: topology: Fix a signedness bug in soc_tplg_dapm_widget_create() Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 06/81] arm64: dts: allwinner: a64: pine64-plus: Add PHY regulator delay Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 07/81] arm64: dts: allwinner: a64: Drop PMU node Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 08/81] arm64: dts: allwinner: a64: sopine-baseboard: Add PHY regulator delay Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 09/81] arm64: dts: Fix gpio to pinmux mapping Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 10/81] regulator: ti-abb: Fix timeout in ti_abb_wait_txdone/ti_abb_clear_all_txdone Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 11/81] pinctrl: intel: Allocate IRQ chip dynamic Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 12/81] ASoC: SOF: loader: fix kernel oops on firmware boot failure Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 13/81] ASoC: SOF: topology: fix parse fail issue for byte/bool tuple types Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 14/81] ASoC: SOF: Intel: hda: fix warnings during FW load Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 15/81] ASoC: SOF: Intel: initialise and verify FW crash dump data Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 16/81] ASoC: SOF: Intel: hda: Disable DMI L1 entry during capture Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 17/81] ASoC: rt5682: add NULL handler to set_jack function Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 18/81] ASoC: intel: sof_rt5682: add remove function to disable jack Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 19/81] ASoC: intel: bytcr_rt5651: add null check to support_button_press Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 20/81] regulator: pfuze100-regulator: Variable "val" in pfuze100_regulator_probe() could be uninitialized Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 21/81] ASoC: wm_adsp: Don't generate kcontrols without READ flags Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 22/81] ASoc: rockchip: i2s: Fix RPM imbalance Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 23/81] arm64: dts: rockchip: fix Rockpro64 RK808 interrupt line Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 24/81] ARM: dts: logicpd-torpedo-som: Remove twl_keypad Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 25/81] arm64: dts: rockchip: fix RockPro64 vdd-log regulator settings Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 26/81] arm64: dts: rockchip: fix RockPro64 sdhci settings Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 27/81] pinctrl: ns2: Fix off by one bugs in ns2_pinmux_enable() Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 28/81] pinctrl: stmfx: fix null pointer on remove Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 29/81] arm64: dts: zii-ultra: fix ARM regulator states Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 30/81] ARM: dts: am3874-iceboard: Fix 'i2c-mux-idle-disconnect' usage Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 31/81] ASoC: msm8916-wcd-digital: add missing MIX2 path for RX1/2 Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 32/81] ASoC: simple_card_utils.h: Fix potential multiple redefinition error Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 33/81] ARM: dts: Use level interrupt for omap4 & 5 wlcore Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 34/81] ARM: mm: fix alignment handler faults under memory pressure Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 35/81] scsi: qla2xxx: fix a potential NULL pointer dereference Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 36/81] scsi: scsi_dh_alua: handle RTPG sense code correctly during state transitions Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 37/81] scsi: sni_53c710: fix compilation error Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 38/81] scsi: fix kconfig dependency warning related to 53C700_LE_ON_BE Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 39/81] ARM: 8908/1: add __always_inline to functions called from __get_user_check() Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 40/81] ARM: 8914/1: NOMMU: Fix exc_ret for XIP Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 41/81] arm64: dts: rockchip: fix RockPro64 sdmmc settings Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 42/81] arm64: dts: rockchip: Fix usb-c on Hugsun X99 TV Box Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 43/81] arm64: dts: lx2160a: Correct CPU core idle state name Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 44/81] ARM: dts: imx6q-logicpd: Re-Enable SNVS power key Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 45/81] ARM: dts: vf610-zii-scu4-aib: Specify 'i2c-mux-idle-disconnect' Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 46/81] ARM: dts: imx7s: Correct GPT's ipg clock source Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 47/81] arm64: dts: imx8mq: Use correct clock for usdhc's ipg clk Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 48/81] arm64: dts: imx8mm: " Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 49/81] perf tools: Fix resource leak of closedir() on the error paths Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 50/81] perf c2c: Fix memory leak in build_cl_output() Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 51/81] USB: legousbtower: fix a signedness bug in tower_probe() Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 52/81] 8250-men-mcb: fix error checking when get_num_ports returns -ENODEV Sasha Levin
2019-10-30 15:48 ` [PATCH AUTOSEL 5.3 53/81] perf kmem: Fix memory leak in compact_gfp_flags() Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 54/81] ARM: davinci: dm365: Fix McBSP dma_slave_map entry Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 55/81] drm/amdgpu: fix potential VM faults Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 56/81] drm/amdgpu: fix error handling in amdgpu_bo_list_create Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 57/81] scsi: target: core: Do not overwrite CDB byte 1 Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 58/81] scsi: hpsa: add missing hunks in reset-patch Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 59/81] ASoC: Intel: sof-rt5682: add a check for devm_clk_get Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 60/81] ASoC: SOF: control: return true when kcontrol values change Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 61/81] tracing: Fix "gfp_t" format for synthetic events Sasha Levin
2019-10-30 15:49 ` [PATCH AUTOSEL 5.3 62/81] ARM: dts: bcm2837-rpi-cm3: Avoid leds-gpio probing issue Sasha Levin
2019-10-30 15:49 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191030154928.9432-63-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=brendanhiggins@google.com \
    --cc=jae.hyun.yoo@linux.intel.com \
    --cc=joel@jms.id.au \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=taoren@fb.com \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).