xref: /freebsd/sys/dev/sfxge/common/efx_mon.c (revision 079171874c9bf263b69e3af10784ad2bcd1fe699)
1 /*-
2  * Copyright (c) 2007-2015 Solarflare Communications Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are
27  * those of the authors and should not be interpreted as representing official
28  * policies, either expressed or implied, of the FreeBSD Project.
29  */
30 
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
33 
34 #include "efx.h"
35 #include "efx_impl.h"
36 
37 #if EFSYS_OPT_MON_MCDI
38 #include "mcdi_mon.h"
39 #endif
40 
41 #if EFSYS_OPT_NAMES
42 
43 static const char	*__efx_mon_name[] = {
44 	"",
45 	"nullmon",
46 	"lm87",
47 	"max6647",
48 	"sfx90x0",
49 	"sfx91x0"
50 	"sfx92x0"
51 };
52 
53 		const char *
54 efx_mon_name(
55 	__in	efx_nic_t *enp)
56 {
57 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
58 
59 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
60 
61 	EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID);
62 	EFSYS_ASSERT3U(encp->enc_mon_type, <, EFX_MON_NTYPES);
63 	return (__efx_mon_name[encp->enc_mon_type]);
64 }
65 
66 #endif	/* EFSYS_OPT_NAMES */
67 
68 #if EFSYS_OPT_MON_MCDI
69 static const efx_mon_ops_t	__efx_mon_mcdi_ops = {
70 	NULL,				/* emo_reset */
71 	NULL,				/* emo_reconfigure */
72 #if EFSYS_OPT_MON_STATS
73 	mcdi_mon_stats_update		/* emo_stats_update */
74 #endif	/* EFSYS_OPT_MON_STATS */
75 };
76 #endif
77 
78 
79 	__checkReturn	efx_rc_t
80 efx_mon_init(
81 	__in		efx_nic_t *enp)
82 {
83 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
84 	efx_mon_t *emp = &(enp->en_mon);
85 	const efx_mon_ops_t *emop;
86 	efx_rc_t rc;
87 
88 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
89 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
90 
91 	if (enp->en_mod_flags & EFX_MOD_MON) {
92 		rc = EINVAL;
93 		goto fail1;
94 	}
95 
96 	enp->en_mod_flags |= EFX_MOD_MON;
97 
98 	emp->em_type = encp->enc_mon_type;
99 
100 	EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID);
101 	switch (emp->em_type) {
102 #if EFSYS_OPT_MON_MCDI
103 	case EFX_MON_SFC90X0:
104 	case EFX_MON_SFC91X0:
105 	case EFX_MON_SFC92X0:
106 		emop = &__efx_mon_mcdi_ops;
107 		break;
108 #endif
109 	default:
110 		rc = ENOTSUP;
111 		goto fail2;
112 	}
113 
114 	if (emop->emo_reset != NULL) {
115 		if ((rc = emop->emo_reset(enp)) != 0)
116 			goto fail3;
117 	}
118 
119 	if (emop->emo_reconfigure != NULL) {
120 		if ((rc = emop->emo_reconfigure(enp)) != 0)
121 			goto fail4;
122 	}
123 
124 	emp->em_emop = emop;
125 	return (0);
126 
127 fail4:
128 	EFSYS_PROBE(fail5);
129 
130 	if (emop->emo_reset != NULL)
131 		(void) emop->emo_reset(enp);
132 
133 fail3:
134 	EFSYS_PROBE(fail4);
135 fail2:
136 	EFSYS_PROBE(fail3);
137 
138 	emp->em_type = EFX_MON_INVALID;
139 
140 	enp->en_mod_flags &= ~EFX_MOD_MON;
141 
142 fail1:
143 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
144 
145 	return (rc);
146 }
147 
148 #if EFSYS_OPT_MON_STATS
149 
150 #if EFSYS_OPT_NAMES
151 
152 /* START MKCONFIG GENERATED MonitorStatNamesBlock 31f437eafb0b0437 */
153 static const char 	*__mon_stat_name[] = {
154 	"value_2_5v",
155 	"value_vccp1",
156 	"value_vcc",
157 	"value_5v",
158 	"value_12v",
159 	"value_vccp2",
160 	"value_ext_temp",
161 	"value_int_temp",
162 	"value_ain1",
163 	"value_ain2",
164 	"controller_cooling",
165 	"ext_cooling",
166 	"1v",
167 	"1_2v",
168 	"1_8v",
169 	"3_3v",
170 	"1_2va",
171 	"vref",
172 	"vaoe",
173 	"aoe_temperature",
174 	"psu_aoe_temperature",
175 	"psu_temperature",
176 	"fan0",
177 	"fan1",
178 	"fan2",
179 	"fan3",
180 	"fan4",
181 	"vaoe_in",
182 	"iaoe",
183 	"iaoe_in",
184 	"nic_power",
185 	"0_9v",
186 	"i0_9v",
187 	"i1_2v",
188 	"0_9v_adc",
189 	"controller_temperature2",
190 	"vreg_temperature",
191 	"vreg_0_9v_temperature",
192 	"vreg_1_2v_temperature",
193 	"int_vptat",
194 	"controller_internal_adc_temperature",
195 	"ext_vptat",
196 	"controller_external_adc_temperature",
197 	"ambient_temperature",
198 	"airflow",
199 	"vdd08d_vss08d_csr",
200 	"vdd08d_vss08d_csr_extadc",
201 	"hotpoint_temperature",
202 	"phy_power_switch_port0",
203 	"phy_power_switch_port1",
204 	"mum_vcc",
205 	"0v9_a",
206 	"i0v9_a",
207 	"0v9_a_temp",
208 	"0v9_b",
209 	"i0v9_b",
210 	"0v9_b_temp",
211 	"ccom_avreg_1v2_supply",
212 	"ccom_avreg_1v2_supply_ext_adc",
213 	"ccom_avreg_1v8_supply",
214 	"ccom_avreg_1v8_supply_ext_adc",
215 	"controller_master_vptat",
216 	"controller_master_internal_temp",
217 	"controller_master_vptat_ext_adc",
218 	"controller_master_internal_temp_ext_adc",
219 	"controller_slave_vptat",
220 	"controller_slave_internal_temp",
221 	"controller_slave_vptat_ext_adc",
222 	"controller_slave_internal_temp_ext_adc",
223 	"sodimm_vout",
224 	"sodimm_0_temp",
225 	"sodimm_1_temp",
226 	"phy0_vcc",
227 	"phy1_vcc",
228 	"controller_tdiode_temp",
229 	"board_front_temp",
230 	"board_back_temp",
231 };
232 
233 /* END MKCONFIG GENERATED MonitorStatNamesBlock */
234 
235 extern					const char *
236 efx_mon_stat_name(
237 	__in				efx_nic_t *enp,
238 	__in				efx_mon_stat_t id)
239 {
240 	_NOTE(ARGUNUSED(enp))
241 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
242 
243 	EFSYS_ASSERT3U(id, <, EFX_MON_NSTATS);
244 	return (__mon_stat_name[id]);
245 }
246 
247 #endif	/* EFSYS_OPT_NAMES */
248 
249 	__checkReturn			efx_rc_t
250 efx_mon_stats_update(
251 	__in				efx_nic_t *enp,
252 	__in				efsys_mem_t *esmp,
253 	__inout_ecount(EFX_MON_NSTATS)	efx_mon_stat_value_t *values)
254 {
255 	efx_mon_t *emp = &(enp->en_mon);
256 	const efx_mon_ops_t *emop = emp->em_emop;
257 
258 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
259 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON);
260 
261 	return (emop->emo_stats_update(enp, esmp, values));
262 }
263 
264 #endif	/* EFSYS_OPT_MON_STATS */
265 
266 		void
267 efx_mon_fini(
268 	__in	efx_nic_t *enp)
269 {
270 	efx_mon_t *emp = &(enp->en_mon);
271 	const efx_mon_ops_t *emop = emp->em_emop;
272 	efx_rc_t rc;
273 
274 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
275 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
276 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON);
277 
278 	emp->em_emop = NULL;
279 
280 	if (emop->emo_reset != NULL) {
281 		rc = emop->emo_reset(enp);
282 		if (rc != 0)
283 			EFSYS_PROBE1(fail1, efx_rc_t, rc);
284 	}
285 
286 	emp->em_type = EFX_MON_INVALID;
287 
288 	enp->en_mod_flags &= ~EFX_MOD_MON;
289 }
290