driver-ops.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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 ieee80211_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_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. s16 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 void
  773. drv_mgd_protect_tdls_discover(struct ieee80211_local *local,
  774. struct ieee80211_sub_if_data *sdata)
  775. {
  776. might_sleep();
  777. if (!check_sdata_in_driver(sdata))
  778. return;
  779. WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION);
  780. trace_drv_mgd_protect_tdls_discover(local, sdata);
  781. if (local->ops->mgd_protect_tdls_discover)
  782. local->ops->mgd_protect_tdls_discover(&local->hw, &sdata->vif);
  783. trace_drv_return_void(local);
  784. }
  785. static inline int drv_add_chanctx(struct ieee80211_local *local,
  786. struct ieee80211_chanctx *ctx)
  787. {
  788. int ret = -EOPNOTSUPP;
  789. trace_drv_add_chanctx(local, ctx);
  790. if (local->ops->add_chanctx)
  791. ret = local->ops->add_chanctx(&local->hw, &ctx->conf);
  792. trace_drv_return_int(local, ret);
  793. if (!ret)
  794. ctx->driver_present = true;
  795. return ret;
  796. }
  797. static inline void drv_remove_chanctx(struct ieee80211_local *local,
  798. struct ieee80211_chanctx *ctx)
  799. {
  800. if (WARN_ON(!ctx->driver_present))
  801. return;
  802. trace_drv_remove_chanctx(local, ctx);
  803. if (local->ops->remove_chanctx)
  804. local->ops->remove_chanctx(&local->hw, &ctx->conf);
  805. trace_drv_return_void(local);
  806. ctx->driver_present = false;
  807. }
  808. static inline void drv_change_chanctx(struct ieee80211_local *local,
  809. struct ieee80211_chanctx *ctx,
  810. u32 changed)
  811. {
  812. trace_drv_change_chanctx(local, ctx, changed);
  813. if (local->ops->change_chanctx) {
  814. WARN_ON_ONCE(!ctx->driver_present);
  815. local->ops->change_chanctx(&local->hw, &ctx->conf, changed);
  816. }
  817. trace_drv_return_void(local);
  818. }
  819. static inline int drv_assign_vif_chanctx(struct ieee80211_local *local,
  820. struct ieee80211_sub_if_data *sdata,
  821. struct ieee80211_chanctx *ctx)
  822. {
  823. int ret = 0;
  824. if (!check_sdata_in_driver(sdata))
  825. return -EIO;
  826. trace_drv_assign_vif_chanctx(local, sdata, ctx);
  827. if (local->ops->assign_vif_chanctx) {
  828. WARN_ON_ONCE(!ctx->driver_present);
  829. ret = local->ops->assign_vif_chanctx(&local->hw,
  830. &sdata->vif,
  831. &ctx->conf);
  832. }
  833. trace_drv_return_int(local, ret);
  834. return ret;
  835. }
  836. static inline void drv_unassign_vif_chanctx(struct ieee80211_local *local,
  837. struct ieee80211_sub_if_data *sdata,
  838. struct ieee80211_chanctx *ctx)
  839. {
  840. if (!check_sdata_in_driver(sdata))
  841. return;
  842. trace_drv_unassign_vif_chanctx(local, sdata, ctx);
  843. if (local->ops->unassign_vif_chanctx) {
  844. WARN_ON_ONCE(!ctx->driver_present);
  845. local->ops->unassign_vif_chanctx(&local->hw,
  846. &sdata->vif,
  847. &ctx->conf);
  848. }
  849. trace_drv_return_void(local);
  850. }
  851. static inline int
  852. drv_switch_vif_chanctx(struct ieee80211_local *local,
  853. struct ieee80211_vif_chanctx_switch *vifs,
  854. int n_vifs,
  855. enum ieee80211_chanctx_switch_mode mode)
  856. {
  857. int ret = 0;
  858. int i;
  859. if (!local->ops->switch_vif_chanctx)
  860. return -EOPNOTSUPP;
  861. for (i = 0; i < n_vifs; i++) {
  862. struct ieee80211_chanctx *new_ctx =
  863. container_of(vifs[i].new_ctx,
  864. struct ieee80211_chanctx,
  865. conf);
  866. struct ieee80211_chanctx *old_ctx =
  867. container_of(vifs[i].old_ctx,
  868. struct ieee80211_chanctx,
  869. conf);
  870. WARN_ON_ONCE(!old_ctx->driver_present);
  871. WARN_ON_ONCE((mode == CHANCTX_SWMODE_SWAP_CONTEXTS &&
  872. new_ctx->driver_present) ||
  873. (mode == CHANCTX_SWMODE_REASSIGN_VIF &&
  874. !new_ctx->driver_present));
  875. }
  876. trace_drv_switch_vif_chanctx(local, vifs, n_vifs, mode);
  877. ret = local->ops->switch_vif_chanctx(&local->hw,
  878. vifs, n_vifs, mode);
  879. trace_drv_return_int(local, ret);
  880. if (!ret && mode == CHANCTX_SWMODE_SWAP_CONTEXTS) {
  881. for (i = 0; i < n_vifs; i++) {
  882. struct ieee80211_chanctx *new_ctx =
  883. container_of(vifs[i].new_ctx,
  884. struct ieee80211_chanctx,
  885. conf);
  886. struct ieee80211_chanctx *old_ctx =
  887. container_of(vifs[i].old_ctx,
  888. struct ieee80211_chanctx,
  889. conf);
  890. new_ctx->driver_present = true;
  891. old_ctx->driver_present = false;
  892. }
  893. }
  894. return ret;
  895. }
  896. static inline int drv_start_ap(struct ieee80211_local *local,
  897. struct ieee80211_sub_if_data *sdata)
  898. {
  899. int ret = 0;
  900. if (!check_sdata_in_driver(sdata))
  901. return -EIO;
  902. trace_drv_start_ap(local, sdata, &sdata->vif.bss_conf);
  903. if (local->ops->start_ap)
  904. ret = local->ops->start_ap(&local->hw, &sdata->vif);
  905. trace_drv_return_int(local, ret);
  906. return ret;
  907. }
  908. static inline void drv_stop_ap(struct ieee80211_local *local,
  909. struct ieee80211_sub_if_data *sdata)
  910. {
  911. if (!check_sdata_in_driver(sdata))
  912. return;
  913. trace_drv_stop_ap(local, sdata);
  914. if (local->ops->stop_ap)
  915. local->ops->stop_ap(&local->hw, &sdata->vif);
  916. trace_drv_return_void(local);
  917. }
  918. static inline void drv_restart_complete(struct ieee80211_local *local)
  919. {
  920. might_sleep();
  921. trace_drv_restart_complete(local);
  922. if (local->ops->restart_complete)
  923. local->ops->restart_complete(&local->hw);
  924. trace_drv_return_void(local);
  925. }
  926. static inline void
  927. drv_set_default_unicast_key(struct ieee80211_local *local,
  928. struct ieee80211_sub_if_data *sdata,
  929. int key_idx)
  930. {
  931. if (!check_sdata_in_driver(sdata))
  932. return;
  933. WARN_ON_ONCE(key_idx < -1 || key_idx > 3);
  934. trace_drv_set_default_unicast_key(local, sdata, key_idx);
  935. if (local->ops->set_default_unicast_key)
  936. local->ops->set_default_unicast_key(&local->hw, &sdata->vif,
  937. key_idx);
  938. trace_drv_return_void(local);
  939. }
  940. #if IS_ENABLED(CONFIG_IPV6)
  941. static inline void drv_ipv6_addr_change(struct ieee80211_local *local,
  942. struct ieee80211_sub_if_data *sdata,
  943. struct inet6_dev *idev)
  944. {
  945. trace_drv_ipv6_addr_change(local, sdata);
  946. if (local->ops->ipv6_addr_change)
  947. local->ops->ipv6_addr_change(&local->hw, &sdata->vif, idev);
  948. trace_drv_return_void(local);
  949. }
  950. #endif
  951. static inline void
  952. drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
  953. struct cfg80211_chan_def *chandef)
  954. {
  955. struct ieee80211_local *local = sdata->local;
  956. if (local->ops->channel_switch_beacon) {
  957. trace_drv_channel_switch_beacon(local, sdata, chandef);
  958. local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
  959. chandef);
  960. }
  961. }
  962. static inline int drv_join_ibss(struct ieee80211_local *local,
  963. struct ieee80211_sub_if_data *sdata)
  964. {
  965. int ret = 0;
  966. might_sleep();
  967. if (!check_sdata_in_driver(sdata))
  968. return -EIO;
  969. trace_drv_join_ibss(local, sdata, &sdata->vif.bss_conf);
  970. if (local->ops->join_ibss)
  971. ret = local->ops->join_ibss(&local->hw, &sdata->vif);
  972. trace_drv_return_int(local, ret);
  973. return ret;
  974. }
  975. static inline void drv_leave_ibss(struct ieee80211_local *local,
  976. struct ieee80211_sub_if_data *sdata)
  977. {
  978. might_sleep();
  979. if (!check_sdata_in_driver(sdata))
  980. return;
  981. trace_drv_leave_ibss(local, sdata);
  982. if (local->ops->leave_ibss)
  983. local->ops->leave_ibss(&local->hw, &sdata->vif);
  984. trace_drv_return_void(local);
  985. }
  986. static inline u32 drv_get_expected_throughput(struct ieee80211_local *local,
  987. struct ieee80211_sta *sta)
  988. {
  989. u32 ret = 0;
  990. trace_drv_get_expected_throughput(sta);
  991. if (local->ops->get_expected_throughput)
  992. ret = local->ops->get_expected_throughput(sta);
  993. trace_drv_return_u32(local, ret);
  994. return ret;
  995. }
  996. #endif /* __MAC80211_DRIVER_OPS */