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 */
140 #define MCDI_STATIC_SENSOR_ASSERT(_field) \
141 EFX_STATIC_ASSERT(MC_CMD_SENSOR_STATE_ ## _field \
142 == EFX_MON_STAT_STATE_ ## _field)
145 mcdi_mon_decode_stats(
147 __in_bcount(sensor_mask_size) uint32_t *sensor_mask,
148 __in size_t sensor_mask_size,
149 __in_opt efsys_mem_t *esmp,
150 __out_bcount_opt(sensor_mask_size) uint32_t *stat_maskp,
151 __inout_ecount_opt(EFX_MON_NSTATS) efx_mon_stat_value_t *stat)
153 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
157 uint32_t stat_mask[(EFX_ARRAY_SIZE(mcdi_sensor_map) + 31) / 32];
161 /* Assert the MC_CMD_SENSOR and EFX_MON_STATE namespaces agree */
162 MCDI_STATIC_SENSOR_ASSERT(OK);
163 MCDI_STATIC_SENSOR_ASSERT(WARNING);
164 MCDI_STATIC_SENSOR_ASSERT(FATAL);
165 MCDI_STATIC_SENSOR_ASSERT(BROKEN);
166 MCDI_STATIC_SENSOR_ASSERT(NO_READING);
168 EFX_STATIC_ASSERT(sizeof (stat_mask[0]) * 8 ==
169 EFX_MON_MASK_ELEMENT_SIZE);
171 MIN((8 * sensor_mask_size), EFX_ARRAY_SIZE(mcdi_sensor_map));
173 EFSYS_ASSERT(emip->emi_port > 0); /* MCDI port number is one-based */
174 port_mask = MCDI_MON_PORT_MASK(emip);
176 memset(stat_mask, 0, sizeof (stat_mask));
179 * The MCDI sensor readings in the DMA buffer are a packed array of
180 * MC_CMD_SENSOR_VALUE_ENTRY structures, which only includes entries for
181 * supported sensors (bit set in sensor_mask). The sensor_mask and
182 * sensor readings do not include entries for the per-page NEXT_PAGE
185 * sensor_mask may legitimately contain MCDI sensors that the driver
186 * does not understand.
188 for (sensor = 0; sensor < sensor_max; ++sensor) {
189 efx_mon_stat_t id = mcdi_sensor_map[sensor].msm_stat;
191 if ((sensor % MCDI_MON_PAGE_SIZE) == MC_CMD_SENSOR_PAGE0_NEXT) {
192 EFSYS_ASSERT3U(id, ==, MCDI_MON_NEXT_PAGE);
196 if (~(sensor_mask[page]) & (1U << sensor))
200 if ((port_mask & mcdi_sensor_map[sensor].msm_port_mask) == 0)
202 EFSYS_ASSERT(id < EFX_MON_NSTATS);
205 * stat_mask is a bitmask indexed by EFX_MON_* monitor statistic
206 * identifiers from efx_mon_stat_t (without NEXT_PAGE bits).
208 * If there is an entry in the MCDI sensor to monitor statistic
209 * map then the sensor reading is used for the value of the
212 stat_mask[id / EFX_MON_MASK_ELEMENT_SIZE] |=
213 (1U << (id % EFX_MON_MASK_ELEMENT_SIZE));
215 if (stat != NULL && esmp != NULL && !EFSYS_MEM_IS_NULL(esmp)) {
218 /* Get MCDI sensor reading from DMA buffer */
219 EFSYS_MEM_READD(esmp, 4 * (idx - 1), &dword);
221 /* Update EFX monitor stat from MCDI sensor reading */
222 stat[id].emsv_value = (uint16_t)EFX_DWORD_FIELD(dword,
223 MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_VALUE);
225 stat[id].emsv_state = (uint16_t)EFX_DWORD_FIELD(dword,
226 MC_CMD_SENSOR_VALUE_ENTRY_TYPEDEF_STATE);
230 if (stat_maskp != NULL) {
231 memcpy(stat_maskp, stat_mask, sizeof (stat_mask));
235 __checkReturn efx_rc_t
238 __in efx_qword_t *eqp,
239 __out efx_mon_stat_t *idp,
240 __out efx_mon_stat_value_t *valuep)
242 efx_mcdi_iface_t *emip = &(enp->en_mcdi.em_emip);
250 EFSYS_ASSERT(emip->emi_port > 0); /* MCDI port number is one-based */
251 port_mask = MCDI_MON_PORT_MASK(emip);
253 sensor = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_MONITOR);
254 state = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_STATE);
255 value = (uint16_t)MCDI_EV_FIELD(eqp, SENSOREVT_VALUE);
257 /* Hardware must support this MCDI sensor */
258 EFSYS_ASSERT3U(sensor, <,
259 (8 * enp->en_nic_cfg.enc_mcdi_sensor_mask_size));
260 EFSYS_ASSERT((sensor % MCDI_MON_PAGE_SIZE) != MC_CMD_SENSOR_PAGE0_NEXT);
261 EFSYS_ASSERT(enp->en_nic_cfg.enc_mcdi_sensor_maskp != NULL);
263 (enp->en_nic_cfg.enc_mcdi_sensor_maskp[sensor/MCDI_MON_PAGE_SIZE] &
264 (1U << (sensor % MCDI_MON_PAGE_SIZE))) != 0);
266 /* But we don't have to understand it */
267 if (sensor >= EFX_ARRAY_SIZE(mcdi_sensor_map)) {
271 id = mcdi_sensor_map[sensor].msm_stat;
272 if ((port_mask & mcdi_sensor_map[sensor].msm_port_mask) == 0)
274 EFSYS_ASSERT(id < EFX_MON_NSTATS);
277 valuep->emsv_value = value;
278 valuep->emsv_state = state;
283 EFSYS_PROBE1(fail1, efx_rc_t, rc);
289 static __checkReturn efx_rc_t
290 efx_mcdi_read_sensors(
292 __in efsys_mem_t *esmp,
296 uint8_t payload[MAX(MC_CMD_READ_SENSORS_EXT_IN_LEN,
297 MC_CMD_READ_SENSORS_EXT_OUT_LEN)];
298 uint32_t addr_lo, addr_hi;
300 req.emr_cmd = MC_CMD_READ_SENSORS;
301 req.emr_in_buf = payload;
302 req.emr_in_length = MC_CMD_READ_SENSORS_EXT_IN_LEN;
303 req.emr_out_buf = payload;
304 req.emr_out_length = MC_CMD_READ_SENSORS_EXT_OUT_LEN;
306 addr_lo = (uint32_t)(EFSYS_MEM_ADDR(esmp) & 0xffffffff);
307 addr_hi = (uint32_t)(EFSYS_MEM_ADDR(esmp) >> 32);
309 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_DMA_ADDR_LO, addr_lo);
310 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_DMA_ADDR_HI, addr_hi);
311 MCDI_IN_SET_DWORD(req, READ_SENSORS_EXT_IN_LENGTH, size);
313 efx_mcdi_execute(enp, &req);
318 static __checkReturn efx_rc_t
319 efx_mcdi_sensor_info_npages(
321 __out uint32_t *npagesp)
324 uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
325 MC_CMD_SENSOR_INFO_OUT_LENMAX)];
329 EFSYS_ASSERT(npagesp != NULL);
333 (void) memset(payload, 0, sizeof (payload));
334 req.emr_cmd = MC_CMD_SENSOR_INFO;
335 req.emr_in_buf = payload;
336 req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN;
337 req.emr_out_buf = payload;
338 req.emr_out_length = MC_CMD_SENSOR_INFO_OUT_LENMAX;
340 MCDI_IN_SET_DWORD(req, SENSOR_INFO_EXT_IN_PAGE, page++);
342 efx_mcdi_execute_quiet(enp, &req);
344 if (req.emr_rc != 0) {
348 } while (MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK) &
349 (1U << MC_CMD_SENSOR_PAGE0_NEXT));
356 EFSYS_PROBE1(fail1, efx_rc_t, rc);
361 static __checkReturn efx_rc_t
362 efx_mcdi_sensor_info(
364 __out_ecount(npages) uint32_t *sensor_maskp,
368 uint8_t payload[MAX(MC_CMD_SENSOR_INFO_EXT_IN_LEN,
369 MC_CMD_SENSOR_INFO_OUT_LENMAX)];
373 EFSYS_ASSERT(sensor_maskp != NULL);
380 for (page = 0; page < npages; page++) {
383 (void) memset(payload, 0, sizeof (payload));
384 req.emr_cmd = MC_CMD_SENSOR_INFO;
385 req.emr_in_buf = payload;
386 req.emr_in_length = MC_CMD_SENSOR_INFO_EXT_IN_LEN;
387 req.emr_out_buf = payload;
388 req.emr_out_length = MC_CMD_SENSOR_INFO_OUT_LENMAX;
390 MCDI_IN_SET_DWORD(req, SENSOR_INFO_EXT_IN_PAGE, page);
392 efx_mcdi_execute(enp, &req);
394 if (req.emr_rc != 0) {
399 mask = MCDI_OUT_DWORD(req, SENSOR_INFO_OUT_MASK);
401 if ((page != (npages - 1)) &&
402 ((mask & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) == 0)) {
406 sensor_maskp[page] = mask;
409 if (sensor_maskp[npages - 1] & (1U << MC_CMD_SENSOR_PAGE0_NEXT)) {
423 EFSYS_PROBE1(fail1, efx_rc_t, rc);
428 __checkReturn efx_rc_t
429 mcdi_mon_stats_update(
431 __in efsys_mem_t *esmp,
432 __inout_ecount(EFX_MON_NSTATS) efx_mon_stat_value_t *values)
434 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
435 uint32_t size = encp->enc_mon_stat_dma_buf_size;
438 if ((rc = efx_mcdi_read_sensors(enp, esmp, size)) != 0)
441 EFSYS_DMA_SYNC_FOR_KERNEL(esmp, 0, size);
443 mcdi_mon_decode_stats(enp,
444 encp->enc_mcdi_sensor_maskp,
445 encp->enc_mcdi_sensor_mask_size,
451 EFSYS_PROBE1(fail1, efx_rc_t, rc);
456 __checkReturn efx_rc_t
460 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
464 switch (enp->en_family) {
466 case EFX_FAMILY_SIENA:
467 encp->enc_mon_type = EFX_MON_SFC90X0;
470 #if EFSYS_OPT_HUNTINGTON
471 case EFX_FAMILY_HUNTINGTON:
472 encp->enc_mon_type = EFX_MON_SFC91X0;
475 #if EFSYS_OPT_MEDFORD
476 case EFX_FAMILY_MEDFORD:
477 encp->enc_mon_type = EFX_MON_SFC92X0;
485 /* Get mc sensor mask size */
487 if ((rc = efx_mcdi_sensor_info_npages(enp, &npages)) != 0)
490 encp->enc_mon_stat_dma_buf_size = npages * EFX_MON_STATS_PAGE_SIZE;
491 encp->enc_mcdi_sensor_mask_size = npages * sizeof (uint32_t);
493 /* Allocate mc sensor mask */
494 EFSYS_KMEM_ALLOC(enp->en_esip,
495 encp->enc_mcdi_sensor_mask_size,
496 encp->enc_mcdi_sensor_maskp);
498 if (encp->enc_mcdi_sensor_maskp == NULL) {
503 /* Read mc sensor mask */
504 if ((rc = efx_mcdi_sensor_info(enp,
505 encp->enc_mcdi_sensor_maskp,
509 /* Build monitor statistics mask */
510 mcdi_mon_decode_stats(enp,
511 encp->enc_mcdi_sensor_maskp,
512 encp->enc_mcdi_sensor_mask_size,
513 NULL, encp->enc_mon_stat_mask, NULL);
519 EFSYS_KMEM_FREE(enp->en_esip,
520 encp->enc_mcdi_sensor_mask_size,
521 encp->enc_mcdi_sensor_maskp);
530 EFSYS_PROBE1(fail1, efx_rc_t, rc);
539 efx_nic_cfg_t *encp = &(enp->en_nic_cfg);
541 if (encp->enc_mcdi_sensor_maskp != NULL) {
542 EFSYS_KMEM_FREE(enp->en_esip,
543 encp->enc_mcdi_sensor_mask_size,
544 encp->enc_mcdi_sensor_maskp);
549 #endif /* EFSYS_OPT_MON_STATS */
551 #endif /* EFSYS_OPT_MON_MCDI */