xref: /illumos-gate/usr/src/lib/cfgadm_plugins/ac/common/mema_test.h (revision 86d949f9497332fe19be6b5d711d265eb957439f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1996-1998 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef _MEMA_TEST_H
28 #define	_MEMA_TEST_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct mtest_alloc_ent {
35 	struct mtest_alloc_ent	*next;
36 	void			*buf;
37 };
38 
39 struct mtest_handle {
40 	u_longlong_t		bank_size;
41 	ulong_t			page_size;
42 	ulong_t			line_size;
43 	ulong_t			lines_per_page;
44 	cfga_cond_t		condition;
45 	int			fd;
46 	ulong_t			max_errors;
47 	struct mtest_alloc_ent	*alloc_list;
48 	void			*drvhandle;
49 	struct cfga_msg		*msgp;
50 };
51 
52 typedef struct mtest_handle *mtest_handle_t;
53 
54 typedef int mtest_func_t(mtest_handle_t);
55 
56 struct mtest_table_ent {
57 	const char	*test_name;
58 	mtest_func_t	*test_func;
59 };
60 extern struct mtest_table_ent mtest_table[];
61 #define	MTEST_DEFAULT_TEST	(0)
62 extern char **mtest_build_opts(int *maxerr_idx);
63 
64 #define	BANK_SIZE(H)		((H)->bank_size)
65 #define	PAGE_SIZE(H)		((H)->page_size)
66 #define	LINE_SIZE(H)		((H)->line_size)
67 #define	LINES_PER_PAGE(H)	((H)->lines_per_page)
68 #define	SET_CONDITION(H, C)	((H)->condition = (C))
69 
70 struct mtest_error {
71 	int		error_type;
72 };
73 
74 /*
75  * Error types.
76  */
77 #define	MTEST_ERR_NONE		0
78 #define	MTEST_ERR_UE		1
79 #define	MTEST_ERR_CE		2
80 
81 /*
82  * Test routine return codes.
83  */
84 #define	MTEST_DONE		0
85 #define	MTEST_LIB_ERROR		1
86 #define	MTEST_DEV_ERROR		2
87 
88 /*
89  * Each test is allowed maximum number of errors and the index has
90  * to be coordinated with the token table size in mema_test_config.c
91  */
92 #define	MAX_ERRORS		32
93 #define	REPORT_SEC		5
94 
95 /*
96  * Test functions should use this buffer allocation interface.
97  * The test framework will deallocate them on return.
98  */
99 extern void *mtest_allocate_buf(mtest_handle_t, size_t);
100 #define	mtest_allocate_page_buf(H)	mtest_allocate_buf((H), \
101 					(size_t)PAGE_SIZE(H))
102 extern void mtest_deallocate_buf(mtest_handle_t, void *);
103 extern void mtest_deallocate_buf_all(mtest_handle_t);
104 
105 /*
106  * Test write: mtest_write(handle, buffer, page_num, line_offset, line_count)
107  * A line count of 0 indicates the whole page.
108  * A return of 0 indicates success.  A return of -1 indicates a failure of
109  * the device interface.
110  */
111 extern int mtest_write(mtest_handle_t, void *, u_longlong_t, uint_t, uint_t);
112 extern int mtest_read(mtest_handle_t, void *, u_longlong_t, uint_t, uint_t,
113     struct mtest_error *);
114 
115 /*
116  * Message interface. If the upper layer has verbose on, the
117  * message will be seen by the user.
118  */
119 extern void mtest_message(mtest_handle_t, const char *);
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif /* _MEMA_TEST_H */
126