Skip to content

Commit eee1504

Browse files
committed
wifi: mt76: add kernel version compatibility for timer APIs
Add version checks to support both old and new timer APIs across different kernel versions: - Use timer_delete_sync() on kernels >= 6.1, fall back to del_timer_sync() on older kernels. The timer_delete_sync() function was introduced in kernel 6.1 as a replacement for del_timer_sync(). - Use from_timer() for timer callbacks on kernels >= 4.15, fall back to container_of() on older kernels. The from_timer() macro was introduced in kernel 4.15 as part of the timer API modernization. - Use hrtimer_setup() on kernels >= 4.15, fall back to manual hrtimer_init() and function assignment on older kernels. The hrtimer_setup() helper was introduced alongside the timer callback changes in kernel 4.15. - Use timer_container_of() on kernels >= 6.16, from_timer() for 4.14 - 6.15, and container_of() for older kernels. Signed-off-by: John Audia <therealgraysky@proton.me>
1 parent 3c23252 commit eee1504

File tree

7 files changed

+67
-2
lines changed

7 files changed

+67
-2
lines changed

mt7615/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ static void mt7615_stop(struct ieee80211_hw *hw, bool suspend)
9797
struct mt7615_phy *phy = mt7615_hw_phy(hw);
9898

9999
cancel_delayed_work_sync(&phy->mt76->mac_work);
100+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
101+
timer_delete_sync(&phy->roc_timer);
102+
#else
100103
del_timer_sync(&phy->roc_timer);
104+
#endif
101105
cancel_work_sync(&phy->roc_work);
102106

103107
cancel_delayed_work_sync(&dev->pm.ps_work);
@@ -1046,7 +1050,13 @@ void mt7615_roc_work(struct work_struct *work)
10461050

10471051
void mt7615_roc_timer(struct timer_list *timer)
10481052
{
1053+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
1054+
struct mt7615_phy *phy = timer_container_of(phy, timer, roc_timer);
1055+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
10491056
struct mt7615_phy *phy = from_timer(phy, timer, roc_timer);
1057+
#else
1058+
struct mt7615_phy *phy = container_of(timer, struct mt7615_phy, roc_timer);
1059+
#endif
10501060

10511061
ieee80211_queue_work(phy->mt76->hw, &phy->roc_work);
10521062
}
@@ -1197,7 +1207,11 @@ static int mt7615_cancel_remain_on_channel(struct ieee80211_hw *hw,
11971207
if (!test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
11981208
return 0;
11991209

1210+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
1211+
timer_delete_sync(&phy->roc_timer);
1212+
#else
12001213
del_timer_sync(&phy->roc_timer);
1214+
#endif
12011215
cancel_work_sync(&phy->roc_work);
12021216

12031217
mt7615_mutex_acquire(phy->dev);

mt7615/pci_mac.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,20 @@ void mt7615_mac_reset_work(struct work_struct *work)
220220
set_bit(MT76_MCU_RESET, &dev->mphy.state);
221221
wake_up(&dev->mt76.mcu.wait);
222222
cancel_delayed_work_sync(&dev->mphy.mac_work);
223+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
224+
timer_delete_sync(&dev->phy.roc_timer);
225+
#else
223226
del_timer_sync(&dev->phy.roc_timer);
227+
#endif
224228
cancel_work_sync(&dev->phy.roc_work);
225229
if (phy2) {
226230
set_bit(MT76_RESET, &phy2->mt76->state);
227231
cancel_delayed_work_sync(&phy2->mt76->mac_work);
232+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
233+
timer_delete_sync(&phy2->roc_timer);
234+
#else
228235
del_timer_sync(&phy2->roc_timer);
236+
#endif
229237
cancel_work_sync(&phy2->roc_work);
230238
}
231239

mt7615/usb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ static void mt7663u_stop(struct ieee80211_hw *hw, bool suspend)
8585
struct mt7615_dev *dev = hw->priv;
8686

8787
clear_bit(MT76_STATE_RUNNING, &dev->mphy.state);
88+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
89+
timer_delete_sync(&phy->roc_timer);
90+
#else
8891
del_timer_sync(&phy->roc_timer);
92+
#endif
8993
cancel_work_sync(&phy->roc_work);
9094
cancel_delayed_work_sync(&phy->scan_work);
9195
cancel_delayed_work_sync(&phy->mt76->mac_work);

mt76x02_usb_core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,13 @@ void mt76x02u_init_beacon_config(struct mt76x02_dev *dev)
264264
};
265265
dev->beacon_ops = &beacon_ops;
266266

267+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
268+
hrtimer_setup(&dev->pre_tbtt_timer, mt76x02u_pre_tbtt_interrupt,
269+
CLOCK_MONOTONIC, HRTIMER_MODE_REL);
270+
#else
267271
hrtimer_init(&dev->pre_tbtt_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
268272
dev->pre_tbtt_timer.function = mt76x02u_pre_tbtt_interrupt;
273+
#endif
269274
INIT_WORK(&dev->pre_tbtt_work, mt76x02u_pre_tbtt_work);
270275

271276
mt76x02_init_beacon_config(dev);

mt7921/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ void mt7921_roc_abort_sync(struct mt792x_dev *dev)
371371
{
372372
struct mt792x_phy *phy = &dev->phy;
373373

374+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
375+
timer_delete_sync(&phy->roc_timer);
376+
#else
374377
del_timer_sync(&phy->roc_timer);
378+
#endif
375379
cancel_work_sync(&phy->roc_work);
376380
if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
377381
ieee80211_iterate_interfaces(mt76_hw(dev),
@@ -402,7 +406,11 @@ static int mt7921_abort_roc(struct mt792x_phy *phy, struct mt792x_vif *vif)
402406
{
403407
int err = 0;
404408

409+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
410+
timer_delete_sync(&phy->roc_timer);
411+
#else
405412
del_timer_sync(&phy->roc_timer);
413+
#endif
406414
cancel_work_sync(&phy->roc_work);
407415

408416
mt792x_mutex_acquire(phy->dev);
@@ -1494,7 +1502,11 @@ static void mt7921_abort_channel_switch(struct ieee80211_hw *hw,
14941502
{
14951503
struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;
14961504

1505+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
1506+
timer_delete_sync(&mvif->csa_timer);
1507+
#else
14971508
del_timer_sync(&mvif->csa_timer);
1509+
#endif
14981510
cancel_work_sync(&mvif->csa_work);
14991511
}
15001512

mt7925/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,11 @@ void mt7925_roc_abort_sync(struct mt792x_dev *dev)
457457
{
458458
struct mt792x_phy *phy = &dev->phy;
459459

460+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
461+
timer_delete_sync(&phy->roc_timer);
462+
#else
460463
del_timer_sync(&phy->roc_timer);
464+
#endif
461465
cancel_work_sync(&phy->roc_work);
462466
if (test_and_clear_bit(MT76_STATE_ROC, &phy->mt76->state))
463467
ieee80211_iterate_interfaces(mt76_hw(dev),
@@ -489,7 +493,11 @@ static int mt7925_abort_roc(struct mt792x_phy *phy,
489493
{
490494
int err = 0;
491495

496+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
497+
timer_delete_sync(&phy->roc_timer);
498+
#else
492499
del_timer_sync(&phy->roc_timer);
500+
#endif
493501
cancel_work_sync(&phy->roc_work);
494502

495503
mt792x_mutex_acquire(phy->dev);

mt792x_core.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,26 @@ EXPORT_SYMBOL_GPL(mt792x_tx_worker);
305305

306306
void mt792x_roc_timer(struct timer_list *timer)
307307
{
308+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
309+
struct mt792x_phy *phy = timer_container_of(phy, timer, roc_timer);
310+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
308311
struct mt792x_phy *phy = from_timer(phy, timer, roc_timer);
312+
#else
313+
struct mt792x_phy *phy = container_of(timer, struct mt792x_phy, roc_timer);
314+
#endif
309315

310316
ieee80211_queue_work(phy->mt76->hw, &phy->roc_work);
311317
}
312-
EXPORT_SYMBOL_GPL(mt792x_roc_timer);
313318

314319
void mt792x_csa_timer(struct timer_list *timer)
315320
{
321+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
322+
struct mt792x_vif *mvif = timer_container_of(mvif, timer, csa_timer);
323+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
316324
struct mt792x_vif *mvif = from_timer(mvif, timer, csa_timer);
317-
325+
#else
326+
struct mt792x_vif *mvif = container_of(timer, struct mt792x_vif, csa_timer);
327+
#endif
318328
ieee80211_queue_work(mvif->phy->mt76->hw, &mvif->csa_work);
319329
}
320330
EXPORT_SYMBOL_GPL(mt792x_csa_timer);
@@ -362,7 +372,11 @@ void mt792x_unassign_vif_chanctx(struct ieee80211_hw *hw,
362372
mutex_unlock(&dev->mt76.mutex);
363373

364374
if (vif->bss_conf.csa_active) {
375+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
376+
timer_delete_sync(&mvif->csa_timer);
377+
#else
365378
del_timer_sync(&mvif->csa_timer);
379+
#endif
366380
cancel_work_sync(&mvif->csa_work);
367381
}
368382
}

0 commit comments

Comments
 (0)