Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Common code for mac80211 Prism54 drivers |
| 3 | * |
| 4 | * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net> |
| 5 | * Copyright (c) 2007, Christian Lamparter <chunkeey@web.de> |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 6 | * Copyright 2008, Johannes Berg <johannes@sipsolutions.net> |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 7 | * |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 8 | * Based on: |
| 9 | * - the islsm (softmac prism54) driver, which is: |
| 10 | * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al. |
| 11 | * - stlc45xx driver |
| 12 | * C Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies). |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License version 2 as |
| 16 | * published by the Free Software Foundation. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/firmware.h> |
| 21 | #include <linux/etherdevice.h> |
| 22 | |
| 23 | #include <net/mac80211.h> |
| 24 | |
| 25 | #include "p54.h" |
| 26 | #include "p54common.h" |
| 27 | |
| 28 | MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>"); |
| 29 | MODULE_DESCRIPTION("Softmac Prism54 common code"); |
| 30 | MODULE_LICENSE("GPL"); |
| 31 | MODULE_ALIAS("prism54common"); |
| 32 | |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 33 | static struct ieee80211_rate p54_bgrates[] = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 34 | { .bitrate = 10, .hw_value = 0, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 35 | { .bitrate = 20, .hw_value = 1, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 36 | { .bitrate = 55, .hw_value = 2, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 37 | { .bitrate = 110, .hw_value = 3, .flags = IEEE80211_RATE_SHORT_PREAMBLE }, |
| 38 | { .bitrate = 60, .hw_value = 4, }, |
| 39 | { .bitrate = 90, .hw_value = 5, }, |
| 40 | { .bitrate = 120, .hw_value = 6, }, |
| 41 | { .bitrate = 180, .hw_value = 7, }, |
| 42 | { .bitrate = 240, .hw_value = 8, }, |
| 43 | { .bitrate = 360, .hw_value = 9, }, |
| 44 | { .bitrate = 480, .hw_value = 10, }, |
| 45 | { .bitrate = 540, .hw_value = 11, }, |
| 46 | }; |
| 47 | |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 48 | static struct ieee80211_channel p54_bgchannels[] = { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 49 | { .center_freq = 2412, .hw_value = 1, }, |
| 50 | { .center_freq = 2417, .hw_value = 2, }, |
| 51 | { .center_freq = 2422, .hw_value = 3, }, |
| 52 | { .center_freq = 2427, .hw_value = 4, }, |
| 53 | { .center_freq = 2432, .hw_value = 5, }, |
| 54 | { .center_freq = 2437, .hw_value = 6, }, |
| 55 | { .center_freq = 2442, .hw_value = 7, }, |
| 56 | { .center_freq = 2447, .hw_value = 8, }, |
| 57 | { .center_freq = 2452, .hw_value = 9, }, |
| 58 | { .center_freq = 2457, .hw_value = 10, }, |
| 59 | { .center_freq = 2462, .hw_value = 11, }, |
| 60 | { .center_freq = 2467, .hw_value = 12, }, |
| 61 | { .center_freq = 2472, .hw_value = 13, }, |
| 62 | { .center_freq = 2484, .hw_value = 14, }, |
| 63 | }; |
| 64 | |
Johannes Berg | c2976ab | 2008-02-20 12:08:12 +0100 | [diff] [blame] | 65 | static struct ieee80211_supported_band band_2GHz = { |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 66 | .channels = p54_bgchannels, |
| 67 | .n_channels = ARRAY_SIZE(p54_bgchannels), |
| 68 | .bitrates = p54_bgrates, |
| 69 | .n_bitrates = ARRAY_SIZE(p54_bgrates), |
| 70 | }; |
| 71 | |
| 72 | static struct ieee80211_rate p54_arates[] = { |
| 73 | { .bitrate = 60, .hw_value = 4, }, |
| 74 | { .bitrate = 90, .hw_value = 5, }, |
| 75 | { .bitrate = 120, .hw_value = 6, }, |
| 76 | { .bitrate = 180, .hw_value = 7, }, |
| 77 | { .bitrate = 240, .hw_value = 8, }, |
| 78 | { .bitrate = 360, .hw_value = 9, }, |
| 79 | { .bitrate = 480, .hw_value = 10, }, |
| 80 | { .bitrate = 540, .hw_value = 11, }, |
| 81 | }; |
| 82 | |
| 83 | static struct ieee80211_channel p54_achannels[] = { |
| 84 | { .center_freq = 4920 }, |
| 85 | { .center_freq = 4940 }, |
| 86 | { .center_freq = 4960 }, |
| 87 | { .center_freq = 4980 }, |
| 88 | { .center_freq = 5040 }, |
| 89 | { .center_freq = 5060 }, |
| 90 | { .center_freq = 5080 }, |
| 91 | { .center_freq = 5170 }, |
| 92 | { .center_freq = 5180 }, |
| 93 | { .center_freq = 5190 }, |
| 94 | { .center_freq = 5200 }, |
| 95 | { .center_freq = 5210 }, |
| 96 | { .center_freq = 5220 }, |
| 97 | { .center_freq = 5230 }, |
| 98 | { .center_freq = 5240 }, |
| 99 | { .center_freq = 5260 }, |
| 100 | { .center_freq = 5280 }, |
| 101 | { .center_freq = 5300 }, |
| 102 | { .center_freq = 5320 }, |
| 103 | { .center_freq = 5500 }, |
| 104 | { .center_freq = 5520 }, |
| 105 | { .center_freq = 5540 }, |
| 106 | { .center_freq = 5560 }, |
| 107 | { .center_freq = 5580 }, |
| 108 | { .center_freq = 5600 }, |
| 109 | { .center_freq = 5620 }, |
| 110 | { .center_freq = 5640 }, |
| 111 | { .center_freq = 5660 }, |
| 112 | { .center_freq = 5680 }, |
| 113 | { .center_freq = 5700 }, |
| 114 | { .center_freq = 5745 }, |
| 115 | { .center_freq = 5765 }, |
| 116 | { .center_freq = 5785 }, |
| 117 | { .center_freq = 5805 }, |
| 118 | { .center_freq = 5825 }, |
| 119 | }; |
| 120 | |
| 121 | static struct ieee80211_supported_band band_5GHz = { |
| 122 | .channels = p54_achannels, |
| 123 | .n_channels = ARRAY_SIZE(p54_achannels), |
| 124 | .bitrates = p54_arates, |
| 125 | .n_bitrates = ARRAY_SIZE(p54_arates), |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 126 | }; |
| 127 | |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 128 | int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 129 | { |
| 130 | struct p54_common *priv = dev->priv; |
| 131 | struct bootrec_exp_if *exp_if; |
| 132 | struct bootrec *bootrec; |
| 133 | u32 *data = (u32 *)fw->data; |
| 134 | u32 *end_data = (u32 *)fw->data + (fw->size >> 2); |
| 135 | u8 *fw_version = NULL; |
| 136 | size_t len; |
| 137 | int i; |
| 138 | |
| 139 | if (priv->rx_start) |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 140 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 141 | |
| 142 | while (data < end_data && *data) |
| 143 | data++; |
| 144 | |
| 145 | while (data < end_data && !*data) |
| 146 | data++; |
| 147 | |
| 148 | bootrec = (struct bootrec *) data; |
| 149 | |
| 150 | while (bootrec->data <= end_data && |
| 151 | (bootrec->data + (len = le32_to_cpu(bootrec->len))) <= end_data) { |
| 152 | u32 code = le32_to_cpu(bootrec->code); |
| 153 | switch (code) { |
| 154 | case BR_CODE_COMPONENT_ID: |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 155 | priv->fw_interface = be32_to_cpup((__be32 *) |
| 156 | bootrec->data); |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 157 | switch (priv->fw_interface) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 158 | case FW_FMAC: |
| 159 | printk(KERN_INFO "p54: FreeMAC firmware\n"); |
| 160 | break; |
| 161 | case FW_LM20: |
| 162 | printk(KERN_INFO "p54: LM20 firmware\n"); |
| 163 | break; |
| 164 | case FW_LM86: |
| 165 | printk(KERN_INFO "p54: LM86 firmware\n"); |
| 166 | break; |
| 167 | case FW_LM87: |
Christian Lamparter | 2b80848 | 2008-09-04 12:29:38 +0200 | [diff] [blame] | 168 | printk(KERN_INFO "p54: LM87 firmware\n"); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 169 | break; |
| 170 | default: |
| 171 | printk(KERN_INFO "p54: unknown firmware\n"); |
| 172 | break; |
| 173 | } |
| 174 | break; |
| 175 | case BR_CODE_COMPONENT_VERSION: |
| 176 | /* 24 bytes should be enough for all firmwares */ |
| 177 | if (strnlen((unsigned char*)bootrec->data, 24) < 24) |
| 178 | fw_version = (unsigned char*)bootrec->data; |
| 179 | break; |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 180 | case BR_CODE_DESCR: { |
| 181 | struct bootrec_desc *desc = |
| 182 | (struct bootrec_desc *)bootrec->data; |
| 183 | priv->rx_start = le32_to_cpu(desc->rx_start); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 184 | /* FIXME add sanity checking */ |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 185 | priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500; |
| 186 | priv->headroom = desc->headroom; |
| 187 | priv->tailroom = desc->tailroom; |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 188 | if (le32_to_cpu(bootrec->len) == 11) |
Larry Finger | 2e20cc3 | 2008-10-09 17:38:52 -0700 | [diff] [blame] | 189 | priv->rx_mtu = le16_to_cpu(desc->rx_mtu); |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 190 | else |
| 191 | priv->rx_mtu = (size_t) |
| 192 | 0x620 - priv->tx_hdr_len; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 193 | break; |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 194 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 195 | case BR_CODE_EXPOSED_IF: |
| 196 | exp_if = (struct bootrec_exp_if *) bootrec->data; |
| 197 | for (i = 0; i < (len * sizeof(*exp_if) / 4); i++) |
Al Viro | dc73c62 | 2007-12-21 23:49:02 -0500 | [diff] [blame] | 198 | if (exp_if[i].if_id == cpu_to_le16(0x1a)) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 199 | priv->fw_var = le16_to_cpu(exp_if[i].variant); |
| 200 | break; |
| 201 | case BR_CODE_DEPENDENT_IF: |
| 202 | break; |
| 203 | case BR_CODE_END_OF_BRA: |
| 204 | case LEGACY_BR_CODE_END_OF_BRA: |
| 205 | end_data = NULL; |
| 206 | break; |
| 207 | default: |
| 208 | break; |
| 209 | } |
| 210 | bootrec = (struct bootrec *)&bootrec->data[len]; |
| 211 | } |
| 212 | |
| 213 | if (fw_version) |
| 214 | printk(KERN_INFO "p54: FW rev %s - Softmac protocol %x.%x\n", |
| 215 | fw_version, priv->fw_var >> 8, priv->fw_var & 0xff); |
| 216 | |
Christian Lamparter | 9a8675d | 2008-10-18 23:04:15 +0200 | [diff] [blame] | 217 | if (priv->fw_var < 0x500) |
| 218 | printk(KERN_INFO "p54: you are using an obsolete firmware. " |
| 219 | "visit http://wireless.kernel.org/en/users/Drivers/p54 " |
| 220 | "and grab one for \"kernel >= 2.6.28\"!\n"); |
| 221 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 222 | if (priv->fw_var >= 0x300) { |
| 223 | /* Firmware supports QoS, use it! */ |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 224 | priv->tx_stats[4].limit = 3; /* AC_VO */ |
| 225 | priv->tx_stats[5].limit = 4; /* AC_VI */ |
| 226 | priv->tx_stats[6].limit = 3; /* AC_BE */ |
| 227 | priv->tx_stats[7].limit = 2; /* AC_BK */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 228 | dev->queues = 4; |
| 229 | } |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 230 | |
| 231 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 232 | } |
| 233 | EXPORT_SYMBOL_GPL(p54_parse_firmware); |
| 234 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 235 | static int p54_convert_rev0(struct ieee80211_hw *dev, |
| 236 | struct pda_pa_curve_data *curve_data) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 237 | { |
| 238 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 239 | struct p54_pa_curve_data_sample *dst; |
| 240 | struct pda_pa_curve_data_sample_rev0 *src; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 241 | size_t cd_len = sizeof(*curve_data) + |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 242 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 243 | curve_data->channels; |
| 244 | unsigned int i, j; |
| 245 | void *source, *target; |
| 246 | |
| 247 | priv->curve_data = kmalloc(cd_len, GFP_KERNEL); |
| 248 | if (!priv->curve_data) |
| 249 | return -ENOMEM; |
| 250 | |
| 251 | memcpy(priv->curve_data, curve_data, sizeof(*curve_data)); |
| 252 | source = curve_data->data; |
| 253 | target = priv->curve_data->data; |
| 254 | for (i = 0; i < curve_data->channels; i++) { |
| 255 | __le16 *freq = source; |
| 256 | source += sizeof(__le16); |
| 257 | *((__le16 *)target) = *freq; |
| 258 | target += sizeof(__le16); |
| 259 | for (j = 0; j < curve_data->points_per_channel; j++) { |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 260 | dst = target; |
| 261 | src = source; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 262 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 263 | dst->rf_power = src->rf_power; |
| 264 | dst->pa_detector = src->pa_detector; |
| 265 | dst->data_64qam = src->pcv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 266 | /* "invent" the points for the other modulations */ |
| 267 | #define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y) |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 268 | dst->data_16qam = SUB(src->pcv, 12); |
| 269 | dst->data_qpsk = SUB(dst->data_16qam, 12); |
| 270 | dst->data_bpsk = SUB(dst->data_qpsk, 12); |
| 271 | dst->data_barker = SUB(dst->data_bpsk, 14); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 272 | #undef SUB |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 273 | target += sizeof(*dst); |
| 274 | source += sizeof(*src); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 281 | static int p54_convert_rev1(struct ieee80211_hw *dev, |
| 282 | struct pda_pa_curve_data *curve_data) |
| 283 | { |
| 284 | struct p54_common *priv = dev->priv; |
| 285 | struct p54_pa_curve_data_sample *dst; |
| 286 | struct pda_pa_curve_data_sample_rev1 *src; |
| 287 | size_t cd_len = sizeof(*curve_data) + |
| 288 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
| 289 | curve_data->channels; |
| 290 | unsigned int i, j; |
| 291 | void *source, *target; |
| 292 | |
| 293 | priv->curve_data = kmalloc(cd_len, GFP_KERNEL); |
| 294 | if (!priv->curve_data) |
| 295 | return -ENOMEM; |
| 296 | |
| 297 | memcpy(priv->curve_data, curve_data, sizeof(*curve_data)); |
| 298 | source = curve_data->data; |
| 299 | target = priv->curve_data->data; |
| 300 | for (i = 0; i < curve_data->channels; i++) { |
| 301 | __le16 *freq = source; |
| 302 | source += sizeof(__le16); |
| 303 | *((__le16 *)target) = *freq; |
| 304 | target += sizeof(__le16); |
| 305 | for (j = 0; j < curve_data->points_per_channel; j++) { |
| 306 | memcpy(target, source, sizeof(*src)); |
| 307 | |
| 308 | target += sizeof(*dst); |
| 309 | source += sizeof(*src); |
| 310 | } |
| 311 | source++; |
| 312 | } |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 317 | static const char *p54_rf_chips[] = { "NULL", "Duette3", "Duette2", |
| 318 | "Frisbee", "Xbow", "Longbow", "NULL", "NULL" }; |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 319 | static int p54_init_xbow_synth(struct ieee80211_hw *dev); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 320 | |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 321 | static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 322 | { |
| 323 | struct p54_common *priv = dev->priv; |
| 324 | struct eeprom_pda_wrap *wrap = NULL; |
| 325 | struct pda_entry *entry; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 326 | unsigned int data_len, entry_len; |
| 327 | void *tmp; |
| 328 | int err; |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 329 | u8 *end = (u8 *)eeprom + len; |
Christian Lamparter | f2c2e25 | 2008-10-25 16:14:14 +0200 | [diff] [blame] | 330 | u16 synth = 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 331 | |
| 332 | wrap = (struct eeprom_pda_wrap *) eeprom; |
Johannes Berg | 8c28293 | 2008-02-29 13:56:33 +0100 | [diff] [blame] | 333 | entry = (void *)wrap->data + le16_to_cpu(wrap->len); |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 334 | |
| 335 | /* verify that at least the entry length/code fits */ |
| 336 | while ((u8 *)entry <= end - sizeof(*entry)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 337 | entry_len = le16_to_cpu(entry->len); |
| 338 | data_len = ((entry_len - 1) << 1); |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 339 | |
| 340 | /* abort if entry exceeds whole structure */ |
| 341 | if ((u8 *)entry + sizeof(*entry) + data_len > end) |
| 342 | break; |
| 343 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 344 | switch (le16_to_cpu(entry->code)) { |
| 345 | case PDR_MAC_ADDRESS: |
| 346 | SET_IEEE80211_PERM_ADDR(dev, entry->data); |
| 347 | break; |
| 348 | case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS: |
| 349 | if (data_len < 2) { |
| 350 | err = -EINVAL; |
| 351 | goto err; |
| 352 | } |
| 353 | |
| 354 | if (2 + entry->data[1]*sizeof(*priv->output_limit) > data_len) { |
| 355 | err = -EINVAL; |
| 356 | goto err; |
| 357 | } |
| 358 | |
| 359 | priv->output_limit = kmalloc(entry->data[1] * |
| 360 | sizeof(*priv->output_limit), GFP_KERNEL); |
| 361 | |
| 362 | if (!priv->output_limit) { |
| 363 | err = -ENOMEM; |
| 364 | goto err; |
| 365 | } |
| 366 | |
| 367 | memcpy(priv->output_limit, &entry->data[2], |
| 368 | entry->data[1]*sizeof(*priv->output_limit)); |
| 369 | priv->output_limit_len = entry->data[1]; |
| 370 | break; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 371 | case PDR_PRISM_PA_CAL_CURVE_DATA: { |
| 372 | struct pda_pa_curve_data *curve_data = |
| 373 | (struct pda_pa_curve_data *)entry->data; |
| 374 | if (data_len < sizeof(*curve_data)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 375 | err = -EINVAL; |
| 376 | goto err; |
| 377 | } |
| 378 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 379 | switch (curve_data->cal_method_rev) { |
| 380 | case 0: |
| 381 | err = p54_convert_rev0(dev, curve_data); |
| 382 | break; |
| 383 | case 1: |
| 384 | err = p54_convert_rev1(dev, curve_data); |
| 385 | break; |
| 386 | default: |
| 387 | printk(KERN_ERR "p54: unknown curve data " |
| 388 | "revision %d\n", |
| 389 | curve_data->cal_method_rev); |
| 390 | err = -ENODEV; |
| 391 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 392 | } |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 393 | if (err) |
| 394 | goto err; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 395 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 396 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 397 | case PDR_PRISM_ZIF_TX_IQ_CALIBRATION: |
| 398 | priv->iq_autocal = kmalloc(data_len, GFP_KERNEL); |
| 399 | if (!priv->iq_autocal) { |
| 400 | err = -ENOMEM; |
| 401 | goto err; |
| 402 | } |
| 403 | |
| 404 | memcpy(priv->iq_autocal, entry->data, data_len); |
| 405 | priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry); |
| 406 | break; |
| 407 | case PDR_INTERFACE_LIST: |
| 408 | tmp = entry->data; |
| 409 | while ((u8 *)tmp < entry->data + data_len) { |
| 410 | struct bootrec_exp_if *exp_if = tmp; |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 411 | if (le16_to_cpu(exp_if->if_id) == 0xf) |
| 412 | synth = le16_to_cpu(exp_if->variant); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 413 | tmp += sizeof(struct bootrec_exp_if); |
| 414 | } |
| 415 | break; |
| 416 | case PDR_HARDWARE_PLATFORM_COMPONENT_ID: |
| 417 | priv->version = *(u8 *)(entry->data + 1); |
| 418 | break; |
| 419 | case PDR_END: |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 420 | /* make it overrun */ |
| 421 | entry_len = len; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 422 | break; |
Pavel Roskin | c8034c4 | 2008-10-29 17:31:43 -0400 | [diff] [blame^] | 423 | case PDR_MANUFACTURING_PART_NUMBER: |
| 424 | case PDR_PDA_VERSION: |
| 425 | case PDR_NIC_SERIAL_NUMBER: |
| 426 | case PDR_REGULATORY_DOMAIN_LIST: |
| 427 | case PDR_TEMPERATURE_TYPE: |
| 428 | case PDR_PRISM_PCI_IDENTIFIER: |
| 429 | case PDR_COUNTRY_INFORMATION: |
| 430 | case PDR_OEM_NAME: |
| 431 | case PDR_PRODUCT_NAME: |
| 432 | case PDR_UTF8_OEM_NAME: |
| 433 | case PDR_UTF8_PRODUCT_NAME: |
| 434 | case PDR_COUNTRY_LIST: |
| 435 | case PDR_DEFAULT_COUNTRY: |
| 436 | case PDR_ANTENNA_GAIN: |
| 437 | case PDR_PRISM_INDIGO_PA_CALIBRATION_DATA: |
| 438 | case PDR_RSSI_LINEAR_APPROXIMATION: |
| 439 | case PDR_RSSI_LINEAR_APPROXIMATION_DUAL_BAND: |
| 440 | case PDR_REGULATORY_POWER_LIMITS: |
| 441 | case PDR_RSSI_LINEAR_APPROXIMATION_EXTENDED: |
| 442 | case PDR_RADIATED_TRANSMISSION_CORRECTION: |
| 443 | case PDR_PRISM_TX_IQ_CALIBRATION: |
| 444 | case PDR_BASEBAND_REGISTERS: |
| 445 | case PDR_PER_CHANNEL_BASEBAND_REGISTERS: |
| 446 | break; |
Florian Fainelli | 58e3073 | 2008-02-25 17:51:53 +0100 | [diff] [blame] | 447 | default: |
| 448 | printk(KERN_INFO "p54: unknown eeprom code : 0x%x\n", |
| 449 | le16_to_cpu(entry->code)); |
| 450 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | entry = (void *)entry + (entry_len + 1)*2; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Christian Lamparter | f2c2e25 | 2008-10-25 16:14:14 +0200 | [diff] [blame] | 456 | if (!synth || !priv->iq_autocal || !priv->output_limit || |
| 457 | !priv->curve_data) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 458 | printk(KERN_ERR "p54: not all required entries found in eeprom!\n"); |
| 459 | err = -EINVAL; |
| 460 | goto err; |
| 461 | } |
| 462 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 463 | priv->rxhw = synth & PDR_SYNTH_FRONTEND_MASK; |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 464 | if (priv->rxhw == 4) |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 465 | p54_init_xbow_synth(dev); |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 466 | if (!(synth & PDR_SYNTH_24_GHZ_DISABLED)) |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 467 | dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 468 | if (!(synth & PDR_SYNTH_5_GHZ_DISABLED)) |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 469 | dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 470 | |
| 471 | if (!is_valid_ether_addr(dev->wiphy->perm_addr)) { |
| 472 | u8 perm_addr[ETH_ALEN]; |
| 473 | |
| 474 | printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n", |
| 475 | wiphy_name(dev->wiphy)); |
| 476 | random_ether_addr(perm_addr); |
| 477 | SET_IEEE80211_PERM_ADDR(dev, perm_addr); |
| 478 | } |
| 479 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 480 | printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n", |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 481 | wiphy_name(dev->wiphy), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 482 | dev->wiphy->perm_addr, |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 483 | priv->version, p54_rf_chips[priv->rxhw]); |
| 484 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 485 | return 0; |
| 486 | |
| 487 | err: |
| 488 | if (priv->iq_autocal) { |
| 489 | kfree(priv->iq_autocal); |
| 490 | priv->iq_autocal = NULL; |
| 491 | } |
| 492 | |
| 493 | if (priv->output_limit) { |
| 494 | kfree(priv->output_limit); |
| 495 | priv->output_limit = NULL; |
| 496 | } |
| 497 | |
| 498 | if (priv->curve_data) { |
| 499 | kfree(priv->curve_data); |
| 500 | priv->curve_data = NULL; |
| 501 | } |
| 502 | |
| 503 | printk(KERN_ERR "p54: eeprom parse failed!\n"); |
| 504 | return err; |
| 505 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 506 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 507 | static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi) |
| 508 | { |
| 509 | /* TODO: get the rssi_add & rssi_mul data from the eeprom */ |
| 510 | return ((rssi * 0x83) / 64 - 400) / 4; |
| 511 | } |
| 512 | |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 513 | static int p54_rx_data(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 514 | { |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 515 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 516 | struct p54_rx_data *hdr = (struct p54_rx_data *) skb->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 517 | struct ieee80211_rx_status rx_status = {0}; |
| 518 | u16 freq = le16_to_cpu(hdr->freq); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 519 | size_t header_len = sizeof(*hdr); |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 520 | u32 tsf32; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 521 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 522 | if (!(hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_IN_FCS_GOOD))) { |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 523 | if (priv->filter_flags & FIF_FCSFAIL) |
| 524 | rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 525 | else |
| 526 | return 0; |
| 527 | } |
| 528 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 529 | rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi); |
| 530 | rx_status.noise = priv->noise; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 531 | /* XX correct? */ |
Larry.Finger@lwfinger.net | 18d7260 | 2008-06-30 10:39:49 -0500 | [diff] [blame] | 532 | rx_status.qual = (100 * hdr->rssi) / 127; |
Christian Lamparter | cf3e74c | 2008-09-30 23:36:00 +0200 | [diff] [blame] | 533 | rx_status.rate_idx = (dev->conf.channel->band == IEEE80211_BAND_2GHZ ? |
| 534 | hdr->rate : (hdr->rate - 4)) & 0xf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 535 | rx_status.freq = freq; |
Christian Lamparter | cf3e74c | 2008-09-30 23:36:00 +0200 | [diff] [blame] | 536 | rx_status.band = dev->conf.channel->band; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 537 | rx_status.antenna = hdr->antenna; |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 538 | |
| 539 | tsf32 = le32_to_cpu(hdr->tsf32); |
| 540 | if (tsf32 < priv->tsf_low32) |
| 541 | priv->tsf_high32++; |
| 542 | rx_status.mactime = ((u64)priv->tsf_high32) << 32 | tsf32; |
| 543 | priv->tsf_low32 = tsf32; |
| 544 | |
Johannes Berg | 03bffc1 | 2007-12-04 20:33:40 +0100 | [diff] [blame] | 545 | rx_status.flag |= RX_FLAG_TSFT; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 546 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 547 | if (hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN)) |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 548 | header_len += hdr->align[0]; |
| 549 | |
| 550 | skb_pull(skb, header_len); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 551 | skb_trim(skb, le16_to_cpu(hdr->len)); |
| 552 | |
| 553 | ieee80211_rx_irqsafe(dev, skb, &rx_status); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 554 | |
| 555 | return -1; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | static void inline p54_wake_free_queues(struct ieee80211_hw *dev) |
| 559 | { |
| 560 | struct p54_common *priv = dev->priv; |
| 561 | int i; |
| 562 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 563 | if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) |
| 564 | return ; |
| 565 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 566 | for (i = 0; i < dev->queues; i++) |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 567 | if (priv->tx_stats[i + 4].len < priv->tx_stats[i + 4].limit) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 568 | ieee80211_wake_queue(dev, i); |
| 569 | } |
| 570 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 571 | void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 572 | { |
| 573 | struct p54_common *priv = dev->priv; |
| 574 | struct ieee80211_tx_info *info; |
| 575 | struct memrecord *range; |
| 576 | unsigned long flags; |
| 577 | u32 freed = 0, last_addr = priv->rx_start; |
| 578 | |
| 579 | if (!skb || !dev) |
| 580 | return; |
| 581 | |
| 582 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
| 583 | info = IEEE80211_SKB_CB(skb); |
| 584 | range = (void *)info->rate_driver_data; |
| 585 | if (skb->prev != (struct sk_buff *)&priv->tx_queue) { |
| 586 | struct ieee80211_tx_info *ni; |
| 587 | struct memrecord *mr; |
| 588 | |
| 589 | ni = IEEE80211_SKB_CB(skb->prev); |
| 590 | mr = (struct memrecord *)ni->rate_driver_data; |
| 591 | last_addr = mr->end_addr; |
| 592 | } |
| 593 | if (skb->next != (struct sk_buff *)&priv->tx_queue) { |
| 594 | struct ieee80211_tx_info *ni; |
| 595 | struct memrecord *mr; |
| 596 | |
| 597 | ni = IEEE80211_SKB_CB(skb->next); |
| 598 | mr = (struct memrecord *)ni->rate_driver_data; |
| 599 | freed = mr->start_addr - last_addr; |
| 600 | } else |
| 601 | freed = priv->rx_end - last_addr; |
| 602 | __skb_unlink(skb, &priv->tx_queue); |
| 603 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 604 | kfree_skb(skb); |
| 605 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 606 | if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 + |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 607 | IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom) |
| 608 | p54_wake_free_queues(dev); |
| 609 | } |
| 610 | EXPORT_SYMBOL_GPL(p54_free_skb); |
| 611 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 612 | static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 613 | { |
| 614 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 615 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
| 616 | struct p54_frame_sent *payload = (struct p54_frame_sent *) hdr->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 617 | struct sk_buff *entry = (struct sk_buff *) priv->tx_queue.next; |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 618 | u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 619 | struct memrecord *range = NULL; |
| 620 | u32 freed = 0; |
| 621 | u32 last_addr = priv->rx_start; |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 622 | unsigned long flags; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 623 | int count, idx; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 624 | |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 625 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 626 | while (entry != (struct sk_buff *)&priv->tx_queue) { |
Johannes Berg | 552fe53 | 2008-05-30 21:07:15 +0200 | [diff] [blame] | 627 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 628 | struct p54_hdr *entry_hdr; |
| 629 | struct p54_tx_data *entry_data; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 630 | int pad = 0; |
| 631 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 632 | range = (void *)info->rate_driver_data; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 633 | if (range->start_addr != addr) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 634 | last_addr = range->end_addr; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 635 | entry = entry->next; |
| 636 | continue; |
| 637 | } |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 638 | |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 639 | if (entry->next != (struct sk_buff *)&priv->tx_queue) { |
| 640 | struct ieee80211_tx_info *ni; |
| 641 | struct memrecord *mr; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 642 | |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 643 | ni = IEEE80211_SKB_CB(entry->next); |
| 644 | mr = (struct memrecord *)ni->rate_driver_data; |
| 645 | freed = mr->start_addr - last_addr; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 646 | } else |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 647 | freed = priv->rx_end - last_addr; |
| 648 | |
| 649 | last_addr = range->end_addr; |
| 650 | __skb_unlink(entry, &priv->tx_queue); |
| 651 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 652 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 653 | if (unlikely(entry == priv->cached_beacon)) { |
| 654 | kfree_skb(entry); |
| 655 | priv->cached_beacon = NULL; |
| 656 | goto out; |
| 657 | } |
| 658 | |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 659 | /* |
| 660 | * Clear manually, ieee80211_tx_info_clear_status would |
| 661 | * clear the counts too and we need them. |
| 662 | */ |
| 663 | memset(&info->status.ampdu_ack_len, 0, |
| 664 | sizeof(struct ieee80211_tx_info) - |
| 665 | offsetof(struct ieee80211_tx_info, status.ampdu_ack_len)); |
| 666 | BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, |
| 667 | status.ampdu_ack_len) != 23); |
| 668 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 669 | entry_hdr = (struct p54_hdr *) entry->data; |
| 670 | entry_data = (struct p54_tx_data *) entry_hdr->data; |
| 671 | if (entry_hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN)) |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 672 | pad = entry_data->align[0]; |
| 673 | |
| 674 | /* walk through the rates array and adjust the counts */ |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 675 | count = payload->tries; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 676 | for (idx = 0; idx < 4; idx++) { |
| 677 | if (count >= info->status.rates[idx].count) { |
| 678 | count -= info->status.rates[idx].count; |
| 679 | } else if (count > 0) { |
| 680 | info->status.rates[idx].count = count; |
| 681 | count = 0; |
| 682 | } else { |
| 683 | info->status.rates[idx].idx = -1; |
| 684 | info->status.rates[idx].count = 0; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | priv->tx_stats[entry_data->hw_queue].len--; |
| 689 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && |
| 690 | (!payload->status)) |
| 691 | info->flags |= IEEE80211_TX_STAT_ACK; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 692 | if (payload->status & P54_TX_PSM_CANCELLED) |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 693 | info->flags |= IEEE80211_TX_STAT_TX_FILTERED; |
| 694 | info->status.ack_signal = p54_rssi_to_dbm(dev, |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 695 | (int)payload->ack_rssi); |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 696 | skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data)); |
| 697 | ieee80211_tx_status_irqsafe(dev, entry); |
| 698 | goto out; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 699 | } |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 700 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 701 | |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 702 | out: |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 703 | if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 + |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 704 | IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 705 | p54_wake_free_queues(dev); |
| 706 | } |
| 707 | |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 708 | static void p54_rx_eeprom_readback(struct ieee80211_hw *dev, |
| 709 | struct sk_buff *skb) |
| 710 | { |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 711 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 712 | struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data; |
| 713 | struct p54_common *priv = dev->priv; |
| 714 | |
| 715 | if (!priv->eeprom) |
| 716 | return ; |
| 717 | |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 718 | memcpy(priv->eeprom, eeprom->data, le16_to_cpu(eeprom->len)); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 719 | |
| 720 | complete(&priv->eeprom_comp); |
| 721 | } |
| 722 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 723 | static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 724 | { |
| 725 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 726 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 727 | struct p54_statistics *stats = (struct p54_statistics *) hdr->data; |
| 728 | u32 tsf32 = le32_to_cpu(stats->tsf32); |
| 729 | |
| 730 | if (tsf32 < priv->tsf_low32) |
| 731 | priv->tsf_high32++; |
| 732 | priv->tsf_low32 = tsf32; |
| 733 | |
| 734 | priv->stats.dot11RTSFailureCount = le32_to_cpu(stats->rts_fail); |
| 735 | priv->stats.dot11RTSSuccessCount = le32_to_cpu(stats->rts_success); |
| 736 | priv->stats.dot11FCSErrorCount = le32_to_cpu(stats->rx_bad_fcs); |
| 737 | |
| 738 | priv->noise = p54_rssi_to_dbm(dev, le32_to_cpu(stats->noise)); |
| 739 | complete(&priv->stats_comp); |
| 740 | |
| 741 | mod_timer(&priv->stats_timer, jiffies + 5 * HZ); |
| 742 | } |
| 743 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 744 | static void p54_rx_trap(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 745 | { |
| 746 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
| 747 | struct p54_trap *trap = (struct p54_trap *) hdr->data; |
| 748 | u16 event = le16_to_cpu(trap->event); |
| 749 | u16 freq = le16_to_cpu(trap->frequency); |
| 750 | |
| 751 | switch (event) { |
| 752 | case P54_TRAP_BEACON_TX: |
| 753 | break; |
| 754 | case P54_TRAP_RADAR: |
| 755 | printk(KERN_INFO "%s: radar (freq:%d MHz)\n", |
| 756 | wiphy_name(dev->wiphy), freq); |
| 757 | break; |
| 758 | case P54_TRAP_NO_BEACON: |
| 759 | break; |
| 760 | case P54_TRAP_SCAN: |
| 761 | break; |
| 762 | case P54_TRAP_TBTT: |
| 763 | break; |
| 764 | case P54_TRAP_TIMER: |
| 765 | break; |
| 766 | default: |
| 767 | printk(KERN_INFO "%s: received event:%x freq:%d\n", |
| 768 | wiphy_name(dev->wiphy), event, freq); |
| 769 | break; |
| 770 | } |
| 771 | } |
| 772 | |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 773 | static int p54_rx_control(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 774 | { |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 775 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 776 | |
| 777 | switch (le16_to_cpu(hdr->type)) { |
| 778 | case P54_CONTROL_TYPE_TXDONE: |
| 779 | p54_rx_frame_sent(dev, skb); |
| 780 | break; |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 781 | case P54_CONTROL_TYPE_TRAP: |
| 782 | p54_rx_trap(dev, skb); |
| 783 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 784 | case P54_CONTROL_TYPE_BBP: |
| 785 | break; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 786 | case P54_CONTROL_TYPE_STAT_READBACK: |
| 787 | p54_rx_stats(dev, skb); |
| 788 | break; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 789 | case P54_CONTROL_TYPE_EEPROM_READBACK: |
| 790 | p54_rx_eeprom_readback(dev, skb); |
| 791 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 792 | default: |
| 793 | printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n", |
| 794 | wiphy_name(dev->wiphy), le16_to_cpu(hdr->type)); |
| 795 | break; |
| 796 | } |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 797 | |
| 798 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /* returns zero if skb can be reused */ |
| 802 | int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 803 | { |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 804 | u16 type = le16_to_cpu(*((__le16 *)skb->data)); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 805 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 806 | if (type & P54_HDR_FLAG_CONTROL) |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 807 | return p54_rx_control(dev, skb); |
| 808 | else |
| 809 | return p54_rx_data(dev, skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 810 | } |
| 811 | EXPORT_SYMBOL_GPL(p54_rx); |
| 812 | |
| 813 | /* |
| 814 | * So, the firmware is somewhat stupid and doesn't know what places in its |
| 815 | * memory incoming data should go to. By poking around in the firmware, we |
| 816 | * can find some unused memory to upload our packets to. However, data that we |
| 817 | * want the card to TX needs to stay intact until the card has told us that |
| 818 | * it is done with it. This function finds empty places we can upload to and |
| 819 | * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees |
| 820 | * allocated areas. |
| 821 | */ |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 822 | static int p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb, |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 823 | struct p54_hdr *data, u32 len) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 824 | { |
| 825 | struct p54_common *priv = dev->priv; |
| 826 | struct sk_buff *entry = priv->tx_queue.next; |
| 827 | struct sk_buff *target_skb = NULL; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 828 | struct ieee80211_tx_info *info; |
| 829 | struct memrecord *range; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 830 | u32 last_addr = priv->rx_start; |
| 831 | u32 largest_hole = 0; |
| 832 | u32 target_addr = priv->rx_start; |
| 833 | unsigned long flags; |
| 834 | unsigned int left; |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 835 | len = (len + priv->headroom + priv->tailroom + 3) & ~0x3; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 836 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 837 | if (!skb) |
| 838 | return -EINVAL; |
| 839 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 840 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
| 841 | left = skb_queue_len(&priv->tx_queue); |
| 842 | while (left--) { |
| 843 | u32 hole_size; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 844 | info = IEEE80211_SKB_CB(entry); |
| 845 | range = (void *)info->rate_driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 846 | hole_size = range->start_addr - last_addr; |
| 847 | if (!target_skb && hole_size >= len) { |
| 848 | target_skb = entry->prev; |
| 849 | hole_size -= len; |
| 850 | target_addr = last_addr; |
| 851 | } |
| 852 | largest_hole = max(largest_hole, hole_size); |
| 853 | last_addr = range->end_addr; |
| 854 | entry = entry->next; |
| 855 | } |
| 856 | if (!target_skb && priv->rx_end - last_addr >= len) { |
| 857 | target_skb = priv->tx_queue.prev; |
| 858 | largest_hole = max(largest_hole, priv->rx_end - last_addr - len); |
| 859 | if (!skb_queue_empty(&priv->tx_queue)) { |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 860 | info = IEEE80211_SKB_CB(target_skb); |
| 861 | range = (void *)info->rate_driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 862 | target_addr = range->end_addr; |
| 863 | } |
| 864 | } else |
| 865 | largest_hole = max(largest_hole, priv->rx_end - last_addr); |
| 866 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 867 | if (!target_skb) { |
| 868 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 869 | ieee80211_stop_queues(dev); |
| 870 | return -ENOMEM; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 871 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 872 | |
| 873 | info = IEEE80211_SKB_CB(skb); |
| 874 | range = (void *)info->rate_driver_data; |
| 875 | range->start_addr = target_addr; |
| 876 | range->end_addr = target_addr + len; |
| 877 | __skb_queue_after(&priv->tx_queue, target_skb, skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 878 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 879 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 880 | if (largest_hole < priv->headroom + sizeof(struct p54_hdr) + |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 881 | 48 + IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom) |
| 882 | ieee80211_stop_queues(dev); |
| 883 | |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 884 | data->req_id = cpu_to_le32(target_addr + priv->headroom); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev, |
| 889 | u16 hdr_flags, u16 len, u16 type, gfp_t memflags) |
| 890 | { |
| 891 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 892 | struct p54_hdr *hdr; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 893 | struct sk_buff *skb; |
| 894 | |
| 895 | skb = __dev_alloc_skb(len + priv->tx_hdr_len, memflags); |
| 896 | if (!skb) |
| 897 | return NULL; |
| 898 | skb_reserve(skb, priv->tx_hdr_len); |
| 899 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 900 | hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr)); |
| 901 | hdr->flags = cpu_to_le16(hdr_flags); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 902 | hdr->len = cpu_to_le16(len - sizeof(*hdr)); |
| 903 | hdr->type = cpu_to_le16(type); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 904 | hdr->tries = hdr->rts_tries = 0; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 905 | |
| 906 | if (unlikely(p54_assign_address(dev, skb, hdr, len))) { |
| 907 | kfree_skb(skb); |
| 908 | return NULL; |
| 909 | } |
| 910 | return skb; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 911 | } |
| 912 | |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 913 | int p54_read_eeprom(struct ieee80211_hw *dev) |
| 914 | { |
| 915 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 916 | struct p54_hdr *hdr = NULL; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 917 | struct p54_eeprom_lm86 *eeprom_hdr; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 918 | struct sk_buff *skb; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 919 | size_t eeprom_size = 0x2020, offset = 0, blocksize; |
| 920 | int ret = -ENOMEM; |
| 921 | void *eeprom = NULL; |
| 922 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 923 | skb = p54_alloc_skb(dev, 0x8000, sizeof(*hdr) + sizeof(*eeprom_hdr) + |
| 924 | EEPROM_READBACK_LEN, |
| 925 | P54_CONTROL_TYPE_EEPROM_READBACK, GFP_KERNEL); |
| 926 | if (!skb) |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 927 | goto free; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 928 | priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL); |
| 929 | if (!priv->eeprom) |
| 930 | goto free; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 931 | eeprom = kzalloc(eeprom_size, GFP_KERNEL); |
| 932 | if (!eeprom) |
| 933 | goto free; |
| 934 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 935 | eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb, |
| 936 | sizeof(*eeprom_hdr) + EEPROM_READBACK_LEN); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 937 | |
| 938 | while (eeprom_size) { |
| 939 | blocksize = min(eeprom_size, (size_t)EEPROM_READBACK_LEN); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 940 | eeprom_hdr->offset = cpu_to_le16(offset); |
| 941 | eeprom_hdr->len = cpu_to_le16(blocksize); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 942 | priv->tx(dev, skb, 0); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 943 | |
| 944 | if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) { |
| 945 | printk(KERN_ERR "%s: device does not respond!\n", |
| 946 | wiphy_name(dev->wiphy)); |
| 947 | ret = -EBUSY; |
| 948 | goto free; |
| 949 | } |
| 950 | |
| 951 | memcpy(eeprom + offset, priv->eeprom, blocksize); |
| 952 | offset += blocksize; |
| 953 | eeprom_size -= blocksize; |
| 954 | } |
| 955 | |
| 956 | ret = p54_parse_eeprom(dev, eeprom, offset); |
| 957 | free: |
| 958 | kfree(priv->eeprom); |
| 959 | priv->eeprom = NULL; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 960 | p54_free_skb(dev, skb); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 961 | kfree(eeprom); |
| 962 | |
| 963 | return ret; |
| 964 | } |
| 965 | EXPORT_SYMBOL_GPL(p54_read_eeprom); |
| 966 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 967 | static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta, |
| 968 | bool set) |
| 969 | { |
| 970 | struct p54_common *priv = dev->priv; |
| 971 | struct sk_buff *skb; |
| 972 | struct p54_tim *tim; |
| 973 | |
| 974 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, |
| 975 | sizeof(struct p54_hdr) + sizeof(*tim), |
| 976 | P54_CONTROL_TYPE_TIM, GFP_KERNEL); |
| 977 | if (!skb) |
| 978 | return -ENOMEM; |
| 979 | |
| 980 | tim = (struct p54_tim *) skb_put(skb, sizeof(*tim)); |
| 981 | tim->count = 1; |
| 982 | tim->entry[0] = cpu_to_le16(set ? (sta->aid | 0x8000) : sta->aid); |
| 983 | priv->tx(dev, skb, 1); |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr) |
| 988 | { |
| 989 | struct p54_common *priv = dev->priv; |
| 990 | struct sk_buff *skb; |
| 991 | struct p54_sta_unlock *sta; |
| 992 | |
| 993 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, |
| 994 | sizeof(struct p54_hdr) + sizeof(*sta), |
| 995 | P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC); |
| 996 | if (!skb) |
| 997 | return -ENOMEM; |
| 998 | |
| 999 | sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta)); |
| 1000 | memcpy(sta->addr, addr, ETH_ALEN); |
| 1001 | priv->tx(dev, skb, 1); |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry) |
| 1006 | { |
| 1007 | struct p54_common *priv = dev->priv; |
| 1008 | struct sk_buff *skb; |
| 1009 | struct p54_hdr *hdr; |
| 1010 | struct p54_txcancel *cancel; |
| 1011 | |
| 1012 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, |
| 1013 | sizeof(struct p54_hdr) + sizeof(*cancel), |
| 1014 | P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC); |
| 1015 | if (!skb) |
| 1016 | return -ENOMEM; |
| 1017 | |
| 1018 | hdr = (void *)entry->data; |
| 1019 | cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel)); |
| 1020 | cancel->req_id = hdr->req_id; |
| 1021 | priv->tx(dev, skb, 1); |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1025 | static int p54_tx_fill(struct ieee80211_hw *dev, struct sk_buff *skb, |
| 1026 | struct ieee80211_tx_info *info, u8 *queue, size_t *extra_len, |
| 1027 | u16 *flags, u16 *aid) |
| 1028 | { |
| 1029 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
| 1030 | struct p54_common *priv = dev->priv; |
| 1031 | int ret = 0; |
| 1032 | |
| 1033 | if (unlikely(ieee80211_is_mgmt(hdr->frame_control))) { |
| 1034 | if (ieee80211_is_beacon(hdr->frame_control)) { |
| 1035 | *aid = 0; |
| 1036 | *queue = 0; |
| 1037 | *extra_len = IEEE80211_MAX_TIM_LEN; |
| 1038 | *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP; |
| 1039 | return 0; |
| 1040 | } else if (ieee80211_is_probe_resp(hdr->frame_control)) { |
| 1041 | *aid = 0; |
| 1042 | *queue = 2; |
| 1043 | *flags = P54_HDR_FLAG_DATA_OUT_TIMESTAMP | |
| 1044 | P54_HDR_FLAG_DATA_OUT_NOCANCEL; |
| 1045 | return 0; |
| 1046 | } else { |
| 1047 | *queue = 2; |
| 1048 | ret = 0; |
| 1049 | } |
| 1050 | } else { |
| 1051 | *queue += 4; |
| 1052 | ret = 1; |
| 1053 | } |
| 1054 | |
| 1055 | switch (priv->mode) { |
| 1056 | case NL80211_IFTYPE_STATION: |
| 1057 | *aid = 1; |
| 1058 | break; |
| 1059 | case NL80211_IFTYPE_AP: |
| 1060 | case NL80211_IFTYPE_ADHOC: |
| 1061 | if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { |
| 1062 | *aid = 0; |
| 1063 | *queue = 3; |
| 1064 | return 0; |
| 1065 | } |
| 1066 | if (info->control.sta) |
| 1067 | *aid = info->control.sta->aid; |
| 1068 | else |
| 1069 | *flags = P54_HDR_FLAG_DATA_OUT_NOCANCEL; |
| 1070 | } |
| 1071 | return ret; |
| 1072 | } |
| 1073 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1074 | static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1075 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1076 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1077 | struct ieee80211_tx_queue_stats *current_queue = NULL; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1078 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1079 | struct p54_hdr *hdr; |
| 1080 | struct p54_tx_data *txhdr; |
John W. Linville | db4186c | 2008-10-31 15:53:12 -0400 | [diff] [blame] | 1081 | size_t padding, len, tim_len = 0; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1082 | int i, j, ridx; |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1083 | u16 hdr_flags = 0, aid = 0; |
| 1084 | u8 rate, queue; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1085 | u8 cts_rate = 0x20; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 1086 | u8 rc_flags; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1087 | u8 calculated_tries[4]; |
| 1088 | u8 nrates = 0, nremaining = 8; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1089 | |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1090 | queue = skb_get_queue_mapping(skb); |
| 1091 | |
| 1092 | if (p54_tx_fill(dev, skb, info, &queue, &tim_len, &hdr_flags, &aid)) { |
| 1093 | current_queue = &priv->tx_stats[queue]; |
| 1094 | if (unlikely(current_queue->len > current_queue->limit)) |
| 1095 | return NETDEV_TX_BUSY; |
| 1096 | current_queue->len++; |
| 1097 | current_queue->count++; |
| 1098 | if (current_queue->len == current_queue->limit) |
| 1099 | ieee80211_stop_queue(dev, skb_get_queue_mapping(skb)); |
| 1100 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1101 | |
| 1102 | padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3; |
| 1103 | len = skb->len; |
| 1104 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1105 | if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT) { |
| 1106 | if (info->control.sta) |
| 1107 | if (p54_sta_unlock(dev, info->control.sta->addr)) { |
| 1108 | if (current_queue) { |
| 1109 | current_queue->len--; |
| 1110 | current_queue->count--; |
| 1111 | } |
| 1112 | return NETDEV_TX_BUSY; |
| 1113 | } |
| 1114 | } |
| 1115 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1116 | txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding); |
| 1117 | hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1118 | |
| 1119 | if (padding) |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1120 | hdr_flags |= P54_HDR_FLAG_DATA_ALIGN; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1121 | hdr->len = cpu_to_le16(len); |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1122 | hdr->type = cpu_to_le16(aid); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1123 | hdr->rts_tries = info->control.rates[0].count; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1124 | |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1125 | /* |
| 1126 | * we register the rates in perfect order, and |
| 1127 | * RTS/CTS won't happen on 5 GHz |
| 1128 | */ |
| 1129 | cts_rate = info->control.rts_cts_rate_idx; |
| 1130 | |
| 1131 | memset(&txhdr->rateset, 0, sizeof(txhdr->rateset)); |
| 1132 | |
| 1133 | /* see how many rates got used */ |
| 1134 | for (i = 0; i < 4; i++) { |
| 1135 | if (info->control.rates[i].idx < 0) |
| 1136 | break; |
| 1137 | nrates++; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1138 | } |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1139 | |
| 1140 | /* limit tries to 8/nrates per rate */ |
| 1141 | for (i = 0; i < nrates; i++) { |
| 1142 | /* |
| 1143 | * The magic expression here is equivalent to 8/nrates for |
| 1144 | * all values that matter, but avoids division and jumps. |
| 1145 | * Note that nrates can only take the values 1 through 4. |
| 1146 | */ |
| 1147 | calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1, |
| 1148 | info->control.rates[i].count); |
| 1149 | nremaining -= calculated_tries[i]; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1150 | } |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1151 | |
| 1152 | /* if there are tries left, distribute from back to front */ |
| 1153 | for (i = nrates - 1; nremaining > 0 && i >= 0; i--) { |
| 1154 | int tmp = info->control.rates[i].count - calculated_tries[i]; |
| 1155 | |
| 1156 | if (tmp <= 0) |
| 1157 | continue; |
| 1158 | /* RC requested more tries at this rate */ |
| 1159 | |
| 1160 | tmp = min_t(int, tmp, nremaining); |
| 1161 | calculated_tries[i] += tmp; |
| 1162 | nremaining -= tmp; |
| 1163 | } |
| 1164 | |
| 1165 | ridx = 0; |
| 1166 | for (i = 0; i < nrates && ridx < 8; i++) { |
| 1167 | /* we register the rates in perfect order */ |
| 1168 | rate = info->control.rates[i].idx; |
| 1169 | if (info->band == IEEE80211_BAND_5GHZ) |
| 1170 | rate += 4; |
| 1171 | |
| 1172 | /* store the count we actually calculated for TX status */ |
| 1173 | info->control.rates[i].count = calculated_tries[i]; |
| 1174 | |
| 1175 | rc_flags = info->control.rates[i].flags; |
| 1176 | if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) { |
| 1177 | rate |= 0x10; |
| 1178 | cts_rate |= 0x10; |
| 1179 | } |
| 1180 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) |
| 1181 | rate |= 0x40; |
| 1182 | else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) |
| 1183 | rate |= 0x20; |
| 1184 | for (j = 0; j < calculated_tries[i] && ridx < 8; j++) { |
| 1185 | txhdr->rateset[ridx] = rate; |
| 1186 | ridx++; |
| 1187 | } |
| 1188 | } |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1189 | |
| 1190 | if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) |
| 1191 | hdr_flags |= P54_HDR_FLAG_DATA_OUT_SEQNR; |
| 1192 | |
| 1193 | /* TODO: enable bursting */ |
| 1194 | hdr->flags = cpu_to_le16(hdr_flags); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1195 | hdr->tries = ridx; |
| 1196 | txhdr->crypt_offset = 0; |
| 1197 | txhdr->rts_rate_idx = 0; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1198 | txhdr->key_type = 0; |
| 1199 | txhdr->key_len = 0; |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1200 | txhdr->hw_queue = queue; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1201 | txhdr->backlog = 32; |
| 1202 | memset(txhdr->durations, 0, sizeof(txhdr->durations)); |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1203 | txhdr->tx_antenna = (info->antenna_sel_tx == 0) ? |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1204 | 2 : info->antenna_sel_tx - 1; |
Christian Lamparter | 09adf28 | 2008-09-06 14:25:53 +0200 | [diff] [blame] | 1205 | txhdr->output_power = priv->output_power; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1206 | txhdr->cts_rate = cts_rate; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1207 | if (padding) |
| 1208 | txhdr->align[0] = padding; |
| 1209 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1210 | /* modifies skb->cb and with it info, so must be last! */ |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1211 | if (unlikely(p54_assign_address(dev, skb, hdr, skb->len + tim_len))) { |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1212 | skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding); |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1213 | if (current_queue) { |
| 1214 | current_queue->len--; |
| 1215 | current_queue->count--; |
| 1216 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1217 | return NETDEV_TX_BUSY; |
| 1218 | } |
| 1219 | priv->tx(dev, skb, 0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1220 | return 0; |
| 1221 | } |
| 1222 | |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1223 | static int p54_setup_mac(struct ieee80211_hw *dev, u16 mode, const u8 *bssid) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1224 | { |
| 1225 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1226 | struct sk_buff *skb; |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1227 | struct p54_setup_mac *setup; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1228 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1229 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) + |
| 1230 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP, |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1231 | GFP_ATOMIC); |
| 1232 | if (!skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1233 | return -ENOMEM; |
| 1234 | |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1235 | setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup)); |
| 1236 | priv->mac_mode = mode; |
| 1237 | setup->mac_mode = cpu_to_le16(mode); |
| 1238 | memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN); |
Christian Lamparter | e0a58ea | 2008-09-03 22:25:20 +0200 | [diff] [blame] | 1239 | if (!bssid) |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1240 | memset(setup->bssid, ~0, ETH_ALEN); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1241 | else |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1242 | memcpy(setup->bssid, bssid, ETH_ALEN); |
| 1243 | setup->rx_antenna = priv->rx_antenna; |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1244 | if (priv->fw_var < 0x500) { |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1245 | setup->v1.basic_rate_mask = cpu_to_le32(0x15f); |
| 1246 | setup->v1.rx_addr = cpu_to_le32(priv->rx_end); |
| 1247 | setup->v1.max_rx = cpu_to_le16(priv->rx_mtu); |
| 1248 | setup->v1.rxhw = cpu_to_le16(priv->rxhw); |
| 1249 | setup->v1.wakeup_timer = cpu_to_le16(500); |
| 1250 | setup->v1.unalloc0 = cpu_to_le16(0); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1251 | } else { |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1252 | setup->v2.rx_addr = cpu_to_le32(priv->rx_end); |
| 1253 | setup->v2.max_rx = cpu_to_le16(priv->rx_mtu); |
| 1254 | setup->v2.rxhw = cpu_to_le16(priv->rxhw); |
| 1255 | setup->v2.timer = cpu_to_le16(1000); |
| 1256 | setup->v2.truncate = cpu_to_le16(48896); |
| 1257 | setup->v2.basic_rate_mask = cpu_to_le32(0x15f); |
| 1258 | setup->v2.sbss_offset = 0; |
| 1259 | setup->v2.mcast_window = 0; |
| 1260 | setup->v2.rx_rssi_threshold = 0; |
| 1261 | setup->v2.rx_ed_threshold = 0; |
| 1262 | setup->v2.ref_clock = cpu_to_le32(644245094); |
| 1263 | setup->v2.lpf_bandwidth = cpu_to_le16(65535); |
| 1264 | setup->v2.osc_start_delay = cpu_to_le16(65535); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1265 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1266 | priv->tx(dev, skb, 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1267 | return 0; |
| 1268 | } |
| 1269 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1270 | static int p54_set_freq(struct ieee80211_hw *dev, u16 frequency) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1271 | { |
| 1272 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1273 | struct sk_buff *skb; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1274 | struct p54_scan *chan; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1275 | unsigned int i; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1276 | void *entry; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1277 | __le16 freq = cpu_to_le16(frequency); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1278 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1279 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) + |
| 1280 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN, |
| 1281 | GFP_ATOMIC); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1282 | if (!skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1283 | return -ENOMEM; |
| 1284 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1285 | chan = (struct p54_scan *) skb_put(skb, sizeof(*chan)); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1286 | memset(chan->padding1, 0, sizeof(chan->padding1)); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1287 | chan->mode = cpu_to_le16(P54_SCAN_EXIT); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1288 | chan->dwell = cpu_to_le16(0x0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1289 | |
| 1290 | for (i = 0; i < priv->iq_autocal_len; i++) { |
| 1291 | if (priv->iq_autocal[i].freq != freq) |
| 1292 | continue; |
| 1293 | |
| 1294 | memcpy(&chan->iq_autocal, &priv->iq_autocal[i], |
| 1295 | sizeof(*priv->iq_autocal)); |
| 1296 | break; |
| 1297 | } |
| 1298 | if (i == priv->iq_autocal_len) |
| 1299 | goto err; |
| 1300 | |
| 1301 | for (i = 0; i < priv->output_limit_len; i++) { |
| 1302 | if (priv->output_limit[i].freq != freq) |
| 1303 | continue; |
| 1304 | |
| 1305 | chan->val_barker = 0x38; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1306 | chan->val_bpsk = chan->dup_bpsk = |
| 1307 | priv->output_limit[i].val_bpsk; |
| 1308 | chan->val_qpsk = chan->dup_qpsk = |
| 1309 | priv->output_limit[i].val_qpsk; |
| 1310 | chan->val_16qam = chan->dup_16qam = |
| 1311 | priv->output_limit[i].val_16qam; |
| 1312 | chan->val_64qam = chan->dup_64qam = |
| 1313 | priv->output_limit[i].val_64qam; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1314 | break; |
| 1315 | } |
| 1316 | if (i == priv->output_limit_len) |
| 1317 | goto err; |
| 1318 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1319 | entry = priv->curve_data->data; |
| 1320 | for (i = 0; i < priv->curve_data->channels; i++) { |
| 1321 | if (*((__le16 *)entry) != freq) { |
| 1322 | entry += sizeof(__le16); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1323 | entry += sizeof(struct p54_pa_curve_data_sample) * |
| 1324 | priv->curve_data->points_per_channel; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1325 | continue; |
| 1326 | } |
| 1327 | |
| 1328 | entry += sizeof(__le16); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1329 | chan->pa_points_per_curve = |
| 1330 | min(priv->curve_data->points_per_channel, (u8) 8); |
| 1331 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1332 | memcpy(chan->curve_data, entry, sizeof(*chan->curve_data) * |
| 1333 | chan->pa_points_per_curve); |
| 1334 | break; |
| 1335 | } |
| 1336 | |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1337 | if (priv->fw_var < 0x500) { |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1338 | chan->v1.rssical_mul = cpu_to_le16(130); |
| 1339 | chan->v1.rssical_add = cpu_to_le16(0xfe70); |
| 1340 | } else { |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1341 | chan->v2.rssical_mul = cpu_to_le16(130); |
| 1342 | chan->v2.rssical_add = cpu_to_le16(0xfe70); |
| 1343 | chan->v2.basic_rate_mask = cpu_to_le32(0x15f); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1344 | memset(chan->v2.rts_rates, 0, 8); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1345 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1346 | priv->tx(dev, skb, 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1347 | return 0; |
| 1348 | |
| 1349 | err: |
| 1350 | printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy)); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1351 | kfree_skb(skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1352 | return -EINVAL; |
| 1353 | } |
| 1354 | |
| 1355 | static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act) |
| 1356 | { |
| 1357 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1358 | struct sk_buff *skb; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1359 | struct p54_led *led; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1360 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1361 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led) + |
| 1362 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_LED, |
| 1363 | GFP_ATOMIC); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1364 | if (!skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1365 | return -ENOMEM; |
| 1366 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1367 | led = (struct p54_led *)skb_put(skb, sizeof(*led)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1368 | led->mode = cpu_to_le16(mode); |
| 1369 | led->led_permanent = cpu_to_le16(link); |
| 1370 | led->led_temporary = cpu_to_le16(act); |
| 1371 | led->duration = cpu_to_le16(1000); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1372 | priv->tx(dev, skb, 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1373 | return 0; |
| 1374 | } |
| 1375 | |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1376 | #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1377 | do { \ |
| 1378 | queue.aifs = cpu_to_le16(ai_fs); \ |
| 1379 | queue.cwmin = cpu_to_le16(cw_min); \ |
| 1380 | queue.cwmax = cpu_to_le16(cw_max); \ |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1381 | queue.txop = cpu_to_le16(_txop); \ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1382 | } while(0) |
| 1383 | |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1384 | static int p54_set_edcf(struct ieee80211_hw *dev) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1385 | { |
| 1386 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1387 | struct sk_buff *skb; |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1388 | struct p54_edcf *edcf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1389 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1390 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf) + |
| 1391 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_DCFINIT, |
| 1392 | GFP_ATOMIC); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1393 | if (!skb) |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1394 | return -ENOMEM; |
| 1395 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1396 | edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf)); |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1397 | if (priv->use_short_slot) { |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1398 | edcf->slottime = 9; |
| 1399 | edcf->sifs = 0x10; |
| 1400 | edcf->eofpad = 0x00; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1401 | } else { |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1402 | edcf->slottime = 20; |
| 1403 | edcf->sifs = 0x0a; |
| 1404 | edcf->eofpad = 0x06; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1405 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1406 | /* (see prism54/isl_oid.h for further details) */ |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1407 | edcf->frameburst = cpu_to_le16(0); |
| 1408 | edcf->round_trip_delay = cpu_to_le16(0); |
| 1409 | memset(edcf->mapping, 0, sizeof(edcf->mapping)); |
| 1410 | memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue)); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1411 | priv->tx(dev, skb, 1); |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1412 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1415 | static int p54_init_stats(struct ieee80211_hw *dev) |
| 1416 | { |
| 1417 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1418 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1419 | priv->cached_stats = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, |
| 1420 | sizeof(struct p54_hdr) + sizeof(struct p54_statistics), |
| 1421 | P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL); |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1422 | if (!priv->cached_stats) |
| 1423 | return -ENOMEM; |
| 1424 | |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1425 | mod_timer(&priv->stats_timer, jiffies + HZ); |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1429 | static int p54_beacon_tim(struct sk_buff *skb) |
| 1430 | { |
| 1431 | /* |
| 1432 | * the good excuse for this mess is ... the firmware. |
| 1433 | * The dummy TIM MUST be at the end of the beacon frame, |
| 1434 | * because it'll be overwritten! |
| 1435 | */ |
| 1436 | |
| 1437 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
| 1438 | u8 *pos, *end; |
| 1439 | |
| 1440 | if (skb->len <= sizeof(mgmt)) { |
| 1441 | printk(KERN_ERR "p54: beacon is too short!\n"); |
| 1442 | return -EINVAL; |
| 1443 | } |
| 1444 | |
| 1445 | pos = (u8 *)mgmt->u.beacon.variable; |
| 1446 | end = skb->data + skb->len; |
| 1447 | while (pos < end) { |
| 1448 | if (pos + 2 + pos[1] > end) { |
| 1449 | printk(KERN_ERR "p54: parsing beacon failed\n"); |
| 1450 | return -EINVAL; |
| 1451 | } |
| 1452 | |
| 1453 | if (pos[0] == WLAN_EID_TIM) { |
| 1454 | u8 dtim_len = pos[1]; |
| 1455 | u8 dtim_period = pos[3]; |
| 1456 | u8 *next = pos + 2 + dtim_len; |
| 1457 | |
| 1458 | if (dtim_len < 3) { |
| 1459 | printk(KERN_ERR "p54: invalid dtim len!\n"); |
| 1460 | return -EINVAL; |
| 1461 | } |
| 1462 | memmove(pos, next, end - next); |
| 1463 | |
| 1464 | if (dtim_len > 3) |
| 1465 | skb_trim(skb, skb->len - (dtim_len - 3)); |
| 1466 | |
| 1467 | pos = end - (dtim_len + 2); |
| 1468 | |
| 1469 | /* add the dummy at the end */ |
| 1470 | pos[0] = WLAN_EID_TIM; |
| 1471 | pos[1] = 3; |
| 1472 | pos[2] = 0; |
| 1473 | pos[3] = dtim_period; |
| 1474 | pos[4] = 0; |
| 1475 | return 0; |
| 1476 | } |
| 1477 | pos += 2 + pos[1]; |
| 1478 | } |
| 1479 | return 0; |
| 1480 | } |
| 1481 | |
| 1482 | static int p54_beacon_update(struct ieee80211_hw *dev, |
| 1483 | struct ieee80211_vif *vif) |
| 1484 | { |
| 1485 | struct p54_common *priv = dev->priv; |
| 1486 | struct sk_buff *beacon; |
| 1487 | int ret; |
| 1488 | |
| 1489 | if (priv->cached_beacon) { |
| 1490 | p54_tx_cancel(dev, priv->cached_beacon); |
| 1491 | /* wait for the last beacon the be freed */ |
| 1492 | msleep(10); |
| 1493 | } |
| 1494 | |
| 1495 | beacon = ieee80211_beacon_get(dev, vif); |
| 1496 | if (!beacon) |
| 1497 | return -ENOMEM; |
| 1498 | ret = p54_beacon_tim(beacon); |
| 1499 | if (ret) |
| 1500 | return ret; |
| 1501 | ret = p54_tx(dev, beacon); |
| 1502 | if (ret) |
| 1503 | return ret; |
| 1504 | priv->cached_beacon = beacon; |
| 1505 | priv->tsf_high32 = 0; |
| 1506 | priv->tsf_low32 = 0; |
| 1507 | |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1511 | static int p54_start(struct ieee80211_hw *dev) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1512 | { |
| 1513 | struct p54_common *priv = dev->priv; |
| 1514 | int err; |
| 1515 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1516 | mutex_lock(&priv->conf_mutex); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1517 | err = priv->open(dev); |
| 1518 | if (!err) |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1519 | priv->mode = NL80211_IFTYPE_MONITOR; |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1520 | P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47); |
| 1521 | P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94); |
| 1522 | P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0); |
| 1523 | P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0); |
| 1524 | err = p54_set_edcf(dev); |
| 1525 | if (!err) |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1526 | err = p54_init_stats(dev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1527 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1528 | mutex_unlock(&priv->conf_mutex); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1529 | return err; |
| 1530 | } |
| 1531 | |
| 1532 | static void p54_stop(struct ieee80211_hw *dev) |
| 1533 | { |
| 1534 | struct p54_common *priv = dev->priv; |
| 1535 | struct sk_buff *skb; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1536 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1537 | mutex_lock(&priv->conf_mutex); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1538 | del_timer(&priv->stats_timer); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1539 | p54_free_skb(dev, priv->cached_stats); |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1540 | priv->cached_stats = NULL; |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1541 | if (priv->cached_beacon) |
| 1542 | p54_tx_cancel(dev, priv->cached_beacon); |
| 1543 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1544 | while ((skb = skb_dequeue(&priv->tx_queue))) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1545 | kfree_skb(skb); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1546 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1547 | kfree(priv->cached_beacon); |
| 1548 | priv->cached_beacon = NULL; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1549 | priv->stop(dev); |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 1550 | priv->tsf_high32 = priv->tsf_low32 = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1551 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1552 | mutex_unlock(&priv->conf_mutex); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | static int p54_add_interface(struct ieee80211_hw *dev, |
| 1556 | struct ieee80211_if_init_conf *conf) |
| 1557 | { |
| 1558 | struct p54_common *priv = dev->priv; |
| 1559 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1560 | mutex_lock(&priv->conf_mutex); |
| 1561 | if (priv->mode != NL80211_IFTYPE_MONITOR) { |
| 1562 | mutex_unlock(&priv->conf_mutex); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1563 | return -EOPNOTSUPP; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1564 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1565 | |
| 1566 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1567 | case NL80211_IFTYPE_STATION: |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1568 | case NL80211_IFTYPE_ADHOC: |
| 1569 | case NL80211_IFTYPE_AP: |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1570 | priv->mode = conf->type; |
| 1571 | break; |
| 1572 | default: |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1573 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1574 | return -EOPNOTSUPP; |
| 1575 | } |
| 1576 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1577 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1578 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1579 | p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1580 | |
| 1581 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1582 | case NL80211_IFTYPE_STATION: |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1583 | p54_setup_mac(dev, P54_FILTER_TYPE_STATION, NULL); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1584 | break; |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1585 | case NL80211_IFTYPE_AP: |
| 1586 | p54_setup_mac(dev, P54_FILTER_TYPE_AP, priv->mac_addr); |
| 1587 | break; |
| 1588 | case NL80211_IFTYPE_ADHOC: |
| 1589 | p54_setup_mac(dev, P54_FILTER_TYPE_IBSS, NULL); |
| 1590 | break; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1591 | default: |
| 1592 | BUG(); /* impossible */ |
| 1593 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | p54_set_leds(dev, 1, 0, 0); |
| 1597 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1598 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1599 | return 0; |
| 1600 | } |
| 1601 | |
| 1602 | static void p54_remove_interface(struct ieee80211_hw *dev, |
| 1603 | struct ieee80211_if_init_conf *conf) |
| 1604 | { |
| 1605 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1606 | |
| 1607 | mutex_lock(&priv->conf_mutex); |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1608 | if (priv->cached_beacon) |
| 1609 | p54_tx_cancel(dev, priv->cached_beacon); |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1610 | p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1611 | priv->mode = NL80211_IFTYPE_MONITOR; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1612 | memset(priv->mac_addr, 0, ETH_ALEN); |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1613 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1616 | static int p54_config(struct ieee80211_hw *dev, u32 changed) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1617 | { |
| 1618 | int ret; |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1619 | struct p54_common *priv = dev->priv; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1620 | struct ieee80211_conf *conf = &dev->conf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1621 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1622 | mutex_lock(&priv->conf_mutex); |
Johannes Berg | 0f4ac38 | 2008-10-09 12:18:04 +0200 | [diff] [blame] | 1623 | priv->rx_antenna = 2; /* automatic */ |
Christian Lamparter | 09adf28 | 2008-09-06 14:25:53 +0200 | [diff] [blame] | 1624 | priv->output_power = conf->power_level << 2; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1625 | ret = p54_set_freq(dev, conf->channel->center_freq); |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1626 | if (!ret) |
| 1627 | ret = p54_set_edcf(dev); |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1628 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1629 | return ret; |
| 1630 | } |
| 1631 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 1632 | static int p54_config_interface(struct ieee80211_hw *dev, |
| 1633 | struct ieee80211_vif *vif, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1634 | struct ieee80211_if_conf *conf) |
| 1635 | { |
| 1636 | struct p54_common *priv = dev->priv; |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1637 | int ret = 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1638 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1639 | mutex_lock(&priv->conf_mutex); |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1640 | switch (priv->mode) { |
| 1641 | case NL80211_IFTYPE_STATION: |
| 1642 | ret = p54_setup_mac(dev, P54_FILTER_TYPE_STATION, conf->bssid); |
| 1643 | if (ret) |
| 1644 | goto out; |
| 1645 | ret = p54_set_leds(dev, 1, |
| 1646 | !is_multicast_ether_addr(conf->bssid), 0); |
| 1647 | if (ret) |
| 1648 | goto out; |
| 1649 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 1650 | break; |
| 1651 | case NL80211_IFTYPE_AP: |
| 1652 | case NL80211_IFTYPE_ADHOC: |
| 1653 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 1654 | ret = p54_set_freq(dev, dev->conf.channel->center_freq); |
| 1655 | if (ret) |
| 1656 | goto out; |
| 1657 | ret = p54_setup_mac(dev, priv->mac_mode, priv->bssid); |
| 1658 | if (ret) |
| 1659 | goto out; |
| 1660 | if (conf->changed & IEEE80211_IFCC_BEACON) { |
| 1661 | ret = p54_beacon_update(dev, vif); |
| 1662 | if (ret) |
| 1663 | goto out; |
| 1664 | ret = p54_set_edcf(dev); |
| 1665 | if (ret) |
| 1666 | goto out; |
| 1667 | } |
| 1668 | } |
| 1669 | out: |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1670 | mutex_unlock(&priv->conf_mutex); |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1671 | return ret; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1674 | static void p54_configure_filter(struct ieee80211_hw *dev, |
| 1675 | unsigned int changed_flags, |
| 1676 | unsigned int *total_flags, |
| 1677 | int mc_count, struct dev_mc_list *mclist) |
| 1678 | { |
| 1679 | struct p54_common *priv = dev->priv; |
| 1680 | |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 1681 | *total_flags &= FIF_BCN_PRBRESP_PROMISC | |
| 1682 | FIF_PROMISC_IN_BSS | |
| 1683 | FIF_FCSFAIL; |
| 1684 | |
| 1685 | priv->filter_flags = *total_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1686 | |
| 1687 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 1688 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1689 | p54_setup_mac(dev, priv->mac_mode, NULL); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1690 | else |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1691 | p54_setup_mac(dev, priv->mac_mode, priv->bssid); |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | if (changed_flags & FIF_PROMISC_IN_BSS) { |
| 1695 | if (*total_flags & FIF_PROMISC_IN_BSS) |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1696 | p54_setup_mac(dev, priv->mac_mode | 0x8, NULL); |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 1697 | else |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1698 | p54_setup_mac(dev, priv->mac_mode & ~0x8, priv->bssid); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1702 | static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1703 | const struct ieee80211_tx_queue_params *params) |
| 1704 | { |
| 1705 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1706 | int ret; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1707 | |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1708 | mutex_lock(&priv->conf_mutex); |
John W. Linville | 3df5ee6 | 2008-05-01 17:07:32 -0400 | [diff] [blame] | 1709 | if ((params) && !(queue > 4)) { |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1710 | P54_SET_QUEUE(priv->qos_params[queue], params->aifs, |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1711 | params->cw_min, params->cw_max, params->txop); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1712 | } else |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1713 | ret = -EINVAL; |
| 1714 | if (!ret) |
| 1715 | ret = p54_set_edcf(dev); |
| 1716 | mutex_unlock(&priv->conf_mutex); |
| 1717 | return ret; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1718 | } |
| 1719 | |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1720 | static int p54_init_xbow_synth(struct ieee80211_hw *dev) |
| 1721 | { |
| 1722 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1723 | struct sk_buff *skb; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1724 | struct p54_xbow_synth *xbow; |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1725 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1726 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow) + |
| 1727 | sizeof(struct p54_hdr), |
| 1728 | P54_CONTROL_TYPE_XBOW_SYNTH_CFG, |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1729 | GFP_KERNEL); |
| 1730 | if (!skb) |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1731 | return -ENOMEM; |
| 1732 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1733 | xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow)); |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1734 | xbow->magic1 = cpu_to_le16(0x1); |
| 1735 | xbow->magic2 = cpu_to_le16(0x2); |
| 1736 | xbow->freq = cpu_to_le16(5390); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1737 | memset(xbow->padding, 0, sizeof(xbow->padding)); |
| 1738 | priv->tx(dev, skb, 1); |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1739 | return 0; |
| 1740 | } |
| 1741 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1742 | static void p54_statistics_timer(unsigned long data) |
| 1743 | { |
| 1744 | struct ieee80211_hw *dev = (struct ieee80211_hw *) data; |
| 1745 | struct p54_common *priv = dev->priv; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1746 | |
| 1747 | BUG_ON(!priv->cached_stats); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1748 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1749 | priv->tx(dev, priv->cached_stats, 0); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1752 | static int p54_get_stats(struct ieee80211_hw *dev, |
| 1753 | struct ieee80211_low_level_stats *stats) |
| 1754 | { |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1755 | struct p54_common *priv = dev->priv; |
| 1756 | |
| 1757 | del_timer(&priv->stats_timer); |
| 1758 | p54_statistics_timer((unsigned long)dev); |
| 1759 | |
| 1760 | if (!wait_for_completion_interruptible_timeout(&priv->stats_comp, HZ)) { |
| 1761 | printk(KERN_ERR "%s: device does not respond!\n", |
| 1762 | wiphy_name(dev->wiphy)); |
| 1763 | return -EBUSY; |
| 1764 | } |
| 1765 | |
| 1766 | memcpy(stats, &priv->stats, sizeof(*stats)); |
| 1767 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1768 | return 0; |
| 1769 | } |
| 1770 | |
| 1771 | static int p54_get_tx_stats(struct ieee80211_hw *dev, |
| 1772 | struct ieee80211_tx_queue_stats *stats) |
| 1773 | { |
| 1774 | struct p54_common *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1775 | |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 1776 | memcpy(stats, &priv->tx_stats[4], sizeof(stats[0]) * dev->queues); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1777 | |
| 1778 | return 0; |
| 1779 | } |
| 1780 | |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1781 | static void p54_bss_info_changed(struct ieee80211_hw *dev, |
| 1782 | struct ieee80211_vif *vif, |
| 1783 | struct ieee80211_bss_conf *info, |
| 1784 | u32 changed) |
| 1785 | { |
| 1786 | struct p54_common *priv = dev->priv; |
| 1787 | |
| 1788 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1789 | priv->use_short_slot = info->use_short_slot; |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1790 | p54_set_edcf(dev); |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1794 | static const struct ieee80211_ops p54_ops = { |
| 1795 | .tx = p54_tx, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1796 | .start = p54_start, |
| 1797 | .stop = p54_stop, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1798 | .add_interface = p54_add_interface, |
| 1799 | .remove_interface = p54_remove_interface, |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1800 | .set_tim = p54_set_tim, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1801 | .config = p54_config, |
| 1802 | .config_interface = p54_config_interface, |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1803 | .bss_info_changed = p54_bss_info_changed, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1804 | .configure_filter = p54_configure_filter, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1805 | .conf_tx = p54_conf_tx, |
| 1806 | .get_stats = p54_get_stats, |
| 1807 | .get_tx_stats = p54_get_tx_stats |
| 1808 | }; |
| 1809 | |
| 1810 | struct ieee80211_hw *p54_init_common(size_t priv_data_len) |
| 1811 | { |
| 1812 | struct ieee80211_hw *dev; |
| 1813 | struct p54_common *priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1814 | |
| 1815 | dev = ieee80211_alloc_hw(priv_data_len, &p54_ops); |
| 1816 | if (!dev) |
| 1817 | return NULL; |
| 1818 | |
| 1819 | priv = dev->priv; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1820 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1821 | skb_queue_head_init(&priv->tx_queue); |
Christian Lamparter | 94585b0 | 2008-10-18 23:18:44 +0200 | [diff] [blame] | 1822 | dev->flags = IEEE80211_HW_RX_INCLUDES_FCS | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1823 | IEEE80211_HW_SIGNAL_DBM | |
| 1824 | IEEE80211_HW_NOISE_DBM; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1825 | |
Christian Lamparter | e5ea92a | 2008-10-18 23:19:00 +0200 | [diff] [blame] | 1826 | dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION | |
| 1827 | NL80211_IFTYPE_ADHOC | |
| 1828 | NL80211_IFTYPE_AP); |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1829 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1830 | dev->channel_change_time = 1000; /* TODO: find actual value */ |
Christian Lamparter | 9e7f3f8 | 2008-10-18 23:18:01 +0200 | [diff] [blame] | 1831 | priv->tx_stats[0].limit = 1; /* Beacon queue */ |
| 1832 | priv->tx_stats[1].limit = 1; /* Probe queue for HW scan */ |
| 1833 | priv->tx_stats[2].limit = 3; /* queue for MLMEs */ |
| 1834 | priv->tx_stats[3].limit = 3; /* Broadcast / MC queue */ |
| 1835 | priv->tx_stats[4].limit = 5; /* Data */ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1836 | dev->queues = 1; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1837 | priv->noise = -94; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1838 | /* |
| 1839 | * We support at most 8 tries no matter which rate they're at, |
| 1840 | * we cannot support max_rates * max_rate_tries as we set it |
| 1841 | * here, but setting it correctly to 4/2 or so would limit us |
| 1842 | * artificially if the RC algorithm wants just two rates, so |
| 1843 | * let's say 4/7, we'll redistribute it at TX time, see the |
| 1844 | * comments there. |
| 1845 | */ |
| 1846 | dev->max_rates = 4; |
| 1847 | dev->max_rate_tries = 7; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame] | 1848 | dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 + |
| 1849 | sizeof(struct p54_tx_data); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1850 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1851 | mutex_init(&priv->conf_mutex); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 1852 | init_completion(&priv->eeprom_comp); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1853 | init_completion(&priv->stats_comp); |
| 1854 | setup_timer(&priv->stats_timer, p54_statistics_timer, |
| 1855 | (unsigned long)dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1856 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1857 | return dev; |
| 1858 | } |
| 1859 | EXPORT_SYMBOL_GPL(p54_init_common); |
| 1860 | |
| 1861 | void p54_free_common(struct ieee80211_hw *dev) |
| 1862 | { |
| 1863 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1864 | del_timer(&priv->stats_timer); |
| 1865 | kfree_skb(priv->cached_stats); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1866 | kfree(priv->iq_autocal); |
| 1867 | kfree(priv->output_limit); |
| 1868 | kfree(priv->curve_data); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1869 | } |
| 1870 | EXPORT_SYMBOL_GPL(p54_free_common); |
| 1871 | |
| 1872 | static int __init p54_init(void) |
| 1873 | { |
| 1874 | return 0; |
| 1875 | } |
| 1876 | |
| 1877 | static void __exit p54_exit(void) |
| 1878 | { |
| 1879 | } |
| 1880 | |
| 1881 | module_init(p54_init); |
| 1882 | module_exit(p54_exit); |