raw/ifpga/base: introduce sensor functions
authorTianfei Zhang <tianfei.zhang@intel.com>
Thu, 14 Nov 2019 09:02:56 +0000 (17:02 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 20 Nov 2019 16:36:05 +0000 (17:36 +0100)
Introducing sensor APIs to PMD driver for PAC N3000 card.

Those sensor APIs:
1. opae_mgr_for_each_sensor()
2. opae_mgr_get_sensor_by_name()
3. opae_mgr_get_sensor_by_id()
4. opae_mgr_get_sensor_value_by_name()
5. opae_mgr_get_sensor_value_by_id()
6. opae_mgr_get_sensor_value()

Signed-off-by: Tianfei Zhang <tianfei.zhang@intel.com>
Signed-off-by: Andy Pei <andy.pei@intel.com>
drivers/raw/ifpga/base/ifpga_api.c
drivers/raw/ifpga/base/ifpga_feature_dev.h
drivers/raw/ifpga/base/ifpga_fme.c
drivers/raw/ifpga/base/opae_hw_api.c
drivers/raw/ifpga/base/opae_hw_api.h

index 7ae626d..33d1da3 100644 (file)
@@ -209,9 +209,19 @@ static int ifpga_mgr_get_eth_group_region_info(struct opae_manager *mgr,
        return 0;
 }
 
+static int ifpga_mgr_get_sensor_value(struct opae_manager *mgr,
+               struct opae_sensor_info *sensor,
+               unsigned int *value)
+{
+       struct ifpga_fme_hw *fme = mgr->data;
+
+       return fme_mgr_get_sensor_value(fme, sensor, value);
+}
+
 struct opae_manager_ops ifpga_mgr_ops = {
        .flash = ifpga_mgr_flash,
        .get_eth_group_region_info = ifpga_mgr_get_eth_group_region_info,
+       .get_sensor_value = ifpga_mgr_get_sensor_value,
 };
 
 static int ifpga_mgr_read_mac_rom(struct opae_manager *mgr, int offset,
index e243d42..2b1309b 100644 (file)
@@ -218,4 +218,7 @@ int fme_mgr_get_retimer_info(struct ifpga_fme_hw *fme,
                struct opae_retimer_info *info);
 int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
                struct opae_retimer_status *status);
+int fme_mgr_get_sensor_value(struct ifpga_fme_hw *fme,
+               struct opae_sensor_info *sensor,
+               unsigned int *value);
 #endif /* _IFPGA_FEATURE_DEV_H_ */
index 2b447fd..794ca09 100644 (file)
@@ -1300,3 +1300,24 @@ int fme_mgr_get_retimer_status(struct ifpga_fme_hw *fme,
 
        return 0;
 }
+
+int fme_mgr_get_sensor_value(struct ifpga_fme_hw *fme,
+               struct opae_sensor_info *sensor,
+               unsigned int *value)
+{
+       struct intel_max10_device *dev;
+
+       dev = (struct intel_max10_device *)fme->max10_dev;
+       if (!dev)
+               return -ENODEV;
+
+       if (max10_reg_read(sensor->value_reg, value)) {
+               dev_err(dev, "%s: read sensor value register 0x%x fail\n",
+                               __func__, sensor->value_reg);
+               return -EINVAL;
+       }
+
+       *value *= sensor->multiplier;
+
+       return 0;
+}
index 8964e79..d0e66d6 100644 (file)
@@ -575,3 +575,118 @@ int opae_manager_get_retimer_status(struct opae_manager *mgr,
 
        return -ENOENT;
 }
+
+/**
+ * opae_manager_get_sensor_by_id - get sensor device
+ * @id: the id of the sensor
+ *
+ * Return: the pointer of the opae_sensor_info
+ */
+struct opae_sensor_info *
+opae_mgr_get_sensor_by_id(unsigned int id)
+{
+       struct opae_sensor_info *sensor;
+
+       opae_mgr_for_each_sensor(sensor)
+               if (sensor->id == id)
+                       return sensor;
+
+       return NULL;
+}
+
+/**
+ * opae_manager_get_sensor_by_name - get sensor device
+ * @name: the name of the sensor
+ *
+ * Return: the pointer of the opae_sensor_info
+ */
+struct opae_sensor_info *
+opae_mgr_get_sensor_by_name(const char *name)
+{
+       struct opae_sensor_info *sensor;
+
+       opae_mgr_for_each_sensor(sensor)
+               if (!strcmp(sensor->name, name))
+                       return sensor;
+
+       return NULL;
+}
+
+/**
+ * opae_manager_get_sensor_value_by_name - find the sensor by name and read out
+ * the value
+ * @mgr: opae_manager for sensor.
+ * @name: the name of the sensor
+ * @value: the readout sensor value
+ *
+ * Return: 0 on success, otherwise error code
+ */
+int
+opae_mgr_get_sensor_value_by_name(struct opae_manager *mgr,
+               const char *name, unsigned int *value)
+{
+       struct opae_sensor_info *sensor;
+
+       if (!mgr)
+               return -EINVAL;
+
+       sensor = opae_mgr_get_sensor_by_name(name);
+       if (!sensor)
+               return -ENODEV;
+
+       if (mgr->ops && mgr->ops->get_sensor_value)
+               return mgr->ops->get_sensor_value(mgr, sensor, value);
+
+       return -ENOENT;
+}
+
+/**
+ * opae_manager_get_sensor_value_by_id - find the sensor by id and readout the
+ * value
+ * @mgr: opae_manager for sensor
+ * @id: the id of the sensor
+ * @value: the readout sensor value
+ *
+ * Return: 0 on success, otherwise error code
+ */
+int
+opae_mgr_get_sensor_value_by_id(struct opae_manager *mgr,
+               unsigned int id, unsigned int *value)
+{
+       struct opae_sensor_info *sensor;
+
+       if (!mgr)
+               return -EINVAL;
+
+       sensor = opae_mgr_get_sensor_by_id(id);
+       if (!sensor)
+               return -ENODEV;
+
+       if (mgr->ops && mgr->ops->get_sensor_value)
+               return mgr->ops->get_sensor_value(mgr, sensor, value);
+
+       return -ENOENT;
+}
+
+/**
+ * opae_manager_get_sensor_value - get the current
+ * sensor value
+ * @mgr: opae_manager for sensor
+ * @sensor: opae_sensor_info for sensor
+ * @value: the readout sensor value
+ *
+ * Return: 0 on success, otherwise error code
+ */
+int
+opae_mgr_get_sensor_value(struct opae_manager *mgr,
+               struct opae_sensor_info *sensor,
+               unsigned int *value)
+{
+       if (!mgr || !sensor)
+               return -EINVAL;
+
+       if (mgr->ops && mgr->ops->get_sensor_value)
+               return mgr->ops->get_sensor_value(mgr, sensor, value);
+
+       return -ENOENT;
+}
index 63405a4..0d7be01 100644 (file)
@@ -48,6 +48,9 @@ struct opae_manager_ops {
                     u32 size, u64 *status);
        int (*get_eth_group_region_info)(struct opae_manager *mgr,
                        struct opae_eth_group_region_info *info);
+       int (*get_sensor_value)(struct opae_manager *mgr,
+                       struct opae_sensor_info *sensor,
+                       unsigned int *value);
 };
 
 /* networking management ops in FME */
@@ -69,6 +72,10 @@ struct opae_manager_networking_ops {
                        struct opae_retimer_status *status);
 };
 
+extern struct opae_sensor_list opae_sensor_list;
+#define opae_mgr_for_each_sensor(sensor) \
+       TAILQ_FOREACH(sensor, &opae_sensor_list, node)
+
 /* OPAE Manager APIs */
 struct opae_manager *
 opae_manager_alloc(const char *name, struct opae_manager_ops *ops,
@@ -78,6 +85,15 @@ int opae_manager_flash(struct opae_manager *mgr, int acc_id, const char *buf,
                       u32 size, u64 *status);
 int opae_manager_get_eth_group_region_info(struct opae_manager *mgr,
                u8 group_id, struct opae_eth_group_region_info *info);
+struct opae_sensor_info *opae_mgr_get_sensor_by_name(const char *name);
+struct opae_sensor_info *opae_mgr_get_sensor_by_id(unsigned int id);
+int opae_mgr_get_sensor_value_by_name(struct opae_manager *mgr,
+               const char *name, unsigned int *value);
+int opae_mgr_get_sensor_value_by_id(struct opae_manager *mgr,
+               unsigned int id, unsigned int *value);
+int opae_mgr_get_sensor_value(struct opae_manager *mgr,
+               struct opae_sensor_info *sensor,
+               unsigned int *value);
 
 /* OPAE Bridge Data Structure */
 struct opae_bridge_ops;