summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/powerpc/scripts/hmi.sh
blob: 83fb253ae3bd35b4150c9d7ffa6019791492a15d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
#
# Copyright 2015, Daniel Axtens, IBM Corporation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.


# do we have ./getscom, ./putscom?
if [ -x ./getscom ] && [ -x ./putscom ]; then
	GETSCOM=./getscom
	PUTSCOM=./putscom
elif which getscom > /dev/null; then
	GETSCOM=$(which getscom)
	PUTSCOM=$(which putscom)
else
	cat <<EOF
Can't find getscom/putscom in . or \$PATH.
See https://github.com/open-power/skiboot.
The tool is in external/xscom-utils
EOF
	exit 1
fi

# We will get 8 HMI events per injection
# todo: deal with things being offline
expected_hmis=8
COUNT_HMIS() {
    dmesg | grep -c 'Harmless Hypervisor Maintenance interrupt'
}

# massively expand snooze delay, allowing injection on all cores
ppc64_cpu --smt-snooze-delay=1000000000

# when we exit, restore it
trap "ppc64_cpu --smt-snooze-delay=100" 0 1

# for each chip+core combination
# todo - less fragile parsing
egrep -o 'OCC: Chip [0-9a-f]+ Core [0-9a-f]' < /sys/firmware/opal/msglog |
while read chipcore; do
	chip=$(echo "$chipcore"|awk '{print $3}')
	core=$(echo "$chipcore"|awk '{print $5}')
	fir="0x1${core}013100"

	# verify that Core FIR is zero as expected
	if [ "$($GETSCOM -c 0x${chip} $fir)" != 0 ]; then
		echo "FIR was not zero before injection for chip $chip, core $core. Aborting!"
		echo "Result of $GETSCOM -c 0x${chip} $fir:"
		$GETSCOM -c 0x${chip} $fir
		echo "If you get a -5 error, the core may be in idle state. Try stress-ng."
		echo "Otherwise, try $PUTSCOM -c 0x${chip} $fir 0"
		exit 1
	fi

	# keep track of the number of HMIs handled
	old_hmis=$(COUNT_HMIS)

	# do injection, adding a marker to dmesg for clarity
	echo "Injecting HMI on core $core, chip $chip" | tee /dev/kmsg
	# inject a RegFile recoverable error
	if ! $PUTSCOM -c 0x${chip} $fir 2000000000000000 > /dev/null; then
		echo "Error injecting. Aborting!"
		exit 1
	fi

	# now we want to wait for all the HMIs to be processed
	# we expect one per thread on the core
	i=0;
	new_hmis=$(COUNT_HMIS)
	while [ $new_hmis -lt $((old_hmis + expected_hmis)) ] && [ $i -lt 12 ]; do
	    echo "Seen $((new_hmis - old_hmis)) HMI(s) out of $expected_hmis expected, sleeping"
	    sleep 5;
	    i=$((i + 1))
	    new_hmis=$(COUNT_HMIS)
	done
	if [ $i = 12 ]; then
	    echo "Haven't seen expected $expected_hmis recoveries after 1 min. Aborting."
	    exit 1
	fi
	echo "Processed $expected_hmis events; presumed success. Check dmesg."
	echo ""
done
on based on DAT[0] monitoring is enabled. 2) Later during run time, since card reported to support internal caches, a MMCI_SWITCH command is sent to eMMC device with FLUSH_CACHE operation. On receiving this command, eMMC may enter busy state (for a relatively short time in the case of the dead-lock). 3) Then mmci interrupt is raised and mmci_irq() is called: MMCISTATUS register is read and is equal to 0x01000440. So the following status bits are set: - MCI_CMDRESPEND (= 6) - MCI_DATABLOCKEND (= 10) - MCI_ST_CARDBUSY (= 24) Since MMCIMASK0 register is 0x3FF, status variable is set to 0x00000040 and BIT MCI_CMDRESPEND is cleared by writing MMCICLEAR register. Then mmci_cmd_irq() is called. Considering the following conditions: - host->busy_status is 0, - this is a "busy response", - reading again MMCISTATUS register gives 0x1000400, MMCIMASK0 is updated to unmask MCI_ST_BUSYEND bit. Thus, MMCIMASK0 is set to 0x010003FF and host->busy_status is set to wait for busy end completion. Back again in status loop of mmci_irq(), we quickly go through mmci_data_irq() as there are no data in that case. And we finally go through following test at the end of while(status) loop: /* * Don't poll for busy completion in irq context. */ if (host->variant->busy_detect && host->busy_status) status &= ~host->variant->busy_detect_flag; Because status variable is not yet null (is equal to 0x40), we do not leave interrupt context yet but we loop again into while(status) loop. So we run across following steps: a) MMCISTATUS register is read again and this time is equal to 0x01000400. So that following bits are set: - MCI_DATABLOCKEND (= 10) - MCI_ST_CARDBUSY (= 24) Since MMCIMASK0 register is equal to 0x010003FF: b) status variable is set to 0x01000000. c) MCI_ST_CARDBUSY bit is cleared by writing MMCICLEAR register. Then, mmci_cmd_irq() is called one more time. Since host->busy_status is set and that MCI_ST_CARDBUSY is set in status variable, we just return from this function. Back again in mmci_irq(), status variable is set to 0 and we finally leave the while(status) loop. As a result we leave interrupt context, waiting for busy end interrupt event. Now, consider that busy end completion is raised IN BETWEEN steps 3.a) and 3.c). In such a case, we may mistakenly clear busy end interrupt at step 3.c) while it has not yet been processed. This will result in mmc command to wait forever for a busy end completion that will never happen. To fix the problem, this patch implements the following changes: Considering that the mmci seems to be triggering the IRQ on both edges while monitoring DAT0 for busy completion and that same status bit is used to monitor start and end of busy detection, special care must be taken to make sure that both start and end interrupts are always cleared one after the other. 1) Clearing of card busy bit is moved in mmc_cmd_irq() function where unmasking of busy end bit is effectively handled. 2) Just before unmasking busy end event, busy start event is cleared by writing card busy bit in MMCICLEAR register. 3) Finally, once we are no more busy with a command, busy end event is cleared writing again card busy bit in MMCICLEAR register. This patch has been tested with the ST Accordo5 machine, not yet supported upstream but relies on the mmci driver. Signed-off-by: Sarang Mairal <sarang.mairal@garmin.com> Signed-off-by: Jean-Nicolas Graux <jean-nicolas.graux@st.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Tested-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/usb/renesas_usbhs/common.c')