aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-08-07 22:14:33 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-08-16 15:26:43 -0400
commit72f7a6671e8a1433467757e94c883d39eeccd4ba (patch)
treee243ce8fede1d762fadf7aa62a582c6ffaa512ce /drivers/net/wireless/libertas
parent5cddea816eec8b5f6ab76d3fafcbb1533c8c2b9d (diff)
libertas: add two-stage firmware request helper
SDIO, GSPI, and CS all use 2-stage firmware and the loading process and logic should be the same. Allow module parameters to override the automatic firmware choice, otherwise just walk the bus driver's firmware table and pick out the first firmware pair that exists for the given model. Some special care is taken to allow overriding of just the helper or the main firmware, but let the other of the pair be chosen automatically. Signed-off-by: Dan Williams <dcbw@redhat.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/libertas')
-rw-r--r--drivers/net/wireless/libertas/decl.h13
-rw-r--r--drivers/net/wireless/libertas/main.c105
2 files changed, 118 insertions, 0 deletions
diff --git a/drivers/net/wireless/libertas/decl.h b/drivers/net/wireless/libertas/decl.h
index 1d141fefd76..2ae752d1006 100644
--- a/drivers/net/wireless/libertas/decl.h
+++ b/drivers/net/wireless/libertas/decl.h
@@ -8,7 +8,14 @@
8#define _LBS_DECL_H_ 8#define _LBS_DECL_H_
9 9
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/firmware.h>
11 12
13/* Should be terminated by a NULL entry */
14struct lbs_fw_table {
15 int model;
16 const char *helper;
17 const char *fwname;
18};
12 19
13struct lbs_private; 20struct lbs_private;
14struct sk_buff; 21struct sk_buff;
@@ -53,4 +60,10 @@ int lbs_exit_auto_deep_sleep(struct lbs_private *priv);
53u32 lbs_fw_index_to_data_rate(u8 index); 60u32 lbs_fw_index_to_data_rate(u8 index);
54u8 lbs_data_rate_to_fw_index(u32 rate); 61u8 lbs_data_rate_to_fw_index(u32 rate);
55 62
63int lbs_get_firmware(struct device *dev, const char *user_helper,
64 const char *user_mainfw, u32 card_model,
65 const struct lbs_fw_table *fw_table,
66 const struct firmware **helper,
67 const struct firmware **mainfw);
68
56#endif 69#endif
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 24958a86747..47ce5a6ba12 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -1047,6 +1047,111 @@ void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
1047} 1047}
1048EXPORT_SYMBOL_GPL(lbs_notify_command_response); 1048EXPORT_SYMBOL_GPL(lbs_notify_command_response);
1049 1049
1050/**
1051 * @brief Retrieves two-stage firmware
1052 *
1053 * @param dev A pointer to device structure
1054 * @param user_helper User-defined helper firmware file
1055 * @param user_mainfw User-defined main firmware file
1056 * @param card_model Bus-specific card model ID used to filter firmware table
1057 * elements
1058 * @param fw_table Table of firmware file names and device model numbers
1059 * terminated by an entry with a NULL helper name
1060 * @param helper On success, the helper firmware; caller must free
1061 * @param mainfw On success, the main firmware; caller must free
1062 *
1063 * @return 0 on success, non-zero on failure
1064 */
1065int lbs_get_firmware(struct device *dev, const char *user_helper,
1066 const char *user_mainfw, u32 card_model,
1067 const struct lbs_fw_table *fw_table,
1068 const struct firmware **helper,
1069 const struct firmware **mainfw)
1070{
1071 const struct lbs_fw_table *iter;
1072 int ret;
1073
1074 BUG_ON(helper == NULL);
1075 BUG_ON(mainfw == NULL);
1076
1077 /* Try user-specified firmware first */
1078 if (user_helper) {
1079 ret = request_firmware(helper, user_helper, dev);
1080 if (ret) {
1081 lbs_pr_err("couldn't find helper firmware %s",
1082 user_helper);
1083 goto fail;
1084 }
1085 }
1086 if (user_mainfw) {
1087 ret = request_firmware(mainfw, user_mainfw, dev);
1088 if (ret) {
1089 lbs_pr_err("couldn't find main firmware %s",
1090 user_mainfw);
1091 goto fail;
1092 }
1093 }
1094
1095 if (*helper && *mainfw)
1096 return 0;
1097
1098 /* Otherwise search for firmware to use. If neither the helper or
1099 * the main firmware were specified by the user, then we need to
1100 * make sure that found helper & main are from the same entry in
1101 * fw_table.
1102 */
1103 iter = fw_table;
1104 while (iter && iter->helper) {
1105 if (iter->model != card_model)
1106 goto next;
1107
1108 if (*helper == NULL) {
1109 ret = request_firmware(helper, iter->helper, dev);
1110 if (ret)
1111 goto next;
1112
1113 /* If the device has one-stage firmware (ie cf8305) and
1114 * we've got it then we don't need to bother with the
1115 * main firmware.
1116 */
1117 if (iter->fwname == NULL)
1118 return 0;
1119 }
1120
1121 if (*mainfw == NULL) {
1122 ret = request_firmware(mainfw, iter->fwname, dev);
1123 if (ret && !user_helper) {
1124 /* Clear the helper if it wasn't user-specified
1125 * and the main firmware load failed, to ensure
1126 * we don't have mismatched firmware pairs.
1127 */
1128 release_firmware(*helper);
1129 *helper = NULL;
1130 }
1131 }
1132
1133 if (*helper && *mainfw)
1134 return 0;
1135
1136 next:
1137 iter++;
1138 }
1139
1140 fail:
1141 /* Failed */
1142 if (*helper) {
1143 release_firmware(*helper);
1144 *helper = NULL;
1145 }
1146 if (*mainfw) {
1147 release_firmware(*mainfw);
1148 *mainfw = NULL;
1149 }
1150
1151 return -ENOENT;
1152}
1153EXPORT_SYMBOL_GPL(lbs_get_firmware);
1154
1050static int __init lbs_init_module(void) 1155static int __init lbs_init_module(void)
1051{ 1156{
1052 lbs_deb_enter(LBS_DEB_MAIN); 1157 lbs_deb_enter(LBS_DEB_MAIN);