1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2009-2018 Solarflare Communications Inc.
10 #if EFSYS_OPT_MON_MCDI
12 #if EFSYS_OPT_MON_STATS
14 #define MCDI_MON_NEXT_PAGE ((uint16_t)0xfffe)
15 #define MCDI_MON_INVALID_SENSOR ((uint16_t)0xfffd)
16 #define MCDI_MON_PAGE_SIZE 0x20
18 /* Bitmasks of valid port(s) for each sensor */
19 #define MCDI_MON_PORT_NONE (0x00)
20 #define MCDI_MON_PORT_P1 (0x01)
21 #define MCDI_MON_PORT_P2 (0x02)
22 #define MCDI_MON_PORT_P3 (0x04)
23 #define MCDI_MON_PORT_P4 (0x08)
24 #define MCDI_MON_PORT_Px (0xFFFF)
26 /* Get port mask from one-based MCDI port number */
27 #define MCDI_MON_PORT_MASK(_emip) (1U << ((_emip)->emi_port - 1))
29 /* Entry for MCDI sensor in sensor map */
30 #define STAT(portmask, stat) \
31 { (MCDI_MON_PORT_##portmask), (EFX_MON_STAT_##stat) }
33 /* Entry for sensor next page flag in sensor map */
34 #define STAT_NEXT_PAGE() \
35 { MCDI_MON_PORT_NONE, MCDI_MON_NEXT_PAGE }
37 /* Placeholder for gaps in the array */
38 #define STAT_NO_SENSOR() \
39 { MCDI_MON_PORT_NONE, MCDI_MON_INVALID_SENSOR }
41 /* Map from MC sensors to monitor statistics */
42 static const struct mcdi_sensor_map_s {
43 uint16_t msm_port_mask;
45 } mcdi_sensor_map[] = {
46 /* Sensor page 0 MC_CMD_SENSOR_xxx */
47 STAT(Px, INT_TEMP), /* 0x00 CONTROLLER_TEMP */
48 STAT(Px, EXT_TEMP), /* 0x01 PHY_COMMON_TEMP */
49 STAT(Px, INT_COOLING), /* 0x02 CONTROLLER_COOLING */
50 STAT(P1, EXT_TEMP), /* 0x03 PHY0_TEMP */
51 STAT(P1, EXT_COOLING), /* 0x04 PHY0_COOLING */
52 STAT(P2, EXT_TEMP), /* 0x05 PHY1_TEMP */
53 STAT(P2, EXT_COOLING), /* 0x06 PHY1_COOLING */
54 STAT(Px, 1V), /* 0x07 IN_1V0 */
55 STAT(Px, 1_2V), /* 0x08 IN_1V2 */
56 STAT(Px, 1_8V), /* 0x09 IN_1V8 */
57 STAT(Px, 2_5V), /* 0x0a IN_2V5 */
58 STAT(Px, 3_3V), /* 0x0b IN_3V3 */
59 STAT(Px, 12V), /* 0x0c IN_12V0 */
60 STAT(Px, 1_2VA), /* 0x0d IN_1V2A */
61 STAT(Px, VREF), /* 0x0e IN_VREF */
62 STAT(Px, VAOE), /* 0x0f OUT_VAOE */
63 STAT(Px, AOE_TEMP), /* 0x10 AOE_TEMP */
64 STAT(Px, PSU_AOE_TEMP), /* 0x11 PSU_AOE_TEMP */
65 STAT(Px, PSU_TEMP), /* 0x12 PSU_TEMP */
66 STAT(Px, FAN0), /* 0x13 FAN_0 */
67 STAT(Px, FAN1), /* 0x14 FAN_1 */
68 STAT(Px, FAN2), /* 0x15 FAN_2 */
69 STAT(Px, FAN3), /* 0x16 FAN_3 */
70 STAT(Px, FAN4), /* 0x17 FAN_4 */
71 STAT(Px, VAOE_IN), /* 0x18 IN_VAOE */
72 STAT(Px, IAOE), /* 0x19 OUT_IAOE */
73 STAT(Px, IAOE_IN), /* 0x1a IN_IAOE */
74 STAT(Px, NIC_POWER), /* 0x1b NIC_POWER */
75 STAT(Px, 0_9V), /* 0x1c IN_0V9 */
76 STAT(Px, I0_9V), /* 0x1d IN_I0V9 */
77 STAT(Px, I1_2V), /* 0x1e IN_I1V2 */
78 STAT_NEXT_PAGE(), /* 0x1f Next page flag (not a sensor) */
80 /* Sensor page 1 MC_CMD_SENSOR_xxx */
81 STAT(Px, 0_9V_ADC), /* 0x20 IN_0V9_ADC */
82 STAT(Px, INT_TEMP2), /* 0x21 CONTROLLER_2_TEMP */
83 STAT(Px, VREG_TEMP), /* 0x22 VREG_INTERNAL_TEMP */
84 STAT(Px, VREG_0_9V_TEMP), /* 0x23 VREG_0V9_TEMP */
85 STAT(Px, VREG_1_2V_TEMP), /* 0x24 VREG_1V2_TEMP */
86 STAT(Px, INT_VPTAT), /* 0x25 CTRLR. VPTAT */
87 STAT(Px, INT_ADC_TEMP), /* 0x26 CTRLR. INTERNAL_TEMP */
88 STAT(Px, EXT_VPTAT), /* 0x27 CTRLR. VPTAT_EXTADC */
89 STAT(Px, EXT_ADC_TEMP), /* 0x28 CTRLR. INTERNAL_TEMP_EXTADC */
90 STAT(Px, AMBIENT_TEMP), /* 0x29 AMBIENT_TEMP */
91 STAT(Px, AIRFLOW), /* 0x2a AIRFLOW */
92 STAT(Px, VDD08D_VSS08D_CSR), /* 0x2b VDD08D_VSS08D_CSR */
93 STAT(Px, VDD08D_VSS08D_CSR_EXTADC), /* 0x2c VDD08D_VSS08D_CSR_EXTADC */
94 STAT(Px, HOTPOINT_TEMP), /* 0x2d HOTPOINT_TEMP */
95 STAT(P1, PHY_POWER_SWITCH_PORT0), /* 0x2e PHY_POWER_SWITCH_PORT0 */
96 STAT(P2, PHY_POWER_SWITCH_PORT1), /* 0x2f PHY_POWER_SWITCH_PORT1 */
97 STAT(Px, MUM_VCC), /* 0x30 MUM_VCC */
98 STAT(Px, 0V9_A), /* 0x31 0V9_A */
99 STAT(Px, I0V9_A), /* 0x32 I0V9_A */
100 STAT(Px, 0V9_A_TEMP), /* 0x33 0V9_A_TEMP */
101 STAT(Px, 0V9_B), /* 0x34 0V9_B */
102 STAT(Px, I0V9_B), /* 0x35 I0V9_B */
103 STAT(Px, 0V9_B_TEMP), /* 0x36 0V9_B_TEMP */
104 STAT(Px, CCOM_AVREG_1V2_SUPPLY), /* 0x37 CCOM_AVREG_1V2_SUPPLY */
105 STAT(Px, CCOM_AVREG_1V2_SUPPLY_EXT_ADC),
106 /* 0x38 CCOM_AVREG_1V2_SUPPLY_EXT_ADC */
107 STAT(Px, CCOM_AVREG_1V8_SUPPLY), /* 0x39 CCOM_AVREG_1V8_SUPPLY */
108 STAT(Px, CCOM_AVREG_1V8_SUPPLY_EXT_ADC),
109 /* 0x3a CCOM_AVREG_1V8_SUPPLY_EXT_ADC */
110 STAT_NO_SENSOR(), /* 0x3b (no sensor) */
111 STAT_NO_SENSOR(), /* 0x3c (no sensor) */
112 STAT_NO_SENSOR(), /* 0x3d (no sensor) */
113 STAT_NO_SENSOR(), /* 0x3e (no sensor) */
114 STAT_NEXT_PAGE(), /* 0x3f Next page flag (not a sensor) */
116 /* Sensor page 2 MC_CMD_SENSOR_xxx */
117 STAT(Px, CONTROLLER_MASTER_VPTAT), /* 0x40 MASTER_VPTAT */
118 STAT(Px, CONTROLLER_MASTER_INTERNAL_TEMP), /* 0x41 MASTER_INT_TEMP */
119 STAT(Px, CONTROLLER_MASTER_VPTAT_EXT_ADC), /* 0x42 MAST_VPTAT_EXT_ADC */
120 STAT(Px, CONTROLLER_MASTER_INTERNAL_TEMP_EXT_ADC),
121 /* 0x43 MASTER_INTERNAL_TEMP_EXT_ADC */
122 STAT(Px, CONTROLLER_SLAVE_VPTAT), /* 0x44 SLAVE_VPTAT */
123 STAT(Px, CONTROLLER_SLAVE_INTERNAL_TEMP), /* 0x45 SLAVE_INTERNAL_TEMP */
124 STAT(Px, CONTROLLER_SLAVE_VPTAT_EXT_ADC), /* 0x46 SLAVE_VPTAT_EXT_ADC */
125 STAT(Px, CONTROLLER_SLAVE_INTERNAL_TEMP_EXT_ADC),
126 /* 0x47 SLAVE_INTERNAL_TEMP_EXT_ADC */
127 STAT_NO_SENSOR(), /* 0x48 (no sensor) */
128 STAT(Px, SODIMM_VOUT), /* 0x49 SODIMM_VOUT */
129 STAT(Px, SODIMM_0_TEMP), /* 0x4a SODIMM_0_TEMP */
130 STAT(Px, SODIMM_1_TEMP), /* 0x4b SODIMM_1_TEMP */
131 STAT(Px, PHY0_VCC), /* 0x4c PHY0_VCC */
132 STAT(Px, PHY1_VCC), /* 0x4d PHY1_VCC */
133 STAT(Px, CONTROLLER_TDIODE_TEMP), /* 0x4e CONTROLLER_TDIODE_TEMP */
134 STAT(Px, BOARD_FRONT_TEMP), /* 0x4f BOARD_FRONT_TEMP */
135 STAT(Px, BOARD_BACK_TEMP), /* 0x50 BOARD_BACK_TEMP */
136 STAT(Px, I1V8), /* 0x51 IN_I1V8 */
137 STAT(Px, I2V5), /* 0x52 IN_I2V5 */
138 STAT(Px, I3V3), /* 0x53 IN_I3V3 */
139 STAT(Px, I12V0), /* 0x54 IN_I12V0 */
140 STAT(Px, 1_3V), /* 0x55 IN_1V3 */
141 STAT(Px, I1V3), /* 0x56 IN_I1V3 */
144 #define MCDI_STATIC_SENSOR_ASSERT(_field) \
145 EFX_STATIC_ASSERT(MC_CMD_SENSOR_STATE_ ## _field \
146 == EFX_MON_STAT_STATE_ ## _field)
149 mcdi_mon_decode_stats(
151 __in_bcount(sensor_mask_size) uint32_t *sensor_mask,
152 __in size_t sensor_mask_size,
153 __in_opt efsys_mem_t *esmp,
154 __out_bcount_opt(sensor_mask_size) uint32_t *stat_maskp,
155 __inout_ecount_opt(EFX_MON_NSTATS) efx_mon_stat_value_t *stat)
157 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
161 uint32_t stat_mask[(EFX_ARRAY_SIZE(mcdi_sensor_map) + 31) / 32];
165 /* Assert the MC_CMD_SENSOR and EFX_MON_STATE namespaces agree */
166 MCDI_STATIC_SENSOR_ASSERT(OK);
167 MCDI_STATIC_SENSOR_ASSERT(WARNING);
168 MCDI_STATIC_SENSOR_ASSERT(FATAL);
169 MCDI_STATIC_SENSOR_ASSERT(BROKEN);
170 MCDI_STATIC_SENSOR_ASSERT(NO_READING);
172 EFX_STATIC_ASSERT(sizeof (stat_mask[0]) * 8 ==
173 EFX_MON_MASK_ELEMENT_SIZE);
175 MIN((8 * sensor_mask_size), EFX_ARRAY_SIZE(mcdi_sensor_map));
177 EFSYS_ASSERT(emip->emi_port > 0); /* MCDI port number is one-based */
178 port_mask = MCDI_MON_PORT_MASK(emip);
180 memset(stat_mask, 0, sizeof (stat_mask));
183 * The MCDI sensor readings in the DMA buffer are a packed array of
184 * MC_CMD_SENSOR_VALUE_ENTRY structures, which only includes entries for
185 * supported sensors (bit set in sensor_mask). The sensor_mask and
186 * sensor readings do not include entries for the per-page NEXT_PAGE
189 * sensor_mask may legitimately contain MCDI sensors that the driver
190 * does not understand.
192 for (sensor = 0; sensor < sensor_max; ++sensor) {
193 efx_mon_stat_t id = mcdi_sensor_map[sensor].msm_stat;
195 if ((sensor % MCDI_MON_PAGE_SIZE) == MC_CMD_SENSOR_PAGE0_NEXT) {
196 EFSYS_ASSERT3U(id, ==, MCDI_MON_NEXT_PAGE);
200 if (~(sensor_mask[page]) & (1U << sensor))
204 if ((port_mask & mcdi_sensor_map[sensor].msm_port_mask) == 0)
206 EFSYS_ASSERT(id < EFX_MON_NSTATS);
209 * stat_mask is a bitmask indexed by EFX_MON_* monitor statistic
210 * identifiers from efx_mon_stat_t (without NEXT_PAGE bits).
212 * If there is an entry in the MCDI sensor to monitor statistic
213 * map then the sensor reading is used for the value of the
216 stat_mask[id / EFX_MON_MASK_ELEMENT_SIZE] |=
217 (1U << (id % EFX_MON_MASK_ELEMENT_SIZE));
219 if (stat != NULL && esmp != NULL && !EFSYS_MEM_IS_NULL(esmp)) {
222 /* Get MCDI sensor reading from DMA buffer */
223 EFSYS_MEM_READD(esmp, 4 * (idx - 1), &dword);
225 /* Update EFX monitor stat from MCDI sensor reading */
226 stat[id].emsv_value = (uint16_t)EFX_DWORD_FIELD(dword,
227 MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_VALUE);
229 stat[id].emsv_state = (uint16_t)EFX_DWORD_FIELD(dword,
230 MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE);
234 if (stat_maskp != NULL) {
235 memcpy(stat_maskp, stat_mask, sizeof (stat_mask));
239 __checkReturn efx_rc_t
242 __in efx_qword_t *eqp,
243 __out efx_mon_stat_t *idp,
244 __out efx_mon_stat_value_t *valuep)
246 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
254 EFSYS_ASSERT(emip->emi_port > 0); /* MCDI port number is one-based */
255 port_mask = MCDI_MON_PORT_MASK(emip);
257 sensor = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_MONITOR);
258 state = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_STATE);
259 value = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_VALUE);
261 /* Hardware must support this MCDI sensor */
262 EFSYS_ASSERT3U(sensor, <,
263 (8 * enp->en_nic_cfg.enc_mcdi_sensor_mask_size));
264 EFSYS_ASSERT((sensor % MCDI_MON_PAGE_SIZE) != MC_CMD_SENSOR_PAGE0_NEXT);
265 EFSYS_ASSERT(enp->en_nic_cfg.enc_mcdi_sensor_maskp != NULL);
267 (enp->en_nic_cfg.enc_mcdi_sensor_maskp[sensor/MCDI_MON_PAGE_SIZE] &
268 (1U << (sensor % MCDI_MON_PAGE_SIZE))) != 0);
270 /* But we don't have to understand it */
271 if (sensor >= EFX_ARRAY_SIZE(mcdi_sensor_map)) {
275 id = mcdi_sensor_map[sensor].msm_stat;
276 if ((port_mask & mcdi_sensor_map[sensor].msm_port_mask) == 0)
278 EFSYS_ASSERT(id < EFX_MON_NSTATS);
281 valuep->emsv_value = value;
282 valuep->emsv_state = state;
287 EFSYS_PROBE1(fail1, efx_rc_t, rc);
293 static __checkReturn efx_rc_t
294 efx_mcdi_read_sensors(
296 __in efsys_mem_t *esmp,
300 uint8_t payload[MAX(MC_CMD_READ_SENSORS_EXT_IN_LEN,
301 MC_CMD_READ_SENSORS_EXT_OUT_LEN)];
302 uint32_t addr_lo, addr_hi;
304 req.emr_cmd = MC_CMD_READ_SENSORS;
305 req.emr_in_buf = payload;
306 req.emr_in_length = MC_CMD_READ_SENSORS_EXT_IN_LEN;
307 req.emr_out_buf = payload;
308 req.emr_out_length = MC_CMD_READ_SENSORS_EXT_OUT_LEN;
310 addr_lo = (uint32_t)(EFSYS_MEM_ADDR(esmp) & 0xffffffff);
311 addr_hi = (uint32_t)(EFSYS_MEM_ADDR(esmp) >> 32);
313 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_DMA_ADDR_LO, addr_lo);
314 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_DMA_ADDR_HI, addr_hi);
315 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_LENGTH, size);
317 efx_mcdi_execute(enp, &req);
322 static __checkReturn efx_rc_t
323 efx_mcdi_sensor_info_npages(
325 __out uint32_t *npagesp)
328 uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
329 MC_CMD_SENSOR_INFO_OUT_LENMAX)];
333 EFSYS_ASSERT(npagesp != NULL);
337 (void) memset(payload, 0, sizeof (payload));
338 req.emr_cmd = MC_CMD_SENSOR_INFO;
339 req.emr_in_buf = payload;
340 req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN;
341 req.emr_out_buf = payload;
342 req.emr_out_length = MC_CMD_SENSOR_INFO_OUT_LENMAX;
344 MCDI_IN_SET_DWORD(req, SENSOR_INFO_EXT_IN_PAGE, page++);
346 efx_mcdi_execute_quiet(enp, &req);
348 if (req.emr_rc != 0) {
352 } while (MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK) &
353 (1U << MC_CMD_SENSOR_PAGE0_NEXT));
360 EFSYS_PROBE1(fail1, efx_rc_t, rc);
365 static __checkReturn efx_rc_t
366 efx_mcdi_sensor_info(
368 __out_ecount(npages) uint32_t *sensor_maskp,
372 uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
373 MC_CMD_SENSOR_INFO_OUT_LENMAX)];
377 EFSYS_ASSERT(sensor_maskp != NULL);
384 for (page = 0; page < npages; page++) {
387 (void) memset(payload, 0, sizeof (payload));
388 req.emr_cmd = MC_CMD_SENSOR_INFO;
389 req.emr_in_buf = payload;
390 req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN;
391 req.emr_out_buf = payload;
392 req.emr_out_length = MC_CMD_SENSOR_INFO_OUT_LENMAX;
394 MCDI_IN_SET_DWORD(req, SENSOR_INFO_EXT_IN_PAGE, page);
396 efx_mcdi_execute(enp, &req);
398 if (req.emr_rc != 0) {
403 mask = MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK);
405 if ((page != (npages - 1)) &&
406 ((mask & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) == 0)) {
410 sensor_maskp[page] = mask;
413 if (sensor_maskp[npages - 1] & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) {
427 EFSYS_PROBE1(fail1, efx_rc_t, rc);
432 __checkReturn efx_rc_t
433 mcdi_mon_stats_update(
435 __in efsys_mem_t *esmp,
436 __inout_ecount(EFX_MON_NSTATS) efx_mon_stat_value_t *values)
438 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
439 uint32_t size = encp->enc_mon_stat_dma_buf_size;
442 if ((rc = efx_mcdi_read_sensors(enp, esmp, size)) != 0)
445 EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, size);
447 mcdi_mon_decode_stats(enp,
448 encp->enc_mcdi_sensor_maskp,
449 encp->enc_mcdi_sensor_mask_size,
455 EFSYS_PROBE1(fail1, efx_rc_t, rc);
460 __checkReturn efx_rc_t
464 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
468 switch (enp->en_family) {
470 case EFX_FAMILY_SIENA:
471 encp->enc_mon_type = EFX_MON_SFC90X0;
474 #if EFSYS_OPT_HUNTINGTON
475 case EFX_FAMILY_HUNTINGTON:
476 encp->enc_mon_type = EFX_MON_SFC91X0;
479 #if EFSYS_OPT_MEDFORD
480 case EFX_FAMILY_MEDFORD:
481 encp->enc_mon_type = EFX_MON_SFC92X0;
484 #if EFSYS_OPT_MEDFORD2
485 case EFX_FAMILY_MEDFORD2:
486 encp->enc_mon_type = EFX_MON_SFC92X0;
494 /* Get mc sensor mask size */
496 if ((rc = efx_mcdi_sensor_info_npages(enp, &npages)) != 0)
499 encp->enc_mon_stat_dma_buf_size = npages * EFX_MON_STATS_PAGE_SIZE;
500 encp->enc_mcdi_sensor_mask_size = npages * sizeof (uint32_t);
502 /* Allocate mc sensor mask */
503 EFSYS_KMEM_ALLOC(enp->en_esip,
504 encp->enc_mcdi_sensor_mask_size,
505 encp->enc_mcdi_sensor_maskp);
507 if (encp->enc_mcdi_sensor_maskp == NULL) {
512 /* Read mc sensor mask */
513 if ((rc = efx_mcdi_sensor_info(enp,
514 encp->enc_mcdi_sensor_maskp,
518 /* Build monitor statistics mask */
519 mcdi_mon_decode_stats(enp,
520 encp->enc_mcdi_sensor_maskp,
521 encp->enc_mcdi_sensor_mask_size,
522 NULL, encp->enc_mon_stat_mask, NULL);
528 EFSYS_KMEM_FREE(enp->en_esip,
529 encp->enc_mcdi_sensor_mask_size,
530 encp->enc_mcdi_sensor_maskp);
539 EFSYS_PROBE1(fail1, efx_rc_t, rc);
548 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
550 if (encp->enc_mcdi_sensor_maskp != NULL) {
551 EFSYS_KMEM_FREE(enp->en_esip,
552 encp->enc_mcdi_sensor_mask_size,
553 encp->enc_mcdi_sensor_maskp);
558 #endif /* EFSYS_OPT_MON_STATS */
560 #endif /* EFSYS_OPT_MON_MCDI */