Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Common code for mac80211 Prism54 drivers |
| 4 | * |
| 5 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> |
| 6 | * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de> |
| 7 | * |
| 8 | * Based on the islsm (softmac prism54) driver, which is: |
| 9 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/firmware.h> |
| 18 | #include <linux/etherdevice.h> |
| 19 | |
| 20 | #include <net/mac80211.h> |
| 21 | |
| 22 | #include "p54.h" |
| 23 | #include "p54common.h" |
| 24 | |
| 25 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); |
| 26 | MODULE_DESCRIPTION("Softmac Prism54 common code"); |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | MODULE_ALIAS("prism54common"); |
| 29 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 30 | static struct ieee80211_rate p54_rates[] = { |
| 31 | { .bitrate = 10, .hw_value = 0, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 32 | { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 33 | { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 34 | { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 35 | { .bitrate = 60, .hw_value = 4, }, |
| 36 | { .bitrate = 90, .hw_value = 5, }, |
| 37 | { .bitrate = 120, .hw_value = 6, }, |
| 38 | { .bitrate = 180, .hw_value = 7, }, |
| 39 | { .bitrate = 240, .hw_value = 8, }, |
| 40 | { .bitrate = 360, .hw_value = 9, }, |
| 41 | { .bitrate = 480, .hw_value = 10, }, |
| 42 | { .bitrate = 540, .hw_value = 11, }, |
| 43 | }; |
| 44 | |
| 45 | static struct ieee80211_channel p54_channels[] = { |
| 46 | { .center_freq = 2412, .hw_value = 1, }, |
| 47 | { .center_freq = 2417, .hw_value = 2, }, |
| 48 | { .center_freq = 2422, .hw_value = 3, }, |
| 49 | { .center_freq = 2427, .hw_value = 4, }, |
| 50 | { .center_freq = 2432, .hw_value = 5, }, |
| 51 | { .center_freq = 2437, .hw_value = 6, }, |
| 52 | { .center_freq = 2442, .hw_value = 7, }, |
| 53 | { .center_freq = 2447, .hw_value = 8, }, |
| 54 | { .center_freq = 2452, .hw_value = 9, }, |
| 55 | { .center_freq = 2457, .hw_value = 10, }, |
| 56 | { .center_freq = 2462, .hw_value = 11, }, |
| 57 | { .center_freq = 2467, .hw_value = 12, }, |
| 58 | { .center_freq = 2472, .hw_value = 13, }, |
| 59 | { .center_freq = 2484, .hw_value = 14, }, |
| 60 | }; |
| 61 | |
Johannes Berg | c2976ab | 2008-02-20 12:08:12 +0100 | [diff] [blame] | 62 | static struct ieee80211_supported_band band_2GHz = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 63 | .channels = p54_channels, |
| 64 | .n_channels = ARRAY_SIZE(p54_channels), |
| 65 | .bitrates = p54_rates, |
| 66 | .n_bitrates = ARRAY_SIZE(p54_rates), |
| 67 | }; |
| 68 | |
| 69 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 70 | void p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw) |
| 71 | { |
| 72 | struct p54_common *priv = dev->priv; |
| 73 | struct bootrec_exp_if *exp_if; |
| 74 | struct bootrec *bootrec; |
| 75 | u32 *data = (u32 *)fw->data; |
| 76 | u32 *end_data = (u32 *)fw->data + (fw->size >> 2); |
| 77 | u8 *fw_version = NULL; |
| 78 | size_t len; |
| 79 | int i; |
| 80 | |
| 81 | if (priv->rx_start) |
| 82 | return; |
| 83 | |
| 84 | while (data < end_data && *data) |
| 85 | data++; |
| 86 | |
| 87 | while (data < end_data && !*data) |
| 88 | data++; |
| 89 | |
| 90 | bootrec = (struct bootrec *) data; |
| 91 | |
| 92 | while (bootrec->data <= end_data && |
| 93 | (bootrec->data + (len = le32_to_cpu(bootrec->len))) <= end_data) { |
| 94 | u32 code = le32_to_cpu(bootrec->code); |
| 95 | switch (code) { |
| 96 | case BR_CODE_COMPONENT_ID: |
Al Viro | dc73c62 | 2007-12-21 23:49:02 -0500 | [diff] [blame] | 97 | switch (be32_to_cpu(*(__be32 *)bootrec->data)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 98 | case FW_FMAC: |
| 99 | printk(KERN_INFO "p54: FreeMAC firmware\n"); |
| 100 | break; |
| 101 | case FW_LM20: |
| 102 | printk(KERN_INFO "p54: LM20 firmware\n"); |
| 103 | break; |
| 104 | case FW_LM86: |
| 105 | printk(KERN_INFO "p54: LM86 firmware\n"); |
| 106 | break; |
| 107 | case FW_LM87: |
| 108 | printk(KERN_INFO "p54: LM87 firmware - not supported yet!\n"); |
| 109 | break; |
| 110 | default: |
| 111 | printk(KERN_INFO "p54: unknown firmware\n"); |
| 112 | break; |
| 113 | } |
| 114 | break; |
| 115 | case BR_CODE_COMPONENT_VERSION: |
| 116 | /* 24 bytes should be enough for all firmwares */ |
| 117 | if (strnlen((unsigned char*)bootrec->data, 24) < 24) |
| 118 | fw_version = (unsigned char*)bootrec->data; |
| 119 | break; |
| 120 | case BR_CODE_DESCR: |
Al Viro | dc73c62 | 2007-12-21 23:49:02 -0500 | [diff] [blame] | 121 | priv->rx_start = le32_to_cpu(((__le32 *)bootrec->data)[1]); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 122 | /* FIXME add sanity checking */ |
Al Viro | dc73c62 | 2007-12-21 23:49:02 -0500 | [diff] [blame] | 123 | priv->rx_end = le32_to_cpu(((__le32 *)bootrec->data)[2]) - 0x3500; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 124 | break; |
| 125 | case BR_CODE_EXPOSED_IF: |
| 126 | exp_if = (struct bootrec_exp_if *) bootrec->data; |
| 127 | for (i = 0; i < (len * sizeof(*exp_if) / 4); i++) |
Al Viro | dc73c62 | 2007-12-21 23:49:02 -0500 | [diff] [blame] | 128 | if (exp_if[i].if_id == cpu_to_le16(0x1a)) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 129 | priv->fw_var = le16_to_cpu(exp_if[i].variant); |
| 130 | break; |
| 131 | case BR_CODE_DEPENDENT_IF: |
| 132 | break; |
| 133 | case BR_CODE_END_OF_BRA: |
| 134 | case LEGACY_BR_CODE_END_OF_BRA: |
| 135 | end_data = NULL; |
| 136 | break; |
| 137 | default: |
| 138 | break; |
| 139 | } |
| 140 | bootrec = (struct bootrec *)&bootrec->data[len]; |
| 141 | } |
| 142 | |
| 143 | if (fw_version) |
| 144 | printk(KERN_INFO "p54: FW rev %s - Softmac protocol %x.%x\n", |
| 145 | fw_version, priv->fw_var >> 8, priv->fw_var & 0xff); |
| 146 | |
| 147 | if (priv->fw_var >= 0x300) { |
| 148 | /* Firmware supports QoS, use it! */ |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 149 | priv->tx_stats[0].limit = 3; |
| 150 | priv->tx_stats[1].limit = 4; |
| 151 | priv->tx_stats[2].limit = 3; |
| 152 | priv->tx_stats[3].limit = 1; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 153 | dev->queues = 4; |
| 154 | } |
| 155 | } |
| 156 | EXPORT_SYMBOL_GPL(p54_parse_firmware); |
| 157 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 158 | static int p54_convert_rev0(struct ieee80211_hw *dev, |
| 159 | struct pda_pa_curve_data *curve_data) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 160 | { |
| 161 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 162 | struct p54_pa_curve_data_sample *dst; |
| 163 | struct pda_pa_curve_data_sample_rev0 *src; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 164 | size_t cd_len = sizeof(*curve_data) + |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 165 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 166 | curve_data->channels; |
| 167 | unsigned int i, j; |
| 168 | void *source, *target; |
| 169 | |
| 170 | priv->curve_data = kmalloc(cd_len, GFP_KERNEL); |
| 171 | if (!priv->curve_data) |
| 172 | return -ENOMEM; |
| 173 | |
| 174 | memcpy(priv->curve_data, curve_data, sizeof(*curve_data)); |
| 175 | source = curve_data->data; |
| 176 | target = priv->curve_data->data; |
| 177 | for (i = 0; i < curve_data->channels; i++) { |
| 178 | __le16 *freq = source; |
| 179 | source += sizeof(__le16); |
| 180 | *((__le16 *)target) = *freq; |
| 181 | target += sizeof(__le16); |
| 182 | for (j = 0; j < curve_data->points_per_channel; j++) { |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 183 | dst = target; |
| 184 | src = source; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 185 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 186 | dst->rf_power = src->rf_power; |
| 187 | dst->pa_detector = src->pa_detector; |
| 188 | dst->data_64qam = src->pcv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 189 | /* "invent" the points for the other modulations */ |
| 190 | #define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y) |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 191 | dst->data_16qam = SUB(src->pcv, 12); |
| 192 | dst->data_qpsk = SUB(dst->data_16qam, 12); |
| 193 | dst->data_bpsk = SUB(dst->data_qpsk, 12); |
| 194 | dst->data_barker = SUB(dst->data_bpsk, 14); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 195 | #undef SUB |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 196 | target += sizeof(*dst); |
| 197 | source += sizeof(*src); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 204 | static int p54_convert_rev1(struct ieee80211_hw *dev, |
| 205 | struct pda_pa_curve_data *curve_data) |
| 206 | { |
| 207 | struct p54_common *priv = dev->priv; |
| 208 | struct p54_pa_curve_data_sample *dst; |
| 209 | struct pda_pa_curve_data_sample_rev1 *src; |
| 210 | size_t cd_len = sizeof(*curve_data) + |
| 211 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
| 212 | curve_data->channels; |
| 213 | unsigned int i, j; |
| 214 | void *source, *target; |
| 215 | |
| 216 | priv->curve_data = kmalloc(cd_len, GFP_KERNEL); |
| 217 | if (!priv->curve_data) |
| 218 | return -ENOMEM; |
| 219 | |
| 220 | memcpy(priv->curve_data, curve_data, sizeof(*curve_data)); |
| 221 | source = curve_data->data; |
| 222 | target = priv->curve_data->data; |
| 223 | for (i = 0; i < curve_data->channels; i++) { |
| 224 | __le16 *freq = source; |
| 225 | source += sizeof(__le16); |
| 226 | *((__le16 *)target) = *freq; |
| 227 | target += sizeof(__le16); |
| 228 | for (j = 0; j < curve_data->points_per_channel; j++) { |
| 229 | memcpy(target, source, sizeof(*src)); |
| 230 | |
| 231 | target += sizeof(*dst); |
| 232 | source += sizeof(*src); |
| 233 | } |
| 234 | source++; |
| 235 | } |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 240 | int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len) |
| 241 | { |
| 242 | struct p54_common *priv = dev->priv; |
| 243 | struct eeprom_pda_wrap *wrap = NULL; |
| 244 | struct pda_entry *entry; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 245 | unsigned int data_len, entry_len; |
| 246 | void *tmp; |
| 247 | int err; |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 248 | u8 *end = (u8 *)eeprom + len; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 249 | |
| 250 | wrap = (struct eeprom_pda_wrap *) eeprom; |
Johannes Berg | 8c28293 | 2008-02-29 13:56:33 +0100 | [diff] [blame] | 251 | entry = (void *)wrap->data + le16_to_cpu(wrap->len); |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 252 | |
| 253 | /* verify that at least the entry length/code fits */ |
| 254 | while ((u8 *)entry <= end - sizeof(*entry)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 255 | entry_len = le16_to_cpu(entry->len); |
| 256 | data_len = ((entry_len - 1) << 1); |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 257 | |
| 258 | /* abort if entry exceeds whole structure */ |
| 259 | if ((u8 *)entry + sizeof(*entry) + data_len > end) |
| 260 | break; |
| 261 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 262 | switch (le16_to_cpu(entry->code)) { |
| 263 | case PDR_MAC_ADDRESS: |
| 264 | SET_IEEE80211_PERM_ADDR(dev, entry->data); |
| 265 | break; |
| 266 | case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS: |
| 267 | if (data_len < 2) { |
| 268 | err = -EINVAL; |
| 269 | goto err; |
| 270 | } |
| 271 | |
| 272 | if (2 + entry->data[1]*sizeof(*priv->output_limit) > data_len) { |
| 273 | err = -EINVAL; |
| 274 | goto err; |
| 275 | } |
| 276 | |
| 277 | priv->output_limit = kmalloc(entry->data[1] * |
| 278 | sizeof(*priv->output_limit), GFP_KERNEL); |
| 279 | |
| 280 | if (!priv->output_limit) { |
| 281 | err = -ENOMEM; |
| 282 | goto err; |
| 283 | } |
| 284 | |
| 285 | memcpy(priv->output_limit, &entry->data[2], |
| 286 | entry->data[1]*sizeof(*priv->output_limit)); |
| 287 | priv->output_limit_len = entry->data[1]; |
| 288 | break; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 289 | case PDR_PRISM_PA_CAL_CURVE_DATA: { |
| 290 | struct pda_pa_curve_data *curve_data = |
| 291 | (struct pda_pa_curve_data *)entry->data; |
| 292 | if (data_len < sizeof(*curve_data)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 293 | err = -EINVAL; |
| 294 | goto err; |
| 295 | } |
| 296 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 297 | switch (curve_data->cal_method_rev) { |
| 298 | case 0: |
| 299 | err = p54_convert_rev0(dev, curve_data); |
| 300 | break; |
| 301 | case 1: |
| 302 | err = p54_convert_rev1(dev, curve_data); |
| 303 | break; |
| 304 | default: |
| 305 | printk(KERN_ERR "p54: unknown curve data " |
| 306 | "revision %d\n", |
| 307 | curve_data->cal_method_rev); |
| 308 | err = -ENODEV; |
| 309 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 310 | } |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 311 | if (err) |
| 312 | goto err; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 313 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 314 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 315 | case PDR_PRISM_ZIF_TX_IQ_CALIBRATION: |
| 316 | priv->iq_autocal = kmalloc(data_len, GFP_KERNEL); |
| 317 | if (!priv->iq_autocal) { |
| 318 | err = -ENOMEM; |
| 319 | goto err; |
| 320 | } |
| 321 | |
| 322 | memcpy(priv->iq_autocal, entry->data, data_len); |
| 323 | priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry); |
| 324 | break; |
| 325 | case PDR_INTERFACE_LIST: |
| 326 | tmp = entry->data; |
| 327 | while ((u8 *)tmp < entry->data + data_len) { |
| 328 | struct bootrec_exp_if *exp_if = tmp; |
| 329 | if (le16_to_cpu(exp_if->if_id) == 0xF) |
| 330 | priv->rxhw = exp_if->variant & cpu_to_le16(0x07); |
| 331 | tmp += sizeof(struct bootrec_exp_if); |
| 332 | } |
| 333 | break; |
| 334 | case PDR_HARDWARE_PLATFORM_COMPONENT_ID: |
| 335 | priv->version = *(u8 *)(entry->data + 1); |
| 336 | break; |
| 337 | case PDR_END: |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 338 | /* make it overrun */ |
| 339 | entry_len = len; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 340 | break; |
Florian Fainelli | 58e3073 | 2008-02-25 17:51:53 +0100 | [diff] [blame] | 341 | default: |
| 342 | printk(KERN_INFO "p54: unknown eeprom code : 0x%x\n", |
| 343 | le16_to_cpu(entry->code)); |
| 344 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | entry = (void *)entry + (entry_len + 1)*2; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | if (!priv->iq_autocal || !priv->output_limit || !priv->curve_data) { |
| 351 | printk(KERN_ERR "p54: not all required entries found in eeprom!\n"); |
| 352 | err = -EINVAL; |
| 353 | goto err; |
| 354 | } |
| 355 | |
| 356 | return 0; |
| 357 | |
| 358 | err: |
| 359 | if (priv->iq_autocal) { |
| 360 | kfree(priv->iq_autocal); |
| 361 | priv->iq_autocal = NULL; |
| 362 | } |
| 363 | |
| 364 | if (priv->output_limit) { |
| 365 | kfree(priv->output_limit); |
| 366 | priv->output_limit = NULL; |
| 367 | } |
| 368 | |
| 369 | if (priv->curve_data) { |
| 370 | kfree(priv->curve_data); |
| 371 | priv->curve_data = NULL; |
| 372 | } |
| 373 | |
| 374 | printk(KERN_ERR "p54: eeprom parse failed!\n"); |
| 375 | return err; |
| 376 | } |
| 377 | EXPORT_SYMBOL_GPL(p54_parse_eeprom); |
| 378 | |
| 379 | void p54_fill_eeprom_readback(struct p54_control_hdr *hdr) |
| 380 | { |
| 381 | struct p54_eeprom_lm86 *eeprom_hdr; |
| 382 | |
| 383 | hdr->magic1 = cpu_to_le16(0x8000); |
| 384 | hdr->len = cpu_to_le16(sizeof(*eeprom_hdr) + 0x2000); |
| 385 | hdr->type = cpu_to_le16(P54_CONTROL_TYPE_EEPROM_READBACK); |
| 386 | hdr->retry1 = hdr->retry2 = 0; |
| 387 | eeprom_hdr = (struct p54_eeprom_lm86 *) hdr->data; |
| 388 | eeprom_hdr->offset = 0x0; |
| 389 | eeprom_hdr->len = cpu_to_le16(0x2000); |
| 390 | } |
| 391 | EXPORT_SYMBOL_GPL(p54_fill_eeprom_readback); |
| 392 | |
| 393 | static void p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 394 | { |
| 395 | struct p54_rx_hdr *hdr = (struct p54_rx_hdr *) skb->data; |
| 396 | struct ieee80211_rx_status rx_status = {0}; |
| 397 | u16 freq = le16_to_cpu(hdr->freq); |
| 398 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 399 | rx_status.signal = hdr->rssi; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 400 | /* XX correct? */ |
Larry.Finger@lwfinger.net | 18d7260 | 2008-06-30 10:39:49 -0500 | [diff] [blame] | 401 | rx_status.qual = (100 * hdr->rssi) / 127; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 402 | rx_status.rate_idx = hdr->rate & 0xf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 403 | rx_status.freq = freq; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 404 | rx_status.band = IEEE80211_BAND_2GHZ; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 405 | rx_status.antenna = hdr->antenna; |
| 406 | rx_status.mactime = le64_to_cpu(hdr->timestamp); |
Johannes Berg | 03bffc1 | 2007-12-04 20:33:40 +0100 | [diff] [blame] | 407 | rx_status.flag |= RX_FLAG_TSFT; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 408 | |
| 409 | skb_pull(skb, sizeof(*hdr)); |
| 410 | skb_trim(skb, le16_to_cpu(hdr->len)); |
| 411 | |
| 412 | ieee80211_rx_irqsafe(dev, skb, &rx_status); |
| 413 | } |
| 414 | |
| 415 | static void inline p54_wake_free_queues(struct ieee80211_hw *dev) |
| 416 | { |
| 417 | struct p54_common *priv = dev->priv; |
| 418 | int i; |
| 419 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 420 | for (i = 0; i < dev->queues; i++) |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 421 | if (priv->tx_stats[i].len < priv->tx_stats[i].limit) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 422 | ieee80211_wake_queue(dev, i); |
| 423 | } |
| 424 | |
| 425 | static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 426 | { |
| 427 | struct p54_common *priv = dev->priv; |
| 428 | struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data; |
| 429 | struct p54_frame_sent_hdr *payload = (struct p54_frame_sent_hdr *) hdr->data; |
| 430 | struct sk_buff *entry = (struct sk_buff *) priv->tx_queue.next; |
| 431 | u32 addr = le32_to_cpu(hdr->req_id) - 0x70; |
| 432 | struct memrecord *range = NULL; |
| 433 | u32 freed = 0; |
| 434 | u32 last_addr = priv->rx_start; |
| 435 | |
| 436 | while (entry != (struct sk_buff *)&priv->tx_queue) { |
Johannes Berg | 552fe53 | 2008-05-30 21:07:15 +0200 | [diff] [blame] | 437 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry); |
| 438 | range = (void *)info->driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 439 | if (range->start_addr == addr) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 440 | struct p54_control_hdr *entry_hdr; |
| 441 | struct p54_tx_control_allocdata *entry_data; |
| 442 | int pad = 0; |
| 443 | |
Johannes Berg | 552fe53 | 2008-05-30 21:07:15 +0200 | [diff] [blame] | 444 | if (entry->next != (struct sk_buff *)&priv->tx_queue) { |
| 445 | struct ieee80211_tx_info *ni; |
| 446 | struct memrecord *mr; |
| 447 | |
| 448 | ni = IEEE80211_SKB_CB(entry->next); |
| 449 | mr = (struct memrecord *)ni->driver_data; |
| 450 | freed = mr->start_addr - last_addr; |
| 451 | } else |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 452 | freed = priv->rx_end - last_addr; |
| 453 | |
| 454 | last_addr = range->end_addr; |
| 455 | __skb_unlink(entry, &priv->tx_queue); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 456 | memset(&info->status, 0, sizeof(info->status)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 457 | entry_hdr = (struct p54_control_hdr *) entry->data; |
| 458 | entry_data = (struct p54_tx_control_allocdata *) entry_hdr->data; |
| 459 | if ((entry_hdr->magic1 & cpu_to_le16(0x4000)) != 0) |
| 460 | pad = entry_data->align[0]; |
| 461 | |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 462 | priv->tx_stats[entry_data->hw_queue - 4].len--; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 463 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 464 | if (!(payload->status & 0x01)) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 465 | info->flags |= IEEE80211_TX_STAT_ACK; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 466 | else |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 467 | info->status.excessive_retries = 1; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 468 | } |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 469 | info->status.retry_count = payload->retries - 1; |
| 470 | info->status.ack_signal = le16_to_cpu(payload->ack_rssi); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 471 | skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data)); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 472 | ieee80211_tx_status_irqsafe(dev, entry); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 473 | break; |
| 474 | } else |
| 475 | last_addr = range->end_addr; |
| 476 | entry = entry->next; |
| 477 | } |
| 478 | |
| 479 | if (freed >= IEEE80211_MAX_RTS_THRESHOLD + 0x170 + |
| 480 | sizeof(struct p54_control_hdr)) |
| 481 | p54_wake_free_queues(dev); |
| 482 | } |
| 483 | |
| 484 | static void p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 485 | { |
| 486 | struct p54_control_hdr *hdr = (struct p54_control_hdr *) skb->data; |
| 487 | |
| 488 | switch (le16_to_cpu(hdr->type)) { |
| 489 | case P54_CONTROL_TYPE_TXDONE: |
| 490 | p54_rx_frame_sent(dev, skb); |
| 491 | break; |
| 492 | case P54_CONTROL_TYPE_BBP: |
| 493 | break; |
| 494 | default: |
| 495 | printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n", |
| 496 | wiphy_name(dev->wiphy), le16_to_cpu(hdr->type)); |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* returns zero if skb can be reused */ |
| 502 | int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 503 | { |
| 504 | u8 type = le16_to_cpu(*((__le16 *)skb->data)) >> 8; |
| 505 | switch (type) { |
| 506 | case 0x00: |
| 507 | case 0x01: |
| 508 | p54_rx_data(dev, skb); |
| 509 | return -1; |
| 510 | case 0x4d: |
| 511 | /* TODO: do something better... but then again, I've never seen this happen */ |
| 512 | printk(KERN_ERR "%s: Received fault. Probably need to restart hardware now..\n", |
| 513 | wiphy_name(dev->wiphy)); |
| 514 | break; |
| 515 | case 0x80: |
| 516 | p54_rx_control(dev, skb); |
| 517 | break; |
| 518 | default: |
| 519 | printk(KERN_ERR "%s: unknown frame RXed (0x%02x)\n", |
| 520 | wiphy_name(dev->wiphy), type); |
| 521 | break; |
| 522 | } |
| 523 | return 0; |
| 524 | } |
| 525 | EXPORT_SYMBOL_GPL(p54_rx); |
| 526 | |
| 527 | /* |
| 528 | * So, the firmware is somewhat stupid and doesn't know what places in its |
| 529 | * memory incoming data should go to. By poking around in the firmware, we |
| 530 | * can find some unused memory to upload our packets to. However, data that we |
| 531 | * want the card to TX needs to stay intact until the card has told us that |
| 532 | * it is done with it. This function finds empty places we can upload to and |
| 533 | * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees |
| 534 | * allocated areas. |
| 535 | */ |
| 536 | static void p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 537 | struct p54_control_hdr *data, u32 len) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 538 | { |
| 539 | struct p54_common *priv = dev->priv; |
| 540 | struct sk_buff *entry = priv->tx_queue.next; |
| 541 | struct sk_buff *target_skb = NULL; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 542 | u32 last_addr = priv->rx_start; |
| 543 | u32 largest_hole = 0; |
| 544 | u32 target_addr = priv->rx_start; |
| 545 | unsigned long flags; |
| 546 | unsigned int left; |
| 547 | len = (len + 0x170 + 3) & ~0x3; /* 0x70 headroom, 0x100 tailroom */ |
| 548 | |
| 549 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
| 550 | left = skb_queue_len(&priv->tx_queue); |
| 551 | while (left--) { |
| 552 | u32 hole_size; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 553 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry); |
| 554 | struct memrecord *range = (void *)info->driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 555 | hole_size = range->start_addr - last_addr; |
| 556 | if (!target_skb && hole_size >= len) { |
| 557 | target_skb = entry->prev; |
| 558 | hole_size -= len; |
| 559 | target_addr = last_addr; |
| 560 | } |
| 561 | largest_hole = max(largest_hole, hole_size); |
| 562 | last_addr = range->end_addr; |
| 563 | entry = entry->next; |
| 564 | } |
| 565 | if (!target_skb && priv->rx_end - last_addr >= len) { |
| 566 | target_skb = priv->tx_queue.prev; |
| 567 | largest_hole = max(largest_hole, priv->rx_end - last_addr - len); |
| 568 | if (!skb_queue_empty(&priv->tx_queue)) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 569 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(target_skb); |
| 570 | struct memrecord *range = (void *)info->driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 571 | target_addr = range->end_addr; |
| 572 | } |
| 573 | } else |
| 574 | largest_hole = max(largest_hole, priv->rx_end - last_addr); |
| 575 | |
| 576 | if (skb) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 577 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 578 | struct memrecord *range = (void *)info->driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 579 | range->start_addr = target_addr; |
| 580 | range->end_addr = target_addr + len; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 581 | __skb_queue_after(&priv->tx_queue, target_skb, skb); |
| 582 | if (largest_hole < IEEE80211_MAX_RTS_THRESHOLD + 0x170 + |
| 583 | sizeof(struct p54_control_hdr)) |
| 584 | ieee80211_stop_queues(dev); |
| 585 | } |
| 586 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 587 | |
| 588 | data->req_id = cpu_to_le32(target_addr + 0x70); |
| 589 | } |
| 590 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 591 | static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 592 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 593 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 594 | struct ieee80211_tx_queue_stats *current_queue; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 595 | struct p54_common *priv = dev->priv; |
| 596 | struct p54_control_hdr *hdr; |
Larry Finger | eda0c00 | 2008-08-05 11:23:16 -0500 | [diff] [blame] | 597 | struct ieee80211_hdr *ieee80211hdr = (struct ieee80211_hdr *)skb->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 598 | struct p54_tx_control_allocdata *txhdr; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 599 | size_t padding, len; |
| 600 | u8 rate; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 601 | u8 cts_rate = 0x20; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 602 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 603 | current_queue = &priv->tx_stats[skb_get_queue_mapping(skb)]; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 604 | if (unlikely(current_queue->len > current_queue->limit)) |
| 605 | return NETDEV_TX_BUSY; |
| 606 | current_queue->len++; |
| 607 | current_queue->count++; |
| 608 | if (current_queue->len == current_queue->limit) |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 609 | ieee80211_stop_queue(dev, skb_get_queue_mapping(skb)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 610 | |
| 611 | padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3; |
| 612 | len = skb->len; |
| 613 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 614 | txhdr = (struct p54_tx_control_allocdata *) |
| 615 | skb_push(skb, sizeof(*txhdr) + padding); |
| 616 | hdr = (struct p54_control_hdr *) skb_push(skb, sizeof(*hdr)); |
| 617 | |
| 618 | if (padding) |
| 619 | hdr->magic1 = cpu_to_le16(0x4010); |
| 620 | else |
| 621 | hdr->magic1 = cpu_to_le16(0x0010); |
| 622 | hdr->len = cpu_to_le16(len); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 623 | hdr->type = (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 0 : cpu_to_le16(1); |
| 624 | hdr->retry1 = hdr->retry2 = info->control.retry_limit; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 625 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 626 | /* TODO: add support for alternate retry TX rates */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 627 | rate = ieee80211_get_tx_rate(dev, info)->hw_value; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 628 | if (info->flags & IEEE80211_TX_CTL_SHORT_PREAMBLE) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 629 | rate |= 0x10; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 630 | cts_rate |= 0x10; |
| 631 | } |
| 632 | if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 633 | rate |= 0x40; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 634 | cts_rate |= ieee80211_get_rts_cts_rate(dev, info)->hw_value; |
| 635 | } else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 636 | rate |= 0x20; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 637 | cts_rate |= ieee80211_get_rts_cts_rate(dev, info)->hw_value; |
| 638 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 639 | memset(txhdr->rateset, rate, 8); |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 640 | txhdr->key_type = 0; |
| 641 | txhdr->key_len = 0; |
| 642 | txhdr->hw_queue = skb_get_queue_mapping(skb) + 4; |
| 643 | txhdr->tx_antenna = (info->antenna_sel_tx == 0) ? |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 644 | 2 : info->antenna_sel_tx - 1; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 645 | txhdr->output_power = 0x7f; // HW Maximum |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 646 | txhdr->cts_rate = (info->flags & IEEE80211_TX_CTL_NO_ACK) ? |
| 647 | 0 : cts_rate; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 648 | if (padding) |
| 649 | txhdr->align[0] = padding; |
| 650 | |
Larry Finger | eda0c00 | 2008-08-05 11:23:16 -0500 | [diff] [blame] | 651 | /* FIXME: The sequence that follows is needed for this driver to |
| 652 | * work with mac80211 since "mac80211: fix TX sequence numbers". |
| 653 | * As with the temporary code in rt2x00, changes will be needed |
| 654 | * to get proper sequence numbers on beacons. In addition, this |
| 655 | * patch places the sequence number in the hardware state, which |
| 656 | * limits us to a single virtual state. |
| 657 | */ |
| 658 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) { |
| 659 | if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT) |
| 660 | priv->seqno += 0x10; |
| 661 | ieee80211hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); |
| 662 | ieee80211hdr->seq_ctrl |= cpu_to_le16(priv->seqno); |
| 663 | } |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 664 | /* modifies skb->cb and with it info, so must be last! */ |
| 665 | p54_assign_address(dev, skb, hdr, skb->len); |
| 666 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 667 | priv->tx(dev, hdr, skb->len, 0); |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | static int p54_set_filter(struct ieee80211_hw *dev, u16 filter_type, |
| 672 | const u8 *dst, const u8 *src, u8 antenna, |
| 673 | u32 magic3, u32 magic8, u32 magic9) |
| 674 | { |
| 675 | struct p54_common *priv = dev->priv; |
| 676 | struct p54_control_hdr *hdr; |
| 677 | struct p54_tx_control_filter *filter; |
| 678 | |
| 679 | hdr = kzalloc(sizeof(*hdr) + sizeof(*filter) + |
Michael Wu | ba8007c | 2007-10-13 20:35:05 -0400 | [diff] [blame] | 680 | priv->tx_hdr_len, GFP_ATOMIC); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 681 | if (!hdr) |
| 682 | return -ENOMEM; |
| 683 | |
| 684 | hdr = (void *)hdr + priv->tx_hdr_len; |
| 685 | |
| 686 | filter = (struct p54_tx_control_filter *) hdr->data; |
| 687 | hdr->magic1 = cpu_to_le16(0x8001); |
| 688 | hdr->len = cpu_to_le16(sizeof(*filter)); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 689 | p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*filter)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 690 | hdr->type = cpu_to_le16(P54_CONTROL_TYPE_FILTER_SET); |
| 691 | |
| 692 | filter->filter_type = cpu_to_le16(filter_type); |
| 693 | memcpy(filter->dst, dst, ETH_ALEN); |
| 694 | if (!src) |
| 695 | memset(filter->src, ~0, ETH_ALEN); |
| 696 | else |
| 697 | memcpy(filter->src, src, ETH_ALEN); |
| 698 | filter->antenna = antenna; |
| 699 | filter->magic3 = cpu_to_le32(magic3); |
| 700 | filter->rx_addr = cpu_to_le32(priv->rx_end); |
| 701 | filter->max_rx = cpu_to_le16(0x0620); /* FIXME: for usb ver 1.. maybe */ |
| 702 | filter->rxhw = priv->rxhw; |
| 703 | filter->magic8 = cpu_to_le16(magic8); |
| 704 | filter->magic9 = cpu_to_le16(magic9); |
| 705 | |
| 706 | priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*filter), 1); |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | static int p54_set_freq(struct ieee80211_hw *dev, __le16 freq) |
| 711 | { |
| 712 | struct p54_common *priv = dev->priv; |
| 713 | struct p54_control_hdr *hdr; |
| 714 | struct p54_tx_control_channel *chan; |
| 715 | unsigned int i; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 716 | void *entry; |
| 717 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 718 | hdr = kzalloc(sizeof(*hdr) + sizeof(*chan) + |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 719 | priv->tx_hdr_len, GFP_KERNEL); |
| 720 | if (!hdr) |
| 721 | return -ENOMEM; |
| 722 | |
| 723 | hdr = (void *)hdr + priv->tx_hdr_len; |
| 724 | |
| 725 | chan = (struct p54_tx_control_channel *) hdr->data; |
| 726 | |
| 727 | hdr->magic1 = cpu_to_le16(0x8001); |
| 728 | hdr->len = cpu_to_le16(sizeof(*chan)); |
| 729 | hdr->type = cpu_to_le16(P54_CONTROL_TYPE_CHANNEL_CHANGE); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 730 | p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*chan)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 731 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 732 | chan->flags = cpu_to_le16(0x1); |
| 733 | chan->dwell = cpu_to_le16(0x0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 734 | |
| 735 | for (i = 0; i < priv->iq_autocal_len; i++) { |
| 736 | if (priv->iq_autocal[i].freq != freq) |
| 737 | continue; |
| 738 | |
| 739 | memcpy(&chan->iq_autocal, &priv->iq_autocal[i], |
| 740 | sizeof(*priv->iq_autocal)); |
| 741 | break; |
| 742 | } |
| 743 | if (i == priv->iq_autocal_len) |
| 744 | goto err; |
| 745 | |
| 746 | for (i = 0; i < priv->output_limit_len; i++) { |
| 747 | if (priv->output_limit[i].freq != freq) |
| 748 | continue; |
| 749 | |
| 750 | chan->val_barker = 0x38; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 751 | chan->val_bpsk = chan->dup_bpsk = |
| 752 | priv->output_limit[i].val_bpsk; |
| 753 | chan->val_qpsk = chan->dup_qpsk = |
| 754 | priv->output_limit[i].val_qpsk; |
| 755 | chan->val_16qam = chan->dup_16qam = |
| 756 | priv->output_limit[i].val_16qam; |
| 757 | chan->val_64qam = chan->dup_64qam = |
| 758 | priv->output_limit[i].val_64qam; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 759 | break; |
| 760 | } |
| 761 | if (i == priv->output_limit_len) |
| 762 | goto err; |
| 763 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 764 | entry = priv->curve_data->data; |
| 765 | for (i = 0; i < priv->curve_data->channels; i++) { |
| 766 | if (*((__le16 *)entry) != freq) { |
| 767 | entry += sizeof(__le16); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 768 | entry += sizeof(struct p54_pa_curve_data_sample) * |
| 769 | priv->curve_data->points_per_channel; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 770 | continue; |
| 771 | } |
| 772 | |
| 773 | entry += sizeof(__le16); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 774 | chan->pa_points_per_curve = |
| 775 | min(priv->curve_data->points_per_channel, (u8) 8); |
| 776 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 777 | memcpy(chan->curve_data, entry, sizeof(*chan->curve_data) * |
| 778 | chan->pa_points_per_curve); |
| 779 | break; |
| 780 | } |
| 781 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 782 | chan->rssical_mul = cpu_to_le16(130); |
| 783 | chan->rssical_add = cpu_to_le16(0xfe70); /* -400 */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 784 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame^] | 785 | priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*chan), 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 786 | return 0; |
| 787 | |
| 788 | err: |
| 789 | printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy)); |
| 790 | kfree(hdr); |
| 791 | return -EINVAL; |
| 792 | } |
| 793 | |
| 794 | static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act) |
| 795 | { |
| 796 | struct p54_common *priv = dev->priv; |
| 797 | struct p54_control_hdr *hdr; |
| 798 | struct p54_tx_control_led *led; |
| 799 | |
| 800 | hdr = kzalloc(sizeof(*hdr) + sizeof(*led) + |
| 801 | priv->tx_hdr_len, GFP_KERNEL); |
| 802 | if (!hdr) |
| 803 | return -ENOMEM; |
| 804 | |
| 805 | hdr = (void *)hdr + priv->tx_hdr_len; |
| 806 | hdr->magic1 = cpu_to_le16(0x8001); |
| 807 | hdr->len = cpu_to_le16(sizeof(*led)); |
| 808 | hdr->type = cpu_to_le16(P54_CONTROL_TYPE_LED); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 809 | p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*led)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 810 | |
| 811 | led = (struct p54_tx_control_led *) hdr->data; |
| 812 | led->mode = cpu_to_le16(mode); |
| 813 | led->led_permanent = cpu_to_le16(link); |
| 814 | led->led_temporary = cpu_to_le16(act); |
| 815 | led->duration = cpu_to_le16(1000); |
| 816 | |
| 817 | priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*led), 1); |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 822 | #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 823 | do { \ |
| 824 | queue.aifs = cpu_to_le16(ai_fs); \ |
| 825 | queue.cwmin = cpu_to_le16(cw_min); \ |
| 826 | queue.cwmax = cpu_to_le16(cw_max); \ |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 827 | queue.txop = cpu_to_le16(_txop); \ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 828 | } while(0) |
| 829 | |
| 830 | static void p54_init_vdcf(struct ieee80211_hw *dev) |
| 831 | { |
| 832 | struct p54_common *priv = dev->priv; |
| 833 | struct p54_control_hdr *hdr; |
| 834 | struct p54_tx_control_vdcf *vdcf; |
| 835 | |
| 836 | /* all USB V1 adapters need a extra headroom */ |
| 837 | hdr = (void *)priv->cached_vdcf + priv->tx_hdr_len; |
| 838 | hdr->magic1 = cpu_to_le16(0x8001); |
| 839 | hdr->len = cpu_to_le16(sizeof(*vdcf)); |
| 840 | hdr->type = cpu_to_le16(P54_CONTROL_TYPE_DCFINIT); |
| 841 | hdr->req_id = cpu_to_le32(priv->rx_start); |
| 842 | |
| 843 | vdcf = (struct p54_tx_control_vdcf *) hdr->data; |
| 844 | |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 845 | P54_SET_QUEUE(vdcf->queue[0], 0x0002, 0x0003, 0x0007, 47); |
| 846 | P54_SET_QUEUE(vdcf->queue[1], 0x0002, 0x0007, 0x000f, 94); |
Christian Lamparter | 5200e8c | 2008-02-12 14:02:06 +0100 | [diff] [blame] | 847 | P54_SET_QUEUE(vdcf->queue[2], 0x0003, 0x000f, 0x03ff, 0); |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 848 | P54_SET_QUEUE(vdcf->queue[3], 0x0007, 0x000f, 0x03ff, 0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static void p54_set_vdcf(struct ieee80211_hw *dev) |
| 852 | { |
| 853 | struct p54_common *priv = dev->priv; |
| 854 | struct p54_control_hdr *hdr; |
| 855 | struct p54_tx_control_vdcf *vdcf; |
| 856 | |
| 857 | hdr = (void *)priv->cached_vdcf + priv->tx_hdr_len; |
| 858 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 859 | p54_assign_address(dev, NULL, hdr, sizeof(*hdr) + sizeof(*vdcf)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 860 | |
| 861 | vdcf = (struct p54_tx_control_vdcf *) hdr->data; |
| 862 | |
| 863 | if (dev->conf.flags & IEEE80211_CONF_SHORT_SLOT_TIME) { |
| 864 | vdcf->slottime = 9; |
Christian Lamparter | 5423b2e | 2008-08-07 10:22:28 +0200 | [diff] [blame] | 865 | vdcf->magic1 = 0x10; |
| 866 | vdcf->magic2 = 0x00; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 867 | } else { |
| 868 | vdcf->slottime = 20; |
| 869 | vdcf->magic1 = 0x0a; |
| 870 | vdcf->magic2 = 0x06; |
| 871 | } |
| 872 | |
| 873 | /* (see prism54/isl_oid.h for further details) */ |
| 874 | vdcf->frameburst = cpu_to_le16(0); |
| 875 | |
| 876 | priv->tx(dev, hdr, sizeof(*hdr) + sizeof(*vdcf), 0); |
| 877 | } |
| 878 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 879 | static int p54_start(struct ieee80211_hw *dev) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 880 | { |
| 881 | struct p54_common *priv = dev->priv; |
| 882 | int err; |
| 883 | |
Christian Lamparter | 69bbc7d | 2008-08-13 23:41:45 +0200 | [diff] [blame] | 884 | if (!priv->cached_vdcf) { |
| 885 | priv->cached_vdcf = kzalloc(sizeof(struct p54_tx_control_vdcf)+ |
| 886 | priv->tx_hdr_len + sizeof(struct p54_control_hdr), |
| 887 | GFP_KERNEL); |
| 888 | |
| 889 | if (!priv->cached_vdcf) |
| 890 | return -ENOMEM; |
| 891 | } |
| 892 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 893 | err = priv->open(dev); |
| 894 | if (!err) |
| 895 | priv->mode = IEEE80211_IF_TYPE_MNTR; |
| 896 | |
Christian Lamparter | 69bbc7d | 2008-08-13 23:41:45 +0200 | [diff] [blame] | 897 | p54_init_vdcf(dev); |
| 898 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 899 | return err; |
| 900 | } |
| 901 | |
| 902 | static void p54_stop(struct ieee80211_hw *dev) |
| 903 | { |
| 904 | struct p54_common *priv = dev->priv; |
| 905 | struct sk_buff *skb; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 906 | while ((skb = skb_dequeue(&priv->tx_queue))) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 907 | kfree_skb(skb); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 908 | priv->stop(dev); |
Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 909 | priv->mode = IEEE80211_IF_TYPE_INVALID; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | static int p54_add_interface(struct ieee80211_hw *dev, |
| 913 | struct ieee80211_if_init_conf *conf) |
| 914 | { |
| 915 | struct p54_common *priv = dev->priv; |
| 916 | |
| 917 | if (priv->mode != IEEE80211_IF_TYPE_MNTR) |
| 918 | return -EOPNOTSUPP; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 919 | |
| 920 | switch (conf->type) { |
| 921 | case IEEE80211_IF_TYPE_STA: |
| 922 | priv->mode = conf->type; |
| 923 | break; |
| 924 | default: |
| 925 | return -EOPNOTSUPP; |
| 926 | } |
| 927 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 928 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 929 | |
| 930 | p54_set_filter(dev, 0, priv->mac_addr, NULL, 0, 1, 0, 0xF642); |
| 931 | p54_set_filter(dev, 0, priv->mac_addr, NULL, 1, 0, 0, 0xF642); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 932 | |
| 933 | switch (conf->type) { |
| 934 | case IEEE80211_IF_TYPE_STA: |
| 935 | p54_set_filter(dev, 1, priv->mac_addr, NULL, 0, 0x15F, 0x1F4, 0); |
| 936 | break; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 937 | default: |
| 938 | BUG(); /* impossible */ |
| 939 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | p54_set_leds(dev, 1, 0, 0); |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | static void p54_remove_interface(struct ieee80211_hw *dev, |
| 948 | struct ieee80211_if_init_conf *conf) |
| 949 | { |
| 950 | struct p54_common *priv = dev->priv; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 951 | priv->mode = IEEE80211_IF_TYPE_MNTR; |
| 952 | memset(priv->mac_addr, 0, ETH_ALEN); |
| 953 | p54_set_filter(dev, 0, priv->mac_addr, NULL, 2, 0, 0, 0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | static int p54_config(struct ieee80211_hw *dev, struct ieee80211_conf *conf) |
| 957 | { |
| 958 | int ret; |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 959 | struct p54_common *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 960 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 961 | mutex_lock(&priv->conf_mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 962 | ret = p54_set_freq(dev, cpu_to_le16(conf->channel->center_freq)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 963 | p54_set_vdcf(dev); |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 964 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 965 | return ret; |
| 966 | } |
| 967 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 968 | static int p54_config_interface(struct ieee80211_hw *dev, |
| 969 | struct ieee80211_vif *vif, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 970 | struct ieee80211_if_conf *conf) |
| 971 | { |
| 972 | struct p54_common *priv = dev->priv; |
| 973 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 974 | mutex_lock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 975 | p54_set_filter(dev, 0, priv->mac_addr, conf->bssid, 0, 1, 0, 0xF642); |
| 976 | p54_set_filter(dev, 0, priv->mac_addr, conf->bssid, 2, 0, 0, 0); |
| 977 | p54_set_leds(dev, 1, !is_multicast_ether_addr(conf->bssid), 0); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 978 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 979 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 980 | return 0; |
| 981 | } |
| 982 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 983 | static void p54_configure_filter(struct ieee80211_hw *dev, |
| 984 | unsigned int changed_flags, |
| 985 | unsigned int *total_flags, |
| 986 | int mc_count, struct dev_mc_list *mclist) |
| 987 | { |
| 988 | struct p54_common *priv = dev->priv; |
| 989 | |
| 990 | *total_flags &= FIF_BCN_PRBRESP_PROMISC; |
| 991 | |
| 992 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 993 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
| 994 | p54_set_filter(dev, 0, priv->mac_addr, |
| 995 | NULL, 2, 0, 0, 0); |
| 996 | else |
| 997 | p54_set_filter(dev, 0, priv->mac_addr, |
| 998 | priv->bssid, 2, 0, 0, 0); |
| 999 | } |
| 1000 | } |
| 1001 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1002 | static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1003 | const struct ieee80211_tx_queue_params *params) |
| 1004 | { |
| 1005 | struct p54_common *priv = dev->priv; |
| 1006 | struct p54_tx_control_vdcf *vdcf; |
| 1007 | |
| 1008 | vdcf = (struct p54_tx_control_vdcf *)(((struct p54_control_hdr *) |
| 1009 | ((void *)priv->cached_vdcf + priv->tx_hdr_len))->data); |
| 1010 | |
John W. Linville | 3df5ee6 | 2008-05-01 17:07:32 -0400 | [diff] [blame] | 1011 | if ((params) && !(queue > 4)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1012 | P54_SET_QUEUE(vdcf->queue[queue], params->aifs, |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1013 | params->cw_min, params->cw_max, params->txop); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1014 | } else |
| 1015 | return -EINVAL; |
| 1016 | |
| 1017 | p54_set_vdcf(dev); |
| 1018 | |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | static int p54_get_stats(struct ieee80211_hw *dev, |
| 1023 | struct ieee80211_low_level_stats *stats) |
| 1024 | { |
| 1025 | /* TODO */ |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | static int p54_get_tx_stats(struct ieee80211_hw *dev, |
| 1030 | struct ieee80211_tx_queue_stats *stats) |
| 1031 | { |
| 1032 | struct p54_common *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1033 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 1034 | memcpy(stats, &priv->tx_stats, sizeof(stats[0]) * dev->queues); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1035 | |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | static const struct ieee80211_ops p54_ops = { |
| 1040 | .tx = p54_tx, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1041 | .start = p54_start, |
| 1042 | .stop = p54_stop, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1043 | .add_interface = p54_add_interface, |
| 1044 | .remove_interface = p54_remove_interface, |
| 1045 | .config = p54_config, |
| 1046 | .config_interface = p54_config_interface, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1047 | .configure_filter = p54_configure_filter, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1048 | .conf_tx = p54_conf_tx, |
| 1049 | .get_stats = p54_get_stats, |
| 1050 | .get_tx_stats = p54_get_tx_stats |
| 1051 | }; |
| 1052 | |
| 1053 | struct ieee80211_hw *p54_init_common(size_t priv_data_len) |
| 1054 | { |
| 1055 | struct ieee80211_hw *dev; |
| 1056 | struct p54_common *priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1057 | |
| 1058 | dev = ieee80211_alloc_hw(priv_data_len, &p54_ops); |
| 1059 | if (!dev) |
| 1060 | return NULL; |
| 1061 | |
| 1062 | priv = dev->priv; |
Johannes Berg | a289755 | 2007-09-28 14:01:25 +0200 | [diff] [blame] | 1063 | priv->mode = IEEE80211_IF_TYPE_INVALID; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1064 | skb_queue_head_init(&priv->tx_queue); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1065 | dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1066 | dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */ |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 1067 | IEEE80211_HW_RX_INCLUDES_FCS | |
| 1068 | IEEE80211_HW_SIGNAL_UNSPEC; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1069 | dev->channel_change_time = 1000; /* TODO: find actual value */ |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 1070 | dev->max_signal = 127; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1071 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 1072 | priv->tx_stats[0].limit = 5; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1073 | dev->queues = 1; |
| 1074 | |
| 1075 | dev->extra_tx_headroom = sizeof(struct p54_control_hdr) + 4 + |
| 1076 | sizeof(struct p54_tx_control_allocdata); |
| 1077 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1078 | mutex_init(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1079 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1080 | return dev; |
| 1081 | } |
| 1082 | EXPORT_SYMBOL_GPL(p54_init_common); |
| 1083 | |
| 1084 | void p54_free_common(struct ieee80211_hw *dev) |
| 1085 | { |
| 1086 | struct p54_common *priv = dev->priv; |
| 1087 | kfree(priv->iq_autocal); |
| 1088 | kfree(priv->output_limit); |
| 1089 | kfree(priv->curve_data); |
| 1090 | kfree(priv->cached_vdcf); |
| 1091 | } |
| 1092 | EXPORT_SYMBOL_GPL(p54_free_common); |
| 1093 | |
| 1094 | static int __init p54_init(void) |
| 1095 | { |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | static void __exit p54_exit(void) |
| 1100 | { |
| 1101 | } |
| 1102 | |
| 1103 | module_init(p54_init); |
| 1104 | module_exit(p54_exit); |