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