1 /*- 2 * Copyright (c) 2009-2016 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_MCDI 38 39 #if EFSYS_OPT_MON_STATS 40 41 #define MCDI_MON_NEXT_PAGE ((uint16_t)0xfffe) 42 #define MCDI_MON_INVALID_SENSOR ((uint16_t)0xfffd) 43 #define MCDI_MON_PAGE_SIZE 0x20 44 45 /* Bitmasks of valid port(s) for each sensor */ 46 #define MCDI_MON_PORT_NONE (0x00) 47 #define MCDI_MON_PORT_P1 (0x01) 48 #define MCDI_MON_PORT_P2 (0x02) 49 #define MCDI_MON_PORT_P3 (0x04) 50 #define MCDI_MON_PORT_P4 (0x08) 51 #define MCDI_MON_PORT_Px (0xFFFF) 52 53 /* Get port mask from one-based MCDI port number */ 54 #define MCDI_MON_PORT_MASK(_emip) (1U << ((_emip)->emi_port - 1)) 55 56 /* Entry for MCDI sensor in sensor map */ 57 #define STAT(portmask, stat) \ 58 { (MCDI_MON_PORT_##portmask), (EFX_MON_STAT_##stat) } 59 60 /* Entry for sensor next page flag in sensor map */ 61 #define STAT_NEXT_PAGE() \ 62 { MCDI_MON_PORT_NONE, MCDI_MON_NEXT_PAGE } 63 64 /* Placeholder for gaps in the array */ 65 #define STAT_NO_SENSOR() \ 66 { MCDI_MON_PORT_NONE, MCDI_MON_INVALID_SENSOR } 67 68 /* Map from MC sensors to monitor statistics */ 69 static const struct mcdi_sensor_map_s { 70 uint16_t msm_port_mask; 71 uint16_t msm_stat; 72 } mcdi_sensor_map[] = { 73 /* Sensor page 0 MC_CMD_SENSOR_xxx */ 74 STAT(Px, INT_TEMP), /* 0x00 CONTROLLER_TEMP */ 75 STAT(Px, EXT_TEMP), /* 0x01 PHY_COMMON_TEMP */ 76 STAT(Px, INT_COOLING), /* 0x02 CONTROLLER_COOLING */ 77 STAT(P1, EXT_TEMP), /* 0x03 PHY0_TEMP */ 78 STAT(P1, EXT_COOLING), /* 0x04 PHY0_COOLING */ 79 STAT(P2, EXT_TEMP), /* 0x05 PHY1_TEMP */ 80 STAT(P2, EXT_COOLING), /* 0x06 PHY1_COOLING */ 81 STAT(Px, 1V), /* 0x07 IN_1V0 */ 82 STAT(Px, 1_2V), /* 0x08 IN_1V2 */ 83 STAT(Px, 1_8V), /* 0x09 IN_1V8 */ 84 STAT(Px, 2_5V), /* 0x0a IN_2V5 */ 85 STAT(Px, 3_3V), /* 0x0b IN_3V3 */ 86 STAT(Px, 12V), /* 0x0c IN_12V0 */ 87 STAT(Px, 1_2VA), /* 0x0d IN_1V2A */ 88 STAT(Px, VREF), /* 0x0e IN_VREF */ 89 STAT(Px, VAOE), /* 0x0f OUT_VAOE */ 90 STAT(Px, AOE_TEMP), /* 0x10 AOE_TEMP */ 91 STAT(Px, PSU_AOE_TEMP), /* 0x11 PSU_AOE_TEMP */ 92 STAT(Px, PSU_TEMP), /* 0x12 PSU_TEMP */ 93 STAT(Px, FAN0), /* 0x13 FAN_0 */ 94 STAT(Px, FAN1), /* 0x14 FAN_1 */ 95 STAT(Px, FAN2), /* 0x15 FAN_2 */ 96 STAT(Px, FAN3), /* 0x16 FAN_3 */ 97 STAT(Px, FAN4), /* 0x17 FAN_4 */ 98 STAT(Px, VAOE_IN), /* 0x18 IN_VAOE */ 99 STAT(Px, IAOE), /* 0x19 OUT_IAOE */ 100 STAT(Px, IAOE_IN), /* 0x1a IN_IAOE */ 101 STAT(Px, NIC_POWER), /* 0x1b NIC_POWER */ 102 STAT(Px, 0_9V), /* 0x1c IN_0V9 */ 103 STAT(Px, I0_9V), /* 0x1d IN_I0V9 */ 104 STAT(Px, I1_2V), /* 0x1e IN_I1V2 */ 105 STAT_NEXT_PAGE(), /* 0x1f Next page flag (not a sensor) */ 106 107 /* Sensor page 1 MC_CMD_SENSOR_xxx */ 108 STAT(Px, 0_9V_ADC), /* 0x20 IN_0V9_ADC */ 109 STAT(Px, INT_TEMP2), /* 0x21 CONTROLLER_2_TEMP */ 110 STAT(Px, VREG_TEMP), /* 0x22 VREG_INTERNAL_TEMP */ 111 STAT(Px, VREG_0_9V_TEMP), /* 0x23 VREG_0V9_TEMP */ 112 STAT(Px, VREG_1_2V_TEMP), /* 0x24 VREG_1V2_TEMP */ 113 STAT(Px, INT_VPTAT), /* 0x25 CTRLR. VPTAT */ 114 STAT(Px, INT_ADC_TEMP), /* 0x26 CTRLR. INTERNAL_TEMP */ 115 STAT(Px, EXT_VPTAT), /* 0x27 CTRLR. VPTAT_EXTADC */ 116 STAT(Px, EXT_ADC_TEMP), /* 0x28 CTRLR. INTERNAL_TEMP_EXTADC */ 117 STAT(Px, AMBIENT_TEMP), /* 0x29 AMBIENT_TEMP */ 118 STAT(Px, AIRFLOW), /* 0x2a AIRFLOW */ 119 STAT(Px, VDD08D_VSS08D_CSR), /* 0x2b VDD08D_VSS08D_CSR */ 120 STAT(Px, VDD08D_VSS08D_CSR_EXTADC), /* 0x2c VDD08D_VSS08D_CSR_EXTADC */ 121 STAT(Px, HOTPOINT_TEMP), /* 0x2d HOTPOINT_TEMP */ 122 STAT(P1, PHY_POWER_SWITCH_PORT0), /* 0x2e PHY_POWER_SWITCH_PORT0 */ 123 STAT(P2, PHY_POWER_SWITCH_PORT1), /* 0x2f PHY_POWER_SWITCH_PORT1 */ 124 STAT(Px, MUM_VCC), /* 0x30 MUM_VCC */ 125 STAT(Px, 0V9_A), /* 0x31 0V9_A */ 126 STAT(Px, I0V9_A), /* 0x32 I0V9_A */ 127 STAT(Px, 0V9_A_TEMP), /* 0x33 0V9_A_TEMP */ 128 STAT(Px, 0V9_B), /* 0x34 0V9_B */ 129 STAT(Px, I0V9_B), /* 0x35 I0V9_B */ 130 STAT(Px, 0V9_B_TEMP), /* 0x36 0V9_B_TEMP */ 131 STAT(Px, CCOM_AVREG_1V2_SUPPLY), /* 0x37 CCOM_AVREG_1V2_SUPPLY */ 132 STAT(Px, CCOM_AVREG_1V2_SUPPLY_EXT_ADC), 133 /* 0x38 CCOM_AVREG_1V2_SUPPLY_EXT_ADC */ 134 STAT(Px, CCOM_AVREG_1V8_SUPPLY), /* 0x39 CCOM_AVREG_1V8_SUPPLY */ 135 STAT(Px, CCOM_AVREG_1V8_SUPPLY_EXT_ADC), 136 /* 0x3a CCOM_AVREG_1V8_SUPPLY_EXT_ADC */ 137 STAT_NO_SENSOR(), /* 0x3b (no sensor) */ 138 STAT_NO_SENSOR(), /* 0x3c (no sensor) */ 139 STAT_NO_SENSOR(), /* 0x3d (no sensor) */ 140 STAT_NO_SENSOR(), /* 0x3e (no sensor) */ 141 STAT_NEXT_PAGE(), /* 0x3f Next page flag (not a sensor) */ 142 143 /* Sensor page 2 MC_CMD_SENSOR_xxx */ 144 STAT(Px, CONTROLLER_MASTER_VPTAT), /* 0x40 MASTER_VPTAT */ 145 STAT(Px, CONTROLLER_MASTER_INTERNAL_TEMP), /* 0x41 MASTER_INT_TEMP */ 146 STAT(Px, CONTROLLER_MASTER_VPTAT_EXT_ADC), /* 0x42 MAST_VPTAT_EXT_ADC */ 147 STAT(Px, CONTROLLER_MASTER_INTERNAL_TEMP_EXT_ADC), 148 /* 0x43 MASTER_INTERNAL_TEMP_EXT_ADC */ 149 STAT(Px, CONTROLLER_SLAVE_VPTAT), /* 0x44 SLAVE_VPTAT */ 150 STAT(Px, CONTROLLER_SLAVE_INTERNAL_TEMP), /* 0x45 SLAVE_INTERNAL_TEMP */ 151 STAT(Px, CONTROLLER_SLAVE_VPTAT_EXT_ADC), /* 0x46 SLAVE_VPTAT_EXT_ADC */ 152 STAT(Px, CONTROLLER_SLAVE_INTERNAL_TEMP_EXT_ADC), 153 /* 0x47 SLAVE_INTERNAL_TEMP_EXT_ADC */ 154 STAT_NO_SENSOR(), /* 0x48 (no sensor) */ 155 STAT(Px, SODIMM_VOUT), /* 0x49 SODIMM_VOUT */ 156 STAT(Px, SODIMM_0_TEMP), /* 0x4a SODIMM_0_TEMP */ 157 STAT(Px, SODIMM_1_TEMP), /* 0x4b SODIMM_1_TEMP */ 158 STAT(Px, PHY0_VCC), /* 0x4c PHY0_VCC */ 159 STAT(Px, PHY1_VCC), /* 0x4d PHY1_VCC */ 160 STAT(Px, CONTROLLER_TDIODE_TEMP), /* 0x4e CONTROLLER_TDIODE_TEMP */ 161 STAT(Px, BOARD_FRONT_TEMP), /* 0x4f BOARD_FRONT_TEMP */ 162 STAT(Px, BOARD_BACK_TEMP), /* 0x50 BOARD_BACK_TEMP */ 163 STAT(Px, I1V8), /* 0x51 IN_I1V8 */ 164 STAT(Px, I2V5), /* 0x52 IN_I2V5 */ 165 }; 166 167 #define MCDI_STATIC_SENSOR_ASSERT(_field) \ 168 EFX_STATIC_ASSERT(MC_CMD_SENSOR_STATE_ ## _field \ 169 == EFX_MON_STAT_STATE_ ## _field) 170 171 static void 172 mcdi_mon_decode_stats( 173 __in efx_nic_t *enp, 174 __in_bcount(sensor_mask_size) uint32_t *sensor_mask, 175 __in size_t sensor_mask_size, 176 __in_opt efsys_mem_t *esmp, 177 __out_bcount_opt(sensor_mask_size) uint32_t *stat_maskp, 178 __inout_ecount_opt(EFX_MON_NSTATS) efx_mon_stat_value_t *stat) 179 { 180 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip); 181 uint16_t port_mask; 182 uint16_t sensor; 183 size_t sensor_max; 184 uint32_t stat_mask[(EFX_ARRAY_SIZE(mcdi_sensor_map) + 31) / 32]; 185 uint32_t idx = 0; 186 uint32_t page = 0; 187 188 /* Assert the MC_CMD_SENSOR and EFX_MON_STATE namespaces agree */ 189 MCDI_STATIC_SENSOR_ASSERT(OK); 190 MCDI_STATIC_SENSOR_ASSERT(WARNING); 191 MCDI_STATIC_SENSOR_ASSERT(FATAL); 192 MCDI_STATIC_SENSOR_ASSERT(BROKEN); 193 MCDI_STATIC_SENSOR_ASSERT(NO_READING); 194 195 EFX_STATIC_ASSERT(sizeof (stat_mask[0]) * 8 == 196 EFX_MON_MASK_ELEMENT_SIZE); 197 sensor_max = 198 MIN((8 * sensor_mask_size), EFX_ARRAY_SIZE(mcdi_sensor_map)); 199 200 EFSYS_ASSERT(emip->emi_port > 0); /* MCDI port number is one-based */ 201 port_mask = MCDI_MON_PORT_MASK(emip); 202 203 memset(stat_mask, 0, sizeof (stat_mask)); 204 205 /* 206 * The MCDI sensor readings in the DMA buffer are a packed array of 207 * MC_CMD_SENSOR_VALUE_ENTRY structures, which only includes entries for 208 * supported sensors (bit set in sensor_mask). The sensor_mask and 209 * sensor readings do not include entries for the per-page NEXT_PAGE 210 * flag. 211 * 212 * sensor_mask may legitimately contain MCDI sensors that the driver 213 * does not understand. 214 */ 215 for (sensor = 0; sensor < sensor_max; ++sensor) { 216 efx_mon_stat_t id = mcdi_sensor_map[sensor].msm_stat; 217 218 if ((sensor % MCDI_MON_PAGE_SIZE) == MC_CMD_SENSOR_PAGE0_NEXT) { 219 EFSYS_ASSERT3U(id, ==, MCDI_MON_NEXT_PAGE); 220 page++; 221 continue; 222 } 223 if (~(sensor_mask[page]) & (1U << sensor)) 224 continue; 225 idx++; 226 227 if ((port_mask & mcdi_sensor_map[sensor].msm_port_mask) == 0) 228 continue; 229 EFSYS_ASSERT(id < EFX_MON_NSTATS); 230 231 /* 232 * stat_mask is a bitmask indexed by EFX_MON_* monitor statistic 233 * identifiers from efx_mon_stat_t (without NEXT_PAGE bits). 234 * 235 * If there is an entry in the MCDI sensor to monitor statistic 236 * map then the sensor reading is used for the value of the 237 * monitor statistic. 238 */ 239 stat_mask[id / EFX_MON_MASK_ELEMENT_SIZE] |= 240 (1U << (id % EFX_MON_MASK_ELEMENT_SIZE)); 241 242 if (stat != NULL && esmp != NULL && !EFSYS_MEM_IS_NULL(esmp)) { 243 efx_dword_t dword; 244 245 /* Get MCDI sensor reading from DMA buffer */ 246 EFSYS_MEM_READD(esmp, 4 * (idx - 1), &dword); 247 248 /* Update EFX monitor stat from MCDI sensor reading */ 249 stat[id].emsv_value = (uint16_t)EFX_DWORD_FIELD(dword, 250 MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_VALUE); 251 252 stat[id].emsv_state = (uint16_t)EFX_DWORD_FIELD(dword, 253 MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE); 254 } 255 } 256 257 if (stat_maskp != NULL) { 258 memcpy(stat_maskp, stat_mask, sizeof (stat_mask)); 259 } 260 } 261 262 __checkReturn efx_rc_t 263 mcdi_mon_ev( 264 __in efx_nic_t *enp, 265 __in efx_qword_t *eqp, 266 __out efx_mon_stat_t *idp, 267 __out efx_mon_stat_value_t *valuep) 268 { 269 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip); 270 uint16_t port_mask; 271 uint16_t sensor; 272 uint16_t state; 273 uint16_t value; 274 efx_mon_stat_t id; 275 efx_rc_t rc; 276 277 EFSYS_ASSERT(emip->emi_port > 0); /* MCDI port number is one-based */ 278 port_mask = MCDI_MON_PORT_MASK(emip); 279 280 sensor = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_MONITOR); 281 state = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_STATE); 282 value = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_VALUE); 283 284 /* Hardware must support this MCDI sensor */ 285 EFSYS_ASSERT3U(sensor, <, 286 (8 * enp->en_nic_cfg.enc_mcdi_sensor_mask_size)); 287 EFSYS_ASSERT((sensor % MCDI_MON_PAGE_SIZE) != MC_CMD_SENSOR_PAGE0_NEXT); 288 EFSYS_ASSERT(enp->en_nic_cfg.enc_mcdi_sensor_maskp != NULL); 289 EFSYS_ASSERT( 290 (enp->en_nic_cfg.enc_mcdi_sensor_maskp[sensor/MCDI_MON_PAGE_SIZE] & 291 (1U << (sensor % MCDI_MON_PAGE_SIZE))) != 0); 292 293 /* But we don't have to understand it */ 294 if (sensor >= EFX_ARRAY_SIZE(mcdi_sensor_map)) { 295 rc = ENOTSUP; 296 goto fail1; 297 } 298 id = mcdi_sensor_map[sensor].msm_stat; 299 if ((port_mask & mcdi_sensor_map[sensor].msm_port_mask) == 0) 300 return (ENODEV); 301 EFSYS_ASSERT(id < EFX_MON_NSTATS); 302 303 *idp = id; 304 valuep->emsv_value = value; 305 valuep->emsv_state = state; 306 307 return (0); 308 309 fail1: 310 EFSYS_PROBE1(fail1, efx_rc_t, rc); 311 312 return (rc); 313 } 314 315 316 static __checkReturn efx_rc_t 317 efx_mcdi_read_sensors( 318 __in efx_nic_t *enp, 319 __in efsys_mem_t *esmp, 320 __in uint32_t size) 321 { 322 efx_mcdi_req_t req; 323 uint8_t payload[MAX(MC_CMD_READ_SENSORS_EXT_IN_LEN, 324 MC_CMD_READ_SENSORS_EXT_OUT_LEN)]; 325 uint32_t addr_lo, addr_hi; 326 327 req.emr_cmd = MC_CMD_READ_SENSORS; 328 req.emr_in_buf = payload; 329 req.emr_in_length = MC_CMD_READ_SENSORS_EXT_IN_LEN; 330 req.emr_out_buf = payload; 331 req.emr_out_length = MC_CMD_READ_SENSORS_EXT_OUT_LEN; 332 333 addr_lo = (uint32_t)(EFSYS_MEM_ADDR(esmp) & 0xffffffff); 334 addr_hi = (uint32_t)(EFSYS_MEM_ADDR(esmp) >> 32); 335 336 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_DMA_ADDR_LO, addr_lo); 337 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_DMA_ADDR_HI, addr_hi); 338 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_LENGTH, size); 339 340 efx_mcdi_execute(enp, &req); 341 342 return (req.emr_rc); 343 } 344 345 static __checkReturn efx_rc_t 346 efx_mcdi_sensor_info_npages( 347 __in efx_nic_t *enp, 348 __out uint32_t *npagesp) 349 { 350 efx_mcdi_req_t req; 351 uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN, 352 MC_CMD_SENSOR_INFO_OUT_LENMAX)]; 353 int page; 354 efx_rc_t rc; 355 356 EFSYS_ASSERT(npagesp != NULL); 357 358 page = 0; 359 do { 360 (void) memset(payload, 0, sizeof (payload)); 361 req.emr_cmd = MC_CMD_SENSOR_INFO; 362 req.emr_in_buf = payload; 363 req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN; 364 req.emr_out_buf = payload; 365 req.emr_out_length = MC_CMD_SENSOR_INFO_OUT_LENMAX; 366 367 MCDI_IN_SET_DWORD(req, SENSOR_INFO_EXT_IN_PAGE, page++); 368 369 efx_mcdi_execute_quiet(enp, &req); 370 371 if (req.emr_rc != 0) { 372 rc = req.emr_rc; 373 goto fail1; 374 } 375 } while (MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK) & 376 (1U << MC_CMD_SENSOR_PAGE0_NEXT)); 377 378 *npagesp = page; 379 380 return (0); 381 382 fail1: 383 EFSYS_PROBE1(fail1, efx_rc_t, rc); 384 385 return (rc); 386 } 387 388 static __checkReturn efx_rc_t 389 efx_mcdi_sensor_info( 390 __in efx_nic_t *enp, 391 __out_ecount(npages) uint32_t *sensor_maskp, 392 __in size_t npages) 393 { 394 efx_mcdi_req_t req; 395 uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN, 396 MC_CMD_SENSOR_INFO_OUT_LENMAX)]; 397 uint32_t page; 398 efx_rc_t rc; 399 400 EFSYS_ASSERT(sensor_maskp != NULL); 401 402 if (npages < 1) { 403 rc = EINVAL; 404 goto fail1; 405 } 406 407 for (page = 0; page < npages; page++) { 408 uint32_t mask; 409 410 (void) memset(payload, 0, sizeof (payload)); 411 req.emr_cmd = MC_CMD_SENSOR_INFO; 412 req.emr_in_buf = payload; 413 req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN; 414 req.emr_out_buf = payload; 415 req.emr_out_length = MC_CMD_SENSOR_INFO_OUT_LENMAX; 416 417 MCDI_IN_SET_DWORD(req, SENSOR_INFO_EXT_IN_PAGE, page); 418 419 efx_mcdi_execute(enp, &req); 420 421 if (req.emr_rc != 0) { 422 rc = req.emr_rc; 423 goto fail2; 424 } 425 426 mask = MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK); 427 428 if ((page != (npages - 1)) && 429 ((mask & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) == 0)) { 430 rc = EINVAL; 431 goto fail3; 432 } 433 sensor_maskp[page] = mask; 434 } 435 436 if (sensor_maskp[npages - 1] & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) { 437 rc = EINVAL; 438 goto fail4; 439 } 440 441 return (0); 442 443 fail4: 444 EFSYS_PROBE(fail4); 445 fail3: 446 EFSYS_PROBE(fail3); 447 fail2: 448 EFSYS_PROBE(fail2); 449 fail1: 450 EFSYS_PROBE1(fail1, efx_rc_t, rc); 451 452 return (rc); 453 } 454 455 __checkReturn efx_rc_t 456 mcdi_mon_stats_update( 457 __in efx_nic_t *enp, 458 __in efsys_mem_t *esmp, 459 __inout_ecount(EFX_MON_NSTATS) efx_mon_stat_value_t *values) 460 { 461 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 462 uint32_t size = encp->enc_mon_stat_dma_buf_size; 463 efx_rc_t rc; 464 465 if ((rc = efx_mcdi_read_sensors(enp, esmp, size)) != 0) 466 goto fail1; 467 468 EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, size); 469 470 mcdi_mon_decode_stats(enp, 471 encp->enc_mcdi_sensor_maskp, 472 encp->enc_mcdi_sensor_mask_size, 473 esmp, NULL, values); 474 475 return (0); 476 477 fail1: 478 EFSYS_PROBE1(fail1, efx_rc_t, rc); 479 480 return (rc); 481 } 482 483 __checkReturn efx_rc_t 484 mcdi_mon_cfg_build( 485 __in efx_nic_t *enp) 486 { 487 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 488 uint32_t npages; 489 efx_rc_t rc; 490 491 switch (enp->en_family) { 492 #if EFSYS_OPT_SIENA 493 case EFX_FAMILY_SIENA: 494 encp->enc_mon_type = EFX_MON_SFC90X0; 495 break; 496 #endif 497 #if EFSYS_OPT_HUNTINGTON 498 case EFX_FAMILY_HUNTINGTON: 499 encp->enc_mon_type = EFX_MON_SFC91X0; 500 break; 501 #endif 502 #if EFSYS_OPT_MEDFORD 503 case EFX_FAMILY_MEDFORD: 504 encp->enc_mon_type = EFX_MON_SFC92X0; 505 break; 506 #endif 507 default: 508 rc = EINVAL; 509 goto fail1; 510 } 511 512 /* Get mc sensor mask size */ 513 npages = 0; 514 if ((rc = efx_mcdi_sensor_info_npages(enp, &npages)) != 0) 515 goto fail2; 516 517 encp->enc_mon_stat_dma_buf_size = npages * EFX_MON_STATS_PAGE_SIZE; 518 encp->enc_mcdi_sensor_mask_size = npages * sizeof (uint32_t); 519 520 /* Allocate mc sensor mask */ 521 EFSYS_KMEM_ALLOC(enp->en_esip, 522 encp->enc_mcdi_sensor_mask_size, 523 encp->enc_mcdi_sensor_maskp); 524 525 if (encp->enc_mcdi_sensor_maskp == NULL) { 526 rc = ENOMEM; 527 goto fail3; 528 } 529 530 /* Read mc sensor mask */ 531 if ((rc = efx_mcdi_sensor_info(enp, 532 encp->enc_mcdi_sensor_maskp, 533 npages)) != 0) 534 goto fail4; 535 536 /* Build monitor statistics mask */ 537 mcdi_mon_decode_stats(enp, 538 encp->enc_mcdi_sensor_maskp, 539 encp->enc_mcdi_sensor_mask_size, 540 NULL, encp->enc_mon_stat_mask, NULL); 541 542 return (0); 543 544 fail4: 545 EFSYS_PROBE(fail4); 546 EFSYS_KMEM_FREE(enp->en_esip, 547 encp->enc_mcdi_sensor_mask_size, 548 encp->enc_mcdi_sensor_maskp); 549 550 fail3: 551 EFSYS_PROBE(fail3); 552 553 fail2: 554 EFSYS_PROBE(fail2); 555 556 fail1: 557 EFSYS_PROBE1(fail1, efx_rc_t, rc); 558 559 return (rc); 560 } 561 562 void 563 mcdi_mon_cfg_free( 564 __in efx_nic_t *enp) 565 { 566 efx_nic_cfg_t *encp = &(enp->en_nic_cfg); 567 568 if (encp->enc_mcdi_sensor_maskp != NULL) { 569 EFSYS_KMEM_FREE(enp->en_esip, 570 encp->enc_mcdi_sensor_mask_size, 571 encp->enc_mcdi_sensor_maskp); 572 } 573 } 574 575 576 #endif /* EFSYS_OPT_MON_STATS */ 577 578 #endif /* EFSYS_OPT_MON_MCDI */ 579