Skip to content

Commit

Permalink
libertas: Firmware loading simplifications
Browse files Browse the repository at this point in the history
Remove the ability to pass module parameters with firmware filenames
for USB and SDIO interfaces.

Remove the ability to pass custom "user" filenames to lbs_get_firmware().

Remove the ability to reprogram internal device memory with a different
firmware from the USB driver (we don't know of any users), and simplify
the OLPC firmware loading quirk to simply placing the OLPC firmware
at the top of the list (we don't know of any users other than OLPC).

Move lbs_get_firmware() into its own file.

These simplifications should have no real-life effect but make the
upcoming transition to asynchronous firmware loading considerably less
painful.

Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-by: Dan Williams <dcbw@redhat.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Daniel Drake authored and John W. Linville committed Apr 17, 2012
1 parent be03d4a commit 370803c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 293 deletions.
1 change: 1 addition & 0 deletions drivers/net/wireless/libertas/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ libertas-y += ethtool.o
libertas-y += main.o
libertas-y += rx.o
libertas-y += tx.o
libertas-y += firmware.o
libertas-$(CONFIG_LIBERTAS_MESH) += mesh.o

usb8xxx-objs += if_usb.o
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/wireless/libertas/decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ int lbs_exit_auto_deep_sleep(struct lbs_private *priv);
u32 lbs_fw_index_to_data_rate(u8 index);
u8 lbs_data_rate_to_fw_index(u32 rate);

int lbs_get_firmware(struct device *dev, const char *user_helper,
const char *user_mainfw, u32 card_model,
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);
Expand Down
79 changes: 79 additions & 0 deletions drivers/net/wireless/libertas/firmware.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Firmware loading and handling functions.
*/

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

#include "decl.h"

/**
* lbs_get_firmware - Retrieves two-stage firmware
*
* @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
* @helper: On success, the helper firmware; caller must free
* @mainfw: On success, the main firmware; caller must free
*
* returns: 0 on success, non-zero on failure
*/
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)
{
const struct lbs_fw_table *iter;
int ret;

BUG_ON(helper == NULL);
BUG_ON(mainfw == NULL);

/* Search for firmware to use from the table. */
iter = fw_table;
while (iter && iter->helper) {
if (iter->model != card_model)
goto next;

if (*helper == NULL) {
ret = request_firmware(helper, iter->helper, dev);
if (ret)
goto next;

/* If the device has one-stage firmware (ie cf8305) and
* we've got it then we don't need to bother with the
* main firmware.
*/
if (iter->fwname == NULL)
return 0;
}

if (*mainfw == NULL) {
ret = request_firmware(mainfw, iter->fwname, dev);
if (ret) {
/* Clear the helper to ensure we don't have
* mismatched firmware pairs.
*/
release_firmware(*helper);
*helper = NULL;
}
}

if (*helper && *mainfw)
return 0;

next:
iter++;
}

/* Failed */
release_firmware(*helper);
*helper = NULL;
release_firmware(*mainfw);
*mainfw = NULL;

return -ENOENT;
}
EXPORT_SYMBOL_GPL(lbs_get_firmware);
4 changes: 2 additions & 2 deletions drivers/net/wireless/libertas/if_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,8 +890,8 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
goto out2;
}

ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model,
&fw_table[0], &helper, &mainfw);
ret = lbs_get_firmware(&p_dev->dev, card->model, &fw_table[0],
&helper, &mainfw);
if (ret) {
pr_err("failed to find firmware (%d)\n", ret);
goto out2;
Expand Down
25 changes: 2 additions & 23 deletions drivers/net/wireless/libertas/if_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ static void if_sdio_interrupt(struct sdio_func *func);
*/
static u8 user_rmmod;

static char *lbs_helper_name = NULL;
module_param_named(helper_name, lbs_helper_name, charp, 0644);

static char *lbs_fw_name = NULL;
module_param_named(fw_name, lbs_fw_name, charp, 0644);

static const struct sdio_device_id if_sdio_ids[] = {
{ SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL,
SDIO_DEVICE_ID_MARVELL_LIBERTAS) },
Expand Down Expand Up @@ -124,11 +118,6 @@ struct if_sdio_card {
unsigned long ioport;
unsigned int scratch_reg;

const char *helper;
const char *firmware;
bool helper_allocated;
bool firmware_allocated;

u8 buffer[65536] __attribute__((aligned(4)));

spinlock_t lock;
Expand Down Expand Up @@ -725,8 +714,8 @@ static int if_sdio_prog_firmware(struct if_sdio_card *card)
goto success;
}

ret = lbs_get_firmware(&card->func->dev, lbs_helper_name, lbs_fw_name,
card->model, &fw_table[0], &helper, &mainfw);
ret = lbs_get_firmware(&card->func->dev, card->model, &fw_table[0],
&helper, &mainfw);
if (ret) {
pr_err("failed to find firmware (%d)\n", ret);
goto out;
Expand Down Expand Up @@ -1242,10 +1231,6 @@ static int if_sdio_probe(struct sdio_func *func,
kfree(packet);
}

if (card->helper_allocated)
kfree(card->helper);
if (card->firmware_allocated)
kfree(card->firmware);
kfree(card);

goto out;
Expand Down Expand Up @@ -1293,12 +1278,6 @@ static void if_sdio_remove(struct sdio_func *func)
kfree(packet);
}

if (card->helper_allocated)
kfree(card->helper);
if (card->firmware_allocated)
kfree(card->firmware);
kfree(card);

lbs_deb_leave(LBS_DEB_SDIO);
}

Expand Down
5 changes: 2 additions & 3 deletions drivers/net/wireless/libertas/if_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,9 +1064,8 @@ static int if_spi_init_card(struct if_spi_card *card)
goto out;
}

err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
card->card_id, &fw_table[0], &helper,
&mainfw);
err = lbs_get_firmware(&card->spi->dev, card->card_id,
&fw_table[0], &helper, &mainfw);
if (err) {
netdev_err(priv->dev, "failed to find firmware (%d)\n",
err);
Expand Down
Loading

0 comments on commit 370803c

Please sign in to comment.