Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 301043
b: refs/heads/master
c: 534111c
h: refs/heads/master
i:
  301041: 807699d
  301039: 83f601c
v: v3
  • Loading branch information
Daniel Drake authored and John W. Linville committed Apr 17, 2012
1 parent 7b23ca3 commit 685a618
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0beecac8abb3af890d470df541142d55343382d6
refs/heads/master: 534111c78c59a8db89c570fd07489243dc366a05
8 changes: 8 additions & 0 deletions trunk/drivers/net/wireless/libertas/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ struct lbs_fw_table {
const char *fwname;
};

struct lbs_private;
typedef void (*lbs_fw_cb)(struct lbs_private *priv, int ret,
const struct firmware *helper, const struct firmware *mainfw);

struct lbs_private;
struct sk_buff;
struct net_device;
Expand Down Expand Up @@ -70,5 +74,9 @@ int lbs_get_firmware(struct device *dev, u32 card_model,
const struct lbs_fw_table *fw_table,
const struct firmware **helper,
const struct firmware **mainfw);
int lbs_get_firmware_async(struct lbs_private *priv, struct device *device,
u32 card_model, const struct lbs_fw_table *fw_table,
lbs_fw_cb callback);
void lbs_wait_for_firmware_load(struct lbs_private *priv);

#endif
10 changes: 10 additions & 0 deletions trunk/drivers/net/wireless/libertas/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define _LBS_DEV_H_

#include "defs.h"
#include "decl.h"
#include "host.h"

#include <linux/kfifo.h>
Expand Down Expand Up @@ -180,6 +181,15 @@ struct lbs_private {
wait_queue_head_t scan_q;
/* Whether the scan was initiated internally and not by cfg80211 */
bool internal_scan;

/* Firmware load */
u32 fw_model;
wait_queue_head_t fw_waitq;
struct device *fw_device;
const struct firmware *helper_fw;
const struct lbs_fw_table *fw_table;
const struct lbs_fw_table *fw_iter;
lbs_fw_cb fw_callback;
};

extern struct cmd_confirm_sleep confirm_sleep;
Expand Down
143 changes: 143 additions & 0 deletions trunk/drivers/net/wireless/libertas/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,152 @@
* Firmware loading and handling functions.
*/

#include <linux/firmware.h>
#include <linux/firmware.h>
#include <linux/module.h>

#include "dev.h"
#include "decl.h"

static void load_next_firmware_from_table(struct lbs_private *private);

static void lbs_fw_loaded(struct lbs_private *priv, int ret,
const struct firmware *helper, const struct firmware *mainfw)
{
unsigned long flags;

lbs_deb_fw("firmware load complete, code %d\n", ret);

/* User must free helper/mainfw */
priv->fw_callback(priv, ret, helper, mainfw);

spin_lock_irqsave(&priv->driver_lock, flags);
priv->fw_callback = NULL;
wake_up(&priv->fw_waitq);
spin_unlock_irqrestore(&priv->driver_lock, flags);
}

static void do_load_firmware(struct lbs_private *priv, const char *name,
void (*cb)(const struct firmware *fw, void *context))
{
int ret;

lbs_deb_fw("Requesting %s\n", name);
ret = request_firmware_nowait(THIS_MODULE, true, name,
priv->fw_device, GFP_KERNEL, priv, cb);
if (ret) {
lbs_deb_fw("request_firmware_nowait error %d\n", ret);
lbs_fw_loaded(priv, ret, NULL, NULL);
}
}

static void main_firmware_cb(const struct firmware *firmware, void *context)
{
struct lbs_private *priv = context;

if (!firmware) {
/* Failed to find firmware: try next table entry */
load_next_firmware_from_table(priv);
return;
}

/* Firmware found! */
lbs_fw_loaded(priv, 0, priv->helper_fw, firmware);
}

static void helper_firmware_cb(const struct firmware *firmware, void *context)
{
struct lbs_private *priv = context;

if (!firmware) {
/* Failed to find firmware: try next table entry */
load_next_firmware_from_table(priv);
return;
}

/* Firmware found! */
if (priv->fw_iter->fwname) {
priv->helper_fw = firmware;
do_load_firmware(priv, priv->fw_iter->fwname, main_firmware_cb);
} else {
/* No main firmware needed for this helper --> success! */
lbs_fw_loaded(priv, 0, firmware, NULL);
}
}

static void load_next_firmware_from_table(struct lbs_private *priv)
{
const struct lbs_fw_table *iter;

if (!priv->fw_iter)
iter = priv->fw_table;
else
iter = ++priv->fw_iter;

if (priv->helper_fw) {
release_firmware(priv->helper_fw);
priv->helper_fw = NULL;
}

next:
if (!iter->helper) {
/* End of table hit. */
lbs_fw_loaded(priv, -ENOENT, NULL, NULL);
return;
}

if (iter->model != priv->fw_model) {
iter++;
goto next;
}

priv->fw_iter = iter;
do_load_firmware(priv, iter->helper, helper_firmware_cb);
}

void lbs_wait_for_firmware_load(struct lbs_private *priv)
{
wait_event(priv->fw_waitq, priv->fw_callback == NULL);
}

/**
* lbs_get_firmware_async - Retrieves firmware asynchronously. Can load
* either a helper firmware and a main firmware (2-stage), or just the helper.
*
* @priv: Pointer to lbs_private instance
* @dev: A pointer to &device structure
* @card_model: Bus-specific card model ID used to filter firmware table
* elements
* @fw_table: Table of firmware file names and device model numbers
* terminated by an entry with a NULL helper name
* @callback: User callback to invoke when firmware load succeeds or fails.
*/
int lbs_get_firmware_async(struct lbs_private *priv, struct device *device,
u32 card_model, const struct lbs_fw_table *fw_table,
lbs_fw_cb callback)
{
unsigned long flags;

spin_lock_irqsave(&priv->driver_lock, flags);
if (priv->fw_callback) {
lbs_deb_fw("firmware load already in progress\n");
spin_unlock_irqrestore(&priv->driver_lock, flags);
return -EBUSY;
}

priv->fw_device = device;
priv->fw_callback = callback;
priv->fw_table = fw_table;
priv->fw_iter = NULL;
priv->fw_model = card_model;
spin_unlock_irqrestore(&priv->driver_lock, flags);

lbs_deb_fw("Starting async firmware load\n");
load_next_firmware_from_table(priv);
return 0;
}
EXPORT_SYMBOL_GPL(lbs_get_firmware_async);

/**
* lbs_get_firmware - Retrieves two-stage firmware
*
Expand All @@ -18,6 +159,8 @@
* @helper: On success, the helper firmware; caller must free
* @mainfw: On success, the main firmware; caller must free
*
* Deprecated: use lbs_get_firmware_async() instead.
*
* returns: 0 on success, non-zero on failure
*/
int lbs_get_firmware(struct device *dev, u32 card_model,
Expand Down
3 changes: 3 additions & 0 deletions trunk/drivers/net/wireless/libertas/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ static int lbs_init_adapter(struct lbs_private *priv)
priv->is_host_sleep_configured = 0;
priv->is_host_sleep_activated = 0;
init_waitqueue_head(&priv->host_sleep_q);
init_waitqueue_head(&priv->fw_waitq);
mutex_init(&priv->lock);

setup_timer(&priv->command_timer, lbs_cmd_timeout_handler,
Expand Down Expand Up @@ -1037,6 +1038,8 @@ void lbs_remove_card(struct lbs_private *priv)
if (priv->wiphy_registered)
lbs_scan_deinit(priv);

lbs_wait_for_firmware_load(priv);

/* worker thread destruction blocks on the in-flight command which
* should have been cleared already in lbs_stop_card().
*/
Expand Down

0 comments on commit 685a618

Please sign in to comment.