mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC/RFT] p54spi: Convert driver to use asynchronous firmware loading
@ 2012-02-10  1:05 Larry Finger
  2012-02-10 10:40 ` Michael Büsch
  2012-02-13  0:20 ` Max Filippov
  0 siblings, 2 replies; 4+ messages in thread
From: Larry Finger @ 2012-02-10  1:05 UTC (permalink / raw)
  To: chunkeey; +Cc: m, jcmvbkbc, linux-kernel, devel, linux-wireless

Drivers that load firmware from their probe routine have problems with the
latest versions of udev as they get timeouts while waiting for user
space to start. The problem is fixed by using request_firmware_nowait()
and delaying the start of mac80211 until the firmware is loaded.

To prevent the possibility of the driver being unloaded while the firmware
loading callback is still active, a completion queue entry is used.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
---

This conversion of p54spi to use asynchronous firmware loading is based
on the method used in p54usb. As I do not have the hardware, it is only
compile tested. I would appreciate any feedback from people that have the
hardware.

Larry
---

Index: wireless-testing-new/drivers/net/wireless/p54/p54spi.c
===================================================================
--- wireless-testing-new.orig/drivers/net/wireless/p54/p54spi.c
+++ wireless-testing-new/drivers/net/wireless/p54/p54spi.c
@@ -163,25 +163,41 @@ static int p54spi_spi_write_dma(struct p
 	return 0;
 }
 
-static int p54spi_request_firmware(struct ieee80211_hw *dev)
+
+static void p54s_load_firmware_cb(const struct firmware *firmware,
+				  void *context)
 {
+	struct ieee80211_hw *dev = context;
 	struct p54s_priv *priv = dev->priv;
 	int ret;
 
-	/* FIXME: should driver use it's own struct device? */
-	ret = request_firmware(&priv->firmware, "3826.arm", &priv->spi->dev);
-
-	if (ret < 0) {
-		dev_err(&priv->spi->dev, "request_firmware() failed: %d", ret);
-		return ret;
+	if (!firmware) {
+		/* alternate firmware not found */
+		dev_err(&priv->spi->dev, "Firmware loading failed\n");
+		return;
 	}
+	complete(&priv->fw_loaded);
+	priv->firmware = firmware;
 
 	ret = p54_parse_firmware(dev, priv->firmware);
-	if (ret) {
+	if (ret)
 		release_firmware(priv->firmware);
+}
+
+static int p54spi_request_firmware(struct ieee80211_hw *dev)
+{
+	struct p54s_priv *priv = dev->priv;
+	int ret;
+
+	init_completion(&priv->fw_loaded);
+	/* FIXME: should driver use it's own struct device? */
+	ret = request_firmware_nowait(THIS_MODULE, 1, "3826.arm",
+				      &priv->spi->dev, GFP_KERNEL, dev,
+				      p54s_load_firmware_cb);
+	if (ret < 0) {
+		dev_err(&priv->spi->dev, "request_firmware() failed: %d", ret);
 		return ret;
 	}
-
 	return 0;
 }
 
@@ -681,6 +697,7 @@ static int __devexit p54spi_remove(struc
 {
 	struct p54s_priv *priv = dev_get_drvdata(&spi->dev);
 
+	wait_for_completion(&priv->fw_loaded);
 	p54_unregister_common(priv->hw);
 
 	free_irq(gpio_to_irq(p54spi_gpio_irq), spi);
Index: wireless-testing-new/drivers/net/wireless/p54/p54spi.h
===================================================================
--- wireless-testing-new.orig/drivers/net/wireless/p54/p54spi.h
+++ wireless-testing-new/drivers/net/wireless/p54/p54spi.h
@@ -120,6 +120,7 @@ struct p54s_priv {
 
 	enum fw_state fw_state;
 	const struct firmware *firmware;
+	struct completion fw_loaded;
 };
 
 #endif /* P54SPI_H */

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-02-13  0:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-10  1:05 [RFC/RFT] p54spi: Convert driver to use asynchronous firmware loading Larry Finger
2012-02-10 10:40 ` Michael Büsch
2012-02-13  0:20 ` Max Filippov
2012-02-13  0:26   ` Larry Finger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome