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