Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [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 | */ |
| 6 | |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 7 | #include <linux/moduleparam.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 8 | #include <linux/delay.h> |
| 9 | #include <linux/freezer.h> |
| 10 | #include <linux/etherdevice.h> |
| 11 | #include <linux/netdevice.h> |
| 12 | #include <linux/if_arp.h> |
| 13 | |
| 14 | #include <net/iw_handler.h> |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 15 | #include <net/ieee80211.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 16 | |
| 17 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 18 | #include "decl.h" |
| 19 | #include "dev.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 20 | #include "wext.h" |
| 21 | #include "debugfs.h" |
| 22 | #include "assoc.h" |
| 23 | |
Dan Williams | 3ce4023 | 2007-05-10 23:03:07 -0400 | [diff] [blame] | 24 | #define DRIVER_RELEASE_VERSION "320.p0" |
| 25 | const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION |
| 26 | #ifdef DEBUG |
| 27 | "-dbg" |
| 28 | #endif |
| 29 | ""; |
| 30 | |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 31 | |
| 32 | /* Module parameters */ |
| 33 | unsigned int libertas_debug = 0; |
| 34 | module_param(libertas_debug, int, 0644); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 35 | EXPORT_SYMBOL_GPL(libertas_debug); |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 36 | |
| 37 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 38 | #define WLAN_TX_PWR_DEFAULT 20 /*100mW */ |
| 39 | #define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */ |
| 40 | #define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */ |
| 41 | #define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */ |
| 42 | #define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */ |
| 43 | |
| 44 | /* Format { channel, frequency (MHz), maxtxpower } */ |
| 45 | /* band: 'B/G', region: USA FCC/Canada IC */ |
| 46 | static struct chan_freq_power channel_freq_power_US_BG[] = { |
| 47 | {1, 2412, WLAN_TX_PWR_US_DEFAULT}, |
| 48 | {2, 2417, WLAN_TX_PWR_US_DEFAULT}, |
| 49 | {3, 2422, WLAN_TX_PWR_US_DEFAULT}, |
| 50 | {4, 2427, WLAN_TX_PWR_US_DEFAULT}, |
| 51 | {5, 2432, WLAN_TX_PWR_US_DEFAULT}, |
| 52 | {6, 2437, WLAN_TX_PWR_US_DEFAULT}, |
| 53 | {7, 2442, WLAN_TX_PWR_US_DEFAULT}, |
| 54 | {8, 2447, WLAN_TX_PWR_US_DEFAULT}, |
| 55 | {9, 2452, WLAN_TX_PWR_US_DEFAULT}, |
| 56 | {10, 2457, WLAN_TX_PWR_US_DEFAULT}, |
| 57 | {11, 2462, WLAN_TX_PWR_US_DEFAULT} |
| 58 | }; |
| 59 | |
| 60 | /* band: 'B/G', region: Europe ETSI */ |
| 61 | static struct chan_freq_power channel_freq_power_EU_BG[] = { |
| 62 | {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 63 | {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 64 | {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 65 | {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 66 | {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 67 | {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 68 | {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 69 | {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 70 | {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 71 | {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 72 | {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 73 | {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 74 | {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT} |
| 75 | }; |
| 76 | |
| 77 | /* band: 'B/G', region: Spain */ |
| 78 | static struct chan_freq_power channel_freq_power_SPN_BG[] = { |
| 79 | {10, 2457, WLAN_TX_PWR_DEFAULT}, |
| 80 | {11, 2462, WLAN_TX_PWR_DEFAULT} |
| 81 | }; |
| 82 | |
| 83 | /* band: 'B/G', region: France */ |
| 84 | static struct chan_freq_power channel_freq_power_FR_BG[] = { |
| 85 | {10, 2457, WLAN_TX_PWR_FR_DEFAULT}, |
| 86 | {11, 2462, WLAN_TX_PWR_FR_DEFAULT}, |
| 87 | {12, 2467, WLAN_TX_PWR_FR_DEFAULT}, |
| 88 | {13, 2472, WLAN_TX_PWR_FR_DEFAULT} |
| 89 | }; |
| 90 | |
| 91 | /* band: 'B/G', region: Japan */ |
| 92 | static struct chan_freq_power channel_freq_power_JPN_BG[] = { |
| 93 | {1, 2412, WLAN_TX_PWR_JP_DEFAULT}, |
| 94 | {2, 2417, WLAN_TX_PWR_JP_DEFAULT}, |
| 95 | {3, 2422, WLAN_TX_PWR_JP_DEFAULT}, |
| 96 | {4, 2427, WLAN_TX_PWR_JP_DEFAULT}, |
| 97 | {5, 2432, WLAN_TX_PWR_JP_DEFAULT}, |
| 98 | {6, 2437, WLAN_TX_PWR_JP_DEFAULT}, |
| 99 | {7, 2442, WLAN_TX_PWR_JP_DEFAULT}, |
| 100 | {8, 2447, WLAN_TX_PWR_JP_DEFAULT}, |
| 101 | {9, 2452, WLAN_TX_PWR_JP_DEFAULT}, |
| 102 | {10, 2457, WLAN_TX_PWR_JP_DEFAULT}, |
| 103 | {11, 2462, WLAN_TX_PWR_JP_DEFAULT}, |
| 104 | {12, 2467, WLAN_TX_PWR_JP_DEFAULT}, |
| 105 | {13, 2472, WLAN_TX_PWR_JP_DEFAULT}, |
| 106 | {14, 2484, WLAN_TX_PWR_JP_DEFAULT} |
| 107 | }; |
| 108 | |
| 109 | /** |
| 110 | * the structure for channel, frequency and power |
| 111 | */ |
| 112 | struct region_cfp_table { |
| 113 | u8 region; |
| 114 | struct chan_freq_power *cfp_BG; |
| 115 | int cfp_no_BG; |
| 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * the structure for the mapping between region and CFP |
| 120 | */ |
| 121 | static struct region_cfp_table region_cfp_table[] = { |
| 122 | {0x10, /*US FCC */ |
| 123 | channel_freq_power_US_BG, |
| 124 | sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power), |
| 125 | } |
| 126 | , |
| 127 | {0x20, /*CANADA IC */ |
| 128 | channel_freq_power_US_BG, |
| 129 | sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power), |
| 130 | } |
| 131 | , |
| 132 | {0x30, /*EU*/ channel_freq_power_EU_BG, |
| 133 | sizeof(channel_freq_power_EU_BG) / sizeof(struct chan_freq_power), |
| 134 | } |
| 135 | , |
| 136 | {0x31, /*SPAIN*/ channel_freq_power_SPN_BG, |
| 137 | sizeof(channel_freq_power_SPN_BG) / sizeof(struct chan_freq_power), |
| 138 | } |
| 139 | , |
| 140 | {0x32, /*FRANCE*/ channel_freq_power_FR_BG, |
| 141 | sizeof(channel_freq_power_FR_BG) / sizeof(struct chan_freq_power), |
| 142 | } |
| 143 | , |
| 144 | {0x40, /*JAPAN*/ channel_freq_power_JPN_BG, |
| 145 | sizeof(channel_freq_power_JPN_BG) / sizeof(struct chan_freq_power), |
| 146 | } |
| 147 | , |
| 148 | /*Add new region here */ |
| 149 | }; |
| 150 | |
| 151 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 152 | * the rates supported |
| 153 | */ |
| 154 | u8 libertas_supported_rates[G_SUPPORTED_RATES] = |
| 155 | { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, |
| 156 | 0 }; |
| 157 | |
| 158 | /** |
| 159 | * the rates supported for ad-hoc G mode |
| 160 | */ |
| 161 | u8 libertas_adhoc_rates_g[G_SUPPORTED_RATES] = |
| 162 | { 0x82, 0x84, 0x8b, 0x96, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, |
| 163 | 0 }; |
| 164 | |
| 165 | /** |
| 166 | * the rates supported for ad-hoc B mode |
| 167 | */ |
| 168 | u8 libertas_adhoc_rates_b[4] = { 0x82, 0x84, 0x8b, 0x96 }; |
| 169 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 170 | /** |
| 171 | * the table to keep region code |
| 172 | */ |
| 173 | u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] = |
| 174 | { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; |
| 175 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 176 | /** |
| 177 | * Attributes exported through sysfs |
| 178 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * @brief Get function for sysfs attribute libertas_mpp |
| 182 | */ |
John W. Linville | b3f1b8c | 2007-02-27 14:39:04 -0500 | [diff] [blame] | 183 | static ssize_t libertas_mpp_get(struct device * dev, |
| 184 | struct device_attribute *attr, char * buf) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 185 | struct cmd_ds_mesh_access mesh_access; |
| 186 | |
| 187 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 188 | libertas_prepare_and_send_command(to_net_dev(dev)->priv, |
| 189 | cmd_mesh_access, |
| 190 | cmd_act_mesh_get_mpp, |
| 191 | cmd_option_waitforrsp, 0, (void *)&mesh_access); |
| 192 | |
| 193 | return snprintf(buf, 3, "%d\n", mesh_access.data[0]); |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * @brief Set function for sysfs attribute libertas_mpp |
| 198 | */ |
John W. Linville | b3f1b8c | 2007-02-27 14:39:04 -0500 | [diff] [blame] | 199 | static ssize_t libertas_mpp_set(struct device * dev, |
| 200 | struct device_attribute *attr, const char * buf, size_t count) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 201 | struct cmd_ds_mesh_access mesh_access; |
| 202 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 203 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 204 | sscanf(buf, "%d", &(mesh_access.data[0])); |
| 205 | libertas_prepare_and_send_command((to_net_dev(dev))->priv, |
| 206 | cmd_mesh_access, |
| 207 | cmd_act_mesh_set_mpp, |
| 208 | cmd_option_waitforrsp, 0, (void *)&mesh_access); |
| 209 | return strlen(buf); |
| 210 | } |
| 211 | |
| 212 | /** |
| 213 | * libertas_mpp attribute to be exported per mshX interface |
| 214 | * through sysfs (/sys/class/net/mshX/libertas-mpp) |
| 215 | */ |
John W. Linville | b3f1b8c | 2007-02-27 14:39:04 -0500 | [diff] [blame] | 216 | static DEVICE_ATTR(libertas_mpp, 0644, libertas_mpp_get, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 217 | libertas_mpp_set ); |
| 218 | |
| 219 | /** |
| 220 | * @brief Check if the device can be open and wait if necessary. |
| 221 | * |
| 222 | * @param dev A pointer to net_device structure |
| 223 | * @return 0 |
| 224 | * |
| 225 | * For USB adapter, on some systems the device open handler will be |
| 226 | * called before FW ready. Use the following flag check and wait |
| 227 | * function to work around the issue. |
| 228 | * |
| 229 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 230 | static int pre_open_check(struct net_device *dev) |
| 231 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 232 | wlan_private *priv = (wlan_private *) dev->priv; |
| 233 | wlan_adapter *adapter = priv->adapter; |
| 234 | int i = 0; |
| 235 | |
| 236 | while (!adapter->fw_ready && i < 20) { |
| 237 | i++; |
| 238 | msleep_interruptible(100); |
| 239 | } |
| 240 | if (!adapter->fw_ready) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 241 | lbs_pr_err("firmware not ready\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 242 | return -1; |
| 243 | } |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @brief This function opens the device |
| 250 | * |
| 251 | * @param dev A pointer to net_device structure |
| 252 | * @return 0 |
| 253 | */ |
| 254 | static int wlan_dev_open(struct net_device *dev) |
| 255 | { |
| 256 | wlan_private *priv = (wlan_private *) dev->priv; |
| 257 | wlan_adapter *adapter = priv->adapter; |
| 258 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 259 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 260 | |
| 261 | priv->open = 1; |
| 262 | |
| 263 | if (adapter->connect_status == libertas_connected) { |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 264 | netif_carrier_on(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 265 | netif_carrier_on(priv->mesh_dev); |
| 266 | } else { |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 267 | netif_carrier_off(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 268 | netif_carrier_off(priv->mesh_dev); |
| 269 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 270 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 271 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 272 | return 0; |
| 273 | } |
| 274 | /** |
| 275 | * @brief This function opens the mshX interface |
| 276 | * |
| 277 | * @param dev A pointer to net_device structure |
| 278 | * @return 0 |
| 279 | */ |
| 280 | static int mesh_open(struct net_device *dev) |
| 281 | { |
| 282 | wlan_private *priv = (wlan_private *) dev->priv ; |
| 283 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 284 | if (pre_open_check(dev) == -1) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 285 | return -1; |
| 286 | priv->mesh_open = 1 ; |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 287 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 288 | if (priv->infra_open == 0) |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 289 | return wlan_dev_open(priv->dev) ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * @brief This function opens the ethX interface |
| 295 | * |
| 296 | * @param dev A pointer to net_device structure |
| 297 | * @return 0 |
| 298 | */ |
| 299 | static int wlan_open(struct net_device *dev) |
| 300 | { |
| 301 | wlan_private *priv = (wlan_private *) dev->priv ; |
| 302 | |
| 303 | if(pre_open_check(dev) == -1) |
| 304 | return -1; |
| 305 | priv->infra_open = 1 ; |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 306 | netif_wake_queue(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 307 | if (priv->open == 0) |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 308 | return wlan_dev_open(priv->dev) ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int wlan_dev_close(struct net_device *dev) |
| 313 | { |
| 314 | wlan_private *priv = dev->priv; |
| 315 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 316 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 317 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 318 | netif_carrier_off(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 319 | priv->open = 0; |
| 320 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 321 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * @brief This function closes the mshX interface |
| 327 | * |
| 328 | * @param dev A pointer to net_device structure |
| 329 | * @return 0 |
| 330 | */ |
| 331 | static int mesh_close(struct net_device *dev) |
| 332 | { |
| 333 | wlan_private *priv = (wlan_private *) (dev->priv); |
| 334 | |
| 335 | priv->mesh_open = 0; |
| 336 | netif_stop_queue(priv->mesh_dev); |
| 337 | if (priv->infra_open == 0) |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 338 | return wlan_dev_close(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 339 | else |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @brief This function closes the ethX interface |
| 345 | * |
| 346 | * @param dev A pointer to net_device structure |
| 347 | * @return 0 |
| 348 | */ |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 349 | static int wlan_close(struct net_device *dev) |
| 350 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 351 | wlan_private *priv = (wlan_private *) dev->priv; |
| 352 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 353 | netif_stop_queue(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 354 | priv->infra_open = 0; |
| 355 | if (priv->mesh_open == 0) |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 356 | return wlan_dev_close(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 357 | else |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 362 | static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 363 | { |
| 364 | int ret = 0; |
| 365 | wlan_private *priv = dev->priv; |
| 366 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 367 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 368 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 369 | if (priv->dnld_sent || priv->adapter->TxLockFlag) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 370 | priv->stats.tx_dropped++; |
| 371 | goto done; |
| 372 | } |
| 373 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 374 | netif_stop_queue(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 375 | netif_stop_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 376 | |
| 377 | if (libertas_process_tx(priv, skb) == 0) |
| 378 | dev->trans_start = jiffies; |
| 379 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 380 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * @brief Mark mesh packets and handover them to wlan_hard_start_xmit |
| 386 | * |
| 387 | */ |
| 388 | static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 389 | { |
| 390 | wlan_private *priv = dev->priv; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 391 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 392 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 393 | lbs_deb_enter(LBS_DEB_MESH); |
| 394 | |
| 395 | SET_MESH_FRAME(skb); |
| 396 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 397 | ret = wlan_hard_start_xmit(skb, priv->dev); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 398 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 399 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /** |
| 403 | * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit |
| 404 | * |
| 405 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 406 | static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 407 | { |
| 408 | int ret; |
| 409 | |
| 410 | lbs_deb_enter(LBS_DEB_NET); |
| 411 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 412 | UNSET_MESH_FRAME(skb); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 413 | |
| 414 | ret = wlan_hard_start_xmit(skb, dev); |
| 415 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 416 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static void wlan_tx_timeout(struct net_device *dev) |
| 420 | { |
| 421 | wlan_private *priv = (wlan_private *) dev->priv; |
| 422 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 423 | lbs_deb_enter(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 424 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 425 | lbs_pr_err("tx watch dog timeout\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 426 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 427 | priv->dnld_sent = DNLD_RES_RECEIVED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 428 | dev->trans_start = jiffies; |
| 429 | |
| 430 | if (priv->adapter->currenttxskb) { |
| 431 | if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) { |
| 432 | /* If we are here, we have not received feedback from |
| 433 | the previous packet. Assume TX_FAIL and move on. */ |
| 434 | priv->adapter->eventcause = 0x01000000; |
| 435 | libertas_send_tx_feedback(priv); |
| 436 | } else |
| 437 | wake_up_interruptible(&priv->mainthread.waitq); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 438 | } else if (priv->adapter->connect_status == libertas_connected) { |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 439 | netif_wake_queue(priv->dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 440 | netif_wake_queue(priv->mesh_dev); |
| 441 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 442 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 443 | lbs_deb_leave(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
| 447 | * @brief This function returns the network statistics |
| 448 | * |
| 449 | * @param dev A pointer to wlan_private structure |
| 450 | * @return A pointer to net_device_stats structure |
| 451 | */ |
| 452 | static struct net_device_stats *wlan_get_stats(struct net_device *dev) |
| 453 | { |
| 454 | wlan_private *priv = (wlan_private *) dev->priv; |
| 455 | |
| 456 | return &priv->stats; |
| 457 | } |
| 458 | |
| 459 | static int wlan_set_mac_address(struct net_device *dev, void *addr) |
| 460 | { |
| 461 | int ret = 0; |
| 462 | wlan_private *priv = (wlan_private *) dev->priv; |
| 463 | wlan_adapter *adapter = priv->adapter; |
| 464 | struct sockaddr *phwaddr = addr; |
| 465 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 466 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 467 | |
| 468 | memset(adapter->current_addr, 0, ETH_ALEN); |
| 469 | |
| 470 | /* dev->dev_addr is 8 bytes */ |
| 471 | lbs_dbg_hex("dev->dev_addr:", dev->dev_addr, ETH_ALEN); |
| 472 | |
| 473 | lbs_dbg_hex("addr:", phwaddr->sa_data, ETH_ALEN); |
| 474 | memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN); |
| 475 | |
| 476 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_mac_address, |
| 477 | cmd_act_set, |
| 478 | cmd_option_waitforrsp, 0, NULL); |
| 479 | |
| 480 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 481 | lbs_deb_net("set MAC address failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 482 | ret = -1; |
| 483 | goto done; |
| 484 | } |
| 485 | |
| 486 | lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN); |
| 487 | memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 488 | if (priv->mesh_dev) |
| 489 | memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 490 | |
| 491 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 492 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 493 | return ret; |
| 494 | } |
| 495 | |
| 496 | static int wlan_copy_multicast_address(wlan_adapter * adapter, |
| 497 | struct net_device *dev) |
| 498 | { |
| 499 | int i = 0; |
| 500 | struct dev_mc_list *mcptr = dev->mc_list; |
| 501 | |
| 502 | for (i = 0; i < dev->mc_count; i++) { |
| 503 | memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN); |
| 504 | mcptr = mcptr->next; |
| 505 | } |
| 506 | |
| 507 | return i; |
| 508 | |
| 509 | } |
| 510 | |
| 511 | static void wlan_set_multicast_list(struct net_device *dev) |
| 512 | { |
| 513 | wlan_private *priv = dev->priv; |
| 514 | wlan_adapter *adapter = priv->adapter; |
| 515 | int oldpacketfilter; |
| 516 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 517 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 518 | |
| 519 | oldpacketfilter = adapter->currentpacketfilter; |
| 520 | |
| 521 | if (dev->flags & IFF_PROMISC) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 522 | lbs_deb_net("enable promiscuous mode\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 523 | adapter->currentpacketfilter |= |
| 524 | cmd_act_mac_promiscuous_enable; |
| 525 | adapter->currentpacketfilter &= |
| 526 | ~(cmd_act_mac_all_multicast_enable | |
| 527 | cmd_act_mac_multicast_enable); |
| 528 | } else { |
| 529 | /* Multicast */ |
| 530 | adapter->currentpacketfilter &= |
| 531 | ~cmd_act_mac_promiscuous_enable; |
| 532 | |
| 533 | if (dev->flags & IFF_ALLMULTI || dev->mc_count > |
| 534 | MRVDRV_MAX_MULTICAST_LIST_SIZE) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 535 | lbs_deb_net( "enabling all multicast\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 536 | adapter->currentpacketfilter |= |
| 537 | cmd_act_mac_all_multicast_enable; |
| 538 | adapter->currentpacketfilter &= |
| 539 | ~cmd_act_mac_multicast_enable; |
| 540 | } else { |
| 541 | adapter->currentpacketfilter &= |
| 542 | ~cmd_act_mac_all_multicast_enable; |
| 543 | |
| 544 | if (!dev->mc_count) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 545 | lbs_deb_net("no multicast addresses, " |
| 546 | "disabling multicast\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 547 | adapter->currentpacketfilter &= |
| 548 | ~cmd_act_mac_multicast_enable; |
| 549 | } else { |
| 550 | int i; |
| 551 | |
| 552 | adapter->currentpacketfilter |= |
| 553 | cmd_act_mac_multicast_enable; |
| 554 | |
| 555 | adapter->nr_of_multicastmacaddr = |
| 556 | wlan_copy_multicast_address(adapter, dev); |
| 557 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 558 | lbs_deb_net("multicast addresses: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 559 | dev->mc_count); |
| 560 | |
| 561 | for (i = 0; i < dev->mc_count; i++) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 562 | lbs_deb_net("Multicast address %d:" |
| 563 | MAC_FMT "\n", i, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 564 | adapter->multicastlist[i][0], |
| 565 | adapter->multicastlist[i][1], |
| 566 | adapter->multicastlist[i][2], |
| 567 | adapter->multicastlist[i][3], |
| 568 | adapter->multicastlist[i][4], |
| 569 | adapter->multicastlist[i][5]); |
| 570 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 571 | /* send multicast addresses to firmware */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 572 | libertas_prepare_and_send_command(priv, |
| 573 | cmd_mac_multicast_adr, |
| 574 | cmd_act_set, 0, 0, |
| 575 | NULL); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | if (adapter->currentpacketfilter != oldpacketfilter) { |
| 581 | libertas_set_mac_packet_filter(priv); |
| 582 | } |
| 583 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 584 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 588 | * @brief This function handles the major jobs in the WLAN driver. |
| 589 | * It handles all events generated by firmware, RX data received |
| 590 | * from firmware and TX data sent from kernel. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 591 | * |
| 592 | * @param data A pointer to wlan_thread structure |
| 593 | * @return 0 |
| 594 | */ |
| 595 | static int wlan_service_main_thread(void *data) |
| 596 | { |
| 597 | struct wlan_thread *thread = data; |
| 598 | wlan_private *priv = thread->priv; |
| 599 | wlan_adapter *adapter = priv->adapter; |
| 600 | wait_queue_t wait; |
| 601 | u8 ireg = 0; |
| 602 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 603 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 604 | |
| 605 | wlan_activate_thread(thread); |
| 606 | |
| 607 | init_waitqueue_entry(&wait, current); |
| 608 | |
| 609 | for (;;) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 610 | lbs_deb_thread( "main-thread 111: intcounter=%d " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 611 | "currenttxskb=%p dnld_sent=%d\n", |
| 612 | adapter->intcounter, |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 613 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 614 | |
| 615 | add_wait_queue(&thread->waitq, &wait); |
| 616 | set_current_state(TASK_INTERRUPTIBLE); |
| 617 | spin_lock_irq(&adapter->driver_lock); |
| 618 | if ((adapter->psstate == PS_STATE_SLEEP) || |
| 619 | (!adapter->intcounter |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 620 | && (priv->dnld_sent || adapter->cur_cmd || |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 621 | list_empty(&adapter->cmdpendingq)))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 622 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 623 | "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n", |
| 624 | adapter->connect_status, adapter->intcounter, |
| 625 | adapter->psmode, adapter->psstate); |
| 626 | spin_unlock_irq(&adapter->driver_lock); |
| 627 | schedule(); |
| 628 | } else |
| 629 | spin_unlock_irq(&adapter->driver_lock); |
| 630 | |
| 631 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 632 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 633 | "main-thread 222 (waking up): intcounter=%d currenttxskb=%p " |
| 634 | "dnld_sent=%d\n", adapter->intcounter, |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 635 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 636 | |
| 637 | set_current_state(TASK_RUNNING); |
| 638 | remove_wait_queue(&thread->waitq, &wait); |
| 639 | try_to_freeze(); |
| 640 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 641 | lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 642 | "dnld_sent=%d\n", |
| 643 | adapter->intcounter, |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 644 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 645 | |
| 646 | if (kthread_should_stop() |
| 647 | || adapter->surpriseremoved) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 648 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 649 | "main-thread: break from main thread: surpriseremoved=0x%x\n", |
| 650 | adapter->surpriseremoved); |
| 651 | break; |
| 652 | } |
| 653 | |
| 654 | |
| 655 | spin_lock_irq(&adapter->driver_lock); |
| 656 | if (adapter->intcounter) { |
| 657 | u8 int_status; |
| 658 | adapter->intcounter = 0; |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 659 | int_status = priv->hw_get_int_status(priv, &ireg); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 660 | |
| 661 | if (int_status) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 662 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 663 | "main-thread: reading HOST_INT_STATUS_REG failed\n"); |
| 664 | spin_unlock_irq(&adapter->driver_lock); |
| 665 | continue; |
| 666 | } |
| 667 | adapter->hisregcpy |= ireg; |
| 668 | } |
| 669 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 670 | lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 671 | "dnld_sent=%d\n", |
| 672 | adapter->intcounter, |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 673 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 674 | |
| 675 | /* command response? */ |
| 676 | if (adapter->hisregcpy & his_cmdupldrdy) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 677 | lbs_deb_thread("main-thread: cmd response ready\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 678 | |
| 679 | adapter->hisregcpy &= ~his_cmdupldrdy; |
| 680 | spin_unlock_irq(&adapter->driver_lock); |
| 681 | libertas_process_rx_command(priv); |
| 682 | spin_lock_irq(&adapter->driver_lock); |
| 683 | } |
| 684 | |
| 685 | /* Any Card Event */ |
| 686 | if (adapter->hisregcpy & his_cardevent) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 687 | lbs_deb_thread("main-thread: Card Event Activity\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 688 | |
| 689 | adapter->hisregcpy &= ~his_cardevent; |
| 690 | |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 691 | if (priv->hw_read_event_cause(priv)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 692 | lbs_pr_alert( |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 693 | "main-thread: hw_read_event_cause failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 694 | spin_unlock_irq(&adapter->driver_lock); |
| 695 | continue; |
| 696 | } |
| 697 | spin_unlock_irq(&adapter->driver_lock); |
| 698 | libertas_process_event(priv); |
| 699 | } else |
| 700 | spin_unlock_irq(&adapter->driver_lock); |
| 701 | |
| 702 | /* Check if we need to confirm Sleep Request received previously */ |
| 703 | if (adapter->psstate == PS_STATE_PRE_SLEEP) { |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 704 | if (!priv->dnld_sent && !adapter->cur_cmd) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 705 | if (adapter->connect_status == |
| 706 | libertas_connected) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 707 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 708 | "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p " |
| 709 | "dnld_sent=%d cur_cmd=%p, confirm now\n", |
| 710 | adapter->intcounter, |
| 711 | adapter->currenttxskb, |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 712 | priv->dnld_sent, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 713 | adapter->cur_cmd); |
| 714 | |
| 715 | libertas_ps_confirm_sleep(priv, |
| 716 | (u16) adapter->psmode); |
| 717 | } else { |
| 718 | /* workaround for firmware sending |
| 719 | * deauth/linkloss event immediately |
| 720 | * after sleep request, remove this |
| 721 | * after firmware fixes it |
| 722 | */ |
| 723 | adapter->psstate = PS_STATE_AWAKE; |
| 724 | lbs_pr_alert( |
| 725 | "main-thread: ignore PS_SleepConfirm in non-connected state\n"); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /* The PS state is changed during processing of Sleep Request |
| 731 | * event above |
| 732 | */ |
| 733 | if ((priv->adapter->psstate == PS_STATE_SLEEP) || |
| 734 | (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) |
| 735 | continue; |
| 736 | |
| 737 | /* Execute the next command */ |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 738 | if (!priv->dnld_sent && !priv->adapter->cur_cmd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 739 | libertas_execute_next_command(priv); |
| 740 | |
| 741 | /* Wake-up command waiters which can't sleep in |
| 742 | * libertas_prepare_and_send_command |
| 743 | */ |
| 744 | if (!adapter->nr_cmd_pending) |
| 745 | wake_up_all(&adapter->cmd_pending); |
| 746 | |
| 747 | libertas_tx_runqueue(priv); |
| 748 | } |
| 749 | |
| 750 | del_timer(&adapter->command_timer); |
| 751 | adapter->nr_cmd_pending = 0; |
| 752 | wake_up_all(&adapter->cmd_pending); |
| 753 | wlan_deactivate_thread(thread); |
| 754 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 755 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | /** |
| 760 | * @brief This function adds the card. it will probe the |
| 761 | * card, allocate the wlan_priv and initialize the device. |
| 762 | * |
| 763 | * @param card A pointer to card |
| 764 | * @return A pointer to wlan_private structure |
| 765 | */ |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame^] | 766 | wlan_private *libertas_add_card(void *card, struct device *dmdev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 767 | { |
| 768 | struct net_device *dev = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 769 | wlan_private *priv = NULL; |
| 770 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 771 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 772 | |
| 773 | /* Allocate an Ethernet device and register it */ |
| 774 | if (!(dev = alloc_etherdev(sizeof(wlan_private)))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 775 | lbs_pr_err("init ethX device failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 776 | return NULL; |
| 777 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 778 | priv = dev->priv; |
| 779 | |
| 780 | /* allocate buffer for wlan_adapter */ |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 781 | if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 782 | lbs_pr_err("allocate buffer for wlan_adapter failed\n"); |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 783 | goto err_kzalloc; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 784 | } |
| 785 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 786 | priv->dev = dev; |
| 787 | priv->card = card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 788 | priv->mesh_open = 0; |
| 789 | priv->infra_open = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 790 | |
| 791 | SET_MODULE_OWNER(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 792 | |
| 793 | /* Setup the OS Interface to our functions */ |
| 794 | dev->open = wlan_open; |
| 795 | dev->hard_start_xmit = wlan_pre_start_xmit; |
| 796 | dev->stop = wlan_close; |
| 797 | dev->do_ioctl = libertas_do_ioctl; |
| 798 | dev->set_mac_address = wlan_set_mac_address; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 799 | dev->tx_timeout = wlan_tx_timeout; |
| 800 | dev->get_stats = wlan_get_stats; |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 801 | dev->watchdog_timeo = 5 * HZ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 802 | dev->ethtool_ops = &libertas_ethtool_ops; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 803 | #ifdef WIRELESS_EXT |
| 804 | dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 805 | #endif |
| 806 | #define NETIF_F_DYNALLOC 16 |
| 807 | dev->features |= NETIF_F_DYNALLOC; |
| 808 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
| 809 | dev->set_multicast_list = wlan_set_multicast_list; |
| 810 | |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame^] | 811 | SET_NETDEV_DEV(dev, dmdev); |
| 812 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 813 | INIT_LIST_HEAD(&priv->adapter->cmdfreeq); |
| 814 | INIT_LIST_HEAD(&priv->adapter->cmdpendingq); |
| 815 | |
| 816 | spin_lock_init(&priv->adapter->driver_lock); |
| 817 | init_waitqueue_head(&priv->adapter->cmd_pending); |
| 818 | priv->adapter->nr_cmd_pending = 0; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 819 | goto done; |
| 820 | |
| 821 | err_kzalloc: |
| 822 | free_netdev(dev); |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 823 | priv = NULL; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 824 | done: |
| 825 | lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv); |
| 826 | return priv; |
| 827 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 828 | EXPORT_SYMBOL_GPL(libertas_add_card); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 829 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 830 | int libertas_activate_card(wlan_private *priv, char *fw_name) |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 831 | { |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 832 | struct net_device *dev = priv->dev; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 833 | int ret = -1; |
| 834 | |
| 835 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 836 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 837 | lbs_deb_thread("Starting kthread...\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 838 | priv->mainthread.priv = priv; |
| 839 | wlan_create_thread(wlan_service_main_thread, |
| 840 | &priv->mainthread, "wlan_main_service"); |
| 841 | |
| 842 | priv->assoc_thread = |
| 843 | create_singlethread_workqueue("libertas_assoc"); |
Holger Schurig | eb3ce63 | 2007-05-24 23:41:15 -0400 | [diff] [blame] | 844 | INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 845 | |
| 846 | /* |
| 847 | * Register the device. Fillup the private data structure with |
| 848 | * relevant information from the card and request for the required |
| 849 | * IRQ. |
| 850 | */ |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 851 | if (priv->hw_register_dev(priv) < 0) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 852 | lbs_pr_err("failed to register WLAN device\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 853 | goto err_registerdev; |
| 854 | } |
| 855 | |
| 856 | /* init FW and HW */ |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 857 | if (fw_name && libertas_init_fw(priv, fw_name)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 858 | lbs_pr_err("firmware init failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 859 | goto err_registerdev; |
| 860 | } |
| 861 | |
| 862 | if (register_netdev(dev)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 863 | lbs_pr_err("cannot register ethX device\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 864 | goto err_init_fw; |
| 865 | } |
| 866 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 867 | lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 868 | |
| 869 | libertas_debugfs_init_one(priv, dev); |
| 870 | |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 871 | ret = 0; |
| 872 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 873 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 874 | err_init_fw: |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 875 | priv->hw_unregister_dev(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 876 | err_registerdev: |
| 877 | destroy_workqueue(priv->assoc_thread); |
| 878 | /* Stop the thread servicing the interrupts */ |
| 879 | wake_up_interruptible(&priv->mainthread.waitq); |
| 880 | wlan_terminate_thread(&priv->mainthread); |
| 881 | kfree(priv->adapter); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 882 | free_netdev(dev); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 883 | done: |
| 884 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 885 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 886 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 887 | EXPORT_SYMBOL_GPL(libertas_activate_card); |
| 888 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 889 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 890 | /** |
| 891 | * @brief This function adds mshX interface |
| 892 | * |
| 893 | * @param priv A pointer to the wlan_private structure |
| 894 | * @return 0 if successful, -X otherwise |
| 895 | */ |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame^] | 896 | int libertas_add_mesh(wlan_private *priv, struct device *dev) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 897 | { |
| 898 | struct net_device *mesh_dev = NULL; |
| 899 | int ret = 0; |
| 900 | |
| 901 | lbs_deb_enter(LBS_DEB_MESH); |
| 902 | |
| 903 | /* Allocate a virtual mesh device */ |
| 904 | if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { |
| 905 | lbs_deb_mesh("init mshX device failed\n"); |
| 906 | ret = -ENOMEM; |
| 907 | goto done; |
| 908 | } |
| 909 | mesh_dev->priv = priv; |
| 910 | priv->mesh_dev = mesh_dev; |
| 911 | |
| 912 | SET_MODULE_OWNER(mesh_dev); |
| 913 | |
| 914 | mesh_dev->open = mesh_open; |
| 915 | mesh_dev->hard_start_xmit = mesh_pre_start_xmit; |
| 916 | mesh_dev->stop = mesh_close; |
| 917 | mesh_dev->do_ioctl = libertas_do_ioctl; |
| 918 | mesh_dev->get_stats = wlan_get_stats; |
| 919 | mesh_dev->ethtool_ops = &libertas_ethtool_ops; |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 920 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, |
| 921 | sizeof(priv->dev->dev_addr)); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 922 | |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame^] | 923 | SET_NETDEV_DEV(priv->mesh_dev, dev); |
| 924 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 925 | #ifdef WIRELESS_EXT |
| 926 | mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; |
| 927 | #endif |
| 928 | #define NETIF_F_DYNALLOC 16 |
| 929 | |
| 930 | /* Register virtual mesh interface */ |
| 931 | ret = register_netdev(mesh_dev); |
| 932 | if (ret) { |
| 933 | lbs_pr_err("cannot register mshX virtual interface\n"); |
| 934 | goto err_free; |
| 935 | } |
| 936 | |
| 937 | ret = device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp); |
| 938 | if (ret) |
| 939 | goto err_unregister; |
| 940 | |
| 941 | /* Everything successful */ |
| 942 | ret = 0; |
| 943 | goto done; |
| 944 | |
| 945 | |
| 946 | err_unregister: |
| 947 | unregister_netdev(mesh_dev); |
| 948 | |
| 949 | err_free: |
| 950 | free_netdev(mesh_dev); |
| 951 | |
| 952 | done: |
| 953 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 954 | return ret; |
| 955 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 956 | EXPORT_SYMBOL_GPL(libertas_add_mesh); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 957 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 958 | static void wake_pending_cmdnodes(wlan_private *priv) |
| 959 | { |
| 960 | struct cmd_ctrl_node *cmdnode; |
| 961 | unsigned long flags; |
| 962 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 963 | lbs_deb_enter(LBS_DEB_CMD); |
| 964 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 965 | spin_lock_irqsave(&priv->adapter->driver_lock, flags); |
| 966 | list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) { |
| 967 | cmdnode->cmdwaitqwoken = 1; |
| 968 | wake_up_interruptible(&cmdnode->cmdwait_q); |
| 969 | } |
| 970 | spin_unlock_irqrestore(&priv->adapter->driver_lock, flags); |
| 971 | } |
| 972 | |
| 973 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 974 | int libertas_remove_card(wlan_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 975 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 976 | wlan_adapter *adapter; |
| 977 | struct net_device *dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 978 | union iwreq_data wrqu; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 979 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 980 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 981 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 982 | if (!priv) |
| 983 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 984 | |
| 985 | adapter = priv->adapter; |
| 986 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 987 | if (!adapter) |
| 988 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 989 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 990 | dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 991 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 992 | netif_stop_queue(priv->dev); |
| 993 | netif_carrier_off(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 994 | |
| 995 | wake_pending_cmdnodes(priv); |
| 996 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 997 | unregister_netdev(dev); |
| 998 | |
| 999 | cancel_delayed_work(&priv->assoc_work); |
| 1000 | destroy_workqueue(priv->assoc_thread); |
| 1001 | |
| 1002 | if (adapter->psmode == wlan802_11powermodemax_psp) { |
| 1003 | adapter->psmode = wlan802_11powermodecam; |
| 1004 | libertas_ps_wakeup(priv, cmd_option_waitforrsp); |
| 1005 | } |
| 1006 | |
| 1007 | memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); |
| 1008 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1009 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1010 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1011 | adapter->surpriseremoved = 1; |
| 1012 | |
| 1013 | /* Stop the thread servicing the interrupts */ |
| 1014 | wlan_terminate_thread(&priv->mainthread); |
| 1015 | |
| 1016 | libertas_debugfs_remove_one(priv); |
| 1017 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1018 | lbs_deb_net("free adapter\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1019 | libertas_free_adapter(priv); |
| 1020 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1021 | lbs_deb_net("unregister finish\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1022 | |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1023 | priv->dev = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1024 | free_netdev(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1025 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1026 | out: |
| 1027 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1028 | return 0; |
| 1029 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1030 | EXPORT_SYMBOL_GPL(libertas_remove_card); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1031 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1032 | |
| 1033 | void libertas_remove_mesh(wlan_private *priv) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1034 | { |
| 1035 | struct net_device *mesh_dev; |
| 1036 | |
| 1037 | lbs_deb_enter(LBS_DEB_NET); |
| 1038 | |
| 1039 | if (!priv) |
| 1040 | goto out; |
| 1041 | |
| 1042 | mesh_dev = priv->mesh_dev; |
| 1043 | |
| 1044 | netif_stop_queue(mesh_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1045 | netif_carrier_off(priv->mesh_dev); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1046 | |
| 1047 | device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp); |
| 1048 | unregister_netdev(mesh_dev); |
| 1049 | |
| 1050 | priv->mesh_dev = NULL ; |
| 1051 | free_netdev(mesh_dev); |
| 1052 | |
| 1053 | out: |
| 1054 | lbs_deb_leave(LBS_DEB_NET); |
| 1055 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1056 | EXPORT_SYMBOL_GPL(libertas_remove_mesh); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1057 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1058 | /** |
| 1059 | * @brief This function finds the CFP in |
| 1060 | * region_cfp_table based on region and band parameter. |
| 1061 | * |
| 1062 | * @param region The region code |
| 1063 | * @param band The band |
| 1064 | * @param cfp_no A pointer to CFP number |
| 1065 | * @return A pointer to CFP |
| 1066 | */ |
| 1067 | struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no) |
| 1068 | { |
| 1069 | int i, end; |
| 1070 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1071 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1072 | |
| 1073 | end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table); |
| 1074 | |
| 1075 | for (i = 0; i < end ; i++) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1076 | lbs_deb_main("region_cfp_table[i].region=%d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1077 | region_cfp_table[i].region); |
| 1078 | if (region_cfp_table[i].region == region) { |
| 1079 | *cfp_no = region_cfp_table[i].cfp_no_BG; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1080 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1081 | return region_cfp_table[i].cfp_BG; |
| 1082 | } |
| 1083 | } |
| 1084 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1085 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1086 | return NULL; |
| 1087 | } |
| 1088 | |
| 1089 | int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band) |
| 1090 | { |
| 1091 | wlan_adapter *adapter = priv->adapter; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1092 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1093 | int i = 0; |
| 1094 | |
| 1095 | struct chan_freq_power *cfp; |
| 1096 | int cfp_no; |
| 1097 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1098 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1099 | |
| 1100 | memset(adapter->region_channel, 0, sizeof(adapter->region_channel)); |
| 1101 | |
| 1102 | { |
| 1103 | cfp = libertas_get_region_cfp_table(region, band, &cfp_no); |
| 1104 | if (cfp != NULL) { |
| 1105 | adapter->region_channel[i].nrcfp = cfp_no; |
| 1106 | adapter->region_channel[i].CFP = cfp; |
| 1107 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1108 | lbs_deb_main("wrong region code %#x in band B/G\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1109 | region); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1110 | ret = -1; |
| 1111 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1112 | } |
| 1113 | adapter->region_channel[i].valid = 1; |
| 1114 | adapter->region_channel[i].region = region; |
| 1115 | adapter->region_channel[i].band = band; |
| 1116 | i++; |
| 1117 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1118 | out: |
| 1119 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 1120 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * @brief This function handles the interrupt. it will change PS |
| 1125 | * state if applicable. it will wake up main_thread to handle |
| 1126 | * the interrupt event as well. |
| 1127 | * |
| 1128 | * @param dev A pointer to net_device structure |
| 1129 | * @return n/a |
| 1130 | */ |
| 1131 | void libertas_interrupt(struct net_device *dev) |
| 1132 | { |
| 1133 | wlan_private *priv = dev->priv; |
| 1134 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1135 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1136 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1137 | lbs_deb_thread("libertas_interrupt: intcounter=%d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1138 | priv->adapter->intcounter); |
| 1139 | |
| 1140 | priv->adapter->intcounter++; |
| 1141 | |
| 1142 | if (priv->adapter->psstate == PS_STATE_SLEEP) { |
| 1143 | priv->adapter->psstate = PS_STATE_AWAKE; |
| 1144 | netif_wake_queue(dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1145 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | wake_up_interruptible(&priv->mainthread.waitq); |
| 1149 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1150 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1151 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1152 | EXPORT_SYMBOL_GPL(libertas_interrupt); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1153 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1154 | static int libertas_init_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1155 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1156 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1157 | libertas_debugfs_init(); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1158 | lbs_deb_leave(LBS_DEB_MAIN); |
| 1159 | return 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1160 | } |
| 1161 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1162 | static void libertas_exit_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1163 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1164 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1165 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1166 | libertas_debugfs_remove(); |
| 1167 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1168 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1169 | } |
| 1170 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1171 | module_init(libertas_init_module); |
| 1172 | module_exit(libertas_exit_module); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1173 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1174 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1175 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1176 | MODULE_LICENSE("GPL"); |