mt76x02u: implement beacon_ops
authorStanislaw Gruszka <sgruszka@redhat.com>
Tue, 19 Mar 2019 10:37:39 +0000 (11:37 +0100)
committerFelix Fietkau <nbd@nbd.name>
Wed, 1 May 2019 11:03:56 +0000 (13:03 +0200)
Add implementation of beacon_ops for USB and exit function to
stop the timer if running when device is removed. Still no
actual work on pre tbtt event.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c
drivers/net/wireless/mediatek/mt76/mt76x02_usb.h
drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c

index eb92c27..ab8c47f 100644 (file)
@@ -87,14 +87,11 @@ static void mt76x0u_mac_stop(struct mt76x02_dev *dev)
        cancel_delayed_work_sync(&dev->cal_work);
        cancel_delayed_work_sync(&dev->mac_work);
        mt76u_stop_stat_wk(&dev->mt76);
+       mt76x02u_exit_beacon_config(dev);
 
        if (test_bit(MT76_REMOVED, &dev->mt76.state))
                return;
 
-       mt76_clear(dev, MT_BEACON_TIME_CFG, MT_BEACON_TIME_CFG_TIMER_EN |
-                  MT_BEACON_TIME_CFG_SYNC_MODE | MT_BEACON_TIME_CFG_TBTT_EN |
-                  MT_BEACON_TIME_CFG_BEACON_TX);
-
        if (!mt76_poll(dev, MT_USB_DMA_CFG, MT_USB_DMA_CFG_TX_BUSY, 0, 1000))
                dev_warn(dev->mt76.dev, "TX DMA did not stop\n");
 
index 6ff740f..a012410 100644 (file)
@@ -32,4 +32,5 @@ int mt76x02u_tx_prepare_skb(struct mt76_dev *mdev, void *data,
 void mt76x02u_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
                              struct mt76_queue_entry *e);
 void mt76x02u_init_beacon_config(struct mt76x02_dev *dev);
+void mt76x02u_exit_beacon_config(struct mt76x02_dev *dev);
 #endif /* __MT76x02_USB_H */
index eec6f85..82b78cc 100644 (file)
@@ -151,6 +151,15 @@ static void mt76x02u_restart_pre_tbtt_timer(struct mt76x02_dev *dev)
        hrtimer_start(&dev->pre_tbtt_timer, time, HRTIMER_MODE_REL);
 }
 
+static void mt76x02u_stop_pre_tbtt_timer(struct mt76x02_dev *dev)
+{
+       do {
+               hrtimer_cancel(&dev->pre_tbtt_timer);
+               cancel_work_sync(&dev->pre_tbtt_work);
+               /* Timer can be rearmed by work. */
+       } while (hrtimer_active(&dev->pre_tbtt_timer));
+}
+
 static void mt76x02u_pre_tbtt_work(struct work_struct *work)
 {
        struct mt76x02_dev *dev =
@@ -173,10 +182,21 @@ static enum hrtimer_restart mt76x02u_pre_tbtt_interrupt(struct hrtimer *timer)
 
 static void mt76x02u_pre_tbtt_enable(struct mt76x02_dev *dev, bool en)
 {
+       if (en && dev->beacon_mask && !hrtimer_active(&dev->pre_tbtt_timer))
+               mt76x02u_start_pre_tbtt_timer(dev);
+       if (!en)
+               mt76x02u_stop_pre_tbtt_timer(dev);
 }
 
 static void mt76x02u_beacon_enable(struct mt76x02_dev *dev, bool en)
 {
+       if (WARN_ON_ONCE(!dev->beacon_int))
+               return;
+
+       if (en)
+               mt76x02u_start_pre_tbtt_timer(dev);
+
+       /* Nothing to do on disable as timer is already stopped */
 }
 
 void mt76x02u_init_beacon_config(struct mt76x02_dev *dev)
@@ -194,3 +214,16 @@ void mt76x02u_init_beacon_config(struct mt76x02_dev *dev)
        mt76x02_init_beacon_config(dev);
 }
 EXPORT_SYMBOL_GPL(mt76x02u_init_beacon_config);
+
+void mt76x02u_exit_beacon_config(struct mt76x02_dev *dev)
+{
+       if (!test_bit(MT76_REMOVED, &dev->mt76.state))
+               mt76_clear(dev, MT_BEACON_TIME_CFG,
+                          MT_BEACON_TIME_CFG_TIMER_EN |
+                          MT_BEACON_TIME_CFG_SYNC_MODE |
+                          MT_BEACON_TIME_CFG_TBTT_EN |
+                          MT_BEACON_TIME_CFG_BEACON_TX);
+
+       mt76x02u_stop_pre_tbtt_timer(dev);
+}
+EXPORT_SYMBOL_GPL(mt76x02u_exit_beacon_config);