git: a81da2c71ca6 - stable/13 - iwlwifi: enforce FreeBSD specific (expected) behaviour

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 17 Oct 2022 20:41:29 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=a81da2c71ca6538dbf1abfe3998c00a31ef4bee5

commit a81da2c71ca6538dbf1abfe3998c00a31ef4bee5
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-09-25 21:23:12 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-10-17 20:37:03 +0000

    iwlwifi: enforce FreeBSD specific (expected) behaviour
    
    iwlwifi can return early from probe (in FreeBSD attach) while a separate
    thread is still grinding loading the firmware and setting things up.
    For us this means that kldload succeeded but we may not have a physical
    wireless interface (com) yet but the rc framework might already try to
    configure a vap on one.
    
    Wait until we get a firmware completion event from the other thread
    (on success or error) and block returning.  That way we can ensure that
    the "hw" (or com in net80211 terms) is there when we return from attach
    matching the expected FreeBSD driver behaviour.
    
    Reported by:    J.R. Oldroyd (jr opal.com)
    Reported by:    probably inderectly showing as other problem
    Tested by:      J.R. Oldroyd (jr opal.com)
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit f808c43ad9234670770601ba32a7426b00bbf528)
---
 sys/contrib/dev/iwlwifi/iwl-drv.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/sys/contrib/dev/iwlwifi/iwl-drv.c b/sys/contrib/dev/iwlwifi/iwl-drv.c
index 263126a739b5..f531ce13aff4 100644
--- a/sys/contrib/dev/iwlwifi/iwl-drv.c
+++ b/sys/contrib/dev/iwlwifi/iwl-drv.c
@@ -1752,6 +1752,16 @@ struct iwl_drv *iwl_drv_start(struct iwl_trans *trans)
 		goto err_fw;
 	}
 
+#if defined(__FreeBSD__)
+	/*
+	 * Wait until initilization is done before returning in order to
+	 * replicate FreeBSD's synchronous behaviour -- we cannot create
+	 * a vap before the com is fully created but if LinuxKPI "probe"
+	 * returned before it was all done that is what could happen.
+	 */
+	wait_for_completion(&drv->request_firmware_complete);
+#endif
+
 	return drv;
 
 err_fw: