]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/nfp/nfpcore/nfp_nsp_cmds.c
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / nfp / nfpcore / nfp_nsp_cmds.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Netronome Systems, Inc.
3 * All rights reserved.
4 */
5
6 #include <stdio.h>
7 #include <rte_byteorder.h>
8 #include "nfp_cpp.h"
9 #include "nfp_nsp.h"
10 #include "nfp_nffw.h"
11
12 struct nsp_identify {
13 uint8_t version[40];
14 uint8_t flags;
15 uint8_t br_primary;
16 uint8_t br_secondary;
17 uint8_t br_nsp;
18 uint16_t primary;
19 uint16_t secondary;
20 uint16_t nsp;
21 uint8_t reserved[6];
22 uint64_t sensor_mask;
23 };
24
25 struct nfp_nsp_identify *
26 __nfp_nsp_identify(struct nfp_nsp *nsp)
27 {
28 struct nfp_nsp_identify *nspi = NULL;
29 struct nsp_identify *ni;
30 int ret;
31
32 if (nfp_nsp_get_abi_ver_minor(nsp) < 15)
33 return NULL;
34
35 ni = malloc(sizeof(*ni));
36 if (!ni)
37 return NULL;
38
39 memset(ni, 0, sizeof(*ni));
40 ret = nfp_nsp_read_identify(nsp, ni, sizeof(*ni));
41 if (ret < 0) {
42 printf("reading bsp version failed %d\n",
43 ret);
44 goto exit_free;
45 }
46
47 nspi = malloc(sizeof(*nspi));
48 if (!nspi)
49 goto exit_free;
50
51 memset(nspi, 0, sizeof(*nspi));
52 memcpy(nspi->version, ni->version, sizeof(nspi->version));
53 nspi->version[sizeof(nspi->version) - 1] = '\0';
54 nspi->flags = ni->flags;
55 nspi->br_primary = ni->br_primary;
56 nspi->br_secondary = ni->br_secondary;
57 nspi->br_nsp = ni->br_nsp;
58 nspi->primary = rte_le_to_cpu_16(ni->primary);
59 nspi->secondary = rte_le_to_cpu_16(ni->secondary);
60 nspi->nsp = rte_le_to_cpu_16(ni->nsp);
61 nspi->sensor_mask = rte_le_to_cpu_64(ni->sensor_mask);
62
63 exit_free:
64 free(ni);
65 return nspi;
66 }
67
68 struct nfp_sensors {
69 uint32_t chip_temp;
70 uint32_t assembly_power;
71 uint32_t assembly_12v_power;
72 uint32_t assembly_3v3_power;
73 };
74
75 int
76 nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id, long *val)
77 {
78 struct nfp_sensors s;
79 struct nfp_nsp *nsp;
80 int ret;
81
82 nsp = nfp_nsp_open(cpp);
83 if (!nsp)
84 return -EIO;
85
86 ret = nfp_nsp_read_sensors(nsp, BIT(id), &s, sizeof(s));
87 nfp_nsp_close(nsp);
88
89 if (ret < 0)
90 return ret;
91
92 switch (id) {
93 case NFP_SENSOR_CHIP_TEMPERATURE:
94 *val = rte_le_to_cpu_32(s.chip_temp);
95 break;
96 case NFP_SENSOR_ASSEMBLY_POWER:
97 *val = rte_le_to_cpu_32(s.assembly_power);
98 break;
99 case NFP_SENSOR_ASSEMBLY_12V_POWER:
100 *val = rte_le_to_cpu_32(s.assembly_12v_power);
101 break;
102 case NFP_SENSOR_ASSEMBLY_3V3_POWER:
103 *val = rte_le_to_cpu_32(s.assembly_3v3_power);
104 break;
105 default:
106 return -EINVAL;
107 }
108 return 0;
109 }