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