2 * Copyright (C) 2017 Netronome Systems, Inc.
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/kernel.h>
35 #include <linux/slab.h>
53 struct nfp_nsp_identify *__nfp_nsp_identify(struct nfp_nsp *nsp)
55 struct nfp_nsp_identify *nspi = NULL;
56 struct nsp_identify *ni;
59 if (nfp_nsp_get_abi_ver_minor(nsp) < 15)
62 ni = kzalloc(sizeof(*ni), GFP_KERNEL);
66 ret = nfp_nsp_read_identify(nsp, ni, sizeof(*ni));
68 nfp_err(nfp_nsp_cpp(nsp), "reading bsp version failed %d\n",
73 nspi = kzalloc(sizeof(*nspi), GFP_KERNEL);
77 memcpy(nspi->version, ni->version, sizeof(nspi->version));
78 nspi->version[sizeof(nspi->version) - 1] = '\0';
79 nspi->flags = ni->flags;
80 nspi->br_primary = ni->br_primary;
81 nspi->br_secondary = ni->br_secondary;
82 nspi->br_nsp = ni->br_nsp;
83 nspi->primary = le16_to_cpu(ni->primary);
84 nspi->secondary = le16_to_cpu(ni->secondary);
85 nspi->nsp = le16_to_cpu(ni->nsp);
86 nspi->sensor_mask = le64_to_cpu(ni->sensor_mask);
95 __le32 assembly_power;
96 __le32 assembly_12v_power;
97 __le32 assembly_3v3_power;
100 int nfp_hwmon_read_sensor(struct nfp_cpp *cpp, enum nfp_nsp_sensor_id id,
103 struct nfp_sensors s;
107 nsp = nfp_nsp_open(cpp);
111 ret = nfp_nsp_read_sensors(nsp, BIT(id), &s, sizeof(s));
118 case NFP_SENSOR_CHIP_TEMPERATURE:
119 *val = le32_to_cpu(s.chip_temp);
121 case NFP_SENSOR_ASSEMBLY_POWER:
122 *val = le32_to_cpu(s.assembly_power);
124 case NFP_SENSOR_ASSEMBLY_12V_POWER:
125 *val = le32_to_cpu(s.assembly_12v_power);
127 case NFP_SENSOR_ASSEMBLY_3V3_POWER:
128 *val = le32_to_cpu(s.assembly_3v3_power);