Skip to content

Commit

Permalink
mt76x02u: implement beacon_ops
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>
  • Loading branch information
Stanislaw Gruszka authored and nbd168 committed Mar 24, 2019
1 parent 6370485 commit 37af803
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions mt76x0/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ 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;

mutex_lock(&dev->mt76.mutex);
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");
Expand Down
1 change: 1 addition & 0 deletions mt76x02_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
33 changes: 33 additions & 0 deletions mt76x02_usb_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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 =
Expand All @@ -174,10 +183,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)
Expand All @@ -195,3 +215,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);

0 comments on commit 37af803

Please sign in to comment.