driver-ops.h 32 KB

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