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 08518fd1fb4e2612 */ 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 }; 217 218 /* END MKCONFIG GENERATED MonitorStatNamesBlock */ 219 220 extern const char __cs * 221 efx_mon_stat_name( 222 __in efx_nic_t *enp, 223 __in efx_mon_stat_t id) 224 { 225 _NOTE(ARGUNUSED(enp)) 226 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 227 228 EFSYS_ASSERT3U(id, <, EFX_MON_NSTATS); 229 return (__mon_stat_name[id]); 230 } 231 232 #endif /* EFSYS_OPT_NAMES */ 233 234 __checkReturn int 235 efx_mon_stats_update( 236 __in efx_nic_t *enp, 237 __in efsys_mem_t *esmp, 238 __out_ecount(EFX_MON_NSTATS) efx_mon_stat_value_t *values) 239 { 240 efx_mon_t *emp = &(enp->en_mon); 241 efx_mon_ops_t *emop = emp->em_emop; 242 243 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 244 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON); 245 246 return (emop->emo_stats_update(enp, esmp, values)); 247 } 248 249 #endif /* EFSYS_OPT_MON_STATS */ 250 251 void 252 efx_mon_fini( 253 __in efx_nic_t *enp) 254 { 255 efx_mon_t *emp = &(enp->en_mon); 256 efx_mon_ops_t *emop = emp->em_emop; 257 int rc; 258 259 EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC); 260 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE); 261 EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON); 262 263 emp->em_emop = NULL; 264 265 rc = emop->emo_reset(enp); 266 if (rc != 0) 267 EFSYS_PROBE1(fail1, int, rc); 268 269 emp->em_type = EFX_MON_INVALID; 270 271 enp->en_mod_flags &= ~EFX_MOD_MON; 272 } 273