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