driver-ops.h 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. #ifndef __MAC80211_DRIVER_OPS
  2. #define __MAC80211_DRIVER_OPS
  3. #include <net/mac80211.h>
  4. #include "ieee80211_i.h"
  5. #include "trace.h"
  6. static inline bool check_sdata_in_driver(struct ieee80211_sub_if_data *sdata)
  7. {
  8. return !WARN(!(sdata->flags & IEEE80211_SDATA_IN_DRIVER),
  9. "%s: Failed check-sdata-in-driver check, flags: 0x%x\n",
  10. sdata->dev ? sdata->dev->name : sdata->name, sdata->flags);
  11. }
  12. static inline struct ieee80211_sub_if_data *
  13. get_bss_sdata(struct ieee80211_sub_if_data *sdata)
  14. {
  15. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  16. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  17. u.ap);
  18. return sdata;
  19. }
  20. static inline void drv_tx(struct ieee80211_local *local,
  21. struct ieee80211_tx_control *control,
  22. struct sk_buff *skb)
  23. {
  24. local->ops->tx(&local->hw, control, skb);
  25. }
  26. static inline void drv_get_et_strings(struct ieee80211_sub_if_data *sdata,
  27. u32 sset, u8 *data)
  28. {
  29. struct ieee80211_local *local = sdata->local;
  30. if (local->ops->get_et_strings) {
  31. trace_drv_get_et_strings(local, sset);
  32. local->ops->get_et_strings(&local->hw, &sdata->vif, sset, data);
  33. trace_drv_return_void(local);
  34. }
  35. }
  36. static inline void drv_get_et_stats(struct ieee80211_sub_if_data *sdata,
  37. struct ethtool_stats *stats,
  38. u64 *data)
  39. {
  40. struct ieee80211_local *local = sdata->local;
  41. if (local->ops->get_et_stats) {
  42. trace_drv_get_et_stats(local);
  43. local->ops->get_et_stats(&local->hw, &sdata->vif, stats, data);
  44. trace_drv_return_void(local);
  45. }
  46. }
  47. static inline int drv_get_et_sset_count(struct ieee80211_sub_if_data *sdata,
  48. int sset)
  49. {
  50. struct ieee80211_local *local = sdata->local;
  51. int rv = 0;
  52. if (local->ops->get_et_sset_count) {
  53. trace_drv_get_et_sset_count(local, sset);
  54. rv = local->ops->get_et_sset_count(&local->hw, &sdata->vif,
  55. sset);
  56. trace_drv_return_int(local, rv);
  57. }
  58. return rv;
  59. }
  60. static inline int drv_start(struct ieee80211_local *local)
  61. {
  62. int ret;
  63. might_sleep();
  64. trace_drv_start(local);
  65. local->started = true;
  66. smp_mb();
  67. ret = local->ops->start(&local->hw);
  68. trace_drv_return_int(local, ret);
  69. return ret;
  70. }
  71. static inline void drv_stop(struct ieee80211_local *local)
  72. {
  73. might_sleep();
  74. trace_drv_stop(local);
  75. local->ops->stop(&local->hw);
  76. trace_drv_return_void(local);
  77. /* sync away all work on the tasklet before clearing started */
  78. tasklet_disable(&local->tasklet);
  79. tasklet_enable(&local->tasklet);
  80. barrier();
  81. local->started = false;
  82. }
  83. #ifdef CONFIG_PM
  84. static inline int drv_suspend(struct ieee80211_local *local,
  85. struct cfg80211_wowlan *wowlan)
  86. {
  87. int ret;
  88. might_sleep();
  89. trace_drv_suspend(local);
  90. ret = local->ops->suspend(&local->hw, wowlan);
  91. trace_drv_return_int(local, ret);
  92. return ret;
  93. }
  94. static inline int drv_resume(struct ieee80211_local *local)
  95. {
  96. int ret;
  97. might_sleep();
  98. trace_drv_resume(local);
  99. ret = local->ops->resume(&local->hw);
  100. trace_drv_return_int(local, ret);
  101. return ret;
  102. }
  103. static inline void drv_set_wakeup(struct ieee80211_local *local,
  104. bool enabled)
  105. {
  106. might_sleep();
  107. if (!local->ops->set_wakeup)
  108. return;
  109. trace_drv_set_wakeup(local, enabled);
  110. local->ops->set_wakeup(&local->hw, enabled);
  111. trace_drv_return_void(local);
  112. }
  113. #endif
  114. static inline int drv_add_interface(struct ieee80211_local *local,
  115. struct ieee80211_sub_if_data *sdata)
  116. {
  117. int ret;
  118. might_sleep();
  119. if (WARN_ON(sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  120. (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
  121. !(local->hw.flags & IEEE80211_HW_WANT_MONITOR_VIF) &&
  122. !(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))))
  123. return -EINVAL;
  124. trace_drv_add_interface(local, sdata);
  125. ret = local->ops->add_interface(&local->hw, &sdata->vif);
  126. trace_drv_return_int(local, ret);
  127. if (ret == 0)
  128. sdata->flags |= IEEE80211_SDATA_IN_DRIVER;
  129. return ret;
  130. }
  131. static inline int drv_change_interface(struct ieee80211_local *local,
  132. struct ieee80211_sub_if_data *sdata,
  133. enum nl80211_iftype type, bool p2p)
  134. {
  135. int ret;
  136. might_sleep();
  137. if (!check_sdata_in_driver(sdata))
  138. return -EIO;
  139. trace_drv_change_interface(local, sdata, type, p2p);
  140. ret = local->ops->change_interface(&local->hw, &sdata->vif, type, p2p);
  141. trace_drv_return_int(local, ret);
  142. return ret;
  143. }
  144. static inline void drv_remove_interface(struct ieee80211_local *local,
  145. struct ieee80211_sub_if_data *sdata)
  146. {
  147. might_sleep();
  148. if (!check_sdata_in_driver(sdata))
  149. return;
  150. trace_drv_remove_interface(local, sdata);
  151. local->ops->remove_interface(&local->hw, &sdata->vif);
  152. sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
  153. trace_drv_return_void(local);
  154. }
  155. static inline int drv_config(struct ieee80211_local *local, u32 changed)
  156. {
  157. int ret;
  158. might_sleep();
  159. trace_drv_config(local, changed);
  160. ret = local->ops->config(&local->hw, changed);
  161. trace_drv_return_int(local, ret);
  162. return ret;
  163. }
  164. static inline void drv_bss_info_changed(struct ieee80211_local *local,
  165. struct ieee80211_sub_if_data *sdata,
  166. struct ieee80211_bss_conf *info,
  167. u32 changed)
  168. {
  169. might_sleep();
  170. if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
  171. BSS_CHANGED_BEACON_ENABLED) &&
  172. sdata->vif.type != NL80211_IFTYPE_AP &&
  173. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  174. sdata->vif.type != NL80211_IFTYPE_MESH_POINT))
  175. return;
  176. if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
  177. sdata->vif.type == NL80211_IFTYPE_MONITOR))
  178. return;
  179. if (!check_sdata_in_driver(sdata))
  180. return;
  181. trace_drv_bss_info_changed(local, sdata, info, changed);
  182. if (local->ops->bss_info_changed)
  183. local->ops->bss_info_changed(&local->hw, &sdata->vif, info, changed);
  184. trace_drv_return_void(local);
  185. }
  186. static inline u64 drv_prepare_multicast(struct ieee80211_local *local,
  187. struct netdev_hw_addr_list *mc_list)
  188. {
  189. u64 ret = 0;
  190. trace_drv_prepare_multicast(local, mc_list->count);
  191. if (local->ops->prepare_multicast)
  192. ret = local->ops->prepare_multicast(&local->hw, mc_list);
  193. trace_drv_return_u64(local, ret);
  194. return ret;
  195. }
  196. static inline void drv_configure_filter(struct ieee80211_local *local,
  197. unsigned int changed_flags,
  198. unsigned int *total_flags,
  199. u64 multicast)
  200. {
  201. might_sleep();
  202. trace_drv_configure_filter(local, changed_flags, total_flags,
  203. multicast);
  204. local->ops->configure_filter(&local->hw, changed_flags, total_flags,
  205. multicast);
  206. trace_drv_return_void(local);
  207. }
  208. static inline int drv_set_tim(struct ieee80211_local *local,
  209. struct ieee80211_sta *sta, bool set)
  210. {
  211. int ret = 0;
  212. trace_drv_set_tim(local, sta, set);
  213. if (local->ops->set_tim)
  214. ret = local->ops->set_tim(&local->hw, sta, set);
  215. trace_drv_return_int(local, ret);
  216. return ret;
  217. }
  218. static inline int drv_set_key(struct ieee80211_local *local,
  219. enum set_key_cmd cmd,
  220. struct ieee80211_sub_if_data *sdata,
  221. struct ieee80211_sta *sta,
  222. struct ieee80211_key_conf *key)
  223. {
  224. int ret;
  225. might_sleep();
  226. sdata = get_bss_sdata(sdata);
  227. if (!check_sdata_in_driver(sdata))
  228. return -EIO;
  229. trace_drv_set_key(local, cmd, sdata, sta, key);
  230. ret = local->ops->set_key(&local->hw, cmd, &sdata->vif, sta, key);
  231. trace_drv_return_int(local, ret);
  232. return ret;
  233. }
  234. static inline void drv_update_tkip_key(struct ieee80211_local *local,
  235. struct ieee80211_sub_if_data *sdata,
  236. struct ieee80211_key_conf *conf,
  237. struct sta_info *sta, u32 iv32,
  238. u16 *phase1key)
  239. {
  240. struct ieee80211_sta *ista = NULL;
  241. if (sta)
  242. ista = &sta->sta;
  243. sdata = get_bss_sdata(sdata);
  244. if (!check_sdata_in_driver(sdata))
  245. return;
  246. trace_drv_update_tkip_key(local, sdata, conf, ista, iv32);
  247. if (local->ops->update_tkip_key)
  248. local->ops->update_tkip_key(&local->hw, &sdata->vif, conf,
  249. ista, iv32, phase1key);
  250. trace_drv_return_void(local);
  251. }
  252. static inline int drv_hw_scan(struct ieee80211_local *local,
  253. struct ieee80211_sub_if_data *sdata,
  254. struct cfg80211_scan_request *req)
  255. {
  256. int ret;
  257. might_sleep();
  258. if (!check_sdata_in_driver(sdata))
  259. return -EIO;
  260. trace_drv_hw_scan(local, sdata);
  261. ret = local->ops->hw_scan(&local->hw, &sdata->vif, req);
  262. trace_drv_return_int(local, ret);
  263. return ret;
  264. }
  265. static inline void drv_cancel_hw_scan(struct ieee80211_local *local,
  266. struct ieee80211_sub_if_data *sdata)
  267. {
  268. might_sleep();
  269. if (!check_sdata_in_driver(sdata))
  270. return;
  271. trace_drv_cancel_hw_scan(local, sdata);
  272. local->ops->cancel_hw_scan(&local->hw, &sdata->vif);
  273. trace_drv_return_void(local);
  274. }
  275. static inline int
  276. drv_sched_scan_start(struct ieee80211_local *local,
  277. struct ieee80211_sub_if_data *sdata,
  278. struct cfg80211_sched_scan_request *req,
  279. struct ieee80211_sched_scan_ies *ies)
  280. {
  281. int ret;
  282. might_sleep();
  283. if (!check_sdata_in_driver(sdata))
  284. return -EIO;
  285. trace_drv_sched_scan_start(local, sdata);
  286. ret = local->ops->sched_scan_start(&local->hw, &sdata->vif,
  287. req, ies);
  288. trace_drv_return_int(local, ret);
  289. return ret;
  290. }
  291. static inline int drv_sched_scan_stop(struct ieee80211_local *local,
  292. struct ieee80211_sub_if_data *sdata)
  293. {
  294. int ret;
  295. might_sleep();
  296. if (!check_sdata_in_driver(sdata))
  297. return -EIO;
  298. trace_drv_sched_scan_stop(local, sdata);
  299. ret = local->ops->sched_scan_stop(&local->hw, &sdata->vif);
  300. trace_drv_return_int(local, ret);
  301. return ret;
  302. }
  303. static inline void drv_sw_scan_start(struct ieee80211_local *local)
  304. {
  305. might_sleep();
  306. trace_drv_sw_scan_start(local);
  307. if (local->ops->sw_scan_start)
  308. local->ops->sw_scan_start(&local->hw);
  309. trace_drv_return_void(local);
  310. }
  311. static inline void drv_sw_scan_complete(struct ieee80211_local *local)
  312. {
  313. might_sleep();
  314. trace_drv_sw_scan_complete(local);
  315. if (local->ops->sw_scan_complete)
  316. local->ops->sw_scan_complete(&local->hw);
  317. trace_drv_return_void(local);
  318. }
  319. static inline int drv_get_stats(struct ieee80211_local *local,
  320. struct ieee80211_low_level_stats *stats)
  321. {
  322. int ret = -EOPNOTSUPP;
  323. might_sleep();
  324. if (local->ops->get_stats)
  325. ret = local->ops->get_stats(&local->hw, stats);
  326. trace_drv_get_stats(local, stats, ret);
  327. return ret;
  328. }
  329. static inline void drv_get_tkip_seq(struct ieee80211_local *local,
  330. u8 hw_key_idx, u32 *iv32, u16 *iv16)
  331. {
  332. if (local->ops->get_tkip_seq)
  333. local->ops->get_tkip_seq(&local->hw, hw_key_idx, iv32, iv16);
  334. trace_drv_get_tkip_seq(local, hw_key_idx, iv32, iv16);
  335. }
  336. static inline int drv_set_frag_threshold(struct ieee80211_local *local,
  337. u32 value)
  338. {
  339. int ret = 0;
  340. might_sleep();
  341. trace_drv_set_frag_threshold(local, value);
  342. if (local->ops->set_frag_threshold)
  343. ret = local->ops->set_frag_threshold(&local->hw, value);
  344. trace_drv_return_int(local, ret);
  345. return ret;
  346. }
  347. static inline int drv_set_rts_threshold(struct ieee80211_local *local,
  348. u32 value)
  349. {
  350. int ret = 0;
  351. might_sleep();
  352. trace_drv_set_rts_threshold(local, value);
  353. if (local->ops->set_rts_threshold)
  354. ret = local->ops->set_rts_threshold(&local->hw, value);
  355. trace_drv_return_int(local, ret);
  356. return ret;
  357. }
  358. static inline int drv_set_coverage_class(struct ieee80211_local *local,
  359. u8 value)
  360. {
  361. int ret = 0;
  362. might_sleep();
  363. trace_drv_set_coverage_class(local, value);
  364. if (local->ops->set_coverage_class)
  365. local->ops->set_coverage_class(&local->hw, value);
  366. else
  367. ret = -EOPNOTSUPP;
  368. trace_drv_return_int(local, ret);
  369. return ret;
  370. }
  371. static inline void drv_sta_notify(struct ieee80211_local *local,
  372. struct ieee80211_sub_if_data *sdata,
  373. enum sta_notify_cmd cmd,
  374. struct ieee80211_sta *sta)
  375. {
  376. sdata = get_bss_sdata(sdata);
  377. if (!check_sdata_in_driver(sdata))
  378. return;
  379. trace_drv_sta_notify(local, sdata, cmd, sta);
  380. if (local->ops->sta_notify)
  381. local->ops->sta_notify(&local->hw, &sdata->vif, cmd, sta);
  382. trace_drv_return_void(local);
  383. }
  384. static inline int drv_sta_add(struct ieee80211_local *local,
  385. struct ieee80211_sub_if_data *sdata,
  386. struct ieee80211_sta *sta)
  387. {
  388. int ret = 0;
  389. might_sleep();
  390. sdata = get_bss_sdata(sdata);
  391. if (!check_sdata_in_driver(sdata))
  392. return -EIO;
  393. trace_drv_sta_add(local, sdata, sta);
  394. if (local->ops->sta_add)
  395. ret = local->ops->sta_add(&local->hw, &sdata->vif, sta);
  396. trace_drv_return_int(local, ret);
  397. return ret;
  398. }
  399. static inline void drv_sta_remove(struct ieee80211_local *local,
  400. struct ieee80211_sub_if_data *sdata,
  401. struct ieee80211_sta *sta)
  402. {
  403. might_sleep();
  404. sdata = get_bss_sdata(sdata);
  405. if (!check_sdata_in_driver(sdata))
  406. return;
  407. trace_drv_sta_remove(local, sdata, sta);
  408. if (local->ops->sta_remove)
  409. local->ops->sta_remove(&local->hw, &sdata->vif, sta);
  410. trace_drv_return_void(local);
  411. }
  412. #ifdef CONFIG_MAC80211_DEBUGFS
  413. static inline void drv_sta_add_debugfs(struct ieee80211_local *local,
  414. struct ieee80211_sub_if_data *sdata,
  415. struct ieee80211_sta *sta,
  416. struct dentry *dir)
  417. {
  418. might_sleep();
  419. sdata = get_bss_sdata(sdata);
  420. if (!check_sdata_in_driver(sdata))
  421. return;
  422. if (local->ops->sta_add_debugfs)
  423. local->ops->sta_add_debugfs(&local->hw, &sdata->vif,
  424. sta, dir);
  425. }
  426. static inline void drv_sta_remove_debugfs(struct ieee80211_local *local,
  427. struct ieee80211_sub_if_data *sdata,
  428. struct ieee80211_sta *sta,
  429. struct dentry *dir)
  430. {
  431. might_sleep();
  432. sdata = get_bss_sdata(sdata);
  433. check_sdata_in_driver(sdata);
  434. if (local->ops->sta_remove_debugfs)
  435. local->ops->sta_remove_debugfs(&local->hw, &sdata->vif,
  436. sta, dir);
  437. }
  438. #endif
  439. static inline void drv_sta_pre_rcu_remove(struct ieee80211_local *local,
  440. struct ieee80211_sub_if_data *sdata,
  441. struct sta_info *sta)
  442. {
  443. might_sleep();
  444. sdata = get_bss_sdata(sdata);
  445. if (!check_sdata_in_driver(sdata))
  446. return;
  447. trace_drv_sta_pre_rcu_remove(local, sdata, &sta->sta);
  448. if (local->ops->sta_pre_rcu_remove)
  449. local->ops->sta_pre_rcu_remove(&local->hw, &sdata->vif,
  450. &sta->sta);
  451. trace_drv_return_void(local);
  452. }
  453. static inline __must_check
  454. int drv_sta_state(struct ieee80211_local *local,
  455. struct ieee80211_sub_if_data *sdata,
  456. struct sta_info *sta,
  457. enum ieee80211_sta_state old_state,
  458. enum ieee80211_sta_state new_state)
  459. {
  460. int ret = 0;
  461. might_sleep();
  462. sdata = get_bss_sdata(sdata);
  463. if (!check_sdata_in_driver(sdata))
  464. return -EIO;
  465. trace_drv_sta_state(local, sdata, &sta->sta, old_state, new_state);
  466. if (local->ops->sta_state) {
  467. ret = local->ops->sta_state(&local->hw, &sdata->vif, &sta->sta,
  468. old_state, new_state);
  469. } else if (old_state == IEEE80211_STA_AUTH &&
  470. new_state == IEEE80211_STA_ASSOC) {
  471. ret = drv_sta_add(local, sdata, &sta->sta);
  472. if (ret == 0)
  473. sta->uploaded = true;
  474. } else if (old_state == IEEE80211_STA_ASSOC &&
  475. new_state == IEEE80211_STA_AUTH) {
  476. drv_sta_remove(local, sdata, &sta->sta);
  477. }
  478. trace_drv_return_int(local, ret);
  479. return ret;
  480. }
  481. static inline void drv_sta_rc_update(struct ieee80211_local *local,
  482. struct ieee80211_sub_if_data *sdata,
  483. struct ieee80211_sta *sta, u32 changed)
  484. {
  485. sdata = get_bss_sdata(sdata);
  486. if (!check_sdata_in_driver(sdata))
  487. return;
  488. WARN_ON(changed & IEEE80211_RC_SUPP_RATES_CHANGED &&
  489. (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  490. sdata->vif.type != NL80211_IFTYPE_MESH_POINT));
  491. trace_drv_sta_rc_update(local, sdata, sta, changed);
  492. if (local->ops->sta_rc_update)
  493. local->ops->sta_rc_update(&local->hw, &sdata->vif,
  494. sta, changed);
  495. trace_drv_return_void(local);
  496. }
  497. static inline int drv_conf_tx(struct ieee80211_local *local,
  498. struct ieee80211_sub_if_data *sdata, u16 ac,
  499. const struct ieee80211_tx_queue_params *params)
  500. {
  501. int ret = -EOPNOTSUPP;
  502. might_sleep();
  503. if (!check_sdata_in_driver(sdata))
  504. return -EIO;
  505. trace_drv_conf_tx(local, sdata, ac, params);
  506. if (local->ops->conf_tx)
  507. ret = local->ops->conf_tx(&local->hw, &sdata->vif,
  508. ac, params);
  509. trace_drv_return_int(local, ret);
  510. return ret;
  511. }
  512. static inline u64 drv_get_tsf(struct ieee80211_local *local,
  513. struct ieee80211_sub_if_data *sdata)
  514. {
  515. u64 ret = -1ULL;
  516. might_sleep();
  517. if (!check_sdata_in_driver(sdata))
  518. return ret;
  519. trace_drv_get_tsf(local, sdata);
  520. if (local->ops->get_tsf)
  521. ret = local->ops->get_tsf(&local->hw, &sdata->vif);
  522. trace_drv_return_u64(local, ret);
  523. return ret;
  524. }
  525. static inline void drv_set_tsf(struct ieee80211_local *local,
  526. struct ieee80211_sub_if_data *sdata,
  527. u64 tsf)
  528. {
  529. might_sleep();
  530. if (!check_sdata_in_driver(sdata))
  531. return;
  532. trace_drv_set_tsf(local, sdata, tsf);
  533. if (local->ops->set_tsf)
  534. local->ops->set_tsf(&local->hw, &sdata->vif, tsf);
  535. trace_drv_return_void(local);
  536. }
  537. static inline void drv_reset_tsf(struct ieee80211_local *local,
  538. struct ieee80211_sub_if_data *sdata)
  539. {
  540. might_sleep();
  541. if (!check_sdata_in_driver(sdata))
  542. return;
  543. trace_drv_reset_tsf(local, sdata);
  544. if (local->ops->reset_tsf)
  545. local->ops->reset_tsf(&local->hw, &sdata->vif);
  546. trace_drv_return_void(local);
  547. }
  548. static inline int drv_tx_last_beacon(struct ieee80211_local *local)
  549. {
  550. int ret = 0; /* default unsupported op for less congestion */
  551. might_sleep();
  552. trace_drv_tx_last_beacon(local);
  553. if (local->ops->tx_last_beacon)
  554. ret = local->ops->tx_last_beacon(&local->hw);
  555. trace_drv_return_int(local, ret);
  556. return ret;
  557. }
  558. static inline int drv_ampdu_action(struct ieee80211_local *local,
  559. struct ieee80211_sub_if_data *sdata,
  560. enum ieee80211_ampdu_mlme_action action,
  561. struct ieee80211_sta *sta, u16 tid,
  562. u16 *ssn, u8 buf_size)
  563. {
  564. int ret = -EOPNOTSUPP;
  565. might_sleep();
  566. sdata = get_bss_sdata(sdata);
  567. if (!check_sdata_in_driver(sdata))
  568. return -EIO;
  569. trace_drv_ampdu_action(local, sdata, action, sta, tid, ssn, buf_size);
  570. if (local->ops->ampdu_action)
  571. ret = local->ops->ampdu_action(&local->hw, &sdata->vif, action,
  572. sta, tid, ssn, buf_size);
  573. trace_drv_return_int(local, ret);
  574. return ret;
  575. }
  576. static inline int drv_get_survey(struct ieee80211_local *local, int idx,
  577. struct survey_info *survey)
  578. {
  579. int ret = -EOPNOTSUPP;
  580. trace_drv_get_survey(local, idx, survey);
  581. if (local->ops->get_survey)
  582. ret = local->ops->get_survey(&local->hw, idx, survey);
  583. trace_drv_return_int(local, ret);
  584. return ret;
  585. }
  586. static inline void drv_rfkill_poll(struct ieee80211_local *local)
  587. {
  588. might_sleep();
  589. if (local->ops->rfkill_poll)
  590. local->ops->rfkill_poll(&local->hw);
  591. }
  592. static inline void drv_flush(struct ieee80211_local *local,
  593. struct ieee80211_sub_if_data *sdata,
  594. u32 queues, bool drop)
  595. {
  596. struct ieee80211_vif *vif = sdata ? &sdata->vif : NULL;
  597. might_sleep();
  598. if (sdata && !check_sdata_in_driver(sdata))
  599. return;
  600. trace_drv_flush(local, queues, drop);
  601. if (local->ops->flush)
  602. local->ops->flush(&local->hw, vif, queues, drop);
  603. trace_drv_return_void(local);
  604. }
  605. static inline void drv_channel_switch(struct ieee80211_local *local,
  606. struct ieee80211_channel_switch *ch_switch)
  607. {
  608. might_sleep();
  609. trace_drv_channel_switch(local, ch_switch);
  610. local->ops->channel_switch(&local->hw, ch_switch);
  611. trace_drv_return_void(local);
  612. }
  613. static inline int drv_set_antenna(struct ieee80211_local *local,
  614. u32 tx_ant, u32 rx_ant)
  615. {
  616. int ret = -EOPNOTSUPP;
  617. might_sleep();
  618. if (local->ops->set_antenna)
  619. ret = local->ops->set_antenna(&local->hw, tx_ant, rx_ant);
  620. trace_drv_set_antenna(local, tx_ant, rx_ant, ret);
  621. return ret;
  622. }
  623. static inline int drv_get_antenna(struct ieee80211_local *local,
  624. u32 *tx_ant, u32 *rx_ant)
  625. {
  626. int ret = -EOPNOTSUPP;
  627. might_sleep();
  628. if (local->ops->get_antenna)
  629. ret = local->ops->get_antenna(&local->hw, tx_ant, rx_ant);
  630. trace_drv_get_antenna(local, *tx_ant, *rx_ant, ret);
  631. return ret;
  632. }
  633. static inline int drv_remain_on_channel(struct ieee80211_local *local,
  634. struct ieee80211_sub_if_data *sdata,
  635. struct ieee80211_channel *chan,
  636. unsigned int duration,
  637. enum ieee80211_roc_type type)
  638. {
  639. int ret;
  640. might_sleep();
  641. trace_drv_remain_on_channel(local, sdata, chan, duration, type);
  642. ret = local->ops->remain_on_channel(&local->hw, &sdata->vif,
  643. chan, duration, type);
  644. trace_drv_return_int(local, ret);
  645. return ret;
  646. }
  647. static inline int drv_cancel_remain_on_channel(struct ieee80211_local *local)
  648. {
  649. int ret;
  650. might_sleep();
  651. trace_drv_cancel_remain_on_channel(local);
  652. ret = local->ops->cancel_remain_on_channel(&local->hw);
  653. trace_drv_return_int(local, ret);
  654. return ret;
  655. }
  656. static inline int drv_set_ringparam(struct ieee80211_local *local,
  657. u32 tx, u32 rx)
  658. {
  659. int ret = -ENOTSUPP;
  660. might_sleep();
  661. trace_drv_set_ringparam(local, tx, rx);
  662. if (local->ops->set_ringparam)
  663. ret = local->ops->set_ringparam(&local->hw, tx, rx);
  664. trace_drv_return_int(local, ret);
  665. return ret;
  666. }
  667. static inline void drv_get_ringparam(struct ieee80211_local *local,
  668. u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
  669. {
  670. might_sleep();
  671. trace_drv_get_ringparam(local, tx, tx_max, rx, rx_max);
  672. if (local->ops->get_ringparam)
  673. local->ops->get_ringparam(&local->hw, tx, tx_max, rx, rx_max);
  674. trace_drv_return_void(local);
  675. }
  676. static inline bool drv_tx_frames_pending(struct ieee80211_local *local)
  677. {
  678. bool ret = false;
  679. might_sleep();
  680. trace_drv_tx_frames_pending(local);
  681. if (local->ops->tx_frames_pending)
  682. ret = local->ops->tx_frames_pending(&local->hw);
  683. trace_drv_return_bool(local, ret);
  684. return ret;
  685. }
  686. static inline int drv_set_bitrate_mask(struct ieee80211_local *local,
  687. struct ieee80211_sub_if_data *sdata,
  688. const struct cfg80211_bitrate_mask *mask)
  689. {
  690. int ret = -EOPNOTSUPP;
  691. might_sleep();
  692. if (!check_sdata_in_driver(sdata))
  693. return -EIO;
  694. trace_drv_set_bitrate_mask(local, sdata, mask);
  695. if (local->ops->set_bitrate_mask)
  696. ret = local->ops->set_bitrate_mask(&local->hw,
  697. &sdata->vif, mask);
  698. trace_drv_return_int(local, ret);
  699. return ret;
  700. }
  701. static inline void drv_set_rekey_data(struct ieee80211_local *local,
  702. struct ieee80211_sub_if_data *sdata,
  703. struct cfg80211_gtk_rekey_data *data)
  704. {
  705. if (!check_sdata_in_driver(sdata))
  706. return;
  707. trace_drv_set_rekey_data(local, sdata, data);
  708. if (local->ops->set_rekey_data)
  709. local->ops->set_rekey_data(&local->hw, &sdata->vif, data);
  710. trace_drv_return_void(local);
  711. }
  712. static inline void drv_rssi_callback(struct ieee80211_local *local,
  713. struct ieee80211_sub_if_data *sdata,
  714. const enum ieee80211_rssi_event event)
  715. {
  716. trace_drv_rssi_callback(local, sdata, event);
  717. if (local->ops->rssi_callback)
  718. local->ops->rssi_callback(&local->hw, &sdata->vif, event);
  719. trace_drv_return_void(local);
  720. }
  721. static inline void
  722. drv_release_buffered_frames(struct ieee80211_local *local,
  723. struct sta_info *sta, u16 tids, int num_frames,
  724. enum ieee80211_frame_release_type reason,
  725. bool more_data)
  726. {
  727. trace_drv_release_buffered_frames(local, &sta->sta, tids, num_frames,
  728. reason, more_data);
  729. if (local->ops->release_buffered_frames)
  730. local->ops->release_buffered_frames(&local->hw, &sta->sta, tids,
  731. num_frames, reason,
  732. more_data);
  733. trace_drv_return_void(local);
  734. }
  735. static inline void
  736. drv_allow_buffered_frames(struct ieee80211_local *local,
  737. struct sta_info *sta, u16 tids, int num_frames,
  738. enum ieee80211_frame_release_type reason,
  739. bool more_data)
  740. {
  741. trace_drv_allow_buffered_frames(local, &sta->sta, tids, num_frames,
  742. reason, more_data);
  743. if (local->ops->allow_buffered_frames)
  744. local->ops->allow_buffered_frames(&local->hw, &sta->sta,
  745. tids, num_frames, reason,
  746. more_data);
  747. trace_drv_return_void(local);
  748. }
  749. static inline int drv_get_rssi(struct ieee80211_local *local,
  750. struct ieee80211_sub_if_data *sdata,
  751. struct ieee80211_sta *sta,
  752. s8 *rssi_dbm)
  753. {
  754. int ret;
  755. might_sleep();
  756. ret = local->ops->get_rssi(&local->hw, &sdata->vif, sta, rssi_dbm);
  757. trace_drv_get_rssi(local, sta, *rssi_dbm, ret);
  758. return ret;
  759. }
  760. static inline void drv_mgd_prepare_tx(struct ieee80211_local *local,
  761. struct ieee80211_sub_if_data *sdata)
  762. {
  763. might_sleep();
  764. if (!check_sdata_in_driver(sdata))
  765. return;
  766. WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
  767. trace_drv_mgd_prepare_tx(local, sdata);
  768. if (local->ops->mgd_prepare_tx)
  769. local->ops->mgd_prepare_tx(&local->hw, &sdata->vif);
  770. trace_drv_return_void(local);
  771. }
  772. static inline int drv_add_chanctx(struct ieee80211_local *local,
  773. struct ieee80211_chanctx *ctx)
  774. {
  775. int ret = -EOPNOTSUPP;
  776. trace_drv_add_chanctx(local, ctx);
  777. if (local->ops->add_chanctx)
  778. ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
  779. trace_drv_return_int(local, ret);
  780. if (!ret)
  781. ctx->driver_present = true;
  782. return ret;
  783. }
  784. static inline void drv_remove_chanctx(struct ieee80211_local *local,
  785. struct ieee80211_chanctx *ctx)
  786. {
  787. if (WARN_ON(!ctx->driver_present))
  788. return;
  789. trace_drv_remove_chanctx(local, ctx);
  790. if (local->ops->remove_chanctx)
  791. local->ops->remove_chanctx(&local->hw, &ctx->conf);
  792. trace_drv_return_void(local);
  793. ctx->driver_present = false;
  794. }
  795. static inline void drv_change_chanctx(struct ieee80211_local *local,
  796. struct ieee80211_chanctx *ctx,
  797. u32 changed)
  798. {
  799. trace_drv_change_chanctx(local, ctx, changed);
  800. if (local->ops->change_chanctx) {
  801. WARN_ON_ONCE(!ctx->driver_present);
  802. local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
  803. }
  804. trace_drv_return_void(local);
  805. }
  806. static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
  807. struct ieee80211_sub_if_data *sdata,
  808. struct ieee80211_chanctx *ctx)
  809. {
  810. int ret = 0;
  811. if (!check_sdata_in_driver(sdata))
  812. return -EIO;
  813. trace_drv_assign_vif_chanctx(local, sdata, ctx);
  814. if (local->ops->assign_vif_chanctx) {
  815. WARN_ON_ONCE(!ctx->driver_present);
  816. ret = local->ops->assign_vif_chanctx(&local->hw,
  817. &sdata->vif,
  818. &ctx->conf);
  819. }
  820. trace_drv_return_int(local, ret);
  821. return ret;
  822. }
  823. static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
  824. struct ieee80211_sub_if_data *sdata,
  825. struct ieee80211_chanctx *ctx)
  826. {
  827. if (!check_sdata_in_driver(sdata))
  828. return;
  829. trace_drv_unassign_vif_chanctx(local, sdata, ctx);
  830. if (local->ops->unassign_vif_chanctx) {
  831. WARN_ON_ONCE(!ctx->driver_present);
  832. local->ops->unassign_vif_chanctx(&local->hw,
  833. &sdata->vif,
  834. &ctx->conf);
  835. }
  836. trace_drv_return_void(local);
  837. }
  838. static inline int
  839. drv_switch_vif_chanctx(struct ieee80211_local *local,
  840. struct ieee80211_vif_chanctx_switch *vifs,
  841. int n_vifs,
  842. enum ieee80211_chanctx_switch_mode mode)
  843. {
  844. int ret = 0;
  845. int i;
  846. if (!local->ops->switch_vif_chanctx)
  847. return -EOPNOTSUPP;
  848. for (i = 0; i < n_vifs; i++) {
  849. struct ieee80211_chanctx *new_ctx =
  850. container_of(vifs[i].new_ctx,
  851. struct ieee80211_chanctx,
  852. conf);
  853. struct ieee80211_chanctx *old_ctx =
  854. container_of(vifs[i].old_ctx,
  855. struct ieee80211_chanctx,
  856. conf);
  857. WARN_ON_ONCE(!old_ctx->driver_present);
  858. WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
  859. new_ctx->driver_present) ||
  860. (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
  861. !new_ctx->driver_present));
  862. }
  863. trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
  864. ret = local->ops->switch_vif_chanctx(&local->hw,
  865. vifs, n_vifs, mode);
  866. trace_drv_return_int(local, ret);
  867. if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
  868. for (i = 0; i < n_vifs; i++) {
  869. struct ieee80211_chanctx *new_ctx =
  870. container_of(vifs[i].new_ctx,
  871. struct ieee80211_chanctx,
  872. conf);
  873. struct ieee80211_chanctx *old_ctx =
  874. container_of(vifs[i].old_ctx,
  875. struct ieee80211_chanctx,
  876. conf);
  877. new_ctx->driver_present = true;
  878. old_ctx->driver_present = false;
  879. }
  880. }
  881. return ret;
  882. }
  883. static inline int drv_start_ap(struct ieee80211_local *local,
  884. struct ieee80211_sub_if_data *sdata)
  885. {
  886. int ret = 0;
  887. if (!check_sdata_in_driver(sdata))
  888. return -EIO;
  889. trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
  890. if (local->ops->start_ap)
  891. ret = local->ops->start_ap(&local->hw, &sdata->vif);
  892. trace_drv_return_int(local, ret);
  893. return ret;
  894. }
  895. static inline void drv_stop_ap(struct ieee80211_local *local,
  896. struct ieee80211_sub_if_data *sdata)
  897. {
  898. if (!check_sdata_in_driver(sdata))
  899. return;
  900. trace_drv_stop_ap(local, sdata);
  901. if (local->ops->stop_ap)
  902. local->ops->stop_ap(&local->hw, &sdata->vif);
  903. trace_drv_return_void(local);
  904. }
  905. static inline void drv_restart_complete(struct ieee80211_local *local)
  906. {
  907. might_sleep();
  908. trace_drv_restart_complete(local);
  909. if (local->ops->restart_complete)
  910. local->ops->restart_complete(&local->hw);
  911. trace_drv_return_void(local);
  912. }
  913. static inline void
  914. drv_set_default_unicast_key(struct ieee80211_local *local,
  915. struct ieee80211_sub_if_data *sdata,
  916. int key_idx)
  917. {
  918. if (!check_sdata_in_driver(sdata))
  919. return;
  920. WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
  921. trace_drv_set_default_unicast_key(local, sdata, key_idx);
  922. if (local->ops->set_default_unicast_key)
  923. local->ops->set_default_unicast_key(&local->hw, &sdata->vif,
  924. key_idx);
  925. trace_drv_return_void(local);
  926. }
  927. #if IS_ENABLED(CONFIG_IPV6)
  928. static inline void drv_ipv6_addr_change(struct ieee80211_local *local,
  929. struct ieee80211_sub_if_data *sdata,
  930. struct inet6_dev *idev)
  931. {
  932. trace_drv_ipv6_addr_change(local, sdata);
  933. if (local->ops->ipv6_addr_change)
  934. local->ops->ipv6_addr_change(&local->hw, &sdata->vif, idev);
  935. trace_drv_return_void(local);
  936. }
  937. #endif
  938. static inline void
  939. drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
  940. struct cfg80211_chan_def *chandef)
  941. {
  942. struct ieee80211_local *local = sdata->local;
  943. if (local->ops->channel_switch_beacon) {
  944. trace_drv_channel_switch_beacon(local, sdata, chandef);
  945. local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
  946. chandef);
  947. }
  948. }
  949. static inline int drv_join_ibss(struct ieee80211_local *local,
  950. struct ieee80211_sub_if_data *sdata)
  951. {
  952. int ret = 0;
  953. might_sleep();
  954. if (!check_sdata_in_driver(sdata))
  955. return -EIO;
  956. trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
  957. if (local->ops->join_ibss)
  958. ret = local->ops->join_ibss(&local->hw, &sdata->vif);
  959. trace_drv_return_int(local, ret);
  960. return ret;
  961. }
  962. static inline void drv_leave_ibss(struct ieee80211_local *local,
  963. struct ieee80211_sub_if_data *sdata)
  964. {
  965. might_sleep();
  966. if (!check_sdata_in_driver(sdata))
  967. return;
  968. trace_drv_leave_ibss(local, sdata);
  969. if (local->ops->leave_ibss)
  970. local->ops->leave_ibss(&local->hw, &sdata->vif);
  971. trace_drv_return_void(local);
  972. }
  973. static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
  974. struct ieee80211_sta *sta)
  975. {
  976. u32 ret = 0;
  977. trace_drv_get_expected_throughput(sta);
  978. if (local->ops->get_expected_throughput)
  979. ret = local->ops->get_expected_throughput(sta);
  980. trace_drv_return_u32(local, ret);
  981. return ret;
  982. }
  983. #endif /* __MAC80211_DRIVER_OPS */