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) { |
| 264 | netif_carrier_on(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 265 | netif_carrier_on(priv->mesh_dev); |
| 266 | } else { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 267 | netif_carrier_off(priv->wlan_dev.netdev); |
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) |
| 289 | return wlan_dev_open(priv->wlan_dev.netdev) ; |
| 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 ; |
| 306 | netif_wake_queue(priv->wlan_dev.netdev); |
| 307 | if (priv->open == 0) |
| 308 | return wlan_dev_open(priv->wlan_dev.netdev) ; |
| 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 | |
| 318 | netif_carrier_off(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 319 | netif_carrier_off(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 320 | priv->open = 0; |
| 321 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 322 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /** |
| 327 | * @brief This function closes the mshX interface |
| 328 | * |
| 329 | * @param dev A pointer to net_device structure |
| 330 | * @return 0 |
| 331 | */ |
| 332 | static int mesh_close(struct net_device *dev) |
| 333 | { |
| 334 | wlan_private *priv = (wlan_private *) (dev->priv); |
| 335 | |
| 336 | priv->mesh_open = 0; |
| 337 | netif_stop_queue(priv->mesh_dev); |
| 338 | if (priv->infra_open == 0) |
| 339 | return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ; |
| 340 | else |
| 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * @brief This function closes the ethX interface |
| 346 | * |
| 347 | * @param dev A pointer to net_device structure |
| 348 | * @return 0 |
| 349 | */ |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 350 | static int wlan_close(struct net_device *dev) |
| 351 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 352 | wlan_private *priv = (wlan_private *) dev->priv; |
| 353 | |
| 354 | netif_stop_queue(priv->wlan_dev.netdev); |
| 355 | priv->infra_open = 0; |
| 356 | if (priv->mesh_open == 0) |
| 357 | return wlan_dev_close( ((wlan_private *) dev->priv)->wlan_dev.netdev) ; |
| 358 | else |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 363 | static int wlan_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 364 | { |
| 365 | int ret = 0; |
| 366 | wlan_private *priv = dev->priv; |
| 367 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 368 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 369 | |
| 370 | if (priv->wlan_dev.dnld_sent || priv->adapter->TxLockFlag) { |
| 371 | priv->stats.tx_dropped++; |
| 372 | goto done; |
| 373 | } |
| 374 | |
| 375 | netif_stop_queue(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 376 | netif_stop_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 377 | |
| 378 | if (libertas_process_tx(priv, skb) == 0) |
| 379 | dev->trans_start = jiffies; |
| 380 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 381 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * @brief Mark mesh packets and handover them to wlan_hard_start_xmit |
| 387 | * |
| 388 | */ |
| 389 | static int mesh_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 390 | { |
| 391 | wlan_private *priv = dev->priv; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 392 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 393 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 394 | lbs_deb_enter(LBS_DEB_MESH); |
| 395 | |
| 396 | SET_MESH_FRAME(skb); |
| 397 | |
| 398 | ret = wlan_hard_start_xmit(skb, priv->wlan_dev.netdev); |
| 399 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 400 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /** |
| 404 | * @brief Mark non-mesh packets and handover them to wlan_hard_start_xmit |
| 405 | * |
| 406 | */ |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 407 | static int wlan_pre_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 408 | { |
| 409 | int ret; |
| 410 | |
| 411 | lbs_deb_enter(LBS_DEB_NET); |
| 412 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 413 | UNSET_MESH_FRAME(skb); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 414 | |
| 415 | ret = wlan_hard_start_xmit(skb, dev); |
| 416 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 417 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | static void wlan_tx_timeout(struct net_device *dev) |
| 421 | { |
| 422 | wlan_private *priv = (wlan_private *) dev->priv; |
| 423 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 424 | lbs_deb_enter(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 425 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 426 | lbs_pr_err("tx watch dog timeout\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 427 | |
| 428 | priv->wlan_dev.dnld_sent = DNLD_RES_RECEIVED; |
| 429 | dev->trans_start = jiffies; |
| 430 | |
| 431 | if (priv->adapter->currenttxskb) { |
| 432 | if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP) { |
| 433 | /* If we are here, we have not received feedback from |
| 434 | the previous packet. Assume TX_FAIL and move on. */ |
| 435 | priv->adapter->eventcause = 0x01000000; |
| 436 | libertas_send_tx_feedback(priv); |
| 437 | } else |
| 438 | wake_up_interruptible(&priv->mainthread.waitq); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 439 | } else if (priv->adapter->connect_status == libertas_connected) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 440 | netif_wake_queue(priv->wlan_dev.netdev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 441 | netif_wake_queue(priv->mesh_dev); |
| 442 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 443 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 444 | lbs_deb_leave(LBS_DEB_TX); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /** |
| 448 | * @brief This function returns the network statistics |
| 449 | * |
| 450 | * @param dev A pointer to wlan_private structure |
| 451 | * @return A pointer to net_device_stats structure |
| 452 | */ |
| 453 | static struct net_device_stats *wlan_get_stats(struct net_device *dev) |
| 454 | { |
| 455 | wlan_private *priv = (wlan_private *) dev->priv; |
| 456 | |
| 457 | return &priv->stats; |
| 458 | } |
| 459 | |
| 460 | static int wlan_set_mac_address(struct net_device *dev, void *addr) |
| 461 | { |
| 462 | int ret = 0; |
| 463 | wlan_private *priv = (wlan_private *) dev->priv; |
| 464 | wlan_adapter *adapter = priv->adapter; |
| 465 | struct sockaddr *phwaddr = addr; |
| 466 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 467 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 468 | |
| 469 | memset(adapter->current_addr, 0, ETH_ALEN); |
| 470 | |
| 471 | /* dev->dev_addr is 8 bytes */ |
| 472 | lbs_dbg_hex("dev->dev_addr:", dev->dev_addr, ETH_ALEN); |
| 473 | |
| 474 | lbs_dbg_hex("addr:", phwaddr->sa_data, ETH_ALEN); |
| 475 | memcpy(adapter->current_addr, phwaddr->sa_data, ETH_ALEN); |
| 476 | |
| 477 | ret = libertas_prepare_and_send_command(priv, cmd_802_11_mac_address, |
| 478 | cmd_act_set, |
| 479 | cmd_option_waitforrsp, 0, NULL); |
| 480 | |
| 481 | if (ret) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 482 | lbs_deb_net("set MAC address failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 483 | ret = -1; |
| 484 | goto done; |
| 485 | } |
| 486 | |
| 487 | lbs_dbg_hex("adapter->macaddr:", adapter->current_addr, ETH_ALEN); |
| 488 | memcpy(dev->dev_addr, adapter->current_addr, ETH_ALEN); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 489 | if (priv->mesh_dev) |
| 490 | memcpy(priv->mesh_dev->dev_addr, adapter->current_addr, ETH_ALEN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 491 | |
| 492 | done: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 493 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 494 | return ret; |
| 495 | } |
| 496 | |
| 497 | static int wlan_copy_multicast_address(wlan_adapter * adapter, |
| 498 | struct net_device *dev) |
| 499 | { |
| 500 | int i = 0; |
| 501 | struct dev_mc_list *mcptr = dev->mc_list; |
| 502 | |
| 503 | for (i = 0; i < dev->mc_count; i++) { |
| 504 | memcpy(&adapter->multicastlist[i], mcptr->dmi_addr, ETH_ALEN); |
| 505 | mcptr = mcptr->next; |
| 506 | } |
| 507 | |
| 508 | return i; |
| 509 | |
| 510 | } |
| 511 | |
| 512 | static void wlan_set_multicast_list(struct net_device *dev) |
| 513 | { |
| 514 | wlan_private *priv = dev->priv; |
| 515 | wlan_adapter *adapter = priv->adapter; |
| 516 | int oldpacketfilter; |
| 517 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 518 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 519 | |
| 520 | oldpacketfilter = adapter->currentpacketfilter; |
| 521 | |
| 522 | if (dev->flags & IFF_PROMISC) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 523 | lbs_deb_net("enable promiscuous mode\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 524 | adapter->currentpacketfilter |= |
| 525 | cmd_act_mac_promiscuous_enable; |
| 526 | adapter->currentpacketfilter &= |
| 527 | ~(cmd_act_mac_all_multicast_enable | |
| 528 | cmd_act_mac_multicast_enable); |
| 529 | } else { |
| 530 | /* Multicast */ |
| 531 | adapter->currentpacketfilter &= |
| 532 | ~cmd_act_mac_promiscuous_enable; |
| 533 | |
| 534 | if (dev->flags & IFF_ALLMULTI || dev->mc_count > |
| 535 | MRVDRV_MAX_MULTICAST_LIST_SIZE) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 536 | lbs_deb_net( "enabling all multicast\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 537 | adapter->currentpacketfilter |= |
| 538 | cmd_act_mac_all_multicast_enable; |
| 539 | adapter->currentpacketfilter &= |
| 540 | ~cmd_act_mac_multicast_enable; |
| 541 | } else { |
| 542 | adapter->currentpacketfilter &= |
| 543 | ~cmd_act_mac_all_multicast_enable; |
| 544 | |
| 545 | if (!dev->mc_count) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 546 | lbs_deb_net("no multicast addresses, " |
| 547 | "disabling multicast\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 548 | adapter->currentpacketfilter &= |
| 549 | ~cmd_act_mac_multicast_enable; |
| 550 | } else { |
| 551 | int i; |
| 552 | |
| 553 | adapter->currentpacketfilter |= |
| 554 | cmd_act_mac_multicast_enable; |
| 555 | |
| 556 | adapter->nr_of_multicastmacaddr = |
| 557 | wlan_copy_multicast_address(adapter, dev); |
| 558 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 559 | lbs_deb_net("multicast addresses: %d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 560 | dev->mc_count); |
| 561 | |
| 562 | for (i = 0; i < dev->mc_count; i++) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 563 | lbs_deb_net("Multicast address %d:" |
| 564 | MAC_FMT "\n", i, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 565 | adapter->multicastlist[i][0], |
| 566 | adapter->multicastlist[i][1], |
| 567 | adapter->multicastlist[i][2], |
| 568 | adapter->multicastlist[i][3], |
| 569 | adapter->multicastlist[i][4], |
| 570 | adapter->multicastlist[i][5]); |
| 571 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 572 | /* send multicast addresses to firmware */ |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 573 | libertas_prepare_and_send_command(priv, |
| 574 | cmd_mac_multicast_adr, |
| 575 | cmd_act_set, 0, 0, |
| 576 | NULL); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | if (adapter->currentpacketfilter != oldpacketfilter) { |
| 582 | libertas_set_mac_packet_filter(priv); |
| 583 | } |
| 584 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 585 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /** |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 589 | * @brief This function handles the major jobs in the WLAN driver. |
| 590 | * It handles all events generated by firmware, RX data received |
| 591 | * from firmware and TX data sent from kernel. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 592 | * |
| 593 | * @param data A pointer to wlan_thread structure |
| 594 | * @return 0 |
| 595 | */ |
| 596 | static int wlan_service_main_thread(void *data) |
| 597 | { |
| 598 | struct wlan_thread *thread = data; |
| 599 | wlan_private *priv = thread->priv; |
| 600 | wlan_adapter *adapter = priv->adapter; |
| 601 | wait_queue_t wait; |
| 602 | u8 ireg = 0; |
| 603 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 604 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 605 | |
| 606 | wlan_activate_thread(thread); |
| 607 | |
| 608 | init_waitqueue_entry(&wait, current); |
| 609 | |
| 610 | for (;;) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 611 | lbs_deb_thread( "main-thread 111: intcounter=%d " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 612 | "currenttxskb=%p dnld_sent=%d\n", |
| 613 | adapter->intcounter, |
| 614 | adapter->currenttxskb, priv->wlan_dev.dnld_sent); |
| 615 | |
| 616 | add_wait_queue(&thread->waitq, &wait); |
| 617 | set_current_state(TASK_INTERRUPTIBLE); |
| 618 | spin_lock_irq(&adapter->driver_lock); |
| 619 | if ((adapter->psstate == PS_STATE_SLEEP) || |
| 620 | (!adapter->intcounter |
| 621 | && (priv->wlan_dev.dnld_sent || adapter->cur_cmd || |
| 622 | list_empty(&adapter->cmdpendingq)))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 623 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 624 | "main-thread sleeping... Conn=%d IntC=%d PS_mode=%d PS_State=%d\n", |
| 625 | adapter->connect_status, adapter->intcounter, |
| 626 | adapter->psmode, adapter->psstate); |
| 627 | spin_unlock_irq(&adapter->driver_lock); |
| 628 | schedule(); |
| 629 | } else |
| 630 | spin_unlock_irq(&adapter->driver_lock); |
| 631 | |
| 632 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 633 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | "main-thread 222 (waking up): intcounter=%d currenttxskb=%p " |
| 635 | "dnld_sent=%d\n", adapter->intcounter, |
| 636 | adapter->currenttxskb, priv->wlan_dev.dnld_sent); |
| 637 | |
| 638 | set_current_state(TASK_RUNNING); |
| 639 | remove_wait_queue(&thread->waitq, &wait); |
| 640 | try_to_freeze(); |
| 641 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 642 | lbs_deb_thread("main-thread 333: intcounter=%d currenttxskb=%p " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 643 | "dnld_sent=%d\n", |
| 644 | adapter->intcounter, |
| 645 | adapter->currenttxskb, priv->wlan_dev.dnld_sent); |
| 646 | |
| 647 | if (kthread_should_stop() |
| 648 | || adapter->surpriseremoved) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 649 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 650 | "main-thread: break from main thread: surpriseremoved=0x%x\n", |
| 651 | adapter->surpriseremoved); |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | |
| 656 | spin_lock_irq(&adapter->driver_lock); |
| 657 | if (adapter->intcounter) { |
| 658 | u8 int_status; |
| 659 | adapter->intcounter = 0; |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 660 | int_status = priv->hw_get_int_status(priv, &ireg); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 661 | |
| 662 | if (int_status) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 663 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 664 | "main-thread: reading HOST_INT_STATUS_REG failed\n"); |
| 665 | spin_unlock_irq(&adapter->driver_lock); |
| 666 | continue; |
| 667 | } |
| 668 | adapter->hisregcpy |= ireg; |
| 669 | } |
| 670 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 671 | lbs_deb_thread("main-thread 444: intcounter=%d currenttxskb=%p " |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 672 | "dnld_sent=%d\n", |
| 673 | adapter->intcounter, |
| 674 | adapter->currenttxskb, priv->wlan_dev.dnld_sent); |
| 675 | |
| 676 | /* command response? */ |
| 677 | if (adapter->hisregcpy & his_cmdupldrdy) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 678 | lbs_deb_thread("main-thread: cmd response ready\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 679 | |
| 680 | adapter->hisregcpy &= ~his_cmdupldrdy; |
| 681 | spin_unlock_irq(&adapter->driver_lock); |
| 682 | libertas_process_rx_command(priv); |
| 683 | spin_lock_irq(&adapter->driver_lock); |
| 684 | } |
| 685 | |
| 686 | /* Any Card Event */ |
| 687 | if (adapter->hisregcpy & his_cardevent) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 688 | lbs_deb_thread("main-thread: Card Event Activity\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 689 | |
| 690 | adapter->hisregcpy &= ~his_cardevent; |
| 691 | |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 692 | if (priv->hw_read_event_cause(priv)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 693 | lbs_pr_alert( |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 694 | "main-thread: hw_read_event_cause failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 695 | spin_unlock_irq(&adapter->driver_lock); |
| 696 | continue; |
| 697 | } |
| 698 | spin_unlock_irq(&adapter->driver_lock); |
| 699 | libertas_process_event(priv); |
| 700 | } else |
| 701 | spin_unlock_irq(&adapter->driver_lock); |
| 702 | |
| 703 | /* Check if we need to confirm Sleep Request received previously */ |
| 704 | if (adapter->psstate == PS_STATE_PRE_SLEEP) { |
| 705 | if (!priv->wlan_dev.dnld_sent && !adapter->cur_cmd) { |
| 706 | if (adapter->connect_status == |
| 707 | libertas_connected) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 708 | lbs_deb_thread( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 709 | "main_thread: PRE_SLEEP--intcounter=%d currenttxskb=%p " |
| 710 | "dnld_sent=%d cur_cmd=%p, confirm now\n", |
| 711 | adapter->intcounter, |
| 712 | adapter->currenttxskb, |
| 713 | priv->wlan_dev.dnld_sent, |
| 714 | adapter->cur_cmd); |
| 715 | |
| 716 | libertas_ps_confirm_sleep(priv, |
| 717 | (u16) adapter->psmode); |
| 718 | } else { |
| 719 | /* workaround for firmware sending |
| 720 | * deauth/linkloss event immediately |
| 721 | * after sleep request, remove this |
| 722 | * after firmware fixes it |
| 723 | */ |
| 724 | adapter->psstate = PS_STATE_AWAKE; |
| 725 | lbs_pr_alert( |
| 726 | "main-thread: ignore PS_SleepConfirm in non-connected state\n"); |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | /* The PS state is changed during processing of Sleep Request |
| 732 | * event above |
| 733 | */ |
| 734 | if ((priv->adapter->psstate == PS_STATE_SLEEP) || |
| 735 | (priv->adapter->psstate == PS_STATE_PRE_SLEEP)) |
| 736 | continue; |
| 737 | |
| 738 | /* Execute the next command */ |
| 739 | if (!priv->wlan_dev.dnld_sent && !priv->adapter->cur_cmd) |
| 740 | libertas_execute_next_command(priv); |
| 741 | |
| 742 | /* Wake-up command waiters which can't sleep in |
| 743 | * libertas_prepare_and_send_command |
| 744 | */ |
| 745 | if (!adapter->nr_cmd_pending) |
| 746 | wake_up_all(&adapter->cmd_pending); |
| 747 | |
| 748 | libertas_tx_runqueue(priv); |
| 749 | } |
| 750 | |
| 751 | del_timer(&adapter->command_timer); |
| 752 | adapter->nr_cmd_pending = 0; |
| 753 | wake_up_all(&adapter->cmd_pending); |
| 754 | wlan_deactivate_thread(thread); |
| 755 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 756 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 757 | return 0; |
| 758 | } |
| 759 | |
| 760 | /** |
| 761 | * @brief This function adds the card. it will probe the |
| 762 | * card, allocate the wlan_priv and initialize the device. |
| 763 | * |
| 764 | * @param card A pointer to card |
| 765 | * @return A pointer to wlan_private structure |
| 766 | */ |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 767 | wlan_private *libertas_add_card(void *card) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 768 | { |
| 769 | struct net_device *dev = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 770 | wlan_private *priv = NULL; |
| 771 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 772 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 773 | |
| 774 | /* Allocate an Ethernet device and register it */ |
| 775 | if (!(dev = alloc_etherdev(sizeof(wlan_private)))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 776 | lbs_pr_err("init ethX device failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 777 | return NULL; |
| 778 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 779 | priv = dev->priv; |
| 780 | |
| 781 | /* allocate buffer for wlan_adapter */ |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 782 | if (!(priv->adapter = kzalloc(sizeof(wlan_adapter), GFP_KERNEL))) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 783 | lbs_pr_err("allocate buffer for wlan_adapter failed\n"); |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 784 | goto err_kzalloc; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 785 | } |
| 786 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 787 | priv->wlan_dev.netdev = dev; |
| 788 | priv->wlan_dev.card = card; |
| 789 | priv->mesh_open = 0; |
| 790 | priv->infra_open = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 791 | |
| 792 | SET_MODULE_OWNER(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 793 | |
| 794 | /* Setup the OS Interface to our functions */ |
| 795 | dev->open = wlan_open; |
| 796 | dev->hard_start_xmit = wlan_pre_start_xmit; |
| 797 | dev->stop = wlan_close; |
| 798 | dev->do_ioctl = libertas_do_ioctl; |
| 799 | dev->set_mac_address = wlan_set_mac_address; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 800 | dev->tx_timeout = wlan_tx_timeout; |
| 801 | dev->get_stats = wlan_get_stats; |
Holger Schurig | fb3dddf | 2007-05-25 11:58:22 -0400 | [diff] [blame] | 802 | dev->watchdog_timeo = 5 * HZ; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 803 | dev->ethtool_ops = &libertas_ethtool_ops; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 804 | #ifdef WIRELESS_EXT |
| 805 | dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 806 | #endif |
| 807 | #define NETIF_F_DYNALLOC 16 |
| 808 | dev->features |= NETIF_F_DYNALLOC; |
| 809 | dev->flags |= IFF_BROADCAST | IFF_MULTICAST; |
| 810 | dev->set_multicast_list = wlan_set_multicast_list; |
| 811 | |
| 812 | INIT_LIST_HEAD(&priv->adapter->cmdfreeq); |
| 813 | INIT_LIST_HEAD(&priv->adapter->cmdpendingq); |
| 814 | |
| 815 | spin_lock_init(&priv->adapter->driver_lock); |
| 816 | init_waitqueue_head(&priv->adapter->cmd_pending); |
| 817 | priv->adapter->nr_cmd_pending = 0; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 818 | goto done; |
| 819 | |
| 820 | err_kzalloc: |
| 821 | free_netdev(dev); |
Marcelo Tosatti | 6a81215 | 2007-05-25 12:09:13 -0400 | [diff] [blame] | 822 | priv = NULL; |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 823 | done: |
| 824 | lbs_deb_leave_args(LBS_DEB_NET, "priv %p", priv); |
| 825 | return priv; |
| 826 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 827 | EXPORT_SYMBOL_GPL(libertas_add_card); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 828 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 829 | int libertas_activate_card(wlan_private *priv, char *fw_name) |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 830 | { |
| 831 | struct net_device *dev = priv->wlan_dev.netdev; |
| 832 | int ret = -1; |
| 833 | |
| 834 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 835 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 836 | lbs_deb_thread("Starting kthread...\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 837 | priv->mainthread.priv = priv; |
| 838 | wlan_create_thread(wlan_service_main_thread, |
| 839 | &priv->mainthread, "wlan_main_service"); |
| 840 | |
| 841 | priv->assoc_thread = |
| 842 | create_singlethread_workqueue("libertas_assoc"); |
Holger Schurig | eb3ce63 | 2007-05-24 23:41:15 -0400 | [diff] [blame] | 843 | INIT_DELAYED_WORK(&priv->assoc_work, libertas_association_worker); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 844 | |
| 845 | /* |
| 846 | * Register the device. Fillup the private data structure with |
| 847 | * relevant information from the card and request for the required |
| 848 | * IRQ. |
| 849 | */ |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 850 | if (priv->hw_register_dev(priv) < 0) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 851 | lbs_pr_err("failed to register WLAN device\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 852 | goto err_registerdev; |
| 853 | } |
| 854 | |
| 855 | /* init FW and HW */ |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 856 | if (fw_name && libertas_init_fw(priv, fw_name)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 857 | lbs_pr_err("firmware init failed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 858 | goto err_registerdev; |
| 859 | } |
| 860 | |
| 861 | if (register_netdev(dev)) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 862 | lbs_pr_err("cannot register ethX device\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 863 | goto err_init_fw; |
| 864 | } |
| 865 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 866 | lbs_pr_info("%s: Marvell WLAN 802.11 adapter\n", dev->name); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 867 | |
| 868 | libertas_debugfs_init_one(priv, dev); |
| 869 | |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 870 | ret = 0; |
| 871 | goto done; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 872 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 873 | err_init_fw: |
Holger Schurig | 208fdd2 | 2007-05-25 12:17:06 -0400 | [diff] [blame] | 874 | priv->hw_unregister_dev(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 875 | err_registerdev: |
| 876 | destroy_workqueue(priv->assoc_thread); |
| 877 | /* Stop the thread servicing the interrupts */ |
| 878 | wake_up_interruptible(&priv->mainthread.waitq); |
| 879 | wlan_terminate_thread(&priv->mainthread); |
| 880 | kfree(priv->adapter); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 881 | free_netdev(dev); |
Holger Schurig | 32a74b7 | 2007-05-25 12:04:31 -0400 | [diff] [blame] | 882 | done: |
| 883 | lbs_deb_leave_args(LBS_DEB_NET, "ret %d", ret); |
| 884 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 885 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 886 | EXPORT_SYMBOL_GPL(libertas_activate_card); |
| 887 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 888 | |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 889 | /** |
| 890 | * @brief This function adds mshX interface |
| 891 | * |
| 892 | * @param priv A pointer to the wlan_private structure |
| 893 | * @return 0 if successful, -X otherwise |
| 894 | */ |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 895 | int libertas_add_mesh(wlan_private *priv) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 896 | { |
| 897 | struct net_device *mesh_dev = NULL; |
| 898 | int ret = 0; |
| 899 | |
| 900 | lbs_deb_enter(LBS_DEB_MESH); |
| 901 | |
| 902 | /* Allocate a virtual mesh device */ |
| 903 | if (!(mesh_dev = alloc_netdev(0, "msh%d", ether_setup))) { |
| 904 | lbs_deb_mesh("init mshX device failed\n"); |
| 905 | ret = -ENOMEM; |
| 906 | goto done; |
| 907 | } |
| 908 | mesh_dev->priv = priv; |
| 909 | priv->mesh_dev = mesh_dev; |
| 910 | |
| 911 | SET_MODULE_OWNER(mesh_dev); |
| 912 | |
| 913 | mesh_dev->open = mesh_open; |
| 914 | mesh_dev->hard_start_xmit = mesh_pre_start_xmit; |
| 915 | mesh_dev->stop = mesh_close; |
| 916 | mesh_dev->do_ioctl = libertas_do_ioctl; |
| 917 | mesh_dev->get_stats = wlan_get_stats; |
| 918 | mesh_dev->ethtool_ops = &libertas_ethtool_ops; |
| 919 | memcpy(mesh_dev->dev_addr, priv->wlan_dev.netdev->dev_addr, |
| 920 | sizeof(priv->wlan_dev.netdev->dev_addr)); |
| 921 | |
| 922 | #ifdef WIRELESS_EXT |
| 923 | mesh_dev->wireless_handlers = (struct iw_handler_def *)&libertas_handler_def; |
| 924 | #endif |
| 925 | #define NETIF_F_DYNALLOC 16 |
| 926 | |
| 927 | /* Register virtual mesh interface */ |
| 928 | ret = register_netdev(mesh_dev); |
| 929 | if (ret) { |
| 930 | lbs_pr_err("cannot register mshX virtual interface\n"); |
| 931 | goto err_free; |
| 932 | } |
| 933 | |
| 934 | ret = device_create_file(&(mesh_dev->dev), &dev_attr_libertas_mpp); |
| 935 | if (ret) |
| 936 | goto err_unregister; |
| 937 | |
| 938 | /* Everything successful */ |
| 939 | ret = 0; |
| 940 | goto done; |
| 941 | |
| 942 | |
| 943 | err_unregister: |
| 944 | unregister_netdev(mesh_dev); |
| 945 | |
| 946 | err_free: |
| 947 | free_netdev(mesh_dev); |
| 948 | |
| 949 | done: |
| 950 | lbs_deb_leave_args(LBS_DEB_MESH, "ret %d", ret); |
| 951 | return ret; |
| 952 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 953 | EXPORT_SYMBOL_GPL(libertas_add_mesh); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 954 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 955 | static void wake_pending_cmdnodes(wlan_private *priv) |
| 956 | { |
| 957 | struct cmd_ctrl_node *cmdnode; |
| 958 | unsigned long flags; |
| 959 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 960 | lbs_deb_enter(LBS_DEB_CMD); |
| 961 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 962 | spin_lock_irqsave(&priv->adapter->driver_lock, flags); |
| 963 | list_for_each_entry(cmdnode, &priv->adapter->cmdpendingq, list) { |
| 964 | cmdnode->cmdwaitqwoken = 1; |
| 965 | wake_up_interruptible(&cmdnode->cmdwait_q); |
| 966 | } |
| 967 | spin_unlock_irqrestore(&priv->adapter->driver_lock, flags); |
| 968 | } |
| 969 | |
| 970 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 971 | int libertas_remove_card(wlan_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 972 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 973 | wlan_adapter *adapter; |
| 974 | struct net_device *dev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 975 | union iwreq_data wrqu; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 976 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 977 | lbs_deb_enter(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 978 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 979 | if (!priv) |
| 980 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 981 | |
| 982 | adapter = priv->adapter; |
| 983 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 984 | if (!adapter) |
| 985 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 986 | |
| 987 | dev = priv->wlan_dev.netdev; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 988 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 989 | netif_stop_queue(priv->wlan_dev.netdev); |
| 990 | netif_carrier_off(priv->wlan_dev.netdev); |
| 991 | |
| 992 | wake_pending_cmdnodes(priv); |
| 993 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 994 | unregister_netdev(dev); |
| 995 | |
| 996 | cancel_delayed_work(&priv->assoc_work); |
| 997 | destroy_workqueue(priv->assoc_thread); |
| 998 | |
| 999 | if (adapter->psmode == wlan802_11powermodemax_psp) { |
| 1000 | adapter->psmode = wlan802_11powermodecam; |
| 1001 | libertas_ps_wakeup(priv, cmd_option_waitforrsp); |
| 1002 | } |
| 1003 | |
| 1004 | memset(wrqu.ap_addr.sa_data, 0xaa, ETH_ALEN); |
| 1005 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; |
| 1006 | wireless_send_event(priv->wlan_dev.netdev, SIOCGIWAP, &wrqu, NULL); |
| 1007 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1008 | adapter->surpriseremoved = 1; |
| 1009 | |
| 1010 | /* Stop the thread servicing the interrupts */ |
| 1011 | wlan_terminate_thread(&priv->mainthread); |
| 1012 | |
| 1013 | libertas_debugfs_remove_one(priv); |
| 1014 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1015 | lbs_deb_net("free adapter\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1016 | libertas_free_adapter(priv); |
| 1017 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1018 | lbs_deb_net("unregister finish\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1019 | |
| 1020 | priv->wlan_dev.netdev = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1021 | free_netdev(dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1022 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1023 | out: |
| 1024 | lbs_deb_leave(LBS_DEB_NET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1025 | return 0; |
| 1026 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1027 | EXPORT_SYMBOL_GPL(libertas_remove_card); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1028 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1029 | |
| 1030 | void libertas_remove_mesh(wlan_private *priv) |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1031 | { |
| 1032 | struct net_device *mesh_dev; |
| 1033 | |
| 1034 | lbs_deb_enter(LBS_DEB_NET); |
| 1035 | |
| 1036 | if (!priv) |
| 1037 | goto out; |
| 1038 | |
| 1039 | mesh_dev = priv->mesh_dev; |
| 1040 | |
| 1041 | netif_stop_queue(mesh_dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1042 | netif_carrier_off(priv->mesh_dev); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1043 | |
| 1044 | device_remove_file(&(mesh_dev->dev), &dev_attr_libertas_mpp); |
| 1045 | unregister_netdev(mesh_dev); |
| 1046 | |
| 1047 | priv->mesh_dev = NULL ; |
| 1048 | free_netdev(mesh_dev); |
| 1049 | |
| 1050 | out: |
| 1051 | lbs_deb_leave(LBS_DEB_NET); |
| 1052 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1053 | EXPORT_SYMBOL_GPL(libertas_remove_mesh); |
Holger Schurig | 78523da | 2007-05-25 11:49:19 -0400 | [diff] [blame] | 1054 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1055 | /** |
| 1056 | * @brief This function finds the CFP in |
| 1057 | * region_cfp_table based on region and band parameter. |
| 1058 | * |
| 1059 | * @param region The region code |
| 1060 | * @param band The band |
| 1061 | * @param cfp_no A pointer to CFP number |
| 1062 | * @return A pointer to CFP |
| 1063 | */ |
| 1064 | struct chan_freq_power *libertas_get_region_cfp_table(u8 region, u8 band, int *cfp_no) |
| 1065 | { |
| 1066 | int i, end; |
| 1067 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1068 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1069 | |
| 1070 | end = sizeof(region_cfp_table)/sizeof(struct region_cfp_table); |
| 1071 | |
| 1072 | for (i = 0; i < end ; i++) { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1073 | lbs_deb_main("region_cfp_table[i].region=%d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1074 | region_cfp_table[i].region); |
| 1075 | if (region_cfp_table[i].region == region) { |
| 1076 | *cfp_no = region_cfp_table[i].cfp_no_BG; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1077 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1078 | return region_cfp_table[i].cfp_BG; |
| 1079 | } |
| 1080 | } |
| 1081 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1082 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret NULL"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1083 | return NULL; |
| 1084 | } |
| 1085 | |
| 1086 | int libertas_set_regiontable(wlan_private * priv, u8 region, u8 band) |
| 1087 | { |
| 1088 | wlan_adapter *adapter = priv->adapter; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1089 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1090 | int i = 0; |
| 1091 | |
| 1092 | struct chan_freq_power *cfp; |
| 1093 | int cfp_no; |
| 1094 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1095 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1096 | |
| 1097 | memset(adapter->region_channel, 0, sizeof(adapter->region_channel)); |
| 1098 | |
| 1099 | { |
| 1100 | cfp = libertas_get_region_cfp_table(region, band, &cfp_no); |
| 1101 | if (cfp != NULL) { |
| 1102 | adapter->region_channel[i].nrcfp = cfp_no; |
| 1103 | adapter->region_channel[i].CFP = cfp; |
| 1104 | } else { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1105 | lbs_deb_main("wrong region code %#x in band B/G\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1106 | region); |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1107 | ret = -1; |
| 1108 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1109 | } |
| 1110 | adapter->region_channel[i].valid = 1; |
| 1111 | adapter->region_channel[i].region = region; |
| 1112 | adapter->region_channel[i].band = band; |
| 1113 | i++; |
| 1114 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1115 | out: |
| 1116 | lbs_deb_leave_args(LBS_DEB_MAIN, "ret %d", ret); |
| 1117 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * @brief This function handles the interrupt. it will change PS |
| 1122 | * state if applicable. it will wake up main_thread to handle |
| 1123 | * the interrupt event as well. |
| 1124 | * |
| 1125 | * @param dev A pointer to net_device structure |
| 1126 | * @return n/a |
| 1127 | */ |
| 1128 | void libertas_interrupt(struct net_device *dev) |
| 1129 | { |
| 1130 | wlan_private *priv = dev->priv; |
| 1131 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1132 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1133 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1134 | lbs_deb_thread("libertas_interrupt: intcounter=%d\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1135 | priv->adapter->intcounter); |
| 1136 | |
| 1137 | priv->adapter->intcounter++; |
| 1138 | |
| 1139 | if (priv->adapter->psstate == PS_STATE_SLEEP) { |
| 1140 | priv->adapter->psstate = PS_STATE_AWAKE; |
| 1141 | netif_wake_queue(dev); |
Javier Cardona | 51d84f5 | 2007-05-25 12:06:56 -0400 | [diff] [blame] | 1142 | netif_wake_queue(priv->mesh_dev); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | wake_up_interruptible(&priv->mainthread.waitq); |
| 1146 | |
Holger Schurig | ed37b51 | 2007-05-25 11:52:42 -0400 | [diff] [blame] | 1147 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1148 | } |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1149 | EXPORT_SYMBOL_GPL(libertas_interrupt); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1150 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1151 | static int libertas_init_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1152 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1153 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1154 | libertas_debugfs_init(); |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1155 | lbs_deb_leave(LBS_DEB_MAIN); |
| 1156 | return 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1157 | } |
| 1158 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1159 | static void libertas_exit_module(void) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1160 | { |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1161 | lbs_deb_enter(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1162 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1163 | libertas_debugfs_remove(); |
| 1164 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1165 | lbs_deb_leave(LBS_DEB_MAIN); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1166 | } |
| 1167 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1168 | module_init(libertas_init_module); |
| 1169 | module_exit(libertas_exit_module); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1170 | |
Holger Schurig | 084708b | 2007-05-25 12:37:58 -0400 | [diff] [blame^] | 1171 | MODULE_DESCRIPTION("Libertas WLAN Driver Library"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1172 | MODULE_AUTHOR("Marvell International Ltd."); |
| 1173 | MODULE_LICENSE("GPL"); |