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