aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ia64/sn/kernel/misctest.c
blob: 974c95e6be175c489bd805d79ba570b9aa4be59e (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/* 
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 2000-2002 Silicon Graphics, Inc. All rights reserved.
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <asm/sn/sn_sal.h>
#include <asm/sn/sn_cpuid.h>
#include <asm/processor.h>
#include <asm/pgtable.h>
#include <asm/page.h>
#include <asm/timex.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/sn/intr.h>
#include <asm/hw_irq.h>
#include <asm/sn/leds.h>

extern	int autotest_enabled;
long	mcatest=0, debug0, debug1, debug2, debug3;

#define HDELAY(t)	(IS_RUNNING_ON_SIMULATOR() ? udelay(1) : udelay(t))

/* 
 * mcatest
 *	mactest contains a decimal number (RPTT) where
 *		R - flag, if non zero, run forever
 *
 *		P - identifies when to run the test
 *		    0 execute test at cpu 0 early init
 *		    1 execute test at cpu 0 idle
 *		    2 execute test at last (highest numbered) cpu idle
 *		    3 execute test on all cpus at idle
 *
 *		TT- identifies test to run
 *		    01 = MCA via dup TLB dropin
 *		    02 = MCA via garbage address
 *		    03 = lfetch via garbage address
 *		    05 = INIT self
 *		    06 = INIT other cpu
 *		    07 = INIT non-existent cpu
 *		    10 = IPI stress test. Target cpu 0
 *		    11 = IPI stress test. Target all cpus
 *		    12 = TLB stress test
 *		    13 = Park cpu (spinloop)
 *		    14 = One shot TLB test with tlb spinlock
 *		    15 = One shot TLB test
 *		    16 = One shot TLB test sync'ed with RTC
 *		    20 = set led to the cpuid & spin.
 *		    21 = Try mixed cache/uncached refs & see what happens
 *		    22 = Call SAL reboot
 *		    23 = Call PAL halt
 */
static int __init set_mcatest(char *str)
{
	int	val;
	get_option(&str, &val);
	mcatest = val;
	return 1;
}
__setup("mcatest=", set_mcatest);

static int __init set_debug0(char *str)
{
	int	val;
	get_option(&str, &val);
	debug0 = val;
	return 1;
}
__setup("debug0=", set_debug0);

static int __init set_debug1(char *str)
{
	int	val;
	get_option(&str, &val);
	debug1 = val;
	return 1;
}
__setup("debug1=", set_debug1);

static int __init set_debug2(char *str)
{
	int	val;
	get_option(&str, &val);
	debug2 = val;
	return 1;
}
__setup("debug2=", set_debug2);

static int __init set_debug3(char *str)
{
	int	val;
	get_option(&str, &val);
	debug3 = val;
	return 1;
}
__setup("debug3=", set_debug3);

static volatile int	go;

static void
do_sync(int pos) {
	if (pos != 3)
		return;
	else if (smp_processor_id() == 0)
		go = 1;
	else
		while (!go);
}

static void
sgi_mcatest_bkpt(void)
{
}


/*
 * Optional test
 *	pos - 0 called from early init
 *	pos - called when cpu about to go idle (fully initialized
 */
void
sgi_mcatest(int pos)
{
	long	spos, test, repeat;
	int	cpu, curcpu, i, n;

	//if (IS_RUNNING_ON_SIMULATOR()) mcatest=1323;
	repeat = mcatest/1000;
	spos = (mcatest/100)%10;
	test = mcatest % 100;
	curcpu = smp_processor_id();

	if ( mcatest == 0 || !((pos == 0 && spos == 0) ||
		(pos == 1 && spos == 3) ||
	        (pos == 1 && spos == 1 && curcpu == 0) ||
	        (pos == 1 && spos == 2 && curcpu == smp_num_cpus-1)))
		return;
	     
again:
	if (test == 1 || test == 2 || test == 3) {
		void zzzmca(int);
		printk("CPU %d: About to cause unexpected MCA\n", curcpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		zzzmca(test-1);
	
		HDELAY(100000);
	}

	if (test == 4) {
		long    result, adrs[] = {0xe0021000009821e0UL, 0xc0003f3000000000UL, 0xc0000081101c0000UL, 0xc00000180e021004UL,  0xc00000180e022004UL, 0xc00000180e023004UL };
		long    size[] = {1,2,4,8};
		int     r, i, j, k;

		for (k=0; k<2; k++) {
			for (i=0; i<6; i++) {
				for (j=0; j<4; j++) {
					printk("Probing 0x%lx, size %ld\n", adrs[i], size[j]);
					result = -1;
					r = ia64_sn_probe_io_slot (adrs[i], size[j], &result);
					printk("    status %d, val 0x%lx\n", r, result);
					udelay(100000);
				}
			}
		}

	}

	if (test == 5) {
		cpu =  curcpu;
		printk("CPU %d: About to send INIT to self (cpu %d)\n", curcpu, cpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		platform_send_ipi(cpu, 0, IA64_IPI_DM_INIT, 0);
		
		HDELAY(100000);
		printk("CPU %d: Returned from INIT\n", curcpu);
	}

	if (test == 6) {
		cpu =  curcpu ^ 1;
		printk("CPU %d: About to send INIT to other cpu (cpu %d)\n", curcpu, cpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		platform_send_ipi(cpu, 0, IA64_IPI_DM_INIT, 0);

		HDELAY(100000);
		printk("CPU %d: Done\n", curcpu);
	}

	if (test == 7) {
		printk("CPU %d: About to send INIT to non-existent cpu\n", curcpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		sn_send_IPI_phys(0xffff, 0, IA64_IPI_DM_INIT);

		HDELAY(100000);
		printk("CPU %d: Done\n", curcpu);
	}

	if (test == 10) {
		n = IS_RUNNING_ON_SIMULATOR() ? 10 : 10000000;
		cpu = 0;
		printk("CPU %d: IPI stress test. Target cpu 0\n", curcpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		for (i=0; i<n; i++)
			platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);

		HDELAY(100000);
		printk("CPU %d: Done\n", curcpu);
	}

	if (test == 11) {
		n = IS_RUNNING_ON_SIMULATOR() ? 100 : 10000000;
		printk("CPU %d: IPI stress test. Target all cpus\n", curcpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		for (i=0; i<n; i++)
			for (cpu=0; cpu<smp_num_cpus; cpu++)
				if (smp_num_cpus > 2 && cpu != curcpu)
					platform_send_ipi(cpu, IA64_IPI_RESCHEDULE, IA64_IPI_DM_INT, 0);

		HDELAY(100000);
		printk("CPU %d: Done\n", curcpu);
	}

	if (test == 12) {
		long adr = 0xe002200000000000UL;
		n = IS_RUNNING_ON_SIMULATOR() ? 1000 : 100000;
		printk("CPU %d: TLB flush stress test\n", curcpu);
		HDELAY(100000);
		sgi_mcatest_bkpt();
		do_sync(spos);

		for (i=0; i<n; i++)
			platform_global_tlb_purge(adr, adr+25*PAGE_SIZE, 14);

		HDELAY(100000);
		printk("CPU %d: Done\n", curcpu);
	}
	
	if (test == 13) {
		printk("CPU %d: Park cpu in spinloop\n", curcpu);
		while(1);
	}
	if (test == 14 || test == 15 || test == 16 || test == 17) {
		long adr = 0xe002200000000000UL;
		static int inited=0;
		if (inited == 0) {
			if (debug0 == 0) debug0 = 1;
			repeat = 1;
			do_sync(spos);
			if (curcpu >= smp_num_cpus-2) {
				printk("Parking cpu %d\n", curcpu);
				local_irq_disable();
				while(1);
			} else {
				printk("Waiting cpu %d\n", curcpu);
				HDELAY(1000000);
			}
			HDELAY(1000000);
			inited = 1;
		}
		if (test == 16 || test == 17) {
			unsigned long t, shift, mask;
			mask =  (smp_num_cpus > 16) ? 0x1f : 0xf;
			shift = 25-debug1;
			do {
				t = get_cycles();
				if (IS_RUNNING_ON_SIMULATOR())
					t = (t>>8);
				else
					t = (t>>shift);
				t = t & mask;
			} while (t == curcpu);
			do {
				t = get_cycles();
				if (IS_RUNNING_ON_SIMULATOR())
					t = (t>>8);
				else
					t = (t>>shift);
				t = t & mask;
			} while (t != curcpu);
		}
		if(debug3) printk("CPU %d: One TLB start\n", curcpu);
		if (test != 17) platform_global_tlb_purge(adr, adr+PAGE_SIZE*debug0, 14);
		if(debug3) printk("CPU %d: One TLB flush done\n", curcpu);
	}
	if (test == 20) {
		local_irq_disable();
		set_led_bits(smp_processor_id(), 0xff);
		while(1);
	}
	if (test == 21) {
		extern long ia64_mca_stack[];
		int		i, n;
		volatile long	*p, *up;
		p = (volatile long*)__imva(ia64_mca_stack);
		up = (volatile long*)(__pa(p) | __IA64_UNCACHED_OFFSET);

		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ get data in cache\n");
		for (n=0, i=0; i<100; i++)
			n += *(p+i);
		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ Make uncached refs to same data\n");
		for (n=0, i=0; i<100; i++)
			n += *(up+i);
		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ dirty the data via cached refs\n");
		for (n=0, i=0; i<100; i++)
			*(p+i) = i;
		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ Make uncached refs to same data\n");
		for (n=0, i=0; i<100; i++)
			n += *(up+i);
		if(!IS_RUNNING_ON_SIMULATOR()) printk("ZZZ Flushing cache\n");
		for (n=0, i=0; i<100; i++)
			ia64_fc((void*)(p+i));
		printk("ZZZ done\n");
	}
	if (test == 21) {
		int i;
		volatile long tb, t[10];
		for (i=0; i<10; i++) {
			tb = debug3+ia64_get_itc();
			sgi_mcatest_bkpt();
			t[i] = ia64_get_itc() - tb;
		}
		for (i=0; i<10; i++) {
			printk("ZZZ NULL  0x%lx\n", t[i]);
		}
		for (i=0; i<10; i++) {
			tb = debug3+ia64_get_itc();
			ia64_pal_call_static(PAL_MC_DRAIN, 0, 0, 0, 0);
			t[i] = ia64_get_itc() - tb;
		}
		for (i=0; i<10; i++) {
			printk("ZZZ DRAIN 0x%lx\n", t[i]);
		}
	}
	if (test == 22) {
		extern void machine_restart(char*);
		printk("ZZZ machine_restart\n");
		machine_restart(0);
	}
	if (test == 23) {
		printk("ZZZ ia64_pal_halt_light\n");
		ia64_pal_halt_light();
	}
	if (repeat)
		goto again;

}