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_NULL 38 #include "nullmon.h" 39 #endif 40 41 #if EFSYS_OPT_MON_LM87 42 #include "lm87.h" 43 #endif 44 45 #if EFSYS_OPT_MON_MAX6647 46 #include "max6647.h" 47 #endif 48 49 #if EFSYS_OPT_MON_MCDI 50 #include "mcdi_mon.h" 51 #endif 52 53 #if EFSYS_OPT_NAMES 54 55 static const char *__efx_mon_name[] = { 56 "", 57 "nullmon", 58 "lm87", 59 "max6647", 60 "sfx90x0", 61 "sfx91x0" 62 "sfx92x0" 63 }; 64 65 const char * 66 efx_mon_name( 67 __in efx_nic_t *enp) 68 { 69 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 70 71 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 72 73 EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID); 74 EFSYS_ASSERT3U(encp->enc_mon_type, <, EFX_MON_NTYPES); 75 return (__efx_mon_name[encp->enc_mon_type]); 76 } 77 78 #endif /* EFSYS_OPT_NAMES */ 79 80 #if EFSYS_OPT_MON_NULL 81 static efx_mon_ops_t __efx_mon_null_ops = { 82 nullmon_reset, /* emo_reset */ 83 nullmon_reconfigure, /* emo_reconfigure */ 84 #if EFSYS_OPT_MON_STATS 85 nullmon_stats_update /* emo_stats_update */ 86 #endif /* EFSYS_OPT_MON_STATS */ 87 }; 88 #endif 89 90 #if EFSYS_OPT_MON_LM87 91 static efx_mon_ops_t __efx_mon_lm87_ops = { 92 lm87_reset, /* emo_reset */ 93 lm87_reconfigure, /* emo_reconfigure */ 94 #if EFSYS_OPT_MON_STATS 95 lm87_stats_update /* emo_stats_update */ 96 #endif /* EFSYS_OPT_MON_STATS */ 97 }; 98 #endif 99 100 #if EFSYS_OPT_MON_MAX6647 101 static efx_mon_ops_t __efx_mon_max6647_ops = { 102 max6647_reset, /* emo_reset */ 103 max6647_reconfigure, /* emo_reconfigure */ 104 #if EFSYS_OPT_MON_STATS 105 max6647_stats_update /* emo_stats_update */ 106 #endif /* EFSYS_OPT_MON_STATS */ 107 }; 108 #endif 109 110 #if EFSYS_OPT_MON_MCDI 111 static efx_mon_ops_t __efx_mon_mcdi_ops = { 112 NULL, /* emo_reset */ 113 NULL, /* emo_reconfigure */ 114 #if EFSYS_OPT_MON_STATS 115 mcdi_mon_stats_update /* emo_stats_update */ 116 #endif /* EFSYS_OPT_MON_STATS */ 117 }; 118 #endif 119 120 121 __checkReturn efx_rc_t 122 efx_mon_init( 123 __in efx_nic_t *enp) 124 { 125 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 126 efx_mon_t *emp = &(enp->en_mon); 127 efx_mon_ops_t *emop; 128 efx_rc_t rc; 129 130 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 131 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE); 132 133 if (enp->en_mod_flags & EFX_MOD_MON) { 134 rc = EINVAL; 135 goto fail1; 136 } 137 138 enp->en_mod_flags |= EFX_MOD_MON; 139 140 emp->em_type = encp->enc_mon_type; 141 142 EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID); 143 switch (emp->em_type) { 144 #if EFSYS_OPT_MON_NULL 145 case EFX_MON_NULL: 146 emop = &__efx_mon_null_ops; 147 break; 148 #endif 149 #if EFSYS_OPT_MON_LM87 150 case EFX_MON_LM87: 151 emop = &__efx_mon_lm87_ops; 152 break; 153 #endif 154 #if EFSYS_OPT_MON_MAX6647 155 case EFX_MON_MAX6647: 156 emop = &__efx_mon_max6647_ops; 157 break; 158 #endif 159 #if EFSYS_OPT_MON_MCDI 160 case EFX_MON_SFC90X0: 161 case EFX_MON_SFC91X0: 162 case EFX_MON_SFC92X0: 163 emop = &__efx_mon_mcdi_ops; 164 break; 165 #endif 166 default: 167 rc = ENOTSUP; 168 goto fail2; 169 } 170 171 if (emop->emo_reset != NULL) { 172 if ((rc = emop->emo_reset(enp)) != 0) 173 goto fail3; 174 } 175 176 if (emop->emo_reconfigure != NULL) { 177 if ((rc = emop->emo_reconfigure(enp)) != 0) 178 goto fail4; 179 } 180 181 emp->em_emop = emop; 182 return (0); 183 184 fail4: 185 EFSYS_PROBE(fail5); 186 187 if (emop->emo_reset != NULL) 188 (void) emop->emo_reset(enp); 189 190 fail3: 191 EFSYS_PROBE(fail4); 192 fail2: 193 EFSYS_PROBE(fail3); 194 195 emp->em_type = EFX_MON_INVALID; 196 197 enp->en_mod_flags &= ~EFX_MOD_MON; 198 199 fail1: 200 EFSYS_PROBE1(fail1, efx_rc_t, rc); 201 202 return (rc); 203 } 204 205 #if EFSYS_OPT_MON_STATS 206 207 #if EFSYS_OPT_NAMES 208 209 /* START MKCONFIG GENERATED MonitorStatNamesBlock 01ee3ea01f23a0c4 */ 210 static const char *__mon_stat_name[] = { 211 "value_2_5v", 212 "value_vccp1", 213 "value_vcc", 214 "value_5v", 215 "value_12v", 216 "value_vccp2", 217 "value_ext_temp", 218 "value_int_temp", 219 "value_ain1", 220 "value_ain2", 221 "controller_cooling", 222 "ext_cooling", 223 "1v", 224 "1_2v", 225 "1_8v", 226 "3_3v", 227 "1_2va", 228 "vref", 229 "vaoe", 230 "aoe_temperature", 231 "psu_aoe_temperature", 232 "psu_temperature", 233 "fan0", 234 "fan1", 235 "fan2", 236 "fan3", 237 "fan4", 238 "vaoe_in", 239 "iaoe", 240 "iaoe_in", 241 "nic_power", 242 "0_9v", 243 "i0_9v", 244 "i1_2v", 245 "0_9v_adc", 246 "controller_temperature2", 247 "vreg_temperature", 248 "vreg_0_9v_temperature", 249 "vreg_1_2v_temperature", 250 "int_vptat", 251 "controller_internal_adc_temperature", 252 "ext_vptat", 253 "controller_external_adc_temperature", 254 "ambient_temperature", 255 "airflow", 256 "vdd08d_vss08d_csr", 257 "vdd08d_vss08d_csr_extadc", 258 "hotpoint_temperature", 259 "phy_power_switch_port0", 260 "phy_power_switch_port1", 261 "mum_vcc", 262 "0v9_a", 263 "i0v9_a", 264 "0v9_a_temp", 265 "0v9_b", 266 "i0v9_b", 267 "0v9_b_temp", 268 "ccom_avreg_1v2_supply", 269 "ccom_avreg_1v2_supply_ext_adc", 270 "ccom_avreg_1v8_supply", 271 "ccom_avreg_1v8_supply_ext_adc", 272 "controller_master_vptat", 273 "controller_master_internal_temp", 274 "controller_master_vptat_ext_adc", 275 "controller_master_internal_temp_ext_adc", 276 "controller_slave_vptat", 277 "controller_slave_internal_temp", 278 "controller_slave_vptat_ext_adc", 279 "controller_slave_internal_temp_ext_adc", 280 "sodimm_vout", 281 "sodimm_0_temp", 282 "sodimm_1_temp", 283 "phy0_vcc", 284 "phy1_vcc", 285 "controller_tdiode_temp", 286 }; 287 288 /* END MKCONFIG GENERATED MonitorStatNamesBlock */ 289 290 extern const char * 291 efx_mon_stat_name( 292 __in efx_nic_t *enp, 293 __in efx_mon_stat_t id) 294 { 295 _NOTE(ARGUNUSED(enp)) 296 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 297 298 EFSYS_ASSERT3U(id, <, EFX_MON_NSTATS); 299 return (__mon_stat_name[id]); 300 } 301 302 #endif /* EFSYS_OPT_NAMES */ 303 304 __checkReturn efx_rc_t 305 efx_mon_stats_update( 306 __in efx_nic_t *enp, 307 __in efsys_mem_t *esmp, 308 __inout_ecount(EFX_MON_NSTATS) efx_mon_stat_value_t *values) 309 { 310 efx_mon_t *emp = &(enp->en_mon); 311 efx_mon_ops_t *emop = emp->em_emop; 312 313 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 314 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON); 315 316 return (emop->emo_stats_update(enp, esmp, values)); 317 } 318 319 #endif /* EFSYS_OPT_MON_STATS */ 320 321 void 322 efx_mon_fini( 323 __in efx_nic_t *enp) 324 { 325 efx_mon_t *emp = &(enp->en_mon); 326 efx_mon_ops_t *emop = emp->em_emop; 327 efx_rc_t rc; 328 329 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 330 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE); 331 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON); 332 333 emp->em_emop = NULL; 334 335 if (emop->emo_reset != NULL) { 336 rc = emop->emo_reset(enp); 337 if (rc != 0) 338 EFSYS_PROBE1(fail1, efx_rc_t, rc); 339 } 340 341 emp->em_type = EFX_MON_INVALID; 342 343 enp->en_mod_flags &= ~EFX_MOD_MON; 344 } 345