aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/main.c
diff options
context:
space:
mode:
authorHolger Schurig <hs4233@mail.mn-solutions.de>2007-08-02 11:45:12 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:49:48 -0400
commit1df4e8fe91d5bab3fd7ae7f115e43c52010cd4ad (patch)
tree62a9e58760fe8021adf62f745316a265c2d7dca4 /drivers/net/wireless/libertas/main.c
parent8c5127657549d055ac9d709cdea73902a6ef392c (diff)
[PATCH] libertas: remove fw.c
Firmware download is quite different for different hardware. The SDIO and CF cards have two flat files that need to be downloaded, whereas the USB driver needs only one file, but with an internal structure. The code that handles this (USB only) structured file is currently in fw.c. This patch moves this code into if_usb.c. The remaining functions in fw.c have not much to do with firmware, they are various card- and network-stack initialisation functions. I've moved them into main.c. Signed-off-by: Holger Schurig <hs4233@mail.mn-solutions.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/libertas/main.c')
-rw-r--r--drivers/net/wireless/libertas/main.c278
1 files changed, 276 insertions, 2 deletions
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index 03217f5537ad..7e417eacbc77 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -794,6 +794,280 @@ static int libertas_thread(void *data)
794} 794}
795 795
796/** 796/**
797 * @brief This function downloads firmware image, gets
798 * HW spec from firmware and set basic parameters to
799 * firmware.
800 *
801 * @param priv A pointer to wlan_private structure
802 * @return 0 or -1
803 */
804static int wlan_setup_station_hw(wlan_private * priv)
805{
806 int ret = -1;
807 wlan_adapter *adapter = priv->adapter;
808
809 lbs_deb_enter(LBS_DEB_FW);
810
811 ret = priv->hw_prog_firmware(priv);
812
813 if (ret) {
814 lbs_deb_fw("bootloader in invalid state\n");
815 ret = -1;
816 goto done;
817 }
818
819 /*
820 * Read MAC address from HW
821 */
822 memset(adapter->current_addr, 0xff, ETH_ALEN);
823
824 ret = libertas_prepare_and_send_command(priv, CMD_GET_HW_SPEC,
825 0, CMD_OPTION_WAITFORRSP, 0, NULL);
826
827 if (ret) {
828 ret = -1;
829 goto done;
830 }
831
832 libertas_set_mac_packet_filter(priv);
833
834 /* Get the supported Data rates */
835 ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
836 CMD_ACT_GET_TX_RATE,
837 CMD_OPTION_WAITFORRSP, 0, NULL);
838
839 if (ret) {
840 ret = -1;
841 goto done;
842 }
843
844 ret = 0;
845done:
846 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
847 return ret;
848}
849
850static void command_timer_fn(unsigned long data);
851
852/**
853 * This function handles the timeout of command sending.
854 * It will re-send the same command again.
855 */
856static void command_timer_fn(unsigned long data)
857{
858 wlan_private *priv = (wlan_private *)data;
859 wlan_adapter *adapter = priv->adapter;
860 struct cmd_ctrl_node *ptempnode;
861 struct cmd_ds_command *cmd;
862 unsigned long flags;
863
864 ptempnode = adapter->cur_cmd;
865 if (ptempnode == NULL) {
866 lbs_deb_fw("ptempnode empty\n");
867 return;
868 }
869
870 cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr;
871 if (!cmd) {
872 lbs_deb_fw("cmd is NULL\n");
873 return;
874 }
875
876 lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command);
877
878 if (!adapter->fw_ready)
879 return;
880
881 spin_lock_irqsave(&adapter->driver_lock, flags);
882 adapter->cur_cmd = NULL;
883 spin_unlock_irqrestore(&adapter->driver_lock, flags);
884
885 lbs_deb_fw("re-sending same command because of timeout\n");
886 libertas_queue_cmd(adapter, ptempnode, 0);
887
888 wake_up_interruptible(&priv->waitq);
889
890 return;
891}
892
893static int wlan_allocate_adapter(wlan_private * priv)
894{
895 size_t bufsize;
896 wlan_adapter *adapter = priv->adapter;
897
898 /* Allocate buffer to store the BSSID list */
899 bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor);
900 adapter->networks = kzalloc(bufsize, GFP_KERNEL);
901 if (!adapter->networks) {
902 lbs_pr_err("Out of memory allocating beacons\n");
903 libertas_free_adapter(priv);
904 return -ENOMEM;
905 }
906
907 /* Allocate the command buffers */
908 libertas_allocate_cmd_buffer(priv);
909
910 memset(&adapter->libertas_ps_confirm_sleep, 0, sizeof(struct PS_CMD_ConfirmSleep));
911 adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum);
912 adapter->libertas_ps_confirm_sleep.command =
913 cpu_to_le16(CMD_802_11_PS_MODE);
914 adapter->libertas_ps_confirm_sleep.size =
915 cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep));
916 adapter->libertas_ps_confirm_sleep.result = 0;
917 adapter->libertas_ps_confirm_sleep.action =
918 cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED);
919
920 return 0;
921}
922
923static void wlan_init_adapter(wlan_private * priv)
924{
925 wlan_adapter *adapter = priv->adapter;
926 int i;
927
928 adapter->scanprobes = 0;
929
930 adapter->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR;
931 adapter->data_avg_factor = DEFAULT_DATA_AVG_FACTOR;
932
933 /* ATIM params */
934 adapter->atimwindow = 0;
935
936 adapter->connect_status = LIBERTAS_DISCONNECTED;
937 memset(adapter->current_addr, 0xff, ETH_ALEN);
938
939 /* scan type */
940 adapter->scantype = CMD_SCAN_TYPE_ACTIVE;
941
942 /* scan mode */
943 adapter->scanmode = CMD_BSS_TYPE_ANY;
944
945 /* 802.11 specific */
946 adapter->secinfo.wep_enabled = 0;
947 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]);
948 i++)
949 memset(&adapter->wep_keys[i], 0, sizeof(struct enc_key));
950 adapter->wep_tx_keyidx = 0;
951 adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
952 adapter->mode = IW_MODE_INFRA;
953
954 adapter->pending_assoc_req = NULL;
955 adapter->in_progress_assoc_req = NULL;
956
957 /* Initialize scan result lists */
958 INIT_LIST_HEAD(&adapter->network_free_list);
959 INIT_LIST_HEAD(&adapter->network_list);
960 for (i = 0; i < MAX_NETWORK_COUNT; i++) {
961 list_add_tail(&adapter->networks[i].list,
962 &adapter->network_free_list);
963 }
964
965 mutex_init(&adapter->lock);
966
967 adapter->prescan = 1;
968
969 memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams));
970 adapter->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL;
971
972 /* PnP and power profile */
973 adapter->surpriseremoved = 0;
974
975 adapter->currentpacketfilter =
976 CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON;
977
978 adapter->radioon = RADIO_ON;
979 adapter->txantenna = RF_ANTENNA_2;
980 adapter->rxantenna = RF_ANTENNA_AUTO;
981
982 adapter->auto_rate = 1;
983 adapter->cur_rate = 0;
984 adapter->adhoc_grate_enabled = 0;
985
986 adapter->beaconperiod = MRVDRV_BEACON_INTERVAL;
987
988 // set default capabilities
989 adapter->capability = WLAN_CAPABILITY_SHORT_PREAMBLE;
990
991 adapter->psmode = WLAN802_11POWERMODECAM;
992 adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM;
993
994 adapter->listeninterval = MRVDRV_DEFAULT_LISTEN_INTERVAL;
995
996 adapter->psstate = PS_STATE_FULL_POWER;
997 adapter->needtowakeup = 0;
998 adapter->locallisteninterval = 0; /* default value in firmware will be used */
999
1000 adapter->intcounter = 0;
1001
1002 adapter->currenttxskb = NULL;
1003 adapter->pkttxctrl = 0;
1004
1005 memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*));
1006 adapter->tx_queue_idx = 0;
1007 spin_lock_init(&adapter->txqueue_lock);
1008
1009 return;
1010}
1011
1012void libertas_free_adapter(wlan_private * priv)
1013{
1014 wlan_adapter *adapter = priv->adapter;
1015
1016 if (!adapter) {
1017 lbs_deb_fw("why double free adapter?\n");
1018 return;
1019 }
1020
1021 lbs_deb_fw("free command buffer\n");
1022 libertas_free_cmd_buffer(priv);
1023
1024 lbs_deb_fw("free command_timer\n");
1025 del_timer(&adapter->command_timer);
1026
1027 lbs_deb_fw("free scan results table\n");
1028 kfree(adapter->networks);
1029 adapter->networks = NULL;
1030
1031 /* Free the adapter object itself */
1032 lbs_deb_fw("free adapter\n");
1033 kfree(adapter);
1034 priv->adapter = NULL;
1035}
1036
1037static int libertas_init_fw(wlan_private * priv)
1038{
1039 int ret = -1;
1040 wlan_adapter *adapter = priv->adapter;
1041
1042 lbs_deb_enter(LBS_DEB_FW);
1043
1044 /* Allocate adapter structure */
1045 if ((ret = wlan_allocate_adapter(priv)) != 0)
1046 goto done;
1047
1048 /* init adapter structure */
1049 wlan_init_adapter(priv);
1050
1051 /* init timer etc. */
1052 setup_timer(&adapter->command_timer, command_timer_fn,
1053 (unsigned long)priv);
1054
1055 /* download fimrware etc. */
1056 if ((ret = wlan_setup_station_hw(priv)) != 0) {
1057 del_timer_sync(&adapter->command_timer);
1058 goto done;
1059 }
1060
1061 /* init 802.11d */
1062 libertas_init_11d(priv);
1063
1064 ret = 0;
1065done:
1066 lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret);
1067 return ret;
1068}
1069
1070/**
797 * @brief This function adds the card. it will probe the 1071 * @brief This function adds the card. it will probe the
798 * card, allocate the wlan_priv and initialize the device. 1072 * card, allocate the wlan_priv and initialize the device.
799 * 1073 *
@@ -863,7 +1137,7 @@ done:
863} 1137}
864EXPORT_SYMBOL_GPL(libertas_add_card); 1138EXPORT_SYMBOL_GPL(libertas_add_card);
865 1139
866int libertas_activate_card(wlan_private *priv, char *fw_name) 1140int libertas_activate_card(wlan_private *priv)
867{ 1141{
868 struct net_device *dev = priv->dev; 1142 struct net_device *dev = priv->dev;
869 int ret = -1; 1143 int ret = -1;
@@ -894,7 +1168,7 @@ int libertas_activate_card(wlan_private *priv, char *fw_name)
894 } 1168 }
895 1169
896 /* init FW and HW */ 1170 /* init FW and HW */
897 if (fw_name && libertas_init_fw(priv, fw_name)) { 1171 if (libertas_init_fw(priv)) {
898 lbs_pr_err("firmware init failed\n"); 1172 lbs_pr_err("firmware init failed\n");
899 goto err_registerdev; 1173 goto err_registerdev;
900 } 1174 }