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 "efx.h"
  32 #include "efx_impl.h"
  33 
  34 #if EFSYS_OPT_MON_MCDI
  35 #include "mcdi_mon.h"
  36 #endif
  37 
  38 #if EFSYS_OPT_NAMES
  39 
  40 static const char       *__efx_mon_name[] = {
  41         "",
  42         "sfx90x0",
  43         "sfx91x0"
  44         "sfx92x0"
  45 };
  46 
  47                 const char *
  48 efx_mon_name(
  49         __in    efx_nic_t *enp)
  50 {
  51         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
  52 
  53         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
  54 
  55         EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID);
  56         EFSYS_ASSERT3U(encp->enc_mon_type, <, EFX_MON_NTYPES);
  57         return (__efx_mon_name[encp->enc_mon_type]);
  58 }
  59 
  60 #endif  /* EFSYS_OPT_NAMES */
  61 
  62 #if EFSYS_OPT_MON_MCDI
  63 static const efx_mon_ops_t      __efx_mon_mcdi_ops = {
  64 #if EFSYS_OPT_MON_STATS
  65         mcdi_mon_stats_update           /* emo_stats_update */
  66 #endif  /* EFSYS_OPT_MON_STATS */
  67 };
  68 #endif
  69 
  70 
  71         __checkReturn   efx_rc_t
  72 efx_mon_init(
  73         __in            efx_nic_t *enp)
  74 {
  75         efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
  76         efx_mon_t *emp = &(enp->en_mon);
  77         const efx_mon_ops_t *emop;
  78         efx_rc_t rc;
  79 
  80         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
  81         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
  82 
  83         if (enp->en_mod_flags & EFX_MOD_MON) {
  84                 rc = EINVAL;
  85                 goto fail1;
  86         }
  87 
  88         enp->en_mod_flags |= EFX_MOD_MON;
  89 
  90         emp->em_type = encp->enc_mon_type;
  91 
  92         EFSYS_ASSERT(encp->enc_mon_type != EFX_MON_INVALID);
  93         switch (emp->em_type) {
  94 #if EFSYS_OPT_MON_MCDI
  95         case EFX_MON_SFC90X0:
  96         case EFX_MON_SFC91X0:
  97         case EFX_MON_SFC92X0:
  98                 emop = &__efx_mon_mcdi_ops;
  99                 break;
 100 #endif
 101         default:
 102                 rc = ENOTSUP;
 103                 goto fail2;
 104         }
 105 
 106         emp->em_emop = emop;
 107         return (0);
 108 
 109 fail2:
 110         EFSYS_PROBE(fail2);
 111 
 112         emp->em_type = EFX_MON_INVALID;
 113 
 114         enp->en_mod_flags &= ~EFX_MOD_MON;
 115 
 116 fail1:
 117         EFSYS_PROBE1(fail1, efx_rc_t, rc);
 118 
 119         return (rc);
 120 }
 121 
 122 #if EFSYS_OPT_MON_STATS
 123 
 124 #if EFSYS_OPT_NAMES
 125 
 126 /* START MKCONFIG GENERATED MonitorStatNamesBlock 31f437eafb0b0437 */
 127 static const char       *__mon_stat_name[] = {
 128         "value_2_5v",
 129         "value_vccp1",
 130         "value_vcc",
 131         "value_5v",
 132         "value_12v",
 133         "value_vccp2",
 134         "value_ext_temp",
 135         "value_int_temp",
 136         "value_ain1",
 137         "value_ain2",
 138         "controller_cooling",
 139         "ext_cooling",
 140         "1v",
 141         "1_2v",
 142         "1_8v",
 143         "3_3v",
 144         "1_2va",
 145         "vref",
 146         "vaoe",
 147         "aoe_temperature",
 148         "psu_aoe_temperature",
 149         "psu_temperature",
 150         "fan0",
 151         "fan1",
 152         "fan2",
 153         "fan3",
 154         "fan4",
 155         "vaoe_in",
 156         "iaoe",
 157         "iaoe_in",
 158         "nic_power",
 159         "0_9v",
 160         "i0_9v",
 161         "i1_2v",
 162         "0_9v_adc",
 163         "controller_temperature2",
 164         "vreg_temperature",
 165         "vreg_0_9v_temperature",
 166         "vreg_1_2v_temperature",
 167         "int_vptat",
 168         "controller_internal_adc_temperature",
 169         "ext_vptat",
 170         "controller_external_adc_temperature",
 171         "ambient_temperature",
 172         "airflow",
 173         "vdd08d_vss08d_csr",
 174         "vdd08d_vss08d_csr_extadc",
 175         "hotpoint_temperature",
 176         "phy_power_switch_port0",
 177         "phy_power_switch_port1",
 178         "mum_vcc",
 179         "0v9_a",
 180         "i0v9_a",
 181         "0v9_a_temp",
 182         "0v9_b",
 183         "i0v9_b",
 184         "0v9_b_temp",
 185         "ccom_avreg_1v2_supply",
 186         "ccom_avreg_1v2_supply_ext_adc",
 187         "ccom_avreg_1v8_supply",
 188         "ccom_avreg_1v8_supply_ext_adc",
 189         "controller_master_vptat",
 190         "controller_master_internal_temp",
 191         "controller_master_vptat_ext_adc",
 192         "controller_master_internal_temp_ext_adc",
 193         "controller_slave_vptat",
 194         "controller_slave_internal_temp",
 195         "controller_slave_vptat_ext_adc",
 196         "controller_slave_internal_temp_ext_adc",
 197         "sodimm_vout",
 198         "sodimm_0_temp",
 199         "sodimm_1_temp",
 200         "phy0_vcc",
 201         "phy1_vcc",
 202         "controller_tdiode_temp",
 203         "board_front_temp",
 204         "board_back_temp",
 205 };
 206 
 207 /* END MKCONFIG GENERATED MonitorStatNamesBlock */
 208 
 209 extern                                  const char *
 210 efx_mon_stat_name(
 211         __in                            efx_nic_t *enp,
 212         __in                            efx_mon_stat_t id)
 213 {
 214         _NOTE(ARGUNUSED(enp))
 215         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
 216 
 217         EFSYS_ASSERT3U(id, <, EFX_MON_NSTATS);
 218         return (__mon_stat_name[id]);
 219 }
 220 
 221 #endif  /* EFSYS_OPT_NAMES */
 222 
 223         __checkReturn                   efx_rc_t
 224 efx_mon_stats_update(
 225         __in                            efx_nic_t *enp,
 226         __in                            efsys_mem_t *esmp,
 227         __inout_ecount(EFX_MON_NSTATS)  efx_mon_stat_value_t *values)
 228 {
 229         efx_mon_t *emp = &(enp->en_mon);
 230         const efx_mon_ops_t *emop = emp->em_emop;
 231 
 232         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
 233         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON);
 234 
 235         return (emop->emo_stats_update(enp, esmp, values));
 236 }
 237 
 238 #endif  /* EFSYS_OPT_MON_STATS */
 239 
 240                 void
 241 efx_mon_fini(
 242         __in    efx_nic_t *enp)
 243 {
 244         efx_mon_t *emp = &(enp->en_mon);
 245 
 246         EFSYS_ASSERT3U(enp->en_magic, ==, EFX_NIC_MAGIC);
 247         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_PROBE);
 248         EFSYS_ASSERT3U(enp->en_mod_flags, &, EFX_MOD_MON);
 249 
 250         emp->em_emop = NULL;
 251 
 252         emp->em_type = EFX_MON_INVALID;
 253 
 254         enp->en_mod_flags &= ~EFX_MOD_MON;
 255 }