mt76: mt7615: add support to read temperature from mcu
authorLorenzo Bianconi <lorenzo@kernel.org>
Mon, 2 Sep 2019 12:51:54 +0000 (14:51 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 5 Sep 2019 16:14:15 +0000 (18:14 +0200)
Introduce debugfs entry to read device temperature and related cmu
command. Introduce mt7615_mcu_parse_response to parse mcu response
messages and refactor mt7615_mcu_msg_send routine

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
drivers/net/wireless/mediatek/mt76/mt7615/mcu.h
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h

index e62a5eb1bf5382f14c136dac627f670e122ea403..2428a4659a1c09dcea021cdbdfa42faaabcdd4d1 100644 (file)
@@ -49,6 +49,18 @@ mt7615_radio_read(struct seq_file *s, void *data)
        return 0;
 }
 
+static int mt7615_read_temperature(struct seq_file *s, void *data)
+{
+       struct mt7615_dev *dev = dev_get_drvdata(s->private);
+       int temp;
+
+       /* cpu */
+       temp = mt7615_mcu_get_temperature(dev, 0);
+       seq_printf(s, "Temperature: %d\n", temp);
+
+       return 0;
+}
+
 int mt7615_init_debugfs(struct mt7615_dev *dev)
 {
        struct dentry *dir;
@@ -72,6 +84,8 @@ int mt7615_init_debugfs(struct mt7615_dev *dev)
                           &dev->radar_pattern.power);
        debugfs_create_file("radar_trigger", 0200, dir, dev,
                            &fops_radar_pattern);
+       debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir,
+                                   mt7615_read_temperature);
 
        return 0;
 }
index 51554af5aa2d647f876883cd69bf66440d8391dc..275d5eaed3b7f7aefad2bbb9bd5fbc693fb9c5ed 100644 (file)
@@ -112,13 +112,39 @@ static int __mt7615_mcu_msg_send(struct mt7615_dev *dev, struct sk_buff *skb,
        return mt76_tx_queue_skb_raw(dev, qid, skb, 0);
 }
 
+static int
+mt7615_mcu_parse_response(struct mt7615_dev *dev, int cmd,
+                         struct sk_buff *skb, int seq)
+{
+       struct mt7615_mcu_rxd *rxd = (struct mt7615_mcu_rxd *)skb->data;
+       int ret = 0;
+
+       if (seq != rxd->seq)
+               return -EAGAIN;
+
+       switch (cmd) {
+       case -MCU_CMD_PATCH_SEM_CONTROL:
+               skb_pull(skb, sizeof(*rxd) - 4);
+               ret = *skb->data;
+               break;
+       case MCU_EXT_CMD_GET_TEMP:
+               skb_pull(skb, sizeof(*rxd));
+               ret = le32_to_cpu(*(__le32 *)skb->data);
+               break;
+       default:
+               break;
+       }
+       dev_kfree_skb(skb);
+
+       return ret;
+}
+
 static int
 mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
                    int len, bool wait_resp)
 {
        struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
        unsigned long expires = jiffies + 10 * HZ;
-       struct mt7615_mcu_rxd *rxd;
        struct sk_buff *skb;
        int ret, seq;
 
@@ -141,16 +167,9 @@ mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
                        break;
                }
 
-               rxd = (struct mt7615_mcu_rxd *)skb->data;
-               if (seq != rxd->seq)
-                       continue;
-
-               if (cmd == -MCU_CMD_PATCH_SEM_CONTROL) {
-                       skb_pull(skb, sizeof(*rxd) - 4);
-                       ret = *skb->data;
-               }
-               dev_kfree_skb(skb);
-               break;
+               ret = mt7615_mcu_parse_response(dev, cmd, skb, seq);
+               if (ret != -EAGAIN)
+                       break;
        }
 
 out:
@@ -1574,3 +1593,16 @@ int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev,
        return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_WTBL_UPDATE,
                                   &wtbl_req, sizeof(wtbl_req), true);
 }
+
+int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index)
+{
+       struct {
+               u8 action;
+               u8 rsv[3];
+       } req = {
+               .action = index,
+       };
+
+       return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_GET_TEMP, &req,
+                                  sizeof(req), true);
+}
index d4d08fa593494f413575f38cce782a6807e5f7cc..1fd7dffa6eef58329bcf9ed692a30e956ae6edf1 100644 (file)
@@ -98,6 +98,7 @@ enum {
        MCU_EXT_CMD_BSS_INFO_UPDATE = 0x26,
        MCU_EXT_CMD_EDCA_UPDATE = 0x27,
        MCU_EXT_CMD_DEV_INFO_UPDATE = 0x2A,
+       MCU_EXT_CMD_GET_TEMP = 0x2c,
        MCU_EXT_CMD_WTBL_UPDATE = 0x32,
        MCU_EXT_CMD_SET_RDD_CTRL = 0x3a,
        MCU_EXT_CMD_PROTECT_CTRL = 0x3e,
index a79f4ffcb70f019fdfcc6afbf5fb8906c6f458ee..cef3fd43cb00e716a2b4e44d8afa8a38ec12f410 100644 (file)
@@ -246,6 +246,7 @@ int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
 int mt7615_mcu_init_mac(struct mt7615_dev *dev);
 int mt7615_mcu_set_rts_thresh(struct mt7615_dev *dev, u32 val);
 int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int enter);
+int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
 int mt7615_mcu_set_tx_power(struct mt7615_dev *dev);
 void mt7615_mcu_exit(struct mt7615_dev *dev);