314-cfg80211-implement-APIs-for-dedicated-radar-detectio.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. From: Lorenzo Bianconi <[email protected]>
  2. Date: Sat, 23 Oct 2021 11:10:50 +0200
  3. Subject: [PATCH] cfg80211: implement APIs for dedicated radar detection HW
  4. If a dedicated (off-channel) radar detection hardware (chain)
  5. is available in the hardware/driver, allow this to be used by
  6. calling the NL80211_CMD_RADAR_DETECT command with a new flag
  7. attribute requesting off-channel radar detection is used.
  8. Offchannel CAC (channel availability check) avoids the CAC
  9. downtime when switching to a radar channel or when turning on
  10. the AP.
  11. Drivers advertise support for this using the new feature flag
  12. NL80211_EXT_FEATURE_RADAR_OFFCHAN.
  13. Tested-by: Evelyn Tsai <[email protected]>
  14. Signed-off-by: Lorenzo Bianconi <[email protected]>
  15. Link: https://lore.kernel.org/r/7468e291ef5d05d692c1738d25b8f778d8ea5c3f.1634979655.git.lorenzo@kernel.org
  16. Link: https://lore.kernel.org/r/1e60e60fef00e14401adae81c3d49f3e5f307537.1634979655.git.lorenzo@kernel.org
  17. Link: https://lore.kernel.org/r/85fa50f57fc3adb2934c8d9ca0be30394de6b7e8.1634979655.git.lorenzo@kernel.org
  18. Link: https://lore.kernel.org/r/4b6c08671ad59aae0ac46fc94c02f31b1610eb72.1634979655.git.lorenzo@kernel.org
  19. Link: https://lore.kernel.org/r/241849ccaf2c228873c6f8495bf87b19159ba458.1634979655.git.lorenzo@kernel.org
  20. [remove offchan_mutex, fix cfg80211_stop_offchan_radar_detection(),
  21. remove gfp_t argument, fix documentation, fix tracing]
  22. Signed-off-by: Johannes Berg <[email protected]>
  23. ---
  24. --- a/include/net/cfg80211.h
  25. +++ b/include/net/cfg80211.h
  26. @@ -4060,6 +4060,15 @@ struct mgmt_frame_regs {
  27. * @set_sar_specs: Update the SAR (TX power) settings.
  28. *
  29. * @color_change: Initiate a color change.
  30. + *
  31. + * @set_radar_offchan: Configure dedicated offchannel chain available for
  32. + * radar/CAC detection on some hw. This chain can't be used to transmit
  33. + * or receive frames and it is bounded to a running wdev.
  34. + * Offchannel radar/CAC detection allows to avoid the CAC downtime
  35. + * switching to a different channel during CAC detection on the selected
  36. + * radar channel.
  37. + * The caller is expected to set chandef pointer to NULL in order to
  38. + * disable offchannel CAC/radar detection.
  39. */
  40. struct cfg80211_ops {
  41. int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
  42. @@ -4390,6 +4399,8 @@ struct cfg80211_ops {
  43. int (*color_change)(struct wiphy *wiphy,
  44. struct net_device *dev,
  45. struct cfg80211_color_change_settings *params);
  46. + int (*set_radar_offchan)(struct wiphy *wiphy,
  47. + struct cfg80211_chan_def *chandef);
  48. };
  49. /*
  50. @@ -7611,6 +7622,20 @@ void cfg80211_cac_event(struct net_devic
  51. const struct cfg80211_chan_def *chandef,
  52. enum nl80211_radar_event event, gfp_t gfp);
  53. +/**
  54. + * cfg80211_offchan_cac_event - Channel Availability Check (CAC) offchan event
  55. + * @wiphy: the wiphy
  56. + * @chandef: chandef for the current channel
  57. + * @event: type of event
  58. + *
  59. + * This function is called when a Channel Availability Check (CAC) is finished,
  60. + * started or aborted by a offchannel dedicated chain.
  61. + *
  62. + * Note that this acquires the wiphy lock.
  63. + */
  64. +void cfg80211_offchan_cac_event(struct wiphy *wiphy,
  65. + const struct cfg80211_chan_def *chandef,
  66. + enum nl80211_radar_event event);
  67. /**
  68. * cfg80211_gtk_rekey_notify - notify userspace about driver rekeying
  69. --- a/include/uapi/linux/nl80211.h
  70. +++ b/include/uapi/linux/nl80211.h
  71. @@ -2608,6 +2608,13 @@ enum nl80211_commands {
  72. * Mandatory parameter for the transmitting interface to enable MBSSID.
  73. * Optional for the non-transmitting interfaces.
  74. *
  75. + * @NL80211_ATTR_RADAR_OFFCHAN: Configure dedicated offchannel chain available for
  76. + * radar/CAC detection on some hw. This chain can't be used to transmit
  77. + * or receive frames and it is bounded to a running wdev.
  78. + * Offchannel radar/CAC detection allows to avoid the CAC downtime
  79. + * switching on a different channel during CAC detection on the selected
  80. + * radar channel.
  81. + *
  82. * @NUM_NL80211_ATTR: total number of nl80211_attrs available
  83. * @NL80211_ATTR_MAX: highest attribute number currently defined
  84. * @__NL80211_ATTR_AFTER_LAST: internal use
  85. @@ -3114,6 +3121,8 @@ enum nl80211_attrs {
  86. NL80211_ATTR_MBSSID_CONFIG,
  87. NL80211_ATTR_MBSSID_ELEMS,
  88. + NL80211_ATTR_RADAR_OFFCHAN,
  89. +
  90. /* add attributes here, update the policy in nl80211.c */
  91. __NL80211_ATTR_AFTER_LAST,
  92. @@ -6013,6 +6022,9 @@ enum nl80211_feature_flags {
  93. * @NL80211_EXT_FEATURE_BSS_COLOR: The driver supports BSS color collision
  94. * detection and change announcemnts.
  95. *
  96. + * @NL80211_EXT_FEATURE_RADAR_OFFCHAN: Device supports offchannel radar/CAC
  97. + * detection.
  98. + *
  99. * @NUM_NL80211_EXT_FEATURES: number of extended features.
  100. * @MAX_NL80211_EXT_FEATURES: highest extended feature index.
  101. */
  102. @@ -6078,6 +6090,7 @@ enum nl80211_ext_feature_index {
  103. NL80211_EXT_FEATURE_SECURE_RTT,
  104. NL80211_EXT_FEATURE_PROT_RANGE_NEGO_AND_MEASURE,
  105. NL80211_EXT_FEATURE_BSS_COLOR,
  106. + NL80211_EXT_FEATURE_RADAR_OFFCHAN,
  107. /* add new features before the definition below */
  108. NUM_NL80211_EXT_FEATURES,
  109. --- a/net/wireless/core.c
  110. +++ b/net/wireless/core.c
  111. @@ -545,6 +545,7 @@ use_default_name:
  112. INIT_WORK(&rdev->rfkill_block, cfg80211_rfkill_block_work);
  113. INIT_WORK(&rdev->conn_work, cfg80211_conn_work);
  114. INIT_WORK(&rdev->event_work, cfg80211_event_work);
  115. + INIT_DELAYED_WORK(&rdev->offchan_cac_work, cfg80211_offchan_cac_work);
  116. init_waitqueue_head(&rdev->dev_wait);
  117. @@ -1207,6 +1208,8 @@ void __cfg80211_leave(struct cfg80211_re
  118. cfg80211_pmsr_wdev_down(wdev);
  119. + cfg80211_stop_offchan_radar_detection(wdev);
  120. +
  121. switch (wdev->iftype) {
  122. case NL80211_IFTYPE_ADHOC:
  123. __cfg80211_leave_ibss(rdev, dev, true);
  124. --- a/net/wireless/core.h
  125. +++ b/net/wireless/core.h
  126. @@ -84,6 +84,10 @@ struct cfg80211_registered_device {
  127. struct delayed_work dfs_update_channels_wk;
  128. + struct wireless_dev *offchan_radar_wdev;
  129. + struct cfg80211_chan_def offchan_radar_chandef;
  130. + struct delayed_work offchan_cac_work;
  131. +
  132. /* netlink port which started critical protocol (0 means not started) */
  133. u32 crit_proto_nlportid;
  134. @@ -491,6 +495,15 @@ cfg80211_chandef_dfs_cac_time(struct wip
  135. void cfg80211_sched_dfs_chan_update(struct cfg80211_registered_device *rdev);
  136. +int
  137. +cfg80211_start_offchan_radar_detection(struct cfg80211_registered_device *rdev,
  138. + struct wireless_dev *wdev,
  139. + struct cfg80211_chan_def *chandef);
  140. +
  141. +void cfg80211_stop_offchan_radar_detection(struct wireless_dev *wdev);
  142. +
  143. +void cfg80211_offchan_cac_work(struct work_struct *work);
  144. +
  145. bool cfg80211_any_wiphy_oper_chan(struct wiphy *wiphy,
  146. struct ieee80211_channel *chan);
  147. --- a/net/wireless/mlme.c
  148. +++ b/net/wireless/mlme.c
  149. @@ -970,3 +970,116 @@ void cfg80211_cac_event(struct net_devic
  150. nl80211_radar_notify(rdev, chandef, event, netdev, gfp);
  151. }
  152. EXPORT_SYMBOL(cfg80211_cac_event);
  153. +
  154. +void cfg80211_offchan_cac_work(struct work_struct *work)
  155. +{
  156. + struct delayed_work *delayed_work = to_delayed_work(work);
  157. + struct cfg80211_registered_device *rdev;
  158. +
  159. + rdev = container_of(delayed_work, struct cfg80211_registered_device,
  160. + offchan_cac_work);
  161. + cfg80211_offchan_cac_event(&rdev->wiphy, &rdev->offchan_radar_chandef,
  162. + NL80211_RADAR_CAC_FINISHED);
  163. +}
  164. +
  165. +static void
  166. +__cfg80211_offchan_cac_event(struct cfg80211_registered_device *rdev,
  167. + struct wireless_dev *wdev,
  168. + const struct cfg80211_chan_def *chandef,
  169. + enum nl80211_radar_event event)
  170. +{
  171. + struct wiphy *wiphy = &rdev->wiphy;
  172. + struct net_device *netdev;
  173. +
  174. + lockdep_assert_wiphy(&rdev->wiphy);
  175. +
  176. + if (event != NL80211_RADAR_CAC_STARTED && !rdev->offchan_radar_wdev)
  177. + return;
  178. +
  179. + switch (event) {
  180. + case NL80211_RADAR_CAC_FINISHED:
  181. + cfg80211_set_dfs_state(wiphy, chandef, NL80211_DFS_AVAILABLE);
  182. + memcpy(&rdev->cac_done_chandef, chandef, sizeof(*chandef));
  183. + queue_work(cfg80211_wq, &rdev->propagate_cac_done_wk);
  184. + cfg80211_sched_dfs_chan_update(rdev);
  185. + wdev = rdev->offchan_radar_wdev;
  186. + rdev->offchan_radar_wdev = NULL;
  187. + break;
  188. + case NL80211_RADAR_CAC_ABORTED:
  189. + cancel_delayed_work(&rdev->offchan_cac_work);
  190. + wdev = rdev->offchan_radar_wdev;
  191. + rdev->offchan_radar_wdev = NULL;
  192. + break;
  193. + case NL80211_RADAR_CAC_STARTED:
  194. + WARN_ON(!wdev);
  195. + rdev->offchan_radar_wdev = wdev;
  196. + break;
  197. + default:
  198. + return;
  199. + }
  200. +
  201. + netdev = wdev ? wdev->netdev : NULL;
  202. + nl80211_radar_notify(rdev, chandef, event, netdev, GFP_KERNEL);
  203. +}
  204. +
  205. +void cfg80211_offchan_cac_event(struct wiphy *wiphy,
  206. + const struct cfg80211_chan_def *chandef,
  207. + enum nl80211_radar_event event)
  208. +{
  209. + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  210. +
  211. + wiphy_lock(wiphy);
  212. + __cfg80211_offchan_cac_event(rdev, NULL, chandef, event);
  213. + wiphy_unlock(wiphy);
  214. +}
  215. +EXPORT_SYMBOL(cfg80211_offchan_cac_event);
  216. +
  217. +int
  218. +cfg80211_start_offchan_radar_detection(struct cfg80211_registered_device *rdev,
  219. + struct wireless_dev *wdev,
  220. + struct cfg80211_chan_def *chandef)
  221. +{
  222. + unsigned int cac_time_ms;
  223. + int err;
  224. +
  225. + lockdep_assert_wiphy(&rdev->wiphy);
  226. +
  227. + if (!wiphy_ext_feature_isset(&rdev->wiphy,
  228. + NL80211_EXT_FEATURE_RADAR_OFFCHAN))
  229. + return -EOPNOTSUPP;
  230. +
  231. + if (rdev->offchan_radar_wdev)
  232. + return -EBUSY;
  233. +
  234. + err = rdev_set_radar_offchan(rdev, chandef);
  235. + if (err)
  236. + return err;
  237. +
  238. + cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, chandef);
  239. + if (!cac_time_ms)
  240. + cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
  241. +
  242. + rdev->offchan_radar_chandef = *chandef;
  243. + __cfg80211_offchan_cac_event(rdev, wdev, chandef,
  244. + NL80211_RADAR_CAC_STARTED);
  245. + queue_delayed_work(cfg80211_wq, &rdev->offchan_cac_work,
  246. + msecs_to_jiffies(cac_time_ms));
  247. +
  248. + return 0;
  249. +}
  250. +
  251. +void cfg80211_stop_offchan_radar_detection(struct wireless_dev *wdev)
  252. +{
  253. + struct wiphy *wiphy = wdev->wiphy;
  254. + struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  255. +
  256. + lockdep_assert_wiphy(wiphy);
  257. +
  258. + if (wdev != rdev->offchan_radar_wdev)
  259. + return;
  260. +
  261. + rdev_set_radar_offchan(rdev, NULL);
  262. +
  263. + __cfg80211_offchan_cac_event(rdev, NULL, NULL,
  264. + NL80211_RADAR_CAC_ABORTED);
  265. +}
  266. --- a/net/wireless/nl80211.c
  267. +++ b/net/wireless/nl80211.c
  268. @@ -802,6 +802,7 @@ static const struct nla_policy nl80211_p
  269. [NL80211_ATTR_MBSSID_CONFIG] =
  270. NLA_POLICY_NESTED(nl80211_mbssid_config_policy),
  271. [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED },
  272. + [NL80211_ATTR_RADAR_OFFCHAN] = { .type = NLA_FLAG },
  273. };
  274. /* policy for the key attributes */
  275. @@ -9288,12 +9289,6 @@ static int nl80211_start_radar_detection
  276. if (err)
  277. return err;
  278. - if (netif_carrier_ok(dev))
  279. - return -EBUSY;
  280. -
  281. - if (wdev->cac_started)
  282. - return -EBUSY;
  283. -
  284. err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
  285. if (err < 0)
  286. return err;
  287. @@ -9304,6 +9299,16 @@ static int nl80211_start_radar_detection
  288. if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
  289. return -EINVAL;
  290. + if (nla_get_flag(info->attrs[NL80211_ATTR_RADAR_OFFCHAN]))
  291. + return cfg80211_start_offchan_radar_detection(rdev, wdev,
  292. + &chandef);
  293. +
  294. + if (netif_carrier_ok(dev))
  295. + return -EBUSY;
  296. +
  297. + if (wdev->cac_started)
  298. + return -EBUSY;
  299. +
  300. /* CAC start is offloaded to HW and can't be started manually */
  301. if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
  302. return -EOPNOTSUPP;
  303. --- a/net/wireless/rdev-ops.h
  304. +++ b/net/wireless/rdev-ops.h
  305. @@ -1381,4 +1381,21 @@ static inline int rdev_color_change(stru
  306. return ret;
  307. }
  308. +static inline int
  309. +rdev_set_radar_offchan(struct cfg80211_registered_device *rdev,
  310. + struct cfg80211_chan_def *chandef)
  311. +{
  312. + struct wiphy *wiphy = &rdev->wiphy;
  313. + int ret;
  314. +
  315. + if (!rdev->ops->set_radar_offchan)
  316. + return -EOPNOTSUPP;
  317. +
  318. + trace_rdev_set_radar_offchan(wiphy, chandef);
  319. + ret = rdev->ops->set_radar_offchan(wiphy, chandef);
  320. + trace_rdev_return_int(wiphy, ret);
  321. +
  322. + return ret;
  323. +}
  324. +
  325. #endif /* __CFG80211_RDEV_OPS */
  326. --- a/net/wireless/trace.h
  327. +++ b/net/wireless/trace.h
  328. @@ -3643,6 +3643,25 @@ TRACE_EVENT(cfg80211_bss_color_notify,
  329. __entry->color_bitmap)
  330. );
  331. +TRACE_EVENT(rdev_set_radar_offchan,
  332. + TP_PROTO(struct wiphy *wiphy, struct cfg80211_chan_def *chandef),
  333. +
  334. + TP_ARGS(wiphy, chandef),
  335. +
  336. + TP_STRUCT__entry(
  337. + WIPHY_ENTRY
  338. + CHAN_DEF_ENTRY
  339. + ),
  340. +
  341. + TP_fast_assign(
  342. + WIPHY_ASSIGN;
  343. + CHAN_DEF_ASSIGN(chandef)
  344. + ),
  345. +
  346. + TP_printk(WIPHY_PR_FMT ", " CHAN_DEF_PR_FMT,
  347. + WIPHY_PR_ARG, CHAN_DEF_PR_ARG)
  348. +);
  349. +
  350. #endif /* !__RDEV_OPS_TRACE || TRACE_HEADER_MULTI_READ */
  351. #undef TRACE_INCLUDE_PATH