From nobody Sat Jun 10 23:08:57 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QdttK3zP8z4d6Kk; Sat, 10 Jun 2023 23:08:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QdttK3VlPz3NYQ; Sat, 10 Jun 2023 23:08:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686438537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Fu9CX+/72epYCgEvb5F9545hhxxHNggnHwOzd/PQyrI=; b=qKVb/hQ0XW3ardqc5SqcqqoJhN8QVATJJXdtq61oM0QAyL75xmVjzyP6H9NkmGe9OMMsy4 lhDQhR+RkSNLbeSDztUQ+SLq8PNw2UD98uiuduoCwbK01MBScjzvee3P1AZZf3GZx3rmlg 8GjAVW++KgGbHCB5T0cQ8AbJ+ce/7wavvicu0PteHPAx1PRzCJs/NlS8ftZMWUrwJROubQ au4Uob+wHcIhNxixHJ6qFvSvcf+FzVRTFC9ues2VtpOM9QhfMGdjq12MObqlG20VY+SxFL ouM9TWNS8d8A8ONzUJhwbPcv/RGZksWGSmctwQE9SZsQlgneksdkuS769qBq5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686438537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Fu9CX+/72epYCgEvb5F9545hhxxHNggnHwOzd/PQyrI=; b=WsOYmEYs0NQRsG/u0d7NUv8bavtjLv8aSXWkrGV8I0e3CShxUN8DYmIHNO6JXEBQCTAfma GZ5AmHgI04nME2B0R4dJQjvVc4EXm8kcKQ2AfrXK+tecJdh2aMBfDaYjDgcbVwqltmWW50 SaEfq8dpP7lFd2NPsuQkPgj/UjvjXVAbr4IVKe9DBnYAUZbYVWeJD+27og6nj+pTZdPQ7l HDBTtvyu4XKV6ra/New3owMIeyciZGJ6PFiL+IEVfZJq4f78Yrcu1aHgDaYVxUgM8wyvsQ xR6QuIHAPKIHxqNofTLJFzLgxDi2njEaiKuNatK/UdyyB3R0gI+47iM3PcpCHg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686438537; a=rsa-sha256; cv=none; b=cgGfEA43IchTZyDhWT/0rrTGXsBZOFcPMmlM1a+4DsjvHc+7KQa5iQRZm2c+l0gD0axCeJ X7Uai/HxEPsOcetnFLl/8ML0nmdF7PDjn5IFu2d/XgzHsxuJfazJSpBjB0a6eUE9UeVTNj 05tUpV3FNXTmpY+ASNDdOujOWdUC2CVDL2EFxQlKG8qR2mJneiv10GVeZ1QrLwUbDd7X7b KLgcVaNeiy0xykY7iqXhdb/zGcP6VQuv0A2l+iKiKBAibuH2hgDmEeuGwsC2e+K55SNYE/ yLNsbD4BtOLoX+XhlDntp+1ew4iduGzJzqxAe3qsQ85gJeRo7NrCrIWOzy1/Kw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QdttK2YFJzbSN; Sat, 10 Jun 2023 23:08:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35AN8vvQ060638; Sat, 10 Jun 2023 23:08:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35AN8v2U060637; Sat, 10 Jun 2023 23:08:57 GMT (envelope-from git) Date: Sat, 10 Jun 2023 23:08:57 GMT Message-Id: <202306102308.35AN8v2U060637@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 3206587a20de - main - LinuxKPI: 802.11: improve scan handling List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3206587a20de9810b549ba8fd0032f7ab884bbec Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=3206587a20de9810b549ba8fd0032f7ab884bbec commit 3206587a20de9810b549ba8fd0032f7ab884bbec Author: Bjoern A. Zeeb AuthorDate: 2023-06-10 21:53:56 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-06-10 23:04:40 +0000 LinuxKPI: 802.11: improve scan handling Under certain circumstances a hw_scan may be downgraded to a software scan. Handle these situations better and make sure we free resources in all cases once. [1] Also leave a note about scanning all bands (or we would have to switch bands manually). In both cases hardware doing and driver saying seem not entirely consistent for all and all firmware. Sponsored by: The FreeBSD Foundation MFC after: 10 days Reported by: imp [1] --- sys/compat/linuxkpi/common/src/linux_80211.c | 72 ++++++++++++++++++---- .../linuxkpi/common/src/linux_80211_macops.c | 21 ++++--- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c index 53ddd16413bb..c9279581062e 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.c +++ b/sys/compat/linuxkpi/common/src/linux_80211.c @@ -2669,12 +2669,7 @@ sw_scan: int band, i, ssid_count, common_ie_len; uint32_t band_mask; uint8_t *ie, *ieend; - - if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { - IMPROVE("individual band scans not yet supported"); - /* In theory net80211 would have to drive this. */ - return; - } + bool running; ssid_count = min(ss->ss_nssid, hw->wiphy->max_scan_ssids); ssids_len = ssid_count * sizeof(*ssids); @@ -2688,6 +2683,18 @@ sw_scan: ss->ss_chans[ss->ss_next + i]); band_mask |= (1 << band); } + + if (!ieee80211_hw_check(hw, SINGLE_SCAN_ON_ALL_BANDS)) { + IMPROVE("individual band scans not yet supported, only scanning first band"); + /* In theory net80211 should drive this. */ + /* Probably we need to add local logic for now; + * need to deal with scan_complete + * and cancel_scan and keep local state. + * Also cut the nchan down above. + */ + /* XXX-BZ ath10k does not set this but still does it? &$%^ */ + } + chan_len = nchan * (sizeof(lc) + sizeof(*lc)); common_ie_len = 0; @@ -2704,10 +2711,7 @@ sw_scan: common_ie_len, hw->wiphy->max_scan_ie_len); } - KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " - "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); - - lhw->hw_req = hw_req = malloc(sizeof(*hw_req) + ssids_len + + hw_req = malloc(sizeof(*hw_req) + ssids_len + s6ghzlen + chan_len + lhw->supbands * lhw->scan_ie_len + common_ie_len, M_LKPI80211, M_WAITOK | M_ZERO); @@ -2737,7 +2741,7 @@ sw_scan: c = ss->ss_chans[ss->ss_next + i]; lc->hw_value = c->ic_ieee; - lc->center_freq = c->ic_freq; + lc->center_freq = c->ic_freq; /* XXX */ /* lc->flags */ lc->band = lkpi_net80211_chan_to_nl80211_band(c); lc->max_power = c->ic_maxpower; @@ -2774,12 +2778,48 @@ sw_scan: lvif = VAP_TO_LVIF(vap); vif = LVIF_TO_VIF(lvif); + + LKPI_80211_LHW_SCAN_LOCK(lhw); + /* Re-check under lock. */ + running = (lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0; + if (!running) { + KASSERT(lhw->hw_req == NULL, ("%s: ic %p lhw %p hw_req %p " + "!= NULL\n", __func__, ic, lhw, lhw->hw_req)); + + lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; + lhw->hw_req = hw_req; + } + LKPI_80211_LHW_SCAN_UNLOCK(lhw); + if (running) { + free(hw_req, M_LKPI80211); + return; + } + error = lkpi_80211_mo_hw_scan(hw, vif, hw_req); if (error != 0) { ieee80211_cancel_scan(vap); - free(hw_req, M_LKPI80211); - lhw->hw_req = NULL; + /* + * ieee80211_scan_completed must be called in either + * case of error or none. So let the free happen there + * and only there. + * That would be fine in theory but in practice drivers + * behave differently: + * ath10k does not return hw_scan until after scan_complete + * and can then still return an error. + * rtw88 can return 1 or -EBUSY without scan_complete + * iwlwifi can return various errors before scan starts + * ... + * So we cannot rely on that behaviour and have to check + * and balance between both code paths. + */ + LKPI_80211_LHW_SCAN_LOCK(lhw); + if ((lhw->scan_flags & LKPI_LHW_SCAN_RUNNING) != 0) { + free(lhw->hw_req, M_LKPI80211); + lhw->hw_req = NULL; + lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; + } + LKPI_80211_LHW_SCAN_UNLOCK(lhw); /* * XXX-SIGH magic number. @@ -2790,6 +2830,12 @@ sw_scan: LKPI_80211_LHW_SCAN_LOCK(lhw); lhw->scan_flags &= ~LKPI_LHW_SCAN_HW; LKPI_80211_LHW_SCAN_UNLOCK(lhw); + /* + * XXX If we clear this now and later a driver + * thinks it * can do a hw_scan again, we will + * currently not re-enable it? + */ + vap->iv_flags_ext &= ~IEEE80211_FEXT_SCAN_OFFLOAD; ieee80211_start_scan(vap, IEEE80211_SCAN_ACTIVE | IEEE80211_SCAN_NOPICK | diff --git a/sys/compat/linuxkpi/common/src/linux_80211_macops.c b/sys/compat/linuxkpi/common/src/linux_80211_macops.c index 762a54e4a823..16b502b1ca49 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211_macops.c +++ b/sys/compat/linuxkpi/common/src/linux_80211_macops.c @@ -43,8 +43,9 @@ __FBSDID("$FreeBSD$"); #ifdef LINUXKPI_DEBUG_80211 #define LKPI_80211_TRACE_MO(fmt, ...) \ if (linuxkpi_debug_80211 & D80211_TRACE_MO) \ - printf("LKPI_80211_TRACE_MO %s:%d:_" fmt "\n", \ - __func__, __LINE__, __VA_ARGS__) + printf("LKPI_80211_TRACE_MO %s:%d: %d %d %u_" fmt "\n", \ + __func__, __LINE__, curcpu, curthread->td_tid, \ + (unsigned int)ticks, __VA_ARGS__) #else #define LKPI_80211_TRACE_MO(...) do { } while(0) #endif @@ -215,18 +216,22 @@ lkpi_80211_mo_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct lkpi_hw *lhw; int error; + /* + * MUST NOT return EPERM as that is a "magic number 1" based on rtw88 + * driver indicating hw_scan is not supported despite the ops call + * being available. + */ + lhw = HW_TO_LHW(hw); if (lhw->ops->hw_scan == NULL) { - /* XXX-BZ can we hide other scans like we can for sta_add..? */ - error = EOPNOTSUPP; + /* Return magic number to use sw scan. */ + error = 1; goto out; } - lhw->scan_flags |= LKPI_LHW_SCAN_RUNNING; - LKPI_80211_TRACE_MO("hw %p vif %p sr %p", hw, vif, sr); + LKPI_80211_TRACE_MO("CALLING hw %p vif %p sr %p", hw, vif, sr); error = lhw->ops->hw_scan(hw, vif, sr); - if (error != 0) - lhw->scan_flags &= ~LKPI_LHW_SCAN_RUNNING; + LKPI_80211_TRACE_MO("RETURNING hw %p vif %p sr %p error %d", hw, vif, sr, error); out: return (error);