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> |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 13 | #include <linux/kthread.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 14 | |
| 15 | #include <net/iw_handler.h> |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 16 | #include <net/ieee80211.h> |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 17 | |
| 18 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 19 | #include "decl.h" |
| 20 | #include "dev.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 21 | #include "wext.h" |
| 22 | #include "debugfs.h" |
| 23 | #include "assoc.h" |
| 24 | |
Dan Williams | 125dcab | 2007-08-02 11:34:47 -0400 | [diff] [blame] | 25 | #define DRIVER_RELEASE_VERSION "322.p1" |
Dan Williams | 3ce4023 | 2007-05-10 23:03:07 -0400 | [diff] [blame] | 26 | const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION |
| 27 | #ifdef DEBUG |
| 28 | "-dbg" |
| 29 | #endif |
| 30 | ""; |
| 31 | |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 32 | |
| 33 | /* Module parameters */ |
| 34 | unsigned int libertas_debug = 0; |
| 35 | module_param(libertas_debug, int, 0644); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 36 | EXPORT_SYMBOL_GPL(libertas_debug); |
Holger Schurig | a46c641 | 2007-05-25 11:32:07 -0400 | [diff] [blame] | 37 | |
| 38 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 39 | #define WLAN_TX_PWR_DEFAULT 20 /*100mW */ |
| 40 | #define WLAN_TX_PWR_US_DEFAULT 20 /*100mW */ |
| 41 | #define WLAN_TX_PWR_JP_DEFAULT 16 /*50mW */ |
| 42 | #define WLAN_TX_PWR_FR_DEFAULT 20 /*100mW */ |
| 43 | #define WLAN_TX_PWR_EMEA_DEFAULT 20 /*100mW */ |
| 44 | |
| 45 | /* Format { channel, frequency (MHz), maxtxpower } */ |
| 46 | /* band: 'B/G', region: USA FCC/Canada IC */ |
| 47 | static struct chan_freq_power channel_freq_power_US_BG[] = { |
| 48 | {1, 2412, WLAN_TX_PWR_US_DEFAULT}, |
| 49 | {2, 2417, WLAN_TX_PWR_US_DEFAULT}, |
| 50 | {3, 2422, WLAN_TX_PWR_US_DEFAULT}, |
| 51 | {4, 2427, WLAN_TX_PWR_US_DEFAULT}, |
| 52 | {5, 2432, WLAN_TX_PWR_US_DEFAULT}, |
| 53 | {6, 2437, WLAN_TX_PWR_US_DEFAULT}, |
| 54 | {7, 2442, WLAN_TX_PWR_US_DEFAULT}, |
| 55 | {8, 2447, WLAN_TX_PWR_US_DEFAULT}, |
| 56 | {9, 2452, WLAN_TX_PWR_US_DEFAULT}, |
| 57 | {10, 2457, WLAN_TX_PWR_US_DEFAULT}, |
| 58 | {11, 2462, WLAN_TX_PWR_US_DEFAULT} |
| 59 | }; |
| 60 | |
| 61 | /* band: 'B/G', region: Europe ETSI */ |
| 62 | static struct chan_freq_power channel_freq_power_EU_BG[] = { |
| 63 | {1, 2412, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 64 | {2, 2417, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 65 | {3, 2422, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 66 | {4, 2427, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 67 | {5, 2432, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 68 | {6, 2437, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 69 | {7, 2442, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 70 | {8, 2447, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 71 | {9, 2452, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 72 | {10, 2457, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 73 | {11, 2462, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 74 | {12, 2467, WLAN_TX_PWR_EMEA_DEFAULT}, |
| 75 | {13, 2472, WLAN_TX_PWR_EMEA_DEFAULT} |
| 76 | }; |
| 77 | |
| 78 | /* band: 'B/G', region: Spain */ |
| 79 | static struct chan_freq_power channel_freq_power_SPN_BG[] = { |
| 80 | {10, 2457, WLAN_TX_PWR_DEFAULT}, |
| 81 | {11, 2462, WLAN_TX_PWR_DEFAULT} |
| 82 | }; |
| 83 | |
| 84 | /* band: 'B/G', region: France */ |
| 85 | static struct chan_freq_power channel_freq_power_FR_BG[] = { |
| 86 | {10, 2457, WLAN_TX_PWR_FR_DEFAULT}, |
| 87 | {11, 2462, WLAN_TX_PWR_FR_DEFAULT}, |
| 88 | {12, 2467, WLAN_TX_PWR_FR_DEFAULT}, |
| 89 | {13, 2472, WLAN_TX_PWR_FR_DEFAULT} |
| 90 | }; |
| 91 | |
| 92 | /* band: 'B/G', region: Japan */ |
| 93 | static struct chan_freq_power channel_freq_power_JPN_BG[] = { |
| 94 | {1, 2412, WLAN_TX_PWR_JP_DEFAULT}, |
| 95 | {2, 2417, WLAN_TX_PWR_JP_DEFAULT}, |
| 96 | {3, 2422, WLAN_TX_PWR_JP_DEFAULT}, |
| 97 | {4, 2427, WLAN_TX_PWR_JP_DEFAULT}, |
| 98 | {5, 2432, WLAN_TX_PWR_JP_DEFAULT}, |
| 99 | {6, 2437, WLAN_TX_PWR_JP_DEFAULT}, |
| 100 | {7, 2442, WLAN_TX_PWR_JP_DEFAULT}, |
| 101 | {8, 2447, WLAN_TX_PWR_JP_DEFAULT}, |
| 102 | {9, 2452, WLAN_TX_PWR_JP_DEFAULT}, |
| 103 | {10, 2457, WLAN_TX_PWR_JP_DEFAULT}, |
| 104 | {11, 2462, WLAN_TX_PWR_JP_DEFAULT}, |
| 105 | {12, 2467, WLAN_TX_PWR_JP_DEFAULT}, |
| 106 | {13, 2472, WLAN_TX_PWR_JP_DEFAULT}, |
| 107 | {14, 2484, WLAN_TX_PWR_JP_DEFAULT} |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * the structure for channel, frequency and power |
| 112 | */ |
| 113 | struct region_cfp_table { |
| 114 | u8 region; |
| 115 | struct chan_freq_power *cfp_BG; |
| 116 | int cfp_no_BG; |
| 117 | }; |
| 118 | |
| 119 | /** |
| 120 | * the structure for the mapping between region and CFP |
| 121 | */ |
| 122 | static struct region_cfp_table region_cfp_table[] = { |
| 123 | {0x10, /*US FCC */ |
| 124 | channel_freq_power_US_BG, |
| 125 | sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power), |
| 126 | } |
| 127 | , |
| 128 | {0x20, /*CANADA IC */ |
| 129 | channel_freq_power_US_BG, |
| 130 | sizeof(channel_freq_power_US_BG) / sizeof(struct chan_freq_power), |
| 131 | } |
| 132 | , |
| 133 | {0x30, /*EU*/ channel_freq_power_EU_BG, |
| 134 | sizeof(channel_freq_power_EU_BG) / sizeof(struct chan_freq_power), |
| 135 | } |
| 136 | , |
| 137 | {0x31, /*SPAIN*/ channel_freq_power_SPN_BG, |
| 138 | sizeof(channel_freq_power_SPN_BG) / sizeof(struct chan_freq_power), |
| 139 | } |
| 140 | , |
| 141 | {0x32, /*FRANCE*/ channel_freq_power_FR_BG, |
| 142 | sizeof(channel_freq_power_FR_BG) / sizeof(struct chan_freq_power), |
| 143 | } |
| 144 | , |
| 145 | {0x40, /*JAPAN*/ channel_freq_power_JPN_BG, |
| 146 | sizeof(channel_freq_power_JPN_BG) / sizeof(struct chan_freq_power), |
| 147 | } |
| 148 | , |
| 149 | /*Add new region here */ |
| 150 | }; |
| 151 | |
| 152 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 153 | * the table to keep region code |
| 154 | */ |
| 155 | u16 libertas_region_code_to_index[MRVDRV_MAX_REGION_CODE] = |
| 156 | { 0x10, 0x20, 0x30, 0x31, 0x32, 0x40 }; |
| 157 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 158 | /** |
Dan Williams | 8c51276 | 2007-08-02 11:40:45 -0400 | [diff] [blame] | 159 | * 802.11b/g supported bitrates (in 500Kb/s units) |
| 160 | */ |
| 161 | u8 libertas_bg_rates[MAX_RATES] = |
| 162 | { 0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c, |
| 163 | 0x00, 0x00 }; |
| 164 | |
| 165 | /** |
| 166 | * FW rate table. FW refers to rates by their index in this table, not by the |
| 167 | * rate value itself. Values of 0x00 are |
| 168 | * reserved positions. |
| 169 | */ |
| 170 | static u8 fw_data_rates[MAX_RATES] = |
| 171 | { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12, |
| 172 | 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00 |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * @brief use index to get the data rate |
| 177 | * |
| 178 | * @param idx The index of data rate |
| 179 | * @return data rate or 0 |
| 180 | */ |
| 181 | u32 libertas_fw_index_to_data_rate(u8 idx) |
| 182 | { |
| 183 | if (idx >= sizeof(fw_data_rates)) |
| 184 | idx = 0; |
| 185 | return fw_data_rates[idx]; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * @brief use rate to get the index |
| 190 | * |
| 191 | * @param rate data rate |
| 192 | * @return index or 0 |
| 193 | */ |
| 194 | u8 libertas_data_rate_to_fw_index(u32 rate) |
| 195 | { |
| 196 | u8 i; |
| 197 | |
| 198 | if (!rate) |
| 199 | return 0; |
| 200 | |
| 201 | for (i = 0; i < sizeof(fw_data_rates); i++) { |
| 202 | if (rate == fw_data_rates[i]) |
| 203 | return i; |
| 204 | } |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 209 | * Attributes exported through sysfs |
| 210 | */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 211 | |
| 212 | /** |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 213 | * @brief Get function for sysfs attribute anycast_mask |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 214 | */ |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 215 | static ssize_t libertas_anycast_get(struct device * dev, |
Dan Williams | b59bb61 | 2007-06-18 11:50:43 -0400 | [diff] [blame] | 216 | struct device_attribute *attr, char * buf) |
| 217 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 218 | struct cmd_ds_mesh_access mesh_access; |
| 219 | |
| 220 | memset(&mesh_access, 0, sizeof(mesh_access)); |
| 221 | libertas_prepare_and_send_command(to_net_dev(dev)->priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 222 | CMD_MESH_ACCESS, |
| 223 | CMD_ACT_MESH_GET_ANYCAST, |
| 224 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 225 | |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 226 | return snprintf(buf, 12, "0x%X\n", le32_to_cpu(mesh_access.data[0])); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /** |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 230 | * @brief Set function for sysfs attribute anycast_mask |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 231 | */ |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 232 | static ssize_t libertas_anycast_set(struct device * dev, |
Dan Williams | b59bb61 | 2007-06-18 11:50:43 -0400 | [diff] [blame] | 233 | struct device_attribute *attr, const char * buf, size_t count) |
| 234 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 235 | struct cmd_ds_mesh_access mesh_access; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 236 | uint32_t datum; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 237 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 238 | memset(&mesh_access, 0, sizeof(mesh_access)); |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 239 | sscanf(buf, "%x", &datum); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 240 | mesh_access.data[0] = cpu_to_le32(datum); |
| 241 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 242 | libertas_prepare_and_send_command((to_net_dev(dev))->priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 243 | CMD_MESH_ACCESS, |
| 244 | CMD_ACT_MESH_SET_ANYCAST, |
| 245 | CMD_OPTION_WAITFORRSP, 0, (void *)&mesh_access); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 246 | return strlen(buf); |
| 247 | } |
| 248 | |
| 249 | /** |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 250 | * anycast_mask attribute to be exported per mshX interface |
| 251 | * through sysfs (/sys/class/net/mshX/anycast_mask) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 252 | */ |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 253 | static DEVICE_ATTR(anycast_mask, 0644, libertas_anycast_get, libertas_anycast_set); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * @brief Check if the device can be open and wait if necessary. |
| 257 | * |
| 258 | * @param dev A pointer to net_device structure |
| 259 | * @return 0 |
| 260 | * |
| 261 | * For USB adapter, on some systems the device open handler will be |
| 262 | * called before FW ready. Use the following flag check and wait |
| 263 | * function to work around the issue. |
| 264 | * |
| 265 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 266 | static int pre_open_check(struct net_device *dev) |
| 267 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 268 | wlan_private *priv = (wlan_private *) dev->priv; |
| 269 | wlan_adapter *adapter = priv->adapter; |
| 270 | int i = 0; |
| 271 | |
| 272 | while (!adapter->fw_ready && i < 20) { |
| 273 | i++; |
| 274 | msleep_interruptible(100); |
| 275 | } |
| 276 | if (!adapter->fw_ready) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 277 | lbs_pr_err("firmware not ready\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 278 | return -1; |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * @brief This function opens the device |
| 286 | * |
| 287 | * @param dev A pointer to net_device structure |
| 288 | * @return 0 |
| 289 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 290 | static int libertas_dev_open(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 291 | { |
| 292 | wlan_private *priv = (wlan_private *) dev->priv; |
| 293 | wlan_adapter *adapter = priv->adapter; |
| 294 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 295 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 296 | |
| 297 | priv->open = 1; |
| 298 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 299 | if (adapter->connect_status == LIBERTAS_CONNECTED) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 300 | netif_carrier_on(priv->dev); |
Holger Schurig | 3cf8409 | 2007-08-02 11:50:12 -0400 | [diff] [blame^] | 301 | if (priv->mesh_dev) |
| 302 | netif_carrier_on(priv->mesh_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 303 | } else { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 304 | netif_carrier_off(priv->dev); |
Holger Schurig | 3cf8409 | 2007-08-02 11:50:12 -0400 | [diff] [blame^] | 305 | if (priv->mesh_dev) |
| 306 | netif_carrier_off(priv->mesh_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 307 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 308 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 309 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | /** |
| 313 | * @brief This function opens the mshX interface |
| 314 | * |
| 315 | * @param dev A pointer to net_device structure |
| 316 | * @return 0 |
| 317 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 318 | static int libertas_mesh_open(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 319 | { |
| 320 | wlan_private *priv = (wlan_private *) dev->priv ; |
| 321 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 322 | if (pre_open_check(dev) == -1) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 323 | return -1; |
| 324 | priv->mesh_open = 1 ; |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 325 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 326 | if (priv->infra_open == 0) |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 327 | return libertas_dev_open(priv->dev) ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | * @brief This function opens the ethX interface |
| 333 | * |
| 334 | * @param dev A pointer to net_device structure |
| 335 | * @return 0 |
| 336 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 337 | static int libertas_open(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 338 | { |
| 339 | wlan_private *priv = (wlan_private *) dev->priv ; |
| 340 | |
| 341 | if(pre_open_check(dev) == -1) |
| 342 | return -1; |
| 343 | priv->infra_open = 1 ; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 344 | netif_wake_queue(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 345 | if (priv->open == 0) |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 346 | return libertas_dev_open(priv->dev) ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 347 | return 0; |
| 348 | } |
| 349 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 350 | static int libertas_dev_close(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 351 | { |
| 352 | wlan_private *priv = dev->priv; |
| 353 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 354 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 355 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 356 | netif_carrier_off(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 357 | priv->open = 0; |
| 358 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 359 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * @brief This function closes the mshX interface |
| 365 | * |
| 366 | * @param dev A pointer to net_device structure |
| 367 | * @return 0 |
| 368 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 369 | static int libertas_mesh_close(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 370 | { |
| 371 | wlan_private *priv = (wlan_private *) (dev->priv); |
| 372 | |
| 373 | priv->mesh_open = 0; |
| 374 | netif_stop_queue(priv->mesh_dev); |
| 375 | if (priv->infra_open == 0) |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 376 | return libertas_dev_close(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 377 | else |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * @brief This function closes the ethX interface |
| 383 | * |
| 384 | * @param dev A pointer to net_device structure |
| 385 | * @return 0 |
| 386 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 387 | static int libertas_close(struct net_device *dev) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 388 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 389 | wlan_private *priv = (wlan_private *) dev->priv; |
| 390 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 391 | netif_stop_queue(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 392 | priv->infra_open = 0; |
| 393 | if (priv->mesh_open == 0) |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 394 | return libertas_dev_close(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 395 | else |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 400 | static int libertas_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 401 | { |
| 402 | int ret = 0; |
| 403 | wlan_private *priv = dev->priv; |
| 404 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 405 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 406 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 407 | if (priv->dnld_sent || priv->adapter->TxLockFlag) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 408 | priv->stats.tx_dropped++; |
| 409 | goto done; |
| 410 | } |
| 411 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 412 | netif_stop_queue(priv->dev); |
Holger Schurig | 3cf8409 | 2007-08-02 11:50:12 -0400 | [diff] [blame^] | 413 | if (priv->mesh_dev) |
| 414 | netif_stop_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 415 | |
| 416 | if (libertas_process_tx(priv, skb) == 0) |
| 417 | dev->trans_start = jiffies; |
| 418 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 419 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 420 | return ret; |
| 421 | } |
| 422 | |
| 423 | /** |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 424 | * @brief Mark mesh packets and handover them to libertas_hard_start_xmit |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 425 | * |
| 426 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 427 | static int libertas_mesh_pre_start_xmit(struct sk_buff *skb, |
| 428 | struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 429 | { |
| 430 | wlan_private *priv = dev->priv; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 431 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 432 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 433 | lbs_deb_enter(LBS_DEB_MESH); |
| 434 | |
| 435 | SET_MESH_FRAME(skb); |
| 436 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 437 | ret = libertas_hard_start_xmit(skb, priv->dev); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 438 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 439 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 443 | * @brief Mark non-mesh packets and handover them to libertas_hard_start_xmit |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 444 | * |
| 445 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 446 | static int libertas_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 447 | { |
| 448 | int ret; |
| 449 | |
| 450 | lbs_deb_enter(LBS_DEB_NET); |
| 451 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 452 | UNSET_MESH_FRAME(skb); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 453 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 454 | ret = libertas_hard_start_xmit(skb, dev); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 455 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 456 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 457 | } |
| 458 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 459 | static void libertas_tx_timeout(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 460 | { |
| 461 | wlan_private *priv = (wlan_private *) dev->priv; |
| 462 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 463 | lbs_deb_enter(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 464 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 465 | lbs_pr_err("tx watch dog timeout\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 466 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 467 | priv->dnld_sent = DNLD_RES_RECEIVED; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 468 | dev->trans_start = jiffies; |
| 469 | |
| 470 | if (priv->adapter->currenttxskb) { |
| 471 | if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) { |
| 472 | /* If we are here, we have not received feedback from |
| 473 | the previous packet. Assume TX_FAIL and move on. */ |
| 474 | priv->adapter->eventcause = 0x01000000; |
| 475 | libertas_send_tx_feedback(priv); |
| 476 | } else |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 477 | wake_up_interruptible(&priv->waitq); |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 478 | } else if (priv->adapter->connect_status == LIBERTAS_CONNECTED) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 479 | netif_wake_queue(priv->dev); |
Holger Schurig | 3cf8409 | 2007-08-02 11:50:12 -0400 | [diff] [blame^] | 480 | if (priv->mesh_dev) |
| 481 | netif_wake_queue(priv->mesh_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 482 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 483 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 484 | lbs_deb_leave(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /** |
| 488 | * @brief This function returns the network statistics |
| 489 | * |
| 490 | * @param dev A pointer to wlan_private structure |
| 491 | * @return A pointer to net_device_stats structure |
| 492 | */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 493 | static struct net_device_stats *libertas_get_stats(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 494 | { |
| 495 | wlan_private *priv = (wlan_private *) dev->priv; |
| 496 | |
| 497 | return &priv->stats; |
| 498 | } |
| 499 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 500 | static int libertas_set_mac_address(struct net_device *dev, void *addr) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 501 | { |
| 502 | int ret = 0; |
| 503 | wlan_private *priv = (wlan_private *) dev->priv; |
| 504 | wlan_adapter *adapter = priv->adapter; |
| 505 | struct sockaddr *phwaddr = addr; |
| 506 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 507 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 508 | |
Luis Carlos Cobo Rus | 0a0d08a | 2007-05-25 23:05:27 -0400 | [diff] [blame] | 509 | /* In case it was called from the mesh device */ |
| 510 | dev = priv->dev ; |
| 511 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 512 | memset(adapter->current_addr, 0, ETH_ALEN); |
| 513 | |
| 514 | /* dev->dev_addr is 8 bytes */ |
| 515 | lbs_dbg_hex("dev->dev_addr:", dev->dev_addr, ETH_ALEN); |
| 516 | |
| 517 | lbs_dbg_hex("addr:", phwaddr->sa_data, ETH_ALEN); |
| 518 | memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN); |
| 519 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 520 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_MAC_ADDRESS, |
| 521 | CMD_ACT_SET, |
| 522 | CMD_OPTION_WAITFORRSP, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 523 | |
| 524 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 525 | lbs_deb_net("set MAC address failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 526 | ret = -1; |
| 527 | goto done; |
| 528 | } |
| 529 | |
| 530 | lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN); |
| 531 | memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 532 | if (priv->mesh_dev) |
| 533 | memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 534 | |
| 535 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 536 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 537 | return ret; |
| 538 | } |
| 539 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 540 | static int libertas_copy_multicast_address(wlan_adapter * adapter, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 541 | struct net_device *dev) |
| 542 | { |
| 543 | int i = 0; |
| 544 | struct dev_mc_list *mcptr = dev->mc_list; |
| 545 | |
| 546 | for (i = 0; i < dev->mc_count; i++) { |
| 547 | memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN); |
| 548 | mcptr = mcptr->next; |
| 549 | } |
| 550 | |
| 551 | return i; |
| 552 | |
| 553 | } |
| 554 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 555 | static void libertas_set_multicast_list(struct net_device *dev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 556 | { |
| 557 | wlan_private *priv = dev->priv; |
| 558 | wlan_adapter *adapter = priv->adapter; |
| 559 | int oldpacketfilter; |
| 560 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 561 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 562 | |
| 563 | oldpacketfilter = adapter->currentpacketfilter; |
| 564 | |
| 565 | if (dev->flags & IFF_PROMISC) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 566 | lbs_deb_net("enable promiscuous mode\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 567 | adapter->currentpacketfilter |= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 568 | CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 569 | adapter->currentpacketfilter &= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 570 | ~(CMD_ACT_MAC_ALL_MULTICAST_ENABLE | |
| 571 | CMD_ACT_MAC_MULTICAST_ENABLE); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 572 | } else { |
| 573 | /* Multicast */ |
| 574 | adapter->currentpacketfilter &= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 575 | ~CMD_ACT_MAC_PROMISCUOUS_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 576 | |
| 577 | if (dev->flags & IFF_ALLMULTI || dev->mc_count > |
| 578 | MRVDRV_MAX_MULTICAST_LIST_SIZE) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 579 | lbs_deb_net( "enabling all multicast\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 580 | adapter->currentpacketfilter |= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 581 | CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 582 | adapter->currentpacketfilter &= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 583 | ~CMD_ACT_MAC_MULTICAST_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 584 | } else { |
| 585 | adapter->currentpacketfilter &= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 586 | ~CMD_ACT_MAC_ALL_MULTICAST_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 587 | |
| 588 | if (!dev->mc_count) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 589 | lbs_deb_net("no multicast addresses, " |
| 590 | "disabling multicast\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 591 | adapter->currentpacketfilter &= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 592 | ~CMD_ACT_MAC_MULTICAST_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 593 | } else { |
| 594 | int i; |
| 595 | |
| 596 | adapter->currentpacketfilter |= |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 597 | CMD_ACT_MAC_MULTICAST_ENABLE; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 598 | |
| 599 | adapter->nr_of_multicastmacaddr = |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 600 | libertas_copy_multicast_address(adapter, dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 601 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 602 | lbs_deb_net("multicast addresses: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 603 | dev->mc_count); |
| 604 | |
| 605 | for (i = 0; i < dev->mc_count; i++) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 606 | lbs_deb_net("Multicast address %d:" |
| 607 | MAC_FMT "\n", i, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 608 | adapter->multicastlist[i][0], |
| 609 | adapter->multicastlist[i][1], |
| 610 | adapter->multicastlist[i][2], |
| 611 | adapter->multicastlist[i][3], |
| 612 | adapter->multicastlist[i][4], |
| 613 | adapter->multicastlist[i][5]); |
| 614 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 615 | /* send multicast addresses to firmware */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 616 | libertas_prepare_and_send_command(priv, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 617 | CMD_MAC_MULTICAST_ADR, |
| 618 | CMD_ACT_SET, 0, 0, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 619 | NULL); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | if (adapter->currentpacketfilter != oldpacketfilter) { |
| 625 | libertas_set_mac_packet_filter(priv); |
| 626 | } |
| 627 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 628 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | /** |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 632 | * @brief This function handles the major jobs in the WLAN driver. |
| 633 | * It handles all events generated by firmware, RX data received |
| 634 | * from firmware and TX data sent from kernel. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 635 | * |
| 636 | * @param data A pointer to wlan_thread structure |
| 637 | * @return 0 |
| 638 | */ |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 639 | static int libertas_thread(void *data) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 640 | { |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 641 | struct net_device *dev = data; |
| 642 | wlan_private *priv = dev->priv; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 643 | wlan_adapter *adapter = priv->adapter; |
| 644 | wait_queue_t wait; |
| 645 | u8 ireg = 0; |
| 646 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 647 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 648 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 649 | init_waitqueue_entry(&wait, current); |
| 650 | |
| 651 | for (;;) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 652 | lbs_deb_thread( "main-thread 111: intcounter=%d " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 653 | "currenttxskb=%p dnld_sent=%d\n", |
| 654 | adapter->intcounter, |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 655 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 656 | |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 657 | add_wait_queue(&priv->waitq, &wait); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 658 | set_current_state(TASK_INTERRUPTIBLE); |
| 659 | spin_lock_irq(&adapter->driver_lock); |
| 660 | if ((adapter->psstate == PS_STATE_SLEEP) || |
| 661 | (!adapter->intcounter |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 662 | && (priv->dnld_sent || adapter->cur_cmd || |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 663 | list_empty(&adapter->cmdpendingq)))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 664 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 665 | "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n", |
| 666 | adapter->connect_status, adapter->intcounter, |
| 667 | adapter->psmode, adapter->psstate); |
| 668 | spin_unlock_irq(&adapter->driver_lock); |
| 669 | schedule(); |
| 670 | } else |
| 671 | spin_unlock_irq(&adapter->driver_lock); |
| 672 | |
| 673 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 674 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 675 | "main-thread 222 (waking up): intcounter=%d currenttxskb=%p " |
| 676 | "dnld_sent=%d\n", adapter->intcounter, |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 677 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 678 | |
| 679 | set_current_state(TASK_RUNNING); |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 680 | remove_wait_queue(&priv->waitq, &wait); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 681 | try_to_freeze(); |
| 682 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 683 | lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 684 | "dnld_sent=%d\n", |
| 685 | adapter->intcounter, |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 686 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 687 | |
| 688 | if (kthread_should_stop() |
| 689 | || adapter->surpriseremoved) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 690 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 691 | "main-thread: break from main thread: surpriseremoved=0x%x\n", |
| 692 | adapter->surpriseremoved); |
| 693 | break; |
| 694 | } |
| 695 | |
| 696 | |
| 697 | spin_lock_irq(&adapter->driver_lock); |
| 698 | if (adapter->intcounter) { |
| 699 | u8 int_status; |
| 700 | adapter->intcounter = 0; |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 701 | int_status = priv->hw_get_int_status(priv, &ireg); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 702 | |
| 703 | if (int_status) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 704 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 705 | "main-thread: reading HOST_INT_STATUS_REG failed\n"); |
| 706 | spin_unlock_irq(&adapter->driver_lock); |
| 707 | continue; |
| 708 | } |
| 709 | adapter->hisregcpy |= ireg; |
| 710 | } |
| 711 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 712 | lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 713 | "dnld_sent=%d\n", |
| 714 | adapter->intcounter, |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 715 | adapter->currenttxskb, priv->dnld_sent); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 716 | |
| 717 | /* command response? */ |
Holger Schurig | c95c7f9 | 2007-08-02 11:49:45 -0400 | [diff] [blame] | 718 | if (adapter->hisregcpy & MRVDRV_CMD_UPLD_RDY) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 719 | lbs_deb_thread("main-thread: cmd response ready\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 720 | |
Holger Schurig | c95c7f9 | 2007-08-02 11:49:45 -0400 | [diff] [blame] | 721 | adapter->hisregcpy &= ~MRVDRV_CMD_UPLD_RDY; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 722 | spin_unlock_irq(&adapter->driver_lock); |
| 723 | libertas_process_rx_command(priv); |
| 724 | spin_lock_irq(&adapter->driver_lock); |
| 725 | } |
| 726 | |
| 727 | /* Any Card Event */ |
Holger Schurig | c95c7f9 | 2007-08-02 11:49:45 -0400 | [diff] [blame] | 728 | if (adapter->hisregcpy & MRVDRV_CARDEVENT) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 729 | lbs_deb_thread("main-thread: Card Event Activity\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 730 | |
Holger Schurig | c95c7f9 | 2007-08-02 11:49:45 -0400 | [diff] [blame] | 731 | adapter->hisregcpy &= ~MRVDRV_CARDEVENT; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 732 | |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 733 | if (priv->hw_read_event_cause(priv)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 734 | lbs_pr_alert( |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 735 | "main-thread: hw_read_event_cause failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 736 | spin_unlock_irq(&adapter->driver_lock); |
| 737 | continue; |
| 738 | } |
| 739 | spin_unlock_irq(&adapter->driver_lock); |
| 740 | libertas_process_event(priv); |
| 741 | } else |
| 742 | spin_unlock_irq(&adapter->driver_lock); |
| 743 | |
| 744 | /* Check if we need to confirm Sleep Request received previously */ |
| 745 | if (adapter->psstate == PS_STATE_PRE_SLEEP) { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 746 | if (!priv->dnld_sent && !adapter->cur_cmd) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 747 | if (adapter->connect_status == |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 748 | LIBERTAS_CONNECTED) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 749 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 750 | "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p " |
| 751 | "dnld_sent=%d cur_cmd=%p, confirm now\n", |
| 752 | adapter->intcounter, |
| 753 | adapter->currenttxskb, |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 754 | priv->dnld_sent, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 755 | adapter->cur_cmd); |
| 756 | |
| 757 | libertas_ps_confirm_sleep(priv, |
| 758 | (u16) adapter->psmode); |
| 759 | } else { |
| 760 | /* workaround for firmware sending |
| 761 | * deauth/linkloss event immediately |
| 762 | * after sleep request, remove this |
| 763 | * after firmware fixes it |
| 764 | */ |
| 765 | adapter->psstate = PS_STATE_AWAKE; |
| 766 | lbs_pr_alert( |
| 767 | "main-thread: ignore PS_SleepConfirm in non-connected state\n"); |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | /* The PS state is changed during processing of Sleep Request |
| 773 | * event above |
| 774 | */ |
| 775 | if ((priv->adapter->psstate == PS_STATE_SLEEP) || |
| 776 | (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) |
| 777 | continue; |
| 778 | |
| 779 | /* Execute the next command */ |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 780 | if (!priv->dnld_sent && !priv->adapter->cur_cmd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 781 | libertas_execute_next_command(priv); |
| 782 | |
| 783 | /* Wake-up command waiters which can't sleep in |
| 784 | * libertas_prepare_and_send_command |
| 785 | */ |
| 786 | if (!adapter->nr_cmd_pending) |
| 787 | wake_up_all(&adapter->cmd_pending); |
| 788 | |
| 789 | libertas_tx_runqueue(priv); |
| 790 | } |
| 791 | |
| 792 | del_timer(&adapter->command_timer); |
| 793 | adapter->nr_cmd_pending = 0; |
| 794 | wake_up_all(&adapter->cmd_pending); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 795 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 796 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | /** |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 801 | * @brief This function downloads firmware image, gets |
| 802 | * HW spec from firmware and set basic parameters to |
| 803 | * firmware. |
| 804 | * |
| 805 | * @param priv A pointer to wlan_private structure |
| 806 | * @return 0 or -1 |
| 807 | */ |
| 808 | static int wlan_setup_station_hw(wlan_private * priv) |
| 809 | { |
| 810 | int ret = -1; |
| 811 | wlan_adapter *adapter = priv->adapter; |
| 812 | |
| 813 | lbs_deb_enter(LBS_DEB_FW); |
| 814 | |
| 815 | ret = priv->hw_prog_firmware(priv); |
| 816 | |
| 817 | if (ret) { |
| 818 | lbs_deb_fw("bootloader in invalid state\n"); |
| 819 | ret = -1; |
| 820 | goto done; |
| 821 | } |
| 822 | |
| 823 | /* |
| 824 | * Read MAC address from HW |
| 825 | */ |
| 826 | memset(adapter->current_addr, 0xff, ETH_ALEN); |
| 827 | |
| 828 | ret = libertas_prepare_and_send_command(priv, CMD_GET_HW_SPEC, |
| 829 | 0, CMD_OPTION_WAITFORRSP, 0, NULL); |
| 830 | |
| 831 | if (ret) { |
| 832 | ret = -1; |
| 833 | goto done; |
| 834 | } |
| 835 | |
| 836 | libertas_set_mac_packet_filter(priv); |
| 837 | |
| 838 | /* Get the supported Data rates */ |
| 839 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_DATA_RATE, |
| 840 | CMD_ACT_GET_TX_RATE, |
| 841 | CMD_OPTION_WAITFORRSP, 0, NULL); |
| 842 | |
| 843 | if (ret) { |
| 844 | ret = -1; |
| 845 | goto done; |
| 846 | } |
| 847 | |
| 848 | ret = 0; |
| 849 | done: |
| 850 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); |
| 851 | return ret; |
| 852 | } |
| 853 | |
| 854 | static void command_timer_fn(unsigned long data); |
| 855 | |
| 856 | /** |
| 857 | * This function handles the timeout of command sending. |
| 858 | * It will re-send the same command again. |
| 859 | */ |
| 860 | static void command_timer_fn(unsigned long data) |
| 861 | { |
| 862 | wlan_private *priv = (wlan_private *)data; |
| 863 | wlan_adapter *adapter = priv->adapter; |
| 864 | struct cmd_ctrl_node *ptempnode; |
| 865 | struct cmd_ds_command *cmd; |
| 866 | unsigned long flags; |
| 867 | |
| 868 | ptempnode = adapter->cur_cmd; |
| 869 | if (ptempnode == NULL) { |
| 870 | lbs_deb_fw("ptempnode empty\n"); |
| 871 | return; |
| 872 | } |
| 873 | |
| 874 | cmd = (struct cmd_ds_command *)ptempnode->bufvirtualaddr; |
| 875 | if (!cmd) { |
| 876 | lbs_deb_fw("cmd is NULL\n"); |
| 877 | return; |
| 878 | } |
| 879 | |
| 880 | lbs_deb_fw("command_timer_fn fired, cmd %x\n", cmd->command); |
| 881 | |
| 882 | if (!adapter->fw_ready) |
| 883 | return; |
| 884 | |
| 885 | spin_lock_irqsave(&adapter->driver_lock, flags); |
| 886 | adapter->cur_cmd = NULL; |
| 887 | spin_unlock_irqrestore(&adapter->driver_lock, flags); |
| 888 | |
| 889 | lbs_deb_fw("re-sending same command because of timeout\n"); |
| 890 | libertas_queue_cmd(adapter, ptempnode, 0); |
| 891 | |
| 892 | wake_up_interruptible(&priv->waitq); |
| 893 | |
| 894 | return; |
| 895 | } |
| 896 | |
Holger Schurig | ac558ca | 2007-08-02 11:49:06 -0400 | [diff] [blame] | 897 | static void libertas_free_adapter(wlan_private * priv) |
| 898 | { |
| 899 | wlan_adapter *adapter = priv->adapter; |
| 900 | |
| 901 | if (!adapter) { |
| 902 | lbs_deb_fw("why double free adapter?\n"); |
| 903 | return; |
| 904 | } |
| 905 | |
| 906 | lbs_deb_fw("free command buffer\n"); |
| 907 | libertas_free_cmd_buffer(priv); |
| 908 | |
| 909 | lbs_deb_fw("free command_timer\n"); |
| 910 | del_timer(&adapter->command_timer); |
| 911 | |
| 912 | lbs_deb_fw("free scan results table\n"); |
| 913 | kfree(adapter->networks); |
| 914 | adapter->networks = NULL; |
| 915 | |
| 916 | /* Free the adapter object itself */ |
| 917 | lbs_deb_fw("free adapter\n"); |
| 918 | kfree(adapter); |
| 919 | priv->adapter = NULL; |
| 920 | } |
| 921 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 922 | static int wlan_allocate_adapter(wlan_private * priv) |
| 923 | { |
| 924 | size_t bufsize; |
| 925 | wlan_adapter *adapter = priv->adapter; |
| 926 | |
| 927 | /* Allocate buffer to store the BSSID list */ |
| 928 | bufsize = MAX_NETWORK_COUNT * sizeof(struct bss_descriptor); |
| 929 | adapter->networks = kzalloc(bufsize, GFP_KERNEL); |
| 930 | if (!adapter->networks) { |
| 931 | lbs_pr_err("Out of memory allocating beacons\n"); |
| 932 | libertas_free_adapter(priv); |
| 933 | return -ENOMEM; |
| 934 | } |
| 935 | |
| 936 | /* Allocate the command buffers */ |
| 937 | libertas_allocate_cmd_buffer(priv); |
| 938 | |
| 939 | memset(&adapter->libertas_ps_confirm_sleep, 0, sizeof(struct PS_CMD_ConfirmSleep)); |
| 940 | adapter->libertas_ps_confirm_sleep.seqnum = cpu_to_le16(++adapter->seqnum); |
| 941 | adapter->libertas_ps_confirm_sleep.command = |
| 942 | cpu_to_le16(CMD_802_11_PS_MODE); |
| 943 | adapter->libertas_ps_confirm_sleep.size = |
| 944 | cpu_to_le16(sizeof(struct PS_CMD_ConfirmSleep)); |
| 945 | adapter->libertas_ps_confirm_sleep.result = 0; |
| 946 | adapter->libertas_ps_confirm_sleep.action = |
| 947 | cpu_to_le16(CMD_SUBCMD_SLEEP_CONFIRMED); |
| 948 | |
| 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static void wlan_init_adapter(wlan_private * priv) |
| 953 | { |
| 954 | wlan_adapter *adapter = priv->adapter; |
| 955 | int i; |
| 956 | |
| 957 | adapter->scanprobes = 0; |
| 958 | |
| 959 | adapter->bcn_avg_factor = DEFAULT_BCN_AVG_FACTOR; |
| 960 | adapter->data_avg_factor = DEFAULT_DATA_AVG_FACTOR; |
| 961 | |
| 962 | /* ATIM params */ |
| 963 | adapter->atimwindow = 0; |
| 964 | |
| 965 | adapter->connect_status = LIBERTAS_DISCONNECTED; |
| 966 | memset(adapter->current_addr, 0xff, ETH_ALEN); |
| 967 | |
| 968 | /* scan type */ |
| 969 | adapter->scantype = CMD_SCAN_TYPE_ACTIVE; |
| 970 | |
| 971 | /* scan mode */ |
| 972 | adapter->scanmode = CMD_BSS_TYPE_ANY; |
| 973 | |
| 974 | /* 802.11 specific */ |
| 975 | adapter->secinfo.wep_enabled = 0; |
| 976 | for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]); |
| 977 | i++) |
| 978 | memset(&adapter->wep_keys[i], 0, sizeof(struct enc_key)); |
| 979 | adapter->wep_tx_keyidx = 0; |
| 980 | adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM; |
| 981 | adapter->mode = IW_MODE_INFRA; |
| 982 | |
| 983 | adapter->pending_assoc_req = NULL; |
| 984 | adapter->in_progress_assoc_req = NULL; |
| 985 | |
| 986 | /* Initialize scan result lists */ |
| 987 | INIT_LIST_HEAD(&adapter->network_free_list); |
| 988 | INIT_LIST_HEAD(&adapter->network_list); |
| 989 | for (i = 0; i < MAX_NETWORK_COUNT; i++) { |
| 990 | list_add_tail(&adapter->networks[i].list, |
| 991 | &adapter->network_free_list); |
| 992 | } |
| 993 | |
| 994 | mutex_init(&adapter->lock); |
| 995 | |
| 996 | adapter->prescan = 1; |
| 997 | |
| 998 | memset(&adapter->curbssparams, 0, sizeof(adapter->curbssparams)); |
| 999 | adapter->curbssparams.channel = DEFAULT_AD_HOC_CHANNEL; |
| 1000 | |
| 1001 | /* PnP and power profile */ |
| 1002 | adapter->surpriseremoved = 0; |
| 1003 | |
| 1004 | adapter->currentpacketfilter = |
| 1005 | CMD_ACT_MAC_RX_ON | CMD_ACT_MAC_TX_ON; |
| 1006 | |
| 1007 | adapter->radioon = RADIO_ON; |
| 1008 | adapter->txantenna = RF_ANTENNA_2; |
| 1009 | adapter->rxantenna = RF_ANTENNA_AUTO; |
| 1010 | |
| 1011 | adapter->auto_rate = 1; |
| 1012 | adapter->cur_rate = 0; |
| 1013 | adapter->adhoc_grate_enabled = 0; |
| 1014 | |
| 1015 | adapter->beaconperiod = MRVDRV_BEACON_INTERVAL; |
| 1016 | |
| 1017 | // set default capabilities |
| 1018 | adapter->capability = WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 1019 | |
| 1020 | adapter->psmode = WLAN802_11POWERMODECAM; |
| 1021 | adapter->multipledtim = MRVDRV_DEFAULT_MULTIPLE_DTIM; |
| 1022 | |
| 1023 | adapter->listeninterval = MRVDRV_DEFAULT_LISTEN_INTERVAL; |
| 1024 | |
| 1025 | adapter->psstate = PS_STATE_FULL_POWER; |
| 1026 | adapter->needtowakeup = 0; |
| 1027 | adapter->locallisteninterval = 0; /* default value in firmware will be used */ |
| 1028 | |
| 1029 | adapter->intcounter = 0; |
| 1030 | |
| 1031 | adapter->currenttxskb = NULL; |
| 1032 | adapter->pkttxctrl = 0; |
| 1033 | |
| 1034 | memset(&adapter->tx_queue_ps, 0, NR_TX_QUEUE*sizeof(struct sk_buff*)); |
| 1035 | adapter->tx_queue_idx = 0; |
| 1036 | spin_lock_init(&adapter->txqueue_lock); |
| 1037 | |
| 1038 | return; |
| 1039 | } |
| 1040 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 1041 | static int libertas_init_fw(wlan_private * priv) |
| 1042 | { |
| 1043 | int ret = -1; |
| 1044 | wlan_adapter *adapter = priv->adapter; |
| 1045 | |
| 1046 | lbs_deb_enter(LBS_DEB_FW); |
| 1047 | |
| 1048 | /* Allocate adapter structure */ |
| 1049 | if ((ret = wlan_allocate_adapter(priv)) != 0) |
| 1050 | goto done; |
| 1051 | |
| 1052 | /* init adapter structure */ |
| 1053 | wlan_init_adapter(priv); |
| 1054 | |
| 1055 | /* init timer etc. */ |
| 1056 | setup_timer(&adapter->command_timer, command_timer_fn, |
| 1057 | (unsigned long)priv); |
| 1058 | |
| 1059 | /* download fimrware etc. */ |
| 1060 | if ((ret = wlan_setup_station_hw(priv)) != 0) { |
| 1061 | del_timer_sync(&adapter->command_timer); |
| 1062 | goto done; |
| 1063 | } |
| 1064 | |
| 1065 | /* init 802.11d */ |
| 1066 | libertas_init_11d(priv); |
| 1067 | |
| 1068 | ret = 0; |
| 1069 | done: |
| 1070 | lbs_deb_leave_args(LBS_DEB_FW, "ret %d", ret); |
| 1071 | return ret; |
| 1072 | } |
| 1073 | |
| 1074 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1075 | * @brief This function adds the card. it will probe the |
| 1076 | * card, allocate the wlan_priv and initialize the device. |
| 1077 | * |
| 1078 | * @param card A pointer to card |
| 1079 | * @return A pointer to wlan_private structure |
| 1080 | */ |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame] | 1081 | wlan_private *libertas_add_card(void *card, struct device *dmdev) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1082 | { |
| 1083 | struct net_device *dev = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1084 | wlan_private *priv = NULL; |
| 1085 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1086 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1087 | |
| 1088 | /* Allocate an Ethernet device and register it */ |
| 1089 | if (!(dev = alloc_etherdev(sizeof(wlan_private)))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1090 | lbs_pr_err("init ethX device failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1091 | return NULL; |
| 1092 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1093 | priv = dev->priv; |
| 1094 | |
| 1095 | /* allocate buffer for wlan_adapter */ |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 1096 | if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1097 | lbs_pr_err("allocate buffer for wlan_adapter failed\n"); |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 1098 | goto err_kzalloc; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1101 | priv->dev = dev; |
| 1102 | priv->card = card; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1103 | priv->mesh_open = 0; |
| 1104 | priv->infra_open = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1105 | |
| 1106 | SET_MODULE_OWNER(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1107 | |
| 1108 | /* Setup the OS Interface to our functions */ |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 1109 | dev->open = libertas_open; |
| 1110 | dev->hard_start_xmit = libertas_pre_start_xmit; |
| 1111 | dev->stop = libertas_close; |
| 1112 | dev->set_mac_address = libertas_set_mac_address; |
| 1113 | dev->tx_timeout = libertas_tx_timeout; |
| 1114 | dev->get_stats = libertas_get_stats; |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 1115 | dev->watchdog_timeo = 5 * HZ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1116 | dev->ethtool_ops = &libertas_ethtool_ops; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1117 | #ifdef WIRELESS_EXT |
| 1118 | dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1119 | #endif |
| 1120 | #define NETIF_F_DYNALLOC 16 |
| 1121 | dev->features |= NETIF_F_DYNALLOC; |
| 1122 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 1123 | dev->set_multicast_list = libertas_set_multicast_list; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1124 | |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame] | 1125 | SET_NETDEV_DEV(dev, dmdev); |
| 1126 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1127 | INIT_LIST_HEAD(&priv->adapter->cmdfreeq); |
| 1128 | INIT_LIST_HEAD(&priv->adapter->cmdpendingq); |
| 1129 | |
| 1130 | spin_lock_init(&priv->adapter->driver_lock); |
| 1131 | init_waitqueue_head(&priv->adapter->cmd_pending); |
| 1132 | priv->adapter->nr_cmd_pending = 0; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1133 | goto done; |
| 1134 | |
| 1135 | err_kzalloc: |
| 1136 | free_netdev(dev); |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 1137 | priv = NULL; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1138 | done: |
| 1139 | lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv); |
| 1140 | return priv; |
| 1141 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1142 | EXPORT_SYMBOL_GPL(libertas_add_card); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1143 | |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 1144 | int libertas_activate_card(wlan_private *priv) |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1145 | { |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1146 | struct net_device *dev = priv->dev; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1147 | int ret = -1; |
| 1148 | |
| 1149 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1150 | |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 1151 | lbs_deb_thread("Starting main thread...\n"); |
| 1152 | init_waitqueue_head(&priv->waitq); |
| 1153 | priv->main_thread = kthread_run(libertas_thread, dev, "libertas_main"); |
| 1154 | if (IS_ERR(priv->main_thread)) { |
| 1155 | lbs_deb_thread("Error creating main thread.\n"); |
| 1156 | goto done; |
| 1157 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1158 | |
| 1159 | priv->assoc_thread = |
| 1160 | create_singlethread_workqueue("libertas_assoc"); |
Holger Schurig | eb3ce63 | 2007-05-24 23:41:15 -0400 | [diff] [blame] | 1161 | INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker); |
Luis Carlos Cobo Rus | b8bedef | 2007-05-30 12:14:34 -0400 | [diff] [blame] | 1162 | INIT_WORK(&priv->sync_channel, libertas_sync_channel); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | * Register the device. Fillup the private data structure with |
| 1166 | * relevant information from the card and request for the required |
| 1167 | * IRQ. |
| 1168 | */ |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 1169 | if (priv->hw_register_dev(priv) < 0) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1170 | lbs_pr_err("failed to register WLAN device\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1171 | goto err_registerdev; |
| 1172 | } |
| 1173 | |
| 1174 | /* init FW and HW */ |
Holger Schurig | 1df4e8f | 2007-08-02 11:45:12 -0400 | [diff] [blame] | 1175 | if (libertas_init_fw(priv)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1176 | lbs_pr_err("firmware init failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1177 | goto err_registerdev; |
| 1178 | } |
| 1179 | |
| 1180 | if (register_netdev(dev)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1181 | lbs_pr_err("cannot register ethX device\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1182 | goto err_init_fw; |
| 1183 | } |
| 1184 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1185 | lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1186 | |
| 1187 | libertas_debugfs_init_one(priv, dev); |
| 1188 | |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1189 | ret = 0; |
| 1190 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1191 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1192 | err_init_fw: |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 1193 | priv->hw_unregister_dev(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1194 | err_registerdev: |
| 1195 | destroy_workqueue(priv->assoc_thread); |
| 1196 | /* Stop the thread servicing the interrupts */ |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 1197 | wake_up_interruptible(&priv->waitq); |
| 1198 | kthread_stop(priv->main_thread); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 1199 | done: |
| 1200 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 1201 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1202 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1203 | EXPORT_SYMBOL_GPL(libertas_activate_card); |
| 1204 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1205 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1206 | /** |
| 1207 | * @brief This function adds mshX interface |
| 1208 | * |
| 1209 | * @param priv A pointer to the wlan_private structure |
| 1210 | * @return 0 if successful, -X otherwise |
| 1211 | */ |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame] | 1212 | int libertas_add_mesh(wlan_private *priv, struct device *dev) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1213 | { |
| 1214 | struct net_device *mesh_dev = NULL; |
| 1215 | int ret = 0; |
| 1216 | |
| 1217 | lbs_deb_enter(LBS_DEB_MESH); |
| 1218 | |
| 1219 | /* Allocate a virtual mesh device */ |
| 1220 | if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { |
| 1221 | lbs_deb_mesh("init mshX device failed\n"); |
| 1222 | ret = -ENOMEM; |
| 1223 | goto done; |
| 1224 | } |
| 1225 | mesh_dev->priv = priv; |
| 1226 | priv->mesh_dev = mesh_dev; |
| 1227 | |
| 1228 | SET_MODULE_OWNER(mesh_dev); |
| 1229 | |
Dan Williams | e524147 | 2007-08-02 11:39:19 -0400 | [diff] [blame] | 1230 | mesh_dev->open = libertas_mesh_open; |
| 1231 | mesh_dev->hard_start_xmit = libertas_mesh_pre_start_xmit; |
| 1232 | mesh_dev->stop = libertas_mesh_close; |
| 1233 | mesh_dev->get_stats = libertas_get_stats; |
| 1234 | mesh_dev->set_mac_address = libertas_set_mac_address; |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1235 | mesh_dev->ethtool_ops = &libertas_ethtool_ops; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1236 | memcpy(mesh_dev->dev_addr, priv->dev->dev_addr, |
| 1237 | sizeof(priv->dev->dev_addr)); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1238 | |
Dan Williams | 7732ca4 | 2007-05-25 13:13:25 -0400 | [diff] [blame] | 1239 | SET_NETDEV_DEV(priv->mesh_dev, dev); |
| 1240 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1241 | #ifdef WIRELESS_EXT |
Luis Carlos Cobo Rus | f5e05b6 | 2007-05-25 23:08:34 -0400 | [diff] [blame] | 1242 | mesh_dev->wireless_handlers = (struct iw_handler_def *)&mesh_handler_def; |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1243 | #endif |
| 1244 | #define NETIF_F_DYNALLOC 16 |
| 1245 | |
| 1246 | /* Register virtual mesh interface */ |
| 1247 | ret = register_netdev(mesh_dev); |
| 1248 | if (ret) { |
| 1249 | lbs_pr_err("cannot register mshX virtual interface\n"); |
| 1250 | goto err_free; |
| 1251 | } |
| 1252 | |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 1253 | ret = device_create_file(&(mesh_dev->dev), &dev_attr_anycast_mask); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1254 | if (ret) |
| 1255 | goto err_unregister; |
| 1256 | |
| 1257 | /* Everything successful */ |
| 1258 | ret = 0; |
| 1259 | goto done; |
| 1260 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1261 | err_unregister: |
| 1262 | unregister_netdev(mesh_dev); |
| 1263 | |
| 1264 | err_free: |
| 1265 | free_netdev(mesh_dev); |
| 1266 | |
| 1267 | done: |
| 1268 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 1269 | return ret; |
| 1270 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1271 | EXPORT_SYMBOL_GPL(libertas_add_mesh); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1272 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1273 | static void wake_pending_cmdnodes(wlan_private *priv) |
| 1274 | { |
| 1275 | struct cmd_ctrl_node *cmdnode; |
| 1276 | unsigned long flags; |
| 1277 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1278 | lbs_deb_enter(LBS_DEB_CMD); |
| 1279 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1280 | spin_lock_irqsave(&priv->adapter->driver_lock, flags); |
| 1281 | list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) { |
| 1282 | cmdnode->cmdwaitqwoken = 1; |
| 1283 | wake_up_interruptible(&cmdnode->cmdwait_q); |
| 1284 | } |
| 1285 | spin_unlock_irqrestore(&priv->adapter->driver_lock, flags); |
| 1286 | } |
| 1287 | |
| 1288 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1289 | int libertas_remove_card(wlan_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1290 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1291 | wlan_adapter *adapter; |
| 1292 | struct net_device *dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1293 | union iwreq_data wrqu; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1294 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1295 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1296 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1297 | if (!priv) |
| 1298 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1299 | |
| 1300 | adapter = priv->adapter; |
| 1301 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1302 | if (!adapter) |
| 1303 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1304 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1305 | dev = priv->dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1306 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1307 | netif_stop_queue(priv->dev); |
| 1308 | netif_carrier_off(priv->dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1309 | |
| 1310 | wake_pending_cmdnodes(priv); |
| 1311 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1312 | unregister_netdev(dev); |
| 1313 | |
| 1314 | cancel_delayed_work(&priv->assoc_work); |
| 1315 | destroy_workqueue(priv->assoc_thread); |
| 1316 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1317 | if (adapter->psmode == WLAN802_11POWERMODEMAX_PSP) { |
| 1318 | adapter->psmode = WLAN802_11POWERMODECAM; |
| 1319 | libertas_ps_wakeup(priv, CMD_OPTION_WAITFORRSP); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); |
| 1323 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1324 | wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1325 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1326 | adapter->surpriseremoved = 1; |
| 1327 | |
| 1328 | /* Stop the thread servicing the interrupts */ |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 1329 | kthread_stop(priv->main_thread); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1330 | |
| 1331 | libertas_debugfs_remove_one(priv); |
| 1332 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1333 | lbs_deb_net("free adapter\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1334 | libertas_free_adapter(priv); |
| 1335 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1336 | lbs_deb_net("unregister finish\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1337 | |
Holger Schurig | 634b8f4 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1338 | priv->dev = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1339 | free_netdev(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1340 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1341 | out: |
| 1342 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1343 | return 0; |
| 1344 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1345 | EXPORT_SYMBOL_GPL(libertas_remove_card); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1346 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1347 | |
| 1348 | void libertas_remove_mesh(wlan_private *priv) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1349 | { |
| 1350 | struct net_device *mesh_dev; |
| 1351 | |
| 1352 | lbs_deb_enter(LBS_DEB_NET); |
| 1353 | |
| 1354 | if (!priv) |
| 1355 | goto out; |
| 1356 | |
| 1357 | mesh_dev = priv->mesh_dev; |
| 1358 | |
| 1359 | netif_stop_queue(mesh_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1360 | netif_carrier_off(priv->mesh_dev); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1361 | |
Luis Carlos | 82fde74 | 2007-06-07 16:40:59 -0400 | [diff] [blame] | 1362 | device_remove_file(&(mesh_dev->dev), &dev_attr_anycast_mask); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1363 | unregister_netdev(mesh_dev); |
| 1364 | |
| 1365 | priv->mesh_dev = NULL ; |
| 1366 | free_netdev(mesh_dev); |
| 1367 | |
| 1368 | out: |
| 1369 | lbs_deb_leave(LBS_DEB_NET); |
| 1370 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1371 | EXPORT_SYMBOL_GPL(libertas_remove_mesh); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1372 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1373 | /** |
| 1374 | * @brief This function finds the CFP in |
| 1375 | * region_cfp_table based on region and band parameter. |
| 1376 | * |
| 1377 | * @param region The region code |
| 1378 | * @param band The band |
| 1379 | * @param cfp_no A pointer to CFP number |
| 1380 | * @return A pointer to CFP |
| 1381 | */ |
| 1382 | struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no) |
| 1383 | { |
| 1384 | int i, end; |
| 1385 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1386 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1387 | |
| 1388 | end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table); |
| 1389 | |
| 1390 | for (i = 0; i < end ; i++) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1391 | lbs_deb_main("region_cfp_table[i].region=%d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1392 | region_cfp_table[i].region); |
| 1393 | if (region_cfp_table[i].region == region) { |
| 1394 | *cfp_no = region_cfp_table[i].cfp_no_BG; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1395 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1396 | return region_cfp_table[i].cfp_BG; |
| 1397 | } |
| 1398 | } |
| 1399 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1400 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1401 | return NULL; |
| 1402 | } |
| 1403 | |
| 1404 | int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band) |
| 1405 | { |
| 1406 | wlan_adapter *adapter = priv->adapter; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1407 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1408 | int i = 0; |
| 1409 | |
| 1410 | struct chan_freq_power *cfp; |
| 1411 | int cfp_no; |
| 1412 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1413 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1414 | |
| 1415 | memset(adapter->region_channel, 0, sizeof(adapter->region_channel)); |
| 1416 | |
| 1417 | { |
| 1418 | cfp = libertas_get_region_cfp_table(region, band, &cfp_no); |
| 1419 | if (cfp != NULL) { |
| 1420 | adapter->region_channel[i].nrcfp = cfp_no; |
| 1421 | adapter->region_channel[i].CFP = cfp; |
| 1422 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1423 | lbs_deb_main("wrong region code %#x in band B/G\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1424 | region); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1425 | ret = -1; |
| 1426 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1427 | } |
| 1428 | adapter->region_channel[i].valid = 1; |
| 1429 | adapter->region_channel[i].region = region; |
| 1430 | adapter->region_channel[i].band = band; |
| 1431 | i++; |
| 1432 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1433 | out: |
| 1434 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 1435 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | /** |
| 1439 | * @brief This function handles the interrupt. it will change PS |
| 1440 | * state if applicable. it will wake up main_thread to handle |
| 1441 | * the interrupt event as well. |
| 1442 | * |
| 1443 | * @param dev A pointer to net_device structure |
| 1444 | * @return n/a |
| 1445 | */ |
| 1446 | void libertas_interrupt(struct net_device *dev) |
| 1447 | { |
| 1448 | wlan_private *priv = dev->priv; |
| 1449 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1450 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1451 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1452 | lbs_deb_thread("libertas_interrupt: intcounter=%d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1453 | priv->adapter->intcounter); |
| 1454 | |
| 1455 | priv->adapter->intcounter++; |
| 1456 | |
| 1457 | if (priv->adapter->psstate == PS_STATE_SLEEP) { |
| 1458 | priv->adapter->psstate = PS_STATE_AWAKE; |
| 1459 | netif_wake_queue(dev); |
Holger Schurig | 3cf8409 | 2007-08-02 11:50:12 -0400 | [diff] [blame^] | 1460 | if (priv->mesh_dev) |
| 1461 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1462 | } |
| 1463 | |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 1464 | wake_up_interruptible(&priv->waitq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1465 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1466 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1467 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1468 | EXPORT_SYMBOL_GPL(libertas_interrupt); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1469 | |
Dan Williams | eedc2a3 | 2007-08-02 11:36:22 -0400 | [diff] [blame] | 1470 | int libertas_reset_device(wlan_private *priv) |
| 1471 | { |
| 1472 | int ret; |
| 1473 | |
| 1474 | lbs_deb_enter(LBS_DEB_MAIN); |
| 1475 | ret = libertas_prepare_and_send_command(priv, CMD_802_11_RESET, |
| 1476 | CMD_ACT_HALT, 0, 0, NULL); |
| 1477 | msleep_interruptible(10); |
| 1478 | |
| 1479 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 1480 | return ret; |
| 1481 | } |
| 1482 | EXPORT_SYMBOL_GPL(libertas_reset_device); |
| 1483 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1484 | static int libertas_init_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1485 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1486 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1487 | libertas_debugfs_init(); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1488 | lbs_deb_leave(LBS_DEB_MAIN); |
| 1489 | return 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1492 | static void libertas_exit_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1493 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1494 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1495 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1496 | libertas_debugfs_remove(); |
| 1497 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1498 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1499 | } |
| 1500 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1501 | module_init(libertas_init_module); |
| 1502 | module_exit(libertas_exit_module); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1503 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame] | 1504 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1505 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1506 | MODULE_LICENSE("GPL"); |