xref: /illumos-gate/usr/src/lib/libprtdiag/inc/libprtdiag.h (revision 528737823843346cf95a4a701612f82089135554)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  * Copyright 2020 Peter Tribble.
25  */
26 
27 #ifndef	_SYS_LIBPRTDIAG_H
28 #define	_SYS_LIBPRTDIAG_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/openpromio.h>
35 #include <sys/cheetahregs.h>
36 #include "pdevinfo.h"
37 #include "display.h"
38 #include "pdevinfo_sun4u.h"
39 #include "display_sun4u.h"
40 
41 #ifdef DEBUG
42 #define	D_PRINTF printf
43 #else
44 #define	D_PRINTF
45 #endif
46 
47 #define	EXIT_MSG(msg, err) \
48 	{ printf("\n%s failed with %d\n", msg, err); exit(err); }
49 
50 /* global data */
51 #define	PCI_DEVICE(x)		((x  >> 11) & 0x1f)
52 #define	PCI_REG_TO_DEV(x)	((x & 0xf800) >> 11)
53 #define	PCI_REG_TO_FUNC(x)	((x & 0x700) >> 8)
54 #define	BUS_TYPE		"UPA"
55 #define	MAX_SLOTS_PER_IO_BD	8
56 
57 
58 int	sys_clk;  /* System clock freq. (in MHz) */
59 
60 /*
61  * Defines for identifying PCI devices
62  */
63 #define	PCI_BRIDGE_CLASS		0x6
64 #define	PCI_CLASS_SHIFT			0x10
65 #define	PCI_PCI_BRIDGE_SUBCLASS		0x4
66 #define	PCI_SUBCLASS_SHIFT		0x8
67 #define	PCI_SUBCLASS_MASK		0xFF00
68 #define	PCI_SUBCLASS_OTHER		0x80
69 
70 #define	CLASS_REG_TO_SUBCLASS(class)	(((class) & PCI_SUBCLASS_MASK) \
71 						>> PCI_SUBCLASS_SHIFT)
72 #define	CLASS_REG_TO_CLASS(class)	((class) >> PCI_CLASS_SHIFT)
73 
74 /*
75  * display functions
76  */
77 int	error_check(Sys_tree *tree, struct system_kstat_data *kstats);
78 int	disp_fail_parts(Sys_tree *tree);
79 void	display_hp_fail_fault(Sys_tree *tree, struct system_kstat_data *kstats);
80 void	display_diaginfo(int flag, Prom_node *root, Sys_tree *tree,
81 	    struct system_kstat_data *kstats);
82 void	resolve_board_types(Sys_tree *);
83 void	display_boardnum(int num);
84 void	display_platform_specific_header(void);
85 
86 /*
87  * cpu functions
88  */
89 void	display_cpu_devices(Sys_tree *);
90 void	display_cpus(Board_node *);
91 void	display_mid(int mid);
92 uint_t	get_cpu_freq(Prom_node *);
93 int	get_ecache_size(Prom_node *);
94 
95 /*
96  * io functions
97  */
98 Prom_node *find_pci_bus(Prom_node *, int, int);
99 int	get_pci_bus(Prom_node *);
100 int	get_pci_device(Prom_node *);
101 int	get_pci_to_pci_device(Prom_node *);
102 void	free_io_cards(struct io_card *);
103 struct	io_card *insert_io_card(struct io_card *, struct io_card *);
104 char	*fmt_manf_id(unsigned int, char *);
105 int	get_sbus_slot(Prom_node *);
106 void	display_io_devices(Sys_tree *tree);
107 void	display_pci(Board_node *bnode);
108 void	display_io_cards(struct io_card *);
109 void	display_ffb(Board_node *, int);
110 void	display_sbus(Board_node *);
111 int	populate_slot_name_arr(Prom_node *pci, int *slot_name_bits,
112 	char **slot_name_arr, int num_slots);
113 int	get_card_frequency(Prom_node *pci);
114 void	get_dev_func_num(Prom_node *card_node, int *dev_no, int *func_no);
115 void	get_pci_class_codes(Prom_node *card_node, int *class_code,
116 	int *subclass_code);
117 int	is_pci_bridge(Prom_node *card_node, char *name);
118 int	is_pci_bridge_other(Prom_node *card_node, char *name);
119 void	get_pci_card_model(Prom_node *card_node, char *model);
120 void	create_io_card_name(Prom_node *card_node, char *name,
121 	char *card_name);
122 void	display_psycho_pci(Board_node *bnode);
123 void	get_slot_number_str(struct io_card *card, char **slot_name_arr,
124 	int slot_name_bits);
125 void	distinguish_identical_io_cards(char *name, Prom_node *node,
126 		struct io_card *card);
127 void	decode_qlc_card_model_prop(Prom_node *card_node, struct io_card *card);
128 
129 /*
130  * kstat functions
131  */
132 void	read_platform_kstats(Sys_tree *tree,
133 	    struct system_kstat_data *sys_kstat,
134 	    struct envctrl_kstat_data *ep);
135 void	read_sun4u_kstats(Sys_tree *, struct system_kstat_data *);
136 
137 /*
138  * memory functions
139  */
140 void	display_memorysize(Sys_tree *tree, struct system_kstat_data *kstats,
141 	    struct mem_total *memory_total);
142 void	display_memoryconf(Sys_tree *tree);
143 
144 /*
145  * prom functions
146  */
147 void	platform_disp_prom_version(Sys_tree *);
148 void	disp_prom_version(Prom_node *);
149 void	add_node(Sys_tree *, Prom_node *);
150 Prom_node *find_device(Board_node *, int, char *);
151 Prom_node *walk(Sys_tree *, Prom_node *, int);
152 int	get_pci_class_code_reg(Prom_node *);
153 
154 /*
155  * libdevinfo functions
156  */
157 int	do_devinfo(int, char *, int, int);
158 
159 /*
160  * mc-us3 memory functions and structs
161  */
162 typedef struct memory_bank {
163 	int			id;
164 	int			portid;
165 	ushort_t		valid;
166 	ushort_t		uk;
167 	uint_t			um;
168 	uchar_t			lk;
169 	uchar_t			lm;
170 	uint64_t		bank_size;
171 	char			*bank_status;
172 	struct memory_bank	*next;		/* mc in the devtree */
173 	struct memory_bank	*seg_next;	/* in the segment */
174 } memory_bank_t;
175 
176 typedef struct memory_seg {
177 	int			id;
178 	int			intlv;  /* interleave for this segment */
179 	uint64_t		base;   /* base address for this segment */
180 	uint64_t		size;   /* size of this segment */
181 	int			nbanks; /* number of banks in this segment */
182 	memory_bank_t		*banks; /* pointer to the banks of this seg */
183 	struct memory_seg	*next;
184 } memory_seg_t;
185 
186 #define	NUM_MBANKS_PER_MC		4
187 
188 int	get_us3_mem_regs(Board_node *bnode);
189 void	display_us3_banks(void);
190 int	display_us3_failed_banks(int system_failed);
191 void    print_us3_memory_line(int portid, int bank_id, uint64_t bank_size,
192 	    char *bank_status, uint64_t dimm_size, uint32_t intlv, int seg_id);
193 void	print_us3_failed_memory_line(int portid, int bank_id,
194 	    char *bank_status);
195 
196 #ifdef	__cplusplus
197 }
198 #endif
199 
200 #endif	/* _SYS_LIBPRTDIAG_H */
201