xref: /freebsd/sys/dev/sfxge/common/efx_mon.c (revision 907b59d76938e654f0d040a888e8dfca3de1e222)
1 /*-
2  * Copyright (c) 2007-2016 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 	"sfx90x0",
46 	"sfx91x0",
47 	"sfx92x0"
48 };
49 
50 		const char *
51 efx_mon_name(
52 	__in	efx_nic_t *enp)
53 {
54 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
55 
56 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
57 
58 	EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID);
59 	EFSYS_ASSERT3U(encp->enc_mon_type, <, EFX_MON_NTYPES);
60 	return (__efx_mon_name[encp->enc_mon_type]);
61 }
62 
63 #endif	/* EFSYS_OPT_NAMES */
64 
65 #if EFSYS_OPT_MON_MCDI
66 static const efx_mon_ops_t	__efx_mon_mcdi_ops = {
67 #if EFSYS_OPT_MON_STATS
68 	mcdi_mon_stats_update		/* emo_stats_update */
69 #endif	/* EFSYS_OPT_MON_STATS */
70 };
71 #endif
72 
73 
74 	__checkReturn	efx_rc_t
75 efx_mon_init(
76 	__in		efx_nic_t *enp)
77 {
78 	efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
79 	efx_mon_t *emp = &(enp->en_mon);
80 	const efx_mon_ops_t *emop;
81 	efx_rc_t rc;
82 
83 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
84 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
85 
86 	if (enp->en_mod_flags & EFX_MOD_MON) {
87 		rc = EINVAL;
88 		goto fail1;
89 	}
90 
91 	enp->en_mod_flags |= EFX_MOD_MON;
92 
93 	emp->em_type = encp->enc_mon_type;
94 
95 	EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID);
96 	switch (emp->em_type) {
97 #if EFSYS_OPT_MON_MCDI
98 	case EFX_MON_SFC90X0:
99 	case EFX_MON_SFC91X0:
100 	case EFX_MON_SFC92X0:
101 		emop = &__efx_mon_mcdi_ops;
102 		break;
103 #endif
104 	default:
105 		rc = ENOTSUP;
106 		goto fail2;
107 	}
108 
109 	emp->em_emop = emop;
110 	return (0);
111 
112 fail2:
113 	EFSYS_PROBE(fail2);
114 
115 	emp->em_type = EFX_MON_INVALID;
116 
117 	enp->en_mod_flags &= ~EFX_MOD_MON;
118 
119 fail1:
120 	EFSYS_PROBE1(fail1, efx_rc_t, rc);
121 
122 	return (rc);
123 }
124 
125 #if EFSYS_OPT_MON_STATS
126 
127 #if EFSYS_OPT_NAMES
128 
129 /* START MKCONFIG GENERATED MonitorStatNamesBlock 31f437eafb0b0437 */
130 static const char 	*__mon_stat_name[] = {
131 	"value_2_5v",
132 	"value_vccp1",
133 	"value_vcc",
134 	"value_5v",
135 	"value_12v",
136 	"value_vccp2",
137 	"value_ext_temp",
138 	"value_int_temp",
139 	"value_ain1",
140 	"value_ain2",
141 	"controller_cooling",
142 	"ext_cooling",
143 	"1v",
144 	"1_2v",
145 	"1_8v",
146 	"3_3v",
147 	"1_2va",
148 	"vref",
149 	"vaoe",
150 	"aoe_temperature",
151 	"psu_aoe_temperature",
152 	"psu_temperature",
153 	"fan0",
154 	"fan1",
155 	"fan2",
156 	"fan3",
157 	"fan4",
158 	"vaoe_in",
159 	"iaoe",
160 	"iaoe_in",
161 	"nic_power",
162 	"0_9v",
163 	"i0_9v",
164 	"i1_2v",
165 	"0_9v_adc",
166 	"controller_temperature2",
167 	"vreg_temperature",
168 	"vreg_0_9v_temperature",
169 	"vreg_1_2v_temperature",
170 	"int_vptat",
171 	"controller_internal_adc_temperature",
172 	"ext_vptat",
173 	"controller_external_adc_temperature",
174 	"ambient_temperature",
175 	"airflow",
176 	"vdd08d_vss08d_csr",
177 	"vdd08d_vss08d_csr_extadc",
178 	"hotpoint_temperature",
179 	"phy_power_switch_port0",
180 	"phy_power_switch_port1",
181 	"mum_vcc",
182 	"0v9_a",
183 	"i0v9_a",
184 	"0v9_a_temp",
185 	"0v9_b",
186 	"i0v9_b",
187 	"0v9_b_temp",
188 	"ccom_avreg_1v2_supply",
189 	"ccom_avreg_1v2_supply_ext_adc",
190 	"ccom_avreg_1v8_supply",
191 	"ccom_avreg_1v8_supply_ext_adc",
192 	"controller_master_vptat",
193 	"controller_master_internal_temp",
194 	"controller_master_vptat_ext_adc",
195 	"controller_master_internal_temp_ext_adc",
196 	"controller_slave_vptat",
197 	"controller_slave_internal_temp",
198 	"controller_slave_vptat_ext_adc",
199 	"controller_slave_internal_temp_ext_adc",
200 	"sodimm_vout",
201 	"sodimm_0_temp",
202 	"sodimm_1_temp",
203 	"phy0_vcc",
204 	"phy1_vcc",
205 	"controller_tdiode_temp",
206 	"board_front_temp",
207 	"board_back_temp",
208 };
209 
210 /* END MKCONFIG GENERATED MonitorStatNamesBlock */
211 
212 extern					const char *
213 efx_mon_stat_name(
214 	__in				efx_nic_t *enp,
215 	__in				efx_mon_stat_t id)
216 {
217 	_NOTE(ARGUNUSED(enp))
218 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
219 
220 	EFSYS_ASSERT3U(id, <, EFX_MON_NSTATS);
221 	return (__mon_stat_name[id]);
222 }
223 
224 #endif	/* EFSYS_OPT_NAMES */
225 
226 	__checkReturn			efx_rc_t
227 efx_mon_stats_update(
228 	__in				efx_nic_t *enp,
229 	__in				efsys_mem_t *esmp,
230 	__inout_ecount(EFX_MON_NSTATS)	efx_mon_stat_value_t *values)
231 {
232 	efx_mon_t *emp = &(enp->en_mon);
233 	const efx_mon_ops_t *emop = emp->em_emop;
234 
235 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
236 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON);
237 
238 	return (emop->emo_stats_update(enp, esmp, values));
239 }
240 
241 #endif	/* EFSYS_OPT_MON_STATS */
242 
243 		void
244 efx_mon_fini(
245 	__in	efx_nic_t *enp)
246 {
247 	efx_mon_t *emp = &(enp->en_mon);
248 
249 	EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
250 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
251 	EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON);
252 
253 	emp->em_emop = NULL;
254 
255 	emp->em_type = EFX_MON_INVALID;
256 
257 	enp->en_mod_flags &= ~EFX_MOD_MON;
258 }
259