Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the major functions in WLAN |
| 3 | * driver. It includes init, exit, open, close and main |
| 4 | * thread etc.. |
| 5 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 6 | |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 7 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 8 | |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 9 | #include <linux/moduleparam.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | #include <linux/delay.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 11 | #include <linux/etherdevice.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 12 | #include <linux/hardirq.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 13 | #include <linux/netdevice.h> |
| 14 | #include <linux/if_arp.h> |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 15 | #include <linux/kthread.h> |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 16 | #include <linux/kfifo.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 18 | #include <net/cfg80211.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 19 | |
| 20 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 21 | #include "decl.h" |
| 22 | #include "dev.h" |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 23 | #include "cfg.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 24 | #include "debugfs.h" |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 25 | #include "cmd.h" |
Daniel Drake | 49fee69 | 2011-07-21 20:43:17 +0100 | [diff] [blame] | 26 | #include "mesh.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 27 | |
Dan Williams | 7856a54 | 2007-08-03 09:43:03 -0400 | [diff] [blame] | 28 | #define DRIVER_RELEASE_VERSION "323.p0" |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 29 | const char lbs_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION |
Dan Williams | 3ce4023 | 2007-05-10 23:03:07 -0400 | [diff] [blame] | 30 | #ifdef DEBUG |
| 31 | "-dbg" |
| 32 | #endif |
| 33 | ""; |
| 34 | |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 35 | |
| 36 | /* Module parameters */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 37 | unsigned int lbs_debug; |
| 38 | EXPORT_SYMBOL_GPL(lbs_debug); |
| 39 | module_param_named(libertas_debug, lbs_debug, int, 0644); |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 40 | |
Sascha Silbe | 6bdbdbf | 2011-05-11 14:52:34 +0200 | [diff] [blame] | 41 | unsigned int lbs_disablemesh; |
| 42 | EXPORT_SYMBOL_GPL(lbs_disablemesh); |
| 43 | module_param_named(libertas_disablemesh, lbs_disablemesh, int, 0644); |
| 44 | |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 45 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 46 | /* |
| 47 | * This global structure is used to send the confirm_sleep command as |
| 48 | * fast as possible down to the firmware. |
| 49 | */ |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 50 | struct cmd_confirm_sleep confirm_sleep; |
| 51 | |
| 52 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 53 | /* |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 54 | * the table to keep region code |
| 55 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 56 | u16 lbs_region_code_to_index[MRVDRV_MAX_REGION_CODE] = |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 57 | { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; |
| 58 | |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 59 | /* |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 60 | * FW rate table. FW refers to rates by their index in this table, not by the |
| 61 | * rate value itself. Values of 0x00 are |
| 62 | * reserved positions. |
| 63 | */ |
| 64 | static u8 fw_data_rates[MAX_RATES] = |
| 65 | { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12, |
| 66 | 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00 |
| 67 | }; |
| 68 | |
| 69 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 70 | * lbs_fw_index_to_data_rate - use index to get the data rate |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 71 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 72 | * @idx: The index of data rate |
| 73 | * returns: data rate or 0 |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 74 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 75 | u32 lbs_fw_index_to_data_rate(u8 idx) |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 76 | { |
| 77 | if (idx >= sizeof(fw_data_rates)) |
| 78 | idx = 0; |
| 79 | return fw_data_rates[idx]; |
| 80 | } |
| 81 | |
| 82 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 83 | * lbs_data_rate_to_fw_index - use rate to get the index |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 84 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 85 | * @rate: data rate |
| 86 | * returns: index or 0 |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 87 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 88 | u8 lbs_data_rate_to_fw_index(u32 rate) |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 89 | { |
| 90 | u8 i; |
| 91 | |
| 92 | if (!rate) |
| 93 | return 0; |
| 94 | |
| 95 | for (i = 0; i < sizeof(fw_data_rates); i++) { |
| 96 | if (rate == fw_data_rates[i]) |
| 97 | return i; |
| 98 | } |
| 99 | return 0; |
| 100 | } |
| 101 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 102 | int lbs_start_iface(struct lbs_private *priv) |
| 103 | { |
| 104 | struct cmd_ds_802_11_mac_address cmd; |
| 105 | int ret; |
| 106 | |
| 107 | if (priv->power_restore) { |
| 108 | ret = priv->power_restore(priv); |
| 109 | if (ret) |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 114 | cmd.action = cpu_to_le16(CMD_ACT_SET); |
| 115 | memcpy(cmd.macadd, priv->current_addr, ETH_ALEN); |
| 116 | |
| 117 | ret = lbs_cmd_with_response(priv, CMD_802_11_MAC_ADDRESS, &cmd); |
| 118 | if (ret) { |
| 119 | lbs_deb_net("set MAC address failed\n"); |
| 120 | goto err; |
| 121 | } |
| 122 | |
| 123 | lbs_update_channel(priv); |
| 124 | |
| 125 | priv->iface_running = true; |
| 126 | return 0; |
| 127 | |
| 128 | err: |
| 129 | if (priv->power_save) |
| 130 | priv->power_save(priv); |
| 131 | return ret; |
| 132 | } |
Anna Neal | 6fb5325 | 2008-12-09 13:23:45 -0800 | [diff] [blame] | 133 | |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 134 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 135 | * lbs_dev_open - open the ethX interface |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 136 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 137 | * @dev: A pointer to &net_device structure |
| 138 | * returns: 0 or -EBUSY if monitor mode active |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 139 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 140 | static int lbs_dev_open(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 141 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 142 | struct lbs_private *priv = dev->ml_priv; |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 143 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 144 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 145 | lbs_deb_enter(LBS_DEB_NET); |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 146 | if (!priv->iface_running) { |
| 147 | ret = lbs_start_iface(priv); |
| 148 | if (ret) |
| 149 | goto out; |
| 150 | } |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 151 | |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 152 | spin_lock_irq(&priv->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 153 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 154 | netif_carrier_off(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 155 | |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 156 | if (!priv->tx_pending_len) |
| 157 | netif_wake_queue(dev); |
Brajesh Dave | 01d77d8 | 2007-11-20 17:44:14 -0500 | [diff] [blame] | 158 | |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 159 | spin_unlock_irq(&priv->driver_lock); |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 160 | |
| 161 | out: |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 162 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 163 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 164 | } |
| 165 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 166 | static bool lbs_command_queue_empty(struct lbs_private *priv) |
| 167 | { |
| 168 | unsigned long flags; |
| 169 | bool ret; |
| 170 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 171 | ret = priv->cur_cmd == NULL && list_empty(&priv->cmdpendingq); |
| 172 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | int lbs_stop_iface(struct lbs_private *priv) |
| 177 | { |
| 178 | unsigned long flags; |
| 179 | int ret = 0; |
| 180 | |
| 181 | lbs_deb_enter(LBS_DEB_MAIN); |
| 182 | |
| 183 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 184 | priv->iface_running = false; |
| 185 | kfree_skb(priv->currenttxskb); |
| 186 | priv->currenttxskb = NULL; |
| 187 | priv->tx_pending_len = 0; |
| 188 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 189 | |
| 190 | cancel_work_sync(&priv->mcast_work); |
| 191 | |
| 192 | /* Disable command processing, and wait for all commands to complete */ |
| 193 | lbs_deb_main("waiting for commands to complete\n"); |
| 194 | wait_event(priv->waitq, lbs_command_queue_empty(priv)); |
| 195 | lbs_deb_main("all commands completed\n"); |
| 196 | |
| 197 | if (priv->power_save) |
| 198 | ret = priv->power_save(priv); |
| 199 | |
| 200 | lbs_deb_leave(LBS_DEB_MAIN); |
| 201 | return ret; |
| 202 | } |
| 203 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 204 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 205 | * lbs_eth_stop - close the ethX interface |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 206 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 207 | * @dev: A pointer to &net_device structure |
| 208 | * returns: 0 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 209 | */ |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 210 | static int lbs_eth_stop(struct net_device *dev) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 211 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 212 | struct lbs_private *priv = dev->ml_priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 213 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 214 | lbs_deb_enter(LBS_DEB_NET); |
| 215 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 216 | if (priv->connect_status == LBS_CONNECTED) |
| 217 | lbs_disconnect(priv, WLAN_REASON_DEAUTH_LEAVING); |
| 218 | |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 219 | spin_lock_irq(&priv->driver_lock); |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 220 | netif_stop_queue(dev); |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 221 | spin_unlock_irq(&priv->driver_lock); |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 222 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 223 | lbs_update_mcast(priv); |
Daniel Drake | 2e30168 | 2010-11-04 21:21:52 +0000 | [diff] [blame] | 224 | cancel_delayed_work_sync(&priv->scan_work); |
| 225 | if (priv->scan_req) { |
| 226 | cfg80211_scan_done(priv->scan_req, false); |
| 227 | priv->scan_req = NULL; |
| 228 | } |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 229 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 230 | netif_carrier_off(priv->dev); |
| 231 | |
| 232 | if (!lbs_iface_active(priv)) |
| 233 | lbs_stop_iface(priv); |
| 234 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 235 | lbs_deb_leave(LBS_DEB_NET); |
David Woodhouse | 8552855f | 2007-12-10 16:38:18 -0500 | [diff] [blame] | 236 | return 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 237 | } |
| 238 | |
David Woodhouse | e775ed7 | 2007-12-06 14:36:11 +0000 | [diff] [blame] | 239 | void lbs_host_to_card_done(struct lbs_private *priv) |
| 240 | { |
David Woodhouse | a63b22b | 2007-12-08 20:56:44 +0000 | [diff] [blame] | 241 | unsigned long flags; |
| 242 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 243 | lbs_deb_enter(LBS_DEB_THREAD); |
| 244 | |
David Woodhouse | a63b22b | 2007-12-08 20:56:44 +0000 | [diff] [blame] | 245 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | e775ed7 | 2007-12-06 14:36:11 +0000 | [diff] [blame] | 246 | |
| 247 | priv->dnld_sent = DNLD_RES_RECEIVED; |
| 248 | |
| 249 | /* Wake main thread if commands are pending */ |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 250 | if (!priv->cur_cmd || priv->tx_pending_len > 0) { |
| 251 | if (!priv->wakeup_dev_required) |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 252 | wake_up(&priv->waitq); |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 253 | } |
David Woodhouse | e775ed7 | 2007-12-06 14:36:11 +0000 | [diff] [blame] | 254 | |
David Woodhouse | a63b22b | 2007-12-08 20:56:44 +0000 | [diff] [blame] | 255 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 256 | lbs_deb_leave(LBS_DEB_THREAD); |
David Woodhouse | e775ed7 | 2007-12-06 14:36:11 +0000 | [diff] [blame] | 257 | } |
| 258 | EXPORT_SYMBOL_GPL(lbs_host_to_card_done); |
| 259 | |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 260 | int lbs_set_mac_address(struct net_device *dev, void *addr) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 261 | { |
| 262 | int ret = 0; |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 263 | struct lbs_private *priv = dev->ml_priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 264 | struct sockaddr *phwaddr = addr; |
| 265 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 266 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 267 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 268 | /* |
| 269 | * Can only set MAC address when all interfaces are down, to be written |
| 270 | * to the hardware when one of them is brought up. |
| 271 | */ |
| 272 | if (lbs_iface_active(priv)) |
| 273 | return -EBUSY; |
| 274 | |
Luis Carlos Cobo Rus | 0a0d08a | 2007-05-25 23:05:27 -0400 | [diff] [blame] | 275 | /* In case it was called from the mesh device */ |
Holger Schurig | 2af9f03 | 2008-03-26 09:58:32 +0100 | [diff] [blame] | 276 | dev = priv->dev; |
Luis Carlos Cobo Rus | 0a0d08a | 2007-05-25 23:05:27 -0400 | [diff] [blame] | 277 | |
Holger Schurig | 2af9f03 | 2008-03-26 09:58:32 +0100 | [diff] [blame] | 278 | memcpy(priv->current_addr, phwaddr->sa_data, ETH_ALEN); |
| 279 | memcpy(dev->dev_addr, phwaddr->sa_data, ETH_ALEN); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 280 | if (priv->mesh_dev) |
Holger Schurig | 2af9f03 | 2008-03-26 09:58:32 +0100 | [diff] [blame] | 281 | memcpy(priv->mesh_dev->dev_addr, phwaddr->sa_data, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 282 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 283 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 284 | return ret; |
| 285 | } |
| 286 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 287 | |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 288 | static inline int mac_in_list(unsigned char *list, int list_len, |
| 289 | unsigned char *mac) |
| 290 | { |
| 291 | while (list_len) { |
| 292 | if (!memcmp(list, mac, ETH_ALEN)) |
| 293 | return 1; |
| 294 | list += ETH_ALEN; |
| 295 | list_len--; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 296 | } |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | static int lbs_add_mcast_addrs(struct cmd_ds_mac_multicast_adr *cmd, |
| 302 | struct net_device *dev, int nr_addrs) |
| 303 | { |
| 304 | int i = nr_addrs; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 305 | struct netdev_hw_addr *ha; |
Jiri Pirko | 655ffee | 2010-02-27 07:35:45 +0000 | [diff] [blame] | 306 | int cnt; |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 307 | |
| 308 | if ((dev->flags & (IFF_UP|IFF_MULTICAST)) != (IFF_UP|IFF_MULTICAST)) |
| 309 | return nr_addrs; |
| 310 | |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 311 | netif_addr_lock_bh(dev); |
Jiri Pirko | 655ffee | 2010-02-27 07:35:45 +0000 | [diff] [blame] | 312 | cnt = netdev_mc_count(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 313 | netdev_for_each_mc_addr(ha, dev) { |
| 314 | if (mac_in_list(cmd->maclist, nr_addrs, ha->addr)) { |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 315 | lbs_deb_net("mcast address %s:%pM skipped\n", dev->name, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 316 | ha->addr); |
Jiri Pirko | 655ffee | 2010-02-27 07:35:45 +0000 | [diff] [blame] | 317 | cnt--; |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 318 | continue; |
| 319 | } |
| 320 | |
| 321 | if (i == MRVDRV_MAX_MULTICAST_LIST_SIZE) |
| 322 | break; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 323 | memcpy(&cmd->maclist[6*i], ha->addr, ETH_ALEN); |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 324 | lbs_deb_net("mcast address %s:%pM added to filter\n", dev->name, |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 325 | ha->addr); |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 326 | i++; |
Jiri Pirko | 655ffee | 2010-02-27 07:35:45 +0000 | [diff] [blame] | 327 | cnt--; |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 328 | } |
David S. Miller | b9e4085 | 2008-07-15 00:15:08 -0700 | [diff] [blame] | 329 | netif_addr_unlock_bh(dev); |
Jiri Pirko | 655ffee | 2010-02-27 07:35:45 +0000 | [diff] [blame] | 330 | if (cnt) |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 331 | return -EOVERFLOW; |
| 332 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 333 | return i; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 334 | } |
| 335 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 336 | void lbs_update_mcast(struct lbs_private *priv) |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 337 | { |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 338 | struct cmd_ds_mac_multicast_adr mcast_cmd; |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 339 | int dev_flags = 0; |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 340 | int nr_addrs; |
| 341 | int old_mac_control = priv->mac_control; |
| 342 | |
| 343 | lbs_deb_enter(LBS_DEB_NET); |
| 344 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 345 | if (netif_running(priv->dev)) |
| 346 | dev_flags |= priv->dev->flags; |
| 347 | if (priv->mesh_dev && netif_running(priv->mesh_dev)) |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 348 | dev_flags |= priv->mesh_dev->flags; |
| 349 | |
| 350 | if (dev_flags & IFF_PROMISC) { |
| 351 | priv->mac_control |= CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
| 352 | priv->mac_control &= ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE | |
| 353 | CMD_ACT_MAC_MULTICAST_ENABLE); |
| 354 | goto out_set_mac_control; |
| 355 | } else if (dev_flags & IFF_ALLMULTI) { |
| 356 | do_allmulti: |
| 357 | priv->mac_control |= CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
| 358 | priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE | |
| 359 | CMD_ACT_MAC_MULTICAST_ENABLE); |
| 360 | goto out_set_mac_control; |
| 361 | } |
| 362 | |
| 363 | /* Once for priv->dev, again for priv->mesh_dev if it exists */ |
| 364 | nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->dev, 0); |
| 365 | if (nr_addrs >= 0 && priv->mesh_dev) |
| 366 | nr_addrs = lbs_add_mcast_addrs(&mcast_cmd, priv->mesh_dev, nr_addrs); |
| 367 | if (nr_addrs < 0) |
| 368 | goto do_allmulti; |
| 369 | |
| 370 | if (nr_addrs) { |
| 371 | int size = offsetof(struct cmd_ds_mac_multicast_adr, |
| 372 | maclist[6*nr_addrs]); |
| 373 | |
| 374 | mcast_cmd.action = cpu_to_le16(CMD_ACT_SET); |
| 375 | mcast_cmd.hdr.size = cpu_to_le16(size); |
| 376 | mcast_cmd.nr_of_adrs = cpu_to_le16(nr_addrs); |
| 377 | |
| 378 | lbs_cmd_async(priv, CMD_MAC_MULTICAST_ADR, &mcast_cmd.hdr, size); |
| 379 | |
| 380 | priv->mac_control |= CMD_ACT_MAC_MULTICAST_ENABLE; |
| 381 | } else |
| 382 | priv->mac_control &= ~CMD_ACT_MAC_MULTICAST_ENABLE; |
| 383 | |
| 384 | priv->mac_control &= ~(CMD_ACT_MAC_PROMISCUOUS_ENABLE | |
| 385 | CMD_ACT_MAC_ALL_MULTICAST_ENABLE); |
| 386 | out_set_mac_control: |
| 387 | if (priv->mac_control != old_mac_control) |
| 388 | lbs_set_mac_control(priv); |
| 389 | |
| 390 | lbs_deb_leave(LBS_DEB_NET); |
| 391 | } |
| 392 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 393 | static void lbs_set_mcast_worker(struct work_struct *work) |
| 394 | { |
| 395 | struct lbs_private *priv = container_of(work, struct lbs_private, mcast_work); |
| 396 | lbs_update_mcast(priv); |
| 397 | } |
| 398 | |
Holger Schurig | e0e42da | 2009-11-25 13:10:15 +0100 | [diff] [blame] | 399 | void lbs_set_multicast_list(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 400 | { |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 401 | struct lbs_private *priv = dev->ml_priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 402 | |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 403 | schedule_work(&priv->mcast_work); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 407 | * lbs_thread - handles the major jobs in the LBS driver. |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 408 | * It handles all events generated by firmware, RX data received |
| 409 | * from firmware and TX data sent from kernel. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 410 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 411 | * @data: A pointer to &lbs_thread structure |
| 412 | * returns: 0 |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 413 | */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 414 | static int lbs_thread(void *data) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 415 | { |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 416 | struct net_device *dev = data; |
Kiran Divekar | ab65f64 | 2009-02-19 19:32:39 -0500 | [diff] [blame] | 417 | struct lbs_private *priv = dev->ml_priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 418 | wait_queue_t wait; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 419 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 420 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 421 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 422 | init_waitqueue_entry(&wait, current); |
| 423 | |
| 424 | for (;;) { |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 425 | int shouldsleep; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 426 | u8 resp_idx; |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 427 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 428 | lbs_deb_thread("1: currenttxskb %p, dnld_sent %d\n", |
| 429 | priv->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 430 | |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 431 | add_wait_queue(&priv->waitq, &wait); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 432 | set_current_state(TASK_INTERRUPTIBLE); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 433 | spin_lock_irq(&priv->driver_lock); |
David Woodhouse | 59f3e4b | 2007-12-08 17:42:59 +0000 | [diff] [blame] | 434 | |
David Woodhouse | d9f8870 | 2007-12-13 21:48:00 -0500 | [diff] [blame] | 435 | if (kthread_should_stop()) |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 436 | shouldsleep = 0; /* Bye */ |
David Woodhouse | d9f8870 | 2007-12-13 21:48:00 -0500 | [diff] [blame] | 437 | else if (priv->surpriseremoved) |
| 438 | shouldsleep = 1; /* We need to wait until we're _told_ to die */ |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 439 | else if (priv->psstate == PS_STATE_SLEEP) |
| 440 | shouldsleep = 1; /* Sleep mode. Nothing we can do till it wakes */ |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 441 | else if (priv->cmd_timed_out) |
| 442 | shouldsleep = 0; /* Command timed out. Recover */ |
David Woodhouse | b15152a | 2007-12-11 11:55:37 -0500 | [diff] [blame] | 443 | else if (!priv->fw_ready) |
| 444 | shouldsleep = 1; /* Firmware not ready. We're waiting for it */ |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 445 | else if (priv->dnld_sent) |
| 446 | shouldsleep = 1; /* Something is en route to the device already */ |
David Woodhouse | 2eb188a | 2007-12-09 23:54:27 -0500 | [diff] [blame] | 447 | else if (priv->tx_pending_len > 0) |
| 448 | shouldsleep = 0; /* We've a packet to send */ |
Holger Schurig | ef707b8 | 2008-05-23 16:04:13 +0200 | [diff] [blame] | 449 | else if (priv->resp_len[priv->resp_idx]) |
| 450 | shouldsleep = 0; /* We have a command response */ |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 451 | else if (priv->cur_cmd) |
| 452 | shouldsleep = 1; /* Can't send a command; one already running */ |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 453 | else if (!list_empty(&priv->cmdpendingq) && |
| 454 | !(priv->wakeup_dev_required)) |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 455 | shouldsleep = 0; /* We have a command to send */ |
Stefani Seibold | e64c026 | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 456 | else if (kfifo_len(&priv->event_fifo)) |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 457 | shouldsleep = 0; /* We have an event to process */ |
David Woodhouse | b8d40bc | 2007-12-09 23:44:43 -0500 | [diff] [blame] | 458 | else |
| 459 | shouldsleep = 1; /* No command */ |
| 460 | |
| 461 | if (shouldsleep) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 462 | lbs_deb_thread("sleeping, connect_status %d, " |
Holger Schurig | 5f505d9 | 2008-04-30 10:50:07 +0200 | [diff] [blame] | 463 | "psmode %d, psstate %d\n", |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 464 | priv->connect_status, |
| 465 | priv->psmode, priv->psstate); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 466 | spin_unlock_irq(&priv->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 467 | schedule(); |
| 468 | } else |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 469 | spin_unlock_irq(&priv->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 470 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 471 | lbs_deb_thread("2: currenttxskb %p, dnld_send %d\n", |
| 472 | priv->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 473 | |
| 474 | set_current_state(TASK_RUNNING); |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 475 | remove_wait_queue(&priv->waitq, &wait); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 476 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 477 | lbs_deb_thread("3: currenttxskb %p, dnld_sent %d\n", |
| 478 | priv->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 479 | |
David Woodhouse | d9f8870 | 2007-12-13 21:48:00 -0500 | [diff] [blame] | 480 | if (kthread_should_stop()) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 481 | lbs_deb_thread("break from main thread\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | break; |
| 483 | } |
| 484 | |
David Woodhouse | d9f8870 | 2007-12-13 21:48:00 -0500 | [diff] [blame] | 485 | if (priv->surpriseremoved) { |
| 486 | lbs_deb_thread("adapter removed; waiting to die...\n"); |
| 487 | continue; |
| 488 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 489 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 490 | lbs_deb_thread("4: currenttxskb %p, dnld_sent %d\n", |
| 491 | priv->currenttxskb, priv->dnld_sent); |
| 492 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 493 | /* Process any pending command response */ |
Holger Schurig | a01f545 | 2008-06-04 11:10:40 +0200 | [diff] [blame] | 494 | spin_lock_irq(&priv->driver_lock); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 495 | resp_idx = priv->resp_idx; |
| 496 | if (priv->resp_len[resp_idx]) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 497 | spin_unlock_irq(&priv->driver_lock); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 498 | lbs_process_command_response(priv, |
| 499 | priv->resp_buf[resp_idx], |
| 500 | priv->resp_len[resp_idx]); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 501 | spin_lock_irq(&priv->driver_lock); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 502 | priv->resp_len[resp_idx] = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 503 | } |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 504 | spin_unlock_irq(&priv->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 505 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 506 | /* Process hardware events, e.g. card removed, link lost */ |
| 507 | spin_lock_irq(&priv->driver_lock); |
Stefani Seibold | e64c026 | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 508 | while (kfifo_len(&priv->event_fifo)) { |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 509 | u32 event; |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 510 | |
Stefani Seibold | 9842c38 | 2009-12-21 14:37:29 -0800 | [diff] [blame] | 511 | if (kfifo_out(&priv->event_fifo, |
| 512 | (unsigned char *) &event, sizeof(event)) != |
| 513 | sizeof(event)) |
| 514 | break; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 515 | spin_unlock_irq(&priv->driver_lock); |
| 516 | lbs_process_event(priv, event); |
| 517 | spin_lock_irq(&priv->driver_lock); |
| 518 | } |
| 519 | spin_unlock_irq(&priv->driver_lock); |
| 520 | |
| 521 | if (priv->wakeup_dev_required) { |
| 522 | lbs_deb_thread("Waking up device...\n"); |
| 523 | /* Wake up device */ |
| 524 | if (priv->exit_deep_sleep(priv)) |
| 525 | lbs_deb_thread("Wakeup device failed\n"); |
| 526 | continue; |
| 527 | } |
| 528 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 529 | /* command timeout stuff */ |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 530 | if (priv->cmd_timed_out && priv->cur_cmd) { |
| 531 | struct cmd_ctrl_node *cmdnode = priv->cur_cmd; |
| 532 | |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 533 | netdev_info(dev, "Timeout submitting command 0x%04x\n", |
| 534 | le16_to_cpu(cmdnode->cmdbuf->command)); |
Holger Schurig | 40e6fa8 | 2010-02-04 14:37:45 +0100 | [diff] [blame] | 535 | lbs_complete_command(priv, cmdnode, -ETIMEDOUT); |
| 536 | if (priv->reset_card) |
| 537 | priv->reset_card(priv); |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 538 | } |
| 539 | priv->cmd_timed_out = 0; |
| 540 | |
David Woodhouse | b15152a | 2007-12-11 11:55:37 -0500 | [diff] [blame] | 541 | if (!priv->fw_ready) |
| 542 | continue; |
| 543 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 544 | /* Check if we need to confirm Sleep Request received previously */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 545 | if (priv->psstate == PS_STATE_PRE_SLEEP && |
| 546 | !priv->dnld_sent && !priv->cur_cmd) { |
| 547 | if (priv->connect_status == LBS_CONNECTED) { |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 548 | lbs_deb_thread("pre-sleep, currenttxskb %p, " |
| 549 | "dnld_sent %d, cur_cmd %p\n", |
| 550 | priv->currenttxskb, priv->dnld_sent, |
| 551 | priv->cur_cmd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 552 | |
Holger Schurig | d4ff0ef | 2008-03-19 14:25:18 +0100 | [diff] [blame] | 553 | lbs_ps_confirm_sleep(priv); |
David Woodhouse | 59f3e4b | 2007-12-08 17:42:59 +0000 | [diff] [blame] | 554 | } else { |
| 555 | /* workaround for firmware sending |
| 556 | * deauth/linkloss event immediately |
| 557 | * after sleep request; remove this |
| 558 | * after firmware fixes it |
| 559 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 560 | priv->psstate = PS_STATE_AWAKE; |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 561 | netdev_alert(dev, |
| 562 | "ignore PS_SleepConfirm in non-connected state\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 563 | } |
| 564 | } |
| 565 | |
| 566 | /* The PS state is changed during processing of Sleep Request |
| 567 | * event above |
| 568 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 569 | if ((priv->psstate == PS_STATE_SLEEP) || |
| 570 | (priv->psstate == PS_STATE_PRE_SLEEP)) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 571 | continue; |
| 572 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 573 | if (priv->is_deep_sleep) |
| 574 | continue; |
| 575 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 576 | /* Execute the next command */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 577 | if (!priv->dnld_sent && !priv->cur_cmd) |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 578 | lbs_execute_next_command(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 579 | |
David Woodhouse | 2eb188a | 2007-12-09 23:54:27 -0500 | [diff] [blame] | 580 | spin_lock_irq(&priv->driver_lock); |
| 581 | if (!priv->dnld_sent && priv->tx_pending_len > 0) { |
| 582 | int ret = priv->hw_host_to_card(priv, MVMS_DAT, |
| 583 | priv->tx_pending_buf, |
| 584 | priv->tx_pending_len); |
| 585 | if (ret) { |
| 586 | lbs_deb_tx("host_to_card failed %d\n", ret); |
| 587 | priv->dnld_sent = DNLD_RES_RECEIVED; |
| 588 | } |
| 589 | priv->tx_pending_len = 0; |
| 590 | if (!priv->currenttxskb) { |
| 591 | /* We can wake the queues immediately if we aren't |
| 592 | waiting for TX feedback */ |
| 593 | if (priv->connect_status == LBS_CONNECTED) |
| 594 | netif_wake_queue(priv->dev); |
| 595 | if (priv->mesh_dev && |
Daniel Drake | d931998 | 2011-07-20 17:53:56 +0100 | [diff] [blame] | 596 | netif_running(priv->mesh_dev)) |
David Woodhouse | 2eb188a | 2007-12-09 23:54:27 -0500 | [diff] [blame] | 597 | netif_wake_queue(priv->mesh_dev); |
| 598 | } |
| 599 | } |
| 600 | spin_unlock_irq(&priv->driver_lock); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 601 | } |
| 602 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 603 | del_timer(&priv->command_timer); |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 604 | del_timer(&priv->auto_deepsleep_timer); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 605 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 606 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 607 | return 0; |
| 608 | } |
| 609 | |
Vasily Khoruzhick | 75abde4 | 2011-01-21 22:44:49 +0200 | [diff] [blame] | 610 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 611 | * lbs_setup_firmware - gets the HW spec from the firmware and sets |
| 612 | * some basic parameters |
Vasily Khoruzhick | 75abde4 | 2011-01-21 22:44:49 +0200 | [diff] [blame] | 613 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 614 | * @priv: A pointer to &struct lbs_private structure |
| 615 | * returns: 0 or -1 |
Vasily Khoruzhick | 75abde4 | 2011-01-21 22:44:49 +0200 | [diff] [blame] | 616 | */ |
| 617 | static int lbs_setup_firmware(struct lbs_private *priv) |
| 618 | { |
| 619 | int ret = -1; |
| 620 | s16 curlevel = 0, minlevel = 0, maxlevel = 0; |
| 621 | |
| 622 | lbs_deb_enter(LBS_DEB_FW); |
| 623 | |
| 624 | /* Read MAC address from firmware */ |
| 625 | memset(priv->current_addr, 0xff, ETH_ALEN); |
| 626 | ret = lbs_update_hw_spec(priv); |
| 627 | if (ret) |
| 628 | goto done; |
| 629 | |
| 630 | /* Read power levels if available */ |
| 631 | ret = lbs_get_tx_power(priv, &curlevel, &minlevel, &maxlevel); |
| 632 | if (ret == 0) { |
| 633 | priv->txpower_cur = curlevel; |
| 634 | priv->txpower_min = minlevel; |
| 635 | priv->txpower_max = maxlevel; |
| 636 | } |
| 637 | |
| 638 | /* Send cmd to FW to enable 11D function */ |
| 639 | ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_11D_ENABLE, 1); |
| 640 | |
| 641 | lbs_set_mac_control(priv); |
| 642 | done: |
| 643 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); |
| 644 | return ret; |
| 645 | } |
| 646 | |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 647 | int lbs_suspend(struct lbs_private *priv) |
| 648 | { |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 649 | int ret; |
| 650 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 651 | lbs_deb_enter(LBS_DEB_FW); |
| 652 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 653 | if (priv->is_deep_sleep) { |
| 654 | ret = lbs_set_deep_sleep(priv, 0); |
| 655 | if (ret) { |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 656 | netdev_err(priv->dev, |
| 657 | "deep sleep cancellation failed: %d\n", ret); |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 658 | return ret; |
| 659 | } |
| 660 | priv->deep_sleep_required = 1; |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 661 | } |
| 662 | |
Amitkumar Karwar | 1311843 | 2010-07-08 06:43:48 +0530 | [diff] [blame] | 663 | ret = lbs_set_host_sleep(priv, 1); |
David Woodhouse | 7e22627 | 2007-12-14 22:53:41 -0500 | [diff] [blame] | 664 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 665 | netif_device_detach(priv->dev); |
| 666 | if (priv->mesh_dev) |
| 667 | netif_device_detach(priv->mesh_dev); |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 668 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 669 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 670 | return ret; |
| 671 | } |
| 672 | EXPORT_SYMBOL_GPL(lbs_suspend); |
| 673 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 674 | int lbs_resume(struct lbs_private *priv) |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 675 | { |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 676 | int ret; |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 677 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 678 | lbs_deb_enter(LBS_DEB_FW); |
| 679 | |
Amitkumar Karwar | 1311843 | 2010-07-08 06:43:48 +0530 | [diff] [blame] | 680 | ret = lbs_set_host_sleep(priv, 0); |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 681 | |
| 682 | netif_device_attach(priv->dev); |
| 683 | if (priv->mesh_dev) |
| 684 | netif_device_attach(priv->mesh_dev); |
| 685 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 686 | if (priv->deep_sleep_required) { |
| 687 | priv->deep_sleep_required = 0; |
| 688 | ret = lbs_set_deep_sleep(priv, 1); |
| 689 | if (ret) |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 690 | netdev_err(priv->dev, |
| 691 | "deep sleep activation failed: %d\n", ret); |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 692 | } |
| 693 | |
Vasily Khoruzhick | 75abde4 | 2011-01-21 22:44:49 +0200 | [diff] [blame] | 694 | if (priv->setup_fw_on_resume) |
| 695 | ret = lbs_setup_firmware(priv); |
| 696 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 697 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); |
| 698 | return ret; |
David Woodhouse | ab25eca | 2007-12-12 17:38:56 -0500 | [diff] [blame] | 699 | } |
| 700 | EXPORT_SYMBOL_GPL(lbs_resume); |
| 701 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 702 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 703 | * lbs_cmd_timeout_handler - handles the timeout of command sending. |
| 704 | * It will re-send the same command again. |
| 705 | * |
| 706 | * @data: &struct lbs_private pointer |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 707 | */ |
Holger Schurig | 40e6fa8 | 2010-02-04 14:37:45 +0100 | [diff] [blame] | 708 | static void lbs_cmd_timeout_handler(unsigned long data) |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 709 | { |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 710 | struct lbs_private *priv = (struct lbs_private *)data; |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 711 | unsigned long flags; |
| 712 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 713 | lbs_deb_enter(LBS_DEB_CMD); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 714 | spin_lock_irqsave(&priv->driver_lock, flags); |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 715 | |
Holger Schurig | 57962f0 | 2008-05-14 16:30:28 +0200 | [diff] [blame] | 716 | if (!priv->cur_cmd) |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 717 | goto out; |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 718 | |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 719 | netdev_info(priv->dev, "command 0x%04x timed out\n", |
| 720 | le16_to_cpu(priv->cur_cmd->cmdbuf->command)); |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 721 | |
| 722 | priv->cmd_timed_out = 1; |
Daniel Drake | df90d84 | 2011-07-09 15:41:25 +0100 | [diff] [blame] | 723 | |
| 724 | /* |
| 725 | * If the device didn't even acknowledge the command, reset the state |
| 726 | * so that we don't block all future commands due to this one timeout. |
| 727 | */ |
| 728 | if (priv->dnld_sent == DNLD_CMD_SENT) |
| 729 | priv->dnld_sent = DNLD_RES_RECEIVED; |
| 730 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 731 | wake_up(&priv->waitq); |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 732 | out: |
David Woodhouse | 2a34509 | 2007-12-15 19:33:43 -0500 | [diff] [blame] | 733 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 734 | lbs_deb_leave(LBS_DEB_CMD); |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 735 | } |
| 736 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 737 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 738 | * auto_deepsleep_timer_fn - put the device back to deep sleep mode when |
| 739 | * timer expires and no activity (command, event, data etc.) is detected. |
| 740 | * @data: &struct lbs_private pointer |
| 741 | * returns: N/A |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 742 | */ |
| 743 | static void auto_deepsleep_timer_fn(unsigned long data) |
| 744 | { |
| 745 | struct lbs_private *priv = (struct lbs_private *)data; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 746 | |
| 747 | lbs_deb_enter(LBS_DEB_CMD); |
| 748 | |
| 749 | if (priv->is_activity_detected) { |
| 750 | priv->is_activity_detected = 0; |
| 751 | } else { |
| 752 | if (priv->is_auto_deep_sleep_enabled && |
Dan Williams | 53800f5 | 2010-07-27 13:15:01 -0700 | [diff] [blame] | 753 | (!priv->wakeup_dev_required) && |
| 754 | (priv->connect_status != LBS_CONNECTED)) { |
| 755 | struct cmd_header cmd; |
| 756 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 757 | lbs_deb_main("Entering auto deep sleep mode...\n"); |
Dan Williams | 53800f5 | 2010-07-27 13:15:01 -0700 | [diff] [blame] | 758 | memset(&cmd, 0, sizeof(cmd)); |
| 759 | cmd.size = cpu_to_le16(sizeof(cmd)); |
| 760 | lbs_cmd_async(priv, CMD_802_11_DEEP_SLEEP, &cmd, |
| 761 | sizeof(cmd)); |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | mod_timer(&priv->auto_deepsleep_timer , jiffies + |
| 765 | (priv->auto_deep_sleep_timeout * HZ)/1000); |
| 766 | lbs_deb_leave(LBS_DEB_CMD); |
| 767 | } |
| 768 | |
| 769 | int lbs_enter_auto_deep_sleep(struct lbs_private *priv) |
| 770 | { |
| 771 | lbs_deb_enter(LBS_DEB_SDIO); |
| 772 | |
| 773 | priv->is_auto_deep_sleep_enabled = 1; |
| 774 | if (priv->is_deep_sleep) |
| 775 | priv->wakeup_dev_required = 1; |
| 776 | mod_timer(&priv->auto_deepsleep_timer , |
| 777 | jiffies + (priv->auto_deep_sleep_timeout * HZ)/1000); |
| 778 | |
| 779 | lbs_deb_leave(LBS_DEB_SDIO); |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | int lbs_exit_auto_deep_sleep(struct lbs_private *priv) |
| 784 | { |
| 785 | lbs_deb_enter(LBS_DEB_SDIO); |
| 786 | |
| 787 | priv->is_auto_deep_sleep_enabled = 0; |
| 788 | priv->auto_deep_sleep_timeout = 0; |
| 789 | del_timer(&priv->auto_deepsleep_timer); |
| 790 | |
| 791 | lbs_deb_leave(LBS_DEB_SDIO); |
| 792 | return 0; |
| 793 | } |
| 794 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 795 | static int lbs_init_adapter(struct lbs_private *priv) |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 796 | { |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 797 | int ret; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 798 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 799 | lbs_deb_enter(LBS_DEB_MAIN); |
| 800 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 801 | memset(priv->current_addr, 0xff, ETH_ALEN); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 802 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 803 | priv->connect_status = LBS_DISCONNECTED; |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 804 | priv->channel = DEFAULT_AD_HOC_CHANNEL; |
Holger Schurig | d9e9778 | 2008-03-12 16:06:43 +0100 | [diff] [blame] | 805 | priv->mac_control = CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 806 | priv->radio_on = 1; |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 807 | priv->psmode = LBS802_11POWERMODECAM; |
| 808 | priv->psstate = PS_STATE_FULL_POWER; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 809 | priv->is_deep_sleep = 0; |
| 810 | priv->is_auto_deep_sleep_enabled = 0; |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 811 | priv->deep_sleep_required = 0; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 812 | priv->wakeup_dev_required = 0; |
| 813 | init_waitqueue_head(&priv->ds_awake_q); |
Dan Williams | cc02681 | 2010-08-04 00:43:47 -0500 | [diff] [blame] | 814 | init_waitqueue_head(&priv->scan_q); |
Amitkumar Karwar | 921ca03 | 2010-02-25 17:16:36 -0800 | [diff] [blame] | 815 | priv->authtype_auto = 1; |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 816 | priv->is_host_sleep_configured = 0; |
| 817 | priv->is_host_sleep_activated = 0; |
| 818 | init_waitqueue_head(&priv->host_sleep_q); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 819 | mutex_init(&priv->lock); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 820 | |
Holger Schurig | 40e6fa8 | 2010-02-04 14:37:45 +0100 | [diff] [blame] | 821 | setup_timer(&priv->command_timer, lbs_cmd_timeout_handler, |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 822 | (unsigned long)priv); |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 823 | setup_timer(&priv->auto_deepsleep_timer, auto_deepsleep_timer_fn, |
| 824 | (unsigned long)priv); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 825 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 826 | INIT_LIST_HEAD(&priv->cmdfreeq); |
| 827 | INIT_LIST_HEAD(&priv->cmdpendingq); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 828 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 829 | spin_lock_init(&priv->driver_lock); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 830 | |
| 831 | /* Allocate the command buffers */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 832 | if (lbs_allocate_cmd_buffer(priv)) { |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 833 | pr_err("Out of memory allocating command buffers\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 834 | ret = -ENOMEM; |
| 835 | goto out; |
| 836 | } |
| 837 | priv->resp_idx = 0; |
| 838 | priv->resp_len[0] = priv->resp_len[1] = 0; |
| 839 | |
| 840 | /* Create the event FIFO */ |
Stefani Seibold | c1e13f2 | 2009-12-21 14:37:27 -0800 | [diff] [blame] | 841 | ret = kfifo_alloc(&priv->event_fifo, sizeof(u32) * 16, GFP_KERNEL); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 842 | if (ret) { |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 843 | pr_err("Out of memory allocating event FIFO buffer\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 844 | goto out; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | out: |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 848 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 849 | |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 850 | return ret; |
| 851 | } |
| 852 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 853 | static void lbs_free_adapter(struct lbs_private *priv) |
Holger Schurig | ac558ca | 2007-08-02 11:49:06 -0400 | [diff] [blame] | 854 | { |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 855 | lbs_deb_enter(LBS_DEB_MAIN); |
| 856 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 857 | lbs_free_cmd_buffer(priv); |
Stefani Seibold | 4546548 | 2009-12-21 14:37:26 -0800 | [diff] [blame] | 858 | kfifo_free(&priv->event_fifo); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 859 | del_timer(&priv->command_timer); |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 860 | del_timer(&priv->auto_deepsleep_timer); |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 861 | |
| 862 | lbs_deb_leave(LBS_DEB_MAIN); |
Holger Schurig | ac558ca | 2007-08-02 11:49:06 -0400 | [diff] [blame] | 863 | } |
| 864 | |
Stephen Hemminger | f02abf1 | 2009-03-20 19:36:37 +0000 | [diff] [blame] | 865 | static const struct net_device_ops lbs_netdev_ops = { |
| 866 | .ndo_open = lbs_dev_open, |
| 867 | .ndo_stop = lbs_eth_stop, |
| 868 | .ndo_start_xmit = lbs_hard_start_xmit, |
| 869 | .ndo_set_mac_address = lbs_set_mac_address, |
Stephen Hemminger | f02abf1 | 2009-03-20 19:36:37 +0000 | [diff] [blame] | 870 | .ndo_set_multicast_list = lbs_set_multicast_list, |
| 871 | .ndo_change_mtu = eth_change_mtu, |
| 872 | .ndo_validate_addr = eth_validate_addr, |
| 873 | }; |
| 874 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 875 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 876 | * lbs_add_card - adds the card. It will probe the |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 877 | * card, allocate the lbs_priv and initialize the device. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 878 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 879 | * @card: A pointer to card |
| 880 | * @dmdev: A pointer to &struct device |
| 881 | * returns: A pointer to &struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 882 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 883 | struct lbs_private *lbs_add_card(void *card, struct device *dmdev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 884 | { |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 885 | struct net_device *dev; |
| 886 | struct wireless_dev *wdev; |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 887 | struct lbs_private *priv = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 888 | |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 889 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 890 | |
| 891 | /* Allocate an Ethernet device and register it */ |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 892 | wdev = lbs_cfg_alloc(dmdev); |
| 893 | if (IS_ERR(wdev)) { |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 894 | pr_err("cfg80211 init failed\n"); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 895 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 896 | } |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 897 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 898 | wdev->iftype = NL80211_IFTYPE_STATION; |
| 899 | priv = wdev_priv(wdev); |
| 900 | priv->wdev = wdev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 901 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 902 | if (lbs_init_adapter(priv)) { |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 903 | pr_err("failed to initialize adapter structure\n"); |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 904 | goto err_wdev; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 905 | } |
| 906 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 907 | dev = alloc_netdev(0, "wlan%d", ether_setup); |
| 908 | if (!dev) { |
| 909 | dev_err(dmdev, "no memory for network device instance\n"); |
| 910 | goto err_adapter; |
| 911 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 912 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 913 | dev->ieee80211_ptr = wdev; |
| 914 | dev->ml_priv = priv; |
| 915 | SET_NETDEV_DEV(dev, dmdev); |
| 916 | wdev->netdev = dev; |
| 917 | priv->dev = dev; |
| 918 | |
Stephen Hemminger | f02abf1 | 2009-03-20 19:36:37 +0000 | [diff] [blame] | 919 | dev->netdev_ops = &lbs_netdev_ops; |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 920 | dev->watchdog_timeo = 5 * HZ; |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 921 | dev->ethtool_ops = &lbs_ethtool_ops; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 922 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 923 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 924 | priv->card = card; |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 925 | |
Daniel Mack | c00552c | 2009-08-11 16:09:34 +0200 | [diff] [blame] | 926 | strcpy(dev->name, "wlan%d"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 927 | |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 928 | lbs_deb_thread("Starting main thread...\n"); |
| 929 | init_waitqueue_head(&priv->waitq); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 930 | priv->main_thread = kthread_run(lbs_thread, dev, "lbs_main"); |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 931 | if (IS_ERR(priv->main_thread)) { |
| 932 | lbs_deb_thread("Error creating main thread.\n"); |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 933 | goto err_ndev; |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 934 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 935 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 936 | priv->work_thread = create_singlethread_workqueue("lbs_worker"); |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 937 | INIT_WORK(&priv->mcast_work, lbs_set_mcast_worker); |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 938 | |
Deepak Saxena | ae63a33 | 2010-10-31 13:40:33 +0000 | [diff] [blame] | 939 | priv->wol_criteria = EHS_REMOVE_WAKEUP; |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 940 | priv->wol_gpio = 0xff; |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 941 | priv->wol_gap = 20; |
Deepak Saxena | ae63a33 | 2010-10-31 13:40:33 +0000 | [diff] [blame] | 942 | priv->ehs_remove_supported = true; |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 943 | |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 944 | goto done; |
| 945 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 946 | err_ndev: |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 947 | free_netdev(dev); |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 948 | |
| 949 | err_adapter: |
| 950 | lbs_free_adapter(priv); |
| 951 | |
| 952 | err_wdev: |
| 953 | lbs_cfg_free(priv); |
| 954 | |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 955 | priv = NULL; |
| 956 | |
| 957 | done: |
Holger Schurig | 61d3002 | 2008-01-16 15:59:52 +0100 | [diff] [blame] | 958 | lbs_deb_leave_args(LBS_DEB_MAIN, "priv %p", priv); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 959 | return priv; |
| 960 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 961 | EXPORT_SYMBOL_GPL(lbs_add_card); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 962 | |
| 963 | |
Holger Schurig | a63e5cb | 2008-04-30 10:50:39 +0200 | [diff] [blame] | 964 | void lbs_remove_card(struct lbs_private *priv) |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 965 | { |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 966 | struct net_device *dev = priv->dev; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 967 | |
| 968 | lbs_deb_enter(LBS_DEB_MAIN); |
| 969 | |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 970 | lbs_remove_mesh(priv); |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 971 | lbs_scan_deinit(priv); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 972 | |
Dan Williams | 71b35f3 | 2008-09-08 16:34:40 -0400 | [diff] [blame] | 973 | /* worker thread destruction blocks on the in-flight command which |
| 974 | * should have been cleared already in lbs_stop_card(). |
| 975 | */ |
| 976 | lbs_deb_main("destroying worker thread\n"); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 977 | destroy_workqueue(priv->work_thread); |
Dan Williams | 71b35f3 | 2008-09-08 16:34:40 -0400 | [diff] [blame] | 978 | lbs_deb_main("done destroying worker thread\n"); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 979 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 980 | if (priv->psmode == LBS802_11POWERMODEMAX_PSP) { |
| 981 | priv->psmode = LBS802_11POWERMODECAM; |
Dan Williams | 0bb6408 | 2010-07-27 13:08:08 -0700 | [diff] [blame] | 982 | lbs_set_ps_mode(priv, PS_MODE_ACTION_EXIT_PS, true); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 983 | } |
| 984 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 985 | if (priv->is_deep_sleep) { |
| 986 | priv->is_deep_sleep = 0; |
| 987 | wake_up_interruptible(&priv->ds_awake_q); |
| 988 | } |
| 989 | |
Amitkumar Karwar | 66fceb6 | 2010-05-19 03:24:38 -0700 | [diff] [blame] | 990 | priv->is_host_sleep_configured = 0; |
| 991 | priv->is_host_sleep_activated = 0; |
| 992 | wake_up_interruptible(&priv->host_sleep_q); |
| 993 | |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 994 | /* Stop the thread servicing the interrupts */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 995 | priv->surpriseremoved = 1; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 996 | kthread_stop(priv->main_thread); |
| 997 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 998 | lbs_free_adapter(priv); |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 999 | lbs_cfg_free(priv); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1000 | free_netdev(dev); |
| 1001 | |
| 1002 | lbs_deb_leave(LBS_DEB_MAIN); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1003 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1004 | EXPORT_SYMBOL_GPL(lbs_remove_card); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1005 | |
| 1006 | |
Kiran Divekar | e86dc1c | 2010-06-14 22:01:26 +0530 | [diff] [blame] | 1007 | int lbs_rtap_supported(struct lbs_private *priv) |
Holger Schurig | cd74468 | 2009-12-02 15:25:59 +0100 | [diff] [blame] | 1008 | { |
| 1009 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) |
| 1010 | return 1; |
| 1011 | |
| 1012 | /* newer firmware use a capability mask */ |
| 1013 | return ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) && |
| 1014 | (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)); |
| 1015 | } |
| 1016 | |
| 1017 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1018 | int lbs_start_card(struct lbs_private *priv) |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1019 | { |
| 1020 | struct net_device *dev = priv->dev; |
| 1021 | int ret = -1; |
| 1022 | |
| 1023 | lbs_deb_enter(LBS_DEB_MAIN); |
| 1024 | |
| 1025 | /* poke the firmware */ |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1026 | ret = lbs_setup_firmware(priv); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1027 | if (ret) |
| 1028 | goto done; |
| 1029 | |
Daniel Drake | 49fee69 | 2011-07-21 20:43:17 +0100 | [diff] [blame] | 1030 | if (!lbs_disablemesh) |
| 1031 | lbs_init_mesh(priv); |
| 1032 | else |
| 1033 | pr_info("%s: mesh disabled\n", dev->name); |
| 1034 | |
Holger Schurig | ff9fc79 | 2009-10-06 16:31:54 +0200 | [diff] [blame] | 1035 | if (lbs_cfg_register(priv)) { |
Joe Perches | 0e4e06a | 2011-05-02 16:49:14 -0700 | [diff] [blame] | 1036 | pr_err("cannot register device\n"); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1037 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1038 | } |
David Woodhouse | 020f3d0 | 2007-12-12 23:29:13 -0500 | [diff] [blame] | 1039 | |
Daniel Drake | 49fee69 | 2011-07-21 20:43:17 +0100 | [diff] [blame] | 1040 | if (lbs_mesh_activated(priv)) |
| 1041 | lbs_start_mesh(priv); |
David Woodhouse | 020f3d0 | 2007-12-12 23:29:13 -0500 | [diff] [blame] | 1042 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1043 | lbs_debugfs_init_one(priv, dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1044 | |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 1045 | netdev_info(dev, "Marvell WLAN 802.11 adapter\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1046 | |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1047 | ret = 0; |
| 1048 | |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1049 | done: |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1050 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1051 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1052 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1053 | EXPORT_SYMBOL_GPL(lbs_start_card); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1054 | |
| 1055 | |
Holger Schurig | a63e5cb | 2008-04-30 10:50:39 +0200 | [diff] [blame] | 1056 | void lbs_stop_card(struct lbs_private *priv) |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1057 | { |
Julia Lawall | 43baa5b | 2009-01-09 10:23:10 +0000 | [diff] [blame] | 1058 | struct net_device *dev; |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1059 | |
| 1060 | lbs_deb_enter(LBS_DEB_MAIN); |
| 1061 | |
Holger Schurig | 652e3f2 | 2008-04-30 10:51:15 +0200 | [diff] [blame] | 1062 | if (!priv) |
| 1063 | goto out; |
Julia Lawall | 43baa5b | 2009-01-09 10:23:10 +0000 | [diff] [blame] | 1064 | dev = priv->dev; |
Holger Schurig | 652e3f2 | 2008-04-30 10:51:15 +0200 | [diff] [blame] | 1065 | |
Julia Lawall | 43baa5b | 2009-01-09 10:23:10 +0000 | [diff] [blame] | 1066 | netif_stop_queue(dev); |
| 1067 | netif_carrier_off(dev); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1068 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1069 | lbs_debugfs_remove_one(priv); |
Holger Schurig | cd74468 | 2009-12-02 15:25:59 +0100 | [diff] [blame] | 1070 | lbs_deinit_mesh(priv); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1071 | unregister_netdev(dev); |
| 1072 | |
Holger Schurig | 652e3f2 | 2008-04-30 10:51:15 +0200 | [diff] [blame] | 1073 | out: |
Holger Schurig | a63e5cb | 2008-04-30 10:50:39 +0200 | [diff] [blame] | 1074 | lbs_deb_leave(LBS_DEB_MAIN); |
Dan Williams | 954ee16 | 2007-08-20 11:43:25 -0400 | [diff] [blame] | 1075 | } |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1076 | EXPORT_SYMBOL_GPL(lbs_stop_card); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1077 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1078 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1079 | void lbs_queue_event(struct lbs_private *priv, u32 event) |
| 1080 | { |
| 1081 | unsigned long flags; |
| 1082 | |
| 1083 | lbs_deb_enter(LBS_DEB_THREAD); |
| 1084 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 1085 | |
| 1086 | if (priv->psstate == PS_STATE_SLEEP) |
| 1087 | priv->psstate = PS_STATE_AWAKE; |
| 1088 | |
Stefani Seibold | 7acd72e | 2009-12-21 14:37:28 -0800 | [diff] [blame] | 1089 | kfifo_in(&priv->event_fifo, (unsigned char *) &event, sizeof(u32)); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1090 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 1091 | wake_up(&priv->waitq); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1092 | |
| 1093 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 1094 | lbs_deb_leave(LBS_DEB_THREAD); |
| 1095 | } |
| 1096 | EXPORT_SYMBOL_GPL(lbs_queue_event); |
| 1097 | |
| 1098 | void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1099 | { |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1100 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1101 | |
David Woodhouse | 4f67949 | 2007-12-10 14:58:37 -0500 | [diff] [blame] | 1102 | if (priv->psstate == PS_STATE_SLEEP) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1103 | priv->psstate = PS_STATE_AWAKE; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1104 | |
| 1105 | /* Swap buffers by flipping the response index */ |
| 1106 | BUG_ON(resp_idx > 1); |
| 1107 | priv->resp_idx = resp_idx; |
| 1108 | |
Daniel Drake | d2e7b34 | 2011-08-01 16:43:13 +0100 | [diff] [blame^] | 1109 | wake_up(&priv->waitq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1110 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1111 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1112 | } |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1113 | EXPORT_SYMBOL_GPL(lbs_notify_command_response); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1114 | |
Dan Williams | 72f7a66 | 2010-08-07 21:14:33 -0500 | [diff] [blame] | 1115 | /** |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 1116 | * lbs_get_firmware - Retrieves two-stage firmware |
Dan Williams | 72f7a66 | 2010-08-07 21:14:33 -0500 | [diff] [blame] | 1117 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 1118 | * @dev: A pointer to &device structure |
| 1119 | * @user_helper: User-defined helper firmware file |
| 1120 | * @user_mainfw: User-defined main firmware file |
| 1121 | * @card_model: Bus-specific card model ID used to filter firmware table |
| 1122 | * elements |
| 1123 | * @fw_table: Table of firmware file names and device model numbers |
| 1124 | * terminated by an entry with a NULL helper name |
| 1125 | * @helper: On success, the helper firmware; caller must free |
| 1126 | * @mainfw: On success, the main firmware; caller must free |
Dan Williams | 72f7a66 | 2010-08-07 21:14:33 -0500 | [diff] [blame] | 1127 | * |
Randy Dunlap | 8973a6e | 2011-04-26 15:25:29 -0700 | [diff] [blame] | 1128 | * returns: 0 on success, non-zero on failure |
Dan Williams | 72f7a66 | 2010-08-07 21:14:33 -0500 | [diff] [blame] | 1129 | */ |
| 1130 | int lbs_get_firmware(struct device *dev, const char *user_helper, |
| 1131 | const char *user_mainfw, u32 card_model, |
| 1132 | const struct lbs_fw_table *fw_table, |
| 1133 | const struct firmware **helper, |
| 1134 | const struct firmware **mainfw) |
| 1135 | { |
| 1136 | const struct lbs_fw_table *iter; |
| 1137 | int ret; |
| 1138 | |
| 1139 | BUG_ON(helper == NULL); |
| 1140 | BUG_ON(mainfw == NULL); |
| 1141 | |
| 1142 | /* Try user-specified firmware first */ |
| 1143 | if (user_helper) { |
| 1144 | ret = request_firmware(helper, user_helper, dev); |
| 1145 | if (ret) { |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 1146 | dev_err(dev, "couldn't find helper firmware %s\n", |
| 1147 | user_helper); |
Dan Williams | 72f7a66 | 2010-08-07 21:14:33 -0500 | [diff] [blame] | 1148 | goto fail; |
| 1149 | } |
| 1150 | } |
| 1151 | if (user_mainfw) { |
| 1152 | ret = request_firmware(mainfw, user_mainfw, dev); |
| 1153 | if (ret) { |
Joe Perches | f3a57fd | 2011-05-02 16:49:15 -0700 | [diff] [blame] | 1154 | dev_err(dev, "couldn't find main firmware %s\n", |
| 1155 | user_mainfw); |
Dan Williams | 72f7a66 | 2010-08-07 21:14:33 -0500 | [diff] [blame] | 1156 | goto fail; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | if (*helper && *mainfw) |
| 1161 | return 0; |
| 1162 | |
| 1163 | /* Otherwise search for firmware to use. If neither the helper or |
| 1164 | * the main firmware were specified by the user, then we need to |
| 1165 | * make sure that found helper & main are from the same entry in |
| 1166 | * fw_table. |
| 1167 | */ |
| 1168 | iter = fw_table; |
| 1169 | while (iter && iter->helper) { |
| 1170 | if (iter->model != card_model) |
| 1171 | goto next; |
| 1172 | |
| 1173 | if (*helper == NULL) { |
| 1174 | ret = request_firmware(helper, iter->helper, dev); |
| 1175 | if (ret) |
| 1176 | goto next; |
| 1177 | |
| 1178 | /* If the device has one-stage firmware (ie cf8305) and |
| 1179 | * we've got it then we don't need to bother with the |
| 1180 | * main firmware. |
| 1181 | */ |
| 1182 | if (iter->fwname == NULL) |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | if (*mainfw == NULL) { |
| 1187 | ret = request_firmware(mainfw, iter->fwname, dev); |
| 1188 | if (ret && !user_helper) { |
| 1189 | /* Clear the helper if it wasn't user-specified |
| 1190 | * and the main firmware load failed, to ensure |
| 1191 | * we don't have mismatched firmware pairs. |
| 1192 | */ |
| 1193 | release_firmware(*helper); |
| 1194 | *helper = NULL; |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | if (*helper && *mainfw) |
| 1199 | return 0; |
| 1200 | |
| 1201 | next: |
| 1202 | iter++; |
| 1203 | } |
| 1204 | |
| 1205 | fail: |
| 1206 | /* Failed */ |
| 1207 | if (*helper) { |
| 1208 | release_firmware(*helper); |
| 1209 | *helper = NULL; |
| 1210 | } |
| 1211 | if (*mainfw) { |
| 1212 | release_firmware(*mainfw); |
| 1213 | *mainfw = NULL; |
| 1214 | } |
| 1215 | |
| 1216 | return -ENOENT; |
| 1217 | } |
| 1218 | EXPORT_SYMBOL_GPL(lbs_get_firmware); |
| 1219 | |
Andres Salomon | 4fb910f | 2007-11-20 17:43:45 -0500 | [diff] [blame] | 1220 | static int __init lbs_init_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1221 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1222 | lbs_deb_enter(LBS_DEB_MAIN); |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1223 | memset(&confirm_sleep, 0, sizeof(confirm_sleep)); |
| 1224 | confirm_sleep.hdr.command = cpu_to_le16(CMD_802_11_PS_MODE); |
| 1225 | confirm_sleep.hdr.size = cpu_to_le16(sizeof(confirm_sleep)); |
Dan Williams | 0bb6408 | 2010-07-27 13:08:08 -0700 | [diff] [blame] | 1226 | confirm_sleep.action = cpu_to_le16(PS_MODE_ACTION_SLEEP_CONFIRMED); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1227 | lbs_debugfs_init(); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1228 | lbs_deb_leave(LBS_DEB_MAIN); |
| 1229 | return 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1230 | } |
| 1231 | |
Andres Salomon | 4fb910f | 2007-11-20 17:43:45 -0500 | [diff] [blame] | 1232 | static void __exit lbs_exit_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1233 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1234 | lbs_deb_enter(LBS_DEB_MAIN); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1235 | lbs_debugfs_remove(); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1236 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1237 | } |
| 1238 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1239 | module_init(lbs_init_module); |
| 1240 | module_exit(lbs_exit_module); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1241 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1242 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1243 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1244 | MODULE_LICENSE("GPL"); |