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 | |
| 217 | if (priv->fw_var >= 0x300) { |
| 218 | /* Firmware supports QoS, use it! */ |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 219 | priv->tx_stats[4].limit = 3; |
| 220 | priv->tx_stats[5].limit = 4; |
| 221 | priv->tx_stats[6].limit = 3; |
| 222 | priv->tx_stats[7].limit = 1; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 223 | dev->queues = 4; |
| 224 | } |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 225 | |
| 226 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 227 | } |
| 228 | EXPORT_SYMBOL_GPL(p54_parse_firmware); |
| 229 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 230 | static int p54_convert_rev0(struct ieee80211_hw *dev, |
| 231 | struct pda_pa_curve_data *curve_data) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 232 | { |
| 233 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 234 | struct p54_pa_curve_data_sample *dst; |
| 235 | struct pda_pa_curve_data_sample_rev0 *src; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 236 | size_t cd_len = sizeof(*curve_data) + |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 237 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 238 | curve_data->channels; |
| 239 | unsigned int i, j; |
| 240 | void *source, *target; |
| 241 | |
| 242 | priv->curve_data = kmalloc(cd_len, GFP_KERNEL); |
| 243 | if (!priv->curve_data) |
| 244 | return -ENOMEM; |
| 245 | |
| 246 | memcpy(priv->curve_data, curve_data, sizeof(*curve_data)); |
| 247 | source = curve_data->data; |
| 248 | target = priv->curve_data->data; |
| 249 | for (i = 0; i < curve_data->channels; i++) { |
| 250 | __le16 *freq = source; |
| 251 | source += sizeof(__le16); |
| 252 | *((__le16 *)target) = *freq; |
| 253 | target += sizeof(__le16); |
| 254 | for (j = 0; j < curve_data->points_per_channel; j++) { |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 255 | dst = target; |
| 256 | src = source; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 257 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 258 | dst->rf_power = src->rf_power; |
| 259 | dst->pa_detector = src->pa_detector; |
| 260 | dst->data_64qam = src->pcv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 261 | /* "invent" the points for the other modulations */ |
| 262 | #define SUB(x,y) (u8)((x) - (y)) > (x) ? 0 : (x) - (y) |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 263 | dst->data_16qam = SUB(src->pcv, 12); |
| 264 | dst->data_qpsk = SUB(dst->data_16qam, 12); |
| 265 | dst->data_bpsk = SUB(dst->data_qpsk, 12); |
| 266 | dst->data_barker = SUB(dst->data_bpsk, 14); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 267 | #undef SUB |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 268 | target += sizeof(*dst); |
| 269 | source += sizeof(*src); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 276 | static int p54_convert_rev1(struct ieee80211_hw *dev, |
| 277 | struct pda_pa_curve_data *curve_data) |
| 278 | { |
| 279 | struct p54_common *priv = dev->priv; |
| 280 | struct p54_pa_curve_data_sample *dst; |
| 281 | struct pda_pa_curve_data_sample_rev1 *src; |
| 282 | size_t cd_len = sizeof(*curve_data) + |
| 283 | (curve_data->points_per_channel*sizeof(*dst) + 2) * |
| 284 | curve_data->channels; |
| 285 | unsigned int i, j; |
| 286 | void *source, *target; |
| 287 | |
| 288 | priv->curve_data = kmalloc(cd_len, GFP_KERNEL); |
| 289 | if (!priv->curve_data) |
| 290 | return -ENOMEM; |
| 291 | |
| 292 | memcpy(priv->curve_data, curve_data, sizeof(*curve_data)); |
| 293 | source = curve_data->data; |
| 294 | target = priv->curve_data->data; |
| 295 | for (i = 0; i < curve_data->channels; i++) { |
| 296 | __le16 *freq = source; |
| 297 | source += sizeof(__le16); |
| 298 | *((__le16 *)target) = *freq; |
| 299 | target += sizeof(__le16); |
| 300 | for (j = 0; j < curve_data->points_per_channel; j++) { |
| 301 | memcpy(target, source, sizeof(*src)); |
| 302 | |
| 303 | target += sizeof(*dst); |
| 304 | source += sizeof(*src); |
| 305 | } |
| 306 | source++; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 312 | static const char *p54_rf_chips[] = { "NULL", "Duette3", "Duette2", |
| 313 | "Frisbee", "Xbow", "Longbow", "NULL", "NULL" }; |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 314 | static int p54_init_xbow_synth(struct ieee80211_hw *dev); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 315 | |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 316 | 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] | 317 | { |
| 318 | struct p54_common *priv = dev->priv; |
| 319 | struct eeprom_pda_wrap *wrap = NULL; |
| 320 | struct pda_entry *entry; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 321 | unsigned int data_len, entry_len; |
| 322 | void *tmp; |
| 323 | int err; |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 324 | u8 *end = (u8 *)eeprom + len; |
Christian Lamparter | f2c2e25 | 2008-10-25 16:14:14 +0200 | [diff] [blame] | 325 | u16 synth = 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 326 | |
| 327 | wrap = (struct eeprom_pda_wrap *) eeprom; |
Johannes Berg | 8c28293 | 2008-02-29 13:56:33 +0100 | [diff] [blame] | 328 | entry = (void *)wrap->data + le16_to_cpu(wrap->len); |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 329 | |
| 330 | /* verify that at least the entry length/code fits */ |
| 331 | while ((u8 *)entry <= end - sizeof(*entry)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 332 | entry_len = le16_to_cpu(entry->len); |
| 333 | data_len = ((entry_len - 1) << 1); |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 334 | |
| 335 | /* abort if entry exceeds whole structure */ |
| 336 | if ((u8 *)entry + sizeof(*entry) + data_len > end) |
| 337 | break; |
| 338 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 339 | switch (le16_to_cpu(entry->code)) { |
| 340 | case PDR_MAC_ADDRESS: |
| 341 | SET_IEEE80211_PERM_ADDR(dev, entry->data); |
| 342 | break; |
| 343 | case PDR_PRISM_PA_CAL_OUTPUT_POWER_LIMITS: |
| 344 | if (data_len < 2) { |
| 345 | err = -EINVAL; |
| 346 | goto err; |
| 347 | } |
| 348 | |
| 349 | if (2 + entry->data[1]*sizeof(*priv->output_limit) > data_len) { |
| 350 | err = -EINVAL; |
| 351 | goto err; |
| 352 | } |
| 353 | |
| 354 | priv->output_limit = kmalloc(entry->data[1] * |
| 355 | sizeof(*priv->output_limit), GFP_KERNEL); |
| 356 | |
| 357 | if (!priv->output_limit) { |
| 358 | err = -ENOMEM; |
| 359 | goto err; |
| 360 | } |
| 361 | |
| 362 | memcpy(priv->output_limit, &entry->data[2], |
| 363 | entry->data[1]*sizeof(*priv->output_limit)); |
| 364 | priv->output_limit_len = entry->data[1]; |
| 365 | break; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 366 | case PDR_PRISM_PA_CAL_CURVE_DATA: { |
| 367 | struct pda_pa_curve_data *curve_data = |
| 368 | (struct pda_pa_curve_data *)entry->data; |
| 369 | if (data_len < sizeof(*curve_data)) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 370 | err = -EINVAL; |
| 371 | goto err; |
| 372 | } |
| 373 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 374 | switch (curve_data->cal_method_rev) { |
| 375 | case 0: |
| 376 | err = p54_convert_rev0(dev, curve_data); |
| 377 | break; |
| 378 | case 1: |
| 379 | err = p54_convert_rev1(dev, curve_data); |
| 380 | break; |
| 381 | default: |
| 382 | printk(KERN_ERR "p54: unknown curve data " |
| 383 | "revision %d\n", |
| 384 | curve_data->cal_method_rev); |
| 385 | err = -ENODEV; |
| 386 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 387 | } |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 388 | if (err) |
| 389 | goto err; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 390 | |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 391 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 392 | case PDR_PRISM_ZIF_TX_IQ_CALIBRATION: |
| 393 | priv->iq_autocal = kmalloc(data_len, GFP_KERNEL); |
| 394 | if (!priv->iq_autocal) { |
| 395 | err = -ENOMEM; |
| 396 | goto err; |
| 397 | } |
| 398 | |
| 399 | memcpy(priv->iq_autocal, entry->data, data_len); |
| 400 | priv->iq_autocal_len = data_len / sizeof(struct pda_iq_autocal_entry); |
| 401 | break; |
| 402 | case PDR_INTERFACE_LIST: |
| 403 | tmp = entry->data; |
| 404 | while ((u8 *)tmp < entry->data + data_len) { |
| 405 | struct bootrec_exp_if *exp_if = tmp; |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 406 | if (le16_to_cpu(exp_if->if_id) == 0xf) |
| 407 | synth = le16_to_cpu(exp_if->variant); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 408 | tmp += sizeof(struct bootrec_exp_if); |
| 409 | } |
| 410 | break; |
| 411 | case PDR_HARDWARE_PLATFORM_COMPONENT_ID: |
| 412 | priv->version = *(u8 *)(entry->data + 1); |
| 413 | break; |
| 414 | case PDR_END: |
Johannes Berg | c2f2d3a | 2008-02-29 23:28:25 +0100 | [diff] [blame] | 415 | /* make it overrun */ |
| 416 | entry_len = len; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 417 | break; |
Florian Fainelli | 58e3073 | 2008-02-25 17:51:53 +0100 | [diff] [blame] | 418 | default: |
| 419 | printk(KERN_INFO "p54: unknown eeprom code : 0x%x\n", |
| 420 | le16_to_cpu(entry->code)); |
| 421 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | entry = (void *)entry + (entry_len + 1)*2; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Christian Lamparter | f2c2e25 | 2008-10-25 16:14:14 +0200 | [diff] [blame] | 427 | if (!synth || !priv->iq_autocal || !priv->output_limit || |
| 428 | !priv->curve_data) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 429 | printk(KERN_ERR "p54: not all required entries found in eeprom!\n"); |
| 430 | err = -EINVAL; |
| 431 | goto err; |
| 432 | } |
| 433 | |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 434 | priv->rxhw = synth & 0x07; |
| 435 | if (priv->rxhw == 4) |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 436 | p54_init_xbow_synth(dev); |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 437 | if (!(synth & 0x40)) |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 438 | dev->wiphy->bands[IEEE80211_BAND_2GHZ] = &band_2GHz; |
Christian Lamparter | 4cc683c | 2008-10-15 03:30:06 +0200 | [diff] [blame] | 439 | if (!(synth & 0x80)) |
| 440 | dev->wiphy->bands[IEEE80211_BAND_5GHZ] = &band_5GHz; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 441 | |
| 442 | if (!is_valid_ether_addr(dev->wiphy->perm_addr)) { |
| 443 | u8 perm_addr[ETH_ALEN]; |
| 444 | |
| 445 | printk(KERN_WARNING "%s: Invalid hwaddr! Using randomly generated MAC addr\n", |
| 446 | wiphy_name(dev->wiphy)); |
| 447 | random_ether_addr(perm_addr); |
| 448 | SET_IEEE80211_PERM_ADDR(dev, perm_addr); |
| 449 | } |
| 450 | |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 451 | printk(KERN_INFO "%s: hwaddr %pM, MAC:isl38%02x RF:%s\n", |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 452 | wiphy_name(dev->wiphy), |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 453 | dev->wiphy->perm_addr, |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 454 | priv->version, p54_rf_chips[priv->rxhw]); |
| 455 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 456 | return 0; |
| 457 | |
| 458 | err: |
| 459 | if (priv->iq_autocal) { |
| 460 | kfree(priv->iq_autocal); |
| 461 | priv->iq_autocal = NULL; |
| 462 | } |
| 463 | |
| 464 | if (priv->output_limit) { |
| 465 | kfree(priv->output_limit); |
| 466 | priv->output_limit = NULL; |
| 467 | } |
| 468 | |
| 469 | if (priv->curve_data) { |
| 470 | kfree(priv->curve_data); |
| 471 | priv->curve_data = NULL; |
| 472 | } |
| 473 | |
| 474 | printk(KERN_ERR "p54: eeprom parse failed!\n"); |
| 475 | return err; |
| 476 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 477 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 478 | static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi) |
| 479 | { |
| 480 | /* TODO: get the rssi_add & rssi_mul data from the eeprom */ |
| 481 | return ((rssi * 0x83) / 64 - 400) / 4; |
| 482 | } |
| 483 | |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 484 | 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] | 485 | { |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 486 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 487 | struct p54_rx_data *hdr = (struct p54_rx_data *) skb->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 488 | struct ieee80211_rx_status rx_status = {0}; |
| 489 | u16 freq = le16_to_cpu(hdr->freq); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 490 | size_t header_len = sizeof(*hdr); |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 491 | u32 tsf32; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 492 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 493 | 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] | 494 | if (priv->filter_flags & FIF_FCSFAIL) |
| 495 | rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; |
| 496 | else |
| 497 | return 0; |
| 498 | } |
| 499 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 500 | rx_status.signal = p54_rssi_to_dbm(dev, hdr->rssi); |
| 501 | rx_status.noise = priv->noise; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 502 | /* XX correct? */ |
Larry.Finger@lwfinger.net | 18d7260 | 2008-06-30 10:39:49 -0500 | [diff] [blame] | 503 | rx_status.qual = (100 * hdr->rssi) / 127; |
Christian Lamparter | cf3e74c | 2008-09-30 23:36:00 +0200 | [diff] [blame] | 504 | rx_status.rate_idx = (dev->conf.channel->band == IEEE80211_BAND_2GHZ ? |
| 505 | hdr->rate : (hdr->rate - 4)) & 0xf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 506 | rx_status.freq = freq; |
Christian Lamparter | cf3e74c | 2008-09-30 23:36:00 +0200 | [diff] [blame] | 507 | rx_status.band = dev->conf.channel->band; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 508 | rx_status.antenna = hdr->antenna; |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 509 | |
| 510 | tsf32 = le32_to_cpu(hdr->tsf32); |
| 511 | if (tsf32 < priv->tsf_low32) |
| 512 | priv->tsf_high32++; |
| 513 | rx_status.mactime = ((u64)priv->tsf_high32) << 32 | tsf32; |
| 514 | priv->tsf_low32 = tsf32; |
| 515 | |
Johannes Berg | 03bffc1 | 2007-12-04 20:33:40 +0100 | [diff] [blame] | 516 | rx_status.flag |= RX_FLAG_TSFT; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 517 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 518 | if (hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN)) |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 519 | header_len += hdr->align[0]; |
| 520 | |
| 521 | skb_pull(skb, header_len); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 522 | skb_trim(skb, le16_to_cpu(hdr->len)); |
| 523 | |
| 524 | ieee80211_rx_irqsafe(dev, skb, &rx_status); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 525 | |
| 526 | return -1; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void inline p54_wake_free_queues(struct ieee80211_hw *dev) |
| 530 | { |
| 531 | struct p54_common *priv = dev->priv; |
| 532 | int i; |
| 533 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 534 | if (priv->mode == NL80211_IFTYPE_UNSPECIFIED) |
| 535 | return ; |
| 536 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 537 | for (i = 0; i < dev->queues; i++) |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 538 | 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] | 539 | ieee80211_wake_queue(dev, i); |
| 540 | } |
| 541 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 542 | void p54_free_skb(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 543 | { |
| 544 | struct p54_common *priv = dev->priv; |
| 545 | struct ieee80211_tx_info *info; |
| 546 | struct memrecord *range; |
| 547 | unsigned long flags; |
| 548 | u32 freed = 0, last_addr = priv->rx_start; |
| 549 | |
| 550 | if (!skb || !dev) |
| 551 | return; |
| 552 | |
| 553 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
| 554 | info = IEEE80211_SKB_CB(skb); |
| 555 | range = (void *)info->rate_driver_data; |
| 556 | if (skb->prev != (struct sk_buff *)&priv->tx_queue) { |
| 557 | struct ieee80211_tx_info *ni; |
| 558 | struct memrecord *mr; |
| 559 | |
| 560 | ni = IEEE80211_SKB_CB(skb->prev); |
| 561 | mr = (struct memrecord *)ni->rate_driver_data; |
| 562 | last_addr = mr->end_addr; |
| 563 | } |
| 564 | if (skb->next != (struct sk_buff *)&priv->tx_queue) { |
| 565 | struct ieee80211_tx_info *ni; |
| 566 | struct memrecord *mr; |
| 567 | |
| 568 | ni = IEEE80211_SKB_CB(skb->next); |
| 569 | mr = (struct memrecord *)ni->rate_driver_data; |
| 570 | freed = mr->start_addr - last_addr; |
| 571 | } else |
| 572 | freed = priv->rx_end - last_addr; |
| 573 | __skb_unlink(skb, &priv->tx_queue); |
| 574 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 575 | kfree_skb(skb); |
| 576 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 577 | if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 + |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 578 | IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom) |
| 579 | p54_wake_free_queues(dev); |
| 580 | } |
| 581 | EXPORT_SYMBOL_GPL(p54_free_skb); |
| 582 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 583 | static void p54_rx_frame_sent(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 584 | { |
| 585 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 586 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
| 587 | struct p54_frame_sent *payload = (struct p54_frame_sent *) hdr->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 588 | struct sk_buff *entry = (struct sk_buff *) priv->tx_queue.next; |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 589 | u32 addr = le32_to_cpu(hdr->req_id) - priv->headroom; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 590 | struct memrecord *range = NULL; |
| 591 | u32 freed = 0; |
| 592 | u32 last_addr = priv->rx_start; |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 593 | unsigned long flags; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 594 | int count, idx; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 595 | |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 596 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 597 | while (entry != (struct sk_buff *)&priv->tx_queue) { |
Johannes Berg | 552fe53 | 2008-05-30 21:07:15 +0200 | [diff] [blame] | 598 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(entry); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 599 | struct p54_hdr *entry_hdr; |
| 600 | struct p54_tx_data *entry_data; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 601 | int pad = 0; |
| 602 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 603 | range = (void *)info->rate_driver_data; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 604 | if (range->start_addr != addr) { |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 605 | last_addr = range->end_addr; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 606 | entry = entry->next; |
| 607 | continue; |
| 608 | } |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 609 | |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 610 | if (entry->next != (struct sk_buff *)&priv->tx_queue) { |
| 611 | struct ieee80211_tx_info *ni; |
| 612 | struct memrecord *mr; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 613 | |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 614 | ni = IEEE80211_SKB_CB(entry->next); |
| 615 | mr = (struct memrecord *)ni->rate_driver_data; |
| 616 | freed = mr->start_addr - last_addr; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 617 | } else |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 618 | freed = priv->rx_end - last_addr; |
| 619 | |
| 620 | last_addr = range->end_addr; |
| 621 | __skb_unlink(entry, &priv->tx_queue); |
| 622 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 623 | |
| 624 | /* |
| 625 | * Clear manually, ieee80211_tx_info_clear_status would |
| 626 | * clear the counts too and we need them. |
| 627 | */ |
| 628 | memset(&info->status.ampdu_ack_len, 0, |
| 629 | sizeof(struct ieee80211_tx_info) - |
| 630 | offsetof(struct ieee80211_tx_info, status.ampdu_ack_len)); |
| 631 | BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, |
| 632 | status.ampdu_ack_len) != 23); |
| 633 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 634 | entry_hdr = (struct p54_hdr *) entry->data; |
| 635 | entry_data = (struct p54_tx_data *) entry_hdr->data; |
| 636 | if (entry_hdr->flags & cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN)) |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 637 | pad = entry_data->align[0]; |
| 638 | |
| 639 | /* walk through the rates array and adjust the counts */ |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 640 | count = payload->tries; |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 641 | for (idx = 0; idx < 4; idx++) { |
| 642 | if (count >= info->status.rates[idx].count) { |
| 643 | count -= info->status.rates[idx].count; |
| 644 | } else if (count > 0) { |
| 645 | info->status.rates[idx].count = count; |
| 646 | count = 0; |
| 647 | } else { |
| 648 | info->status.rates[idx].idx = -1; |
| 649 | info->status.rates[idx].count = 0; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | priv->tx_stats[entry_data->hw_queue].len--; |
| 654 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) && |
| 655 | (!payload->status)) |
| 656 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 657 | if (payload->status & 0x02) |
| 658 | info->flags |= IEEE80211_TX_STAT_TX_FILTERED; |
| 659 | info->status.ack_signal = p54_rssi_to_dbm(dev, |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 660 | (int)payload->ack_rssi); |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 661 | skb_pull(entry, sizeof(*hdr) + pad + sizeof(*entry_data)); |
| 662 | ieee80211_tx_status_irqsafe(dev, entry); |
| 663 | goto out; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 664 | } |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 665 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 666 | |
Chr | 031d10e | 2008-08-24 03:15:06 +0200 | [diff] [blame] | 667 | out: |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 668 | if (freed >= priv->headroom + sizeof(struct p54_hdr) + 48 + |
Christian Lamparter | 9de5776f | 2008-10-15 04:05:51 +0200 | [diff] [blame] | 669 | IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 670 | p54_wake_free_queues(dev); |
| 671 | } |
| 672 | |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 673 | static void p54_rx_eeprom_readback(struct ieee80211_hw *dev, |
| 674 | struct sk_buff *skb) |
| 675 | { |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 676 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 677 | struct p54_eeprom_lm86 *eeprom = (struct p54_eeprom_lm86 *) hdr->data; |
| 678 | struct p54_common *priv = dev->priv; |
| 679 | |
| 680 | if (!priv->eeprom) |
| 681 | return ; |
| 682 | |
Larry Finger | 1f1c0e3 | 2008-09-25 14:54:28 -0500 | [diff] [blame] | 683 | memcpy(priv->eeprom, eeprom->data, le16_to_cpu(eeprom->len)); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 684 | |
| 685 | complete(&priv->eeprom_comp); |
| 686 | } |
| 687 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 688 | static void p54_rx_stats(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 689 | { |
| 690 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 691 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 692 | struct p54_statistics *stats = (struct p54_statistics *) hdr->data; |
| 693 | u32 tsf32 = le32_to_cpu(stats->tsf32); |
| 694 | |
| 695 | if (tsf32 < priv->tsf_low32) |
| 696 | priv->tsf_high32++; |
| 697 | priv->tsf_low32 = tsf32; |
| 698 | |
| 699 | priv->stats.dot11RTSFailureCount = le32_to_cpu(stats->rts_fail); |
| 700 | priv->stats.dot11RTSSuccessCount = le32_to_cpu(stats->rts_success); |
| 701 | priv->stats.dot11FCSErrorCount = le32_to_cpu(stats->rx_bad_fcs); |
| 702 | |
| 703 | priv->noise = p54_rssi_to_dbm(dev, le32_to_cpu(stats->noise)); |
| 704 | complete(&priv->stats_comp); |
| 705 | |
| 706 | mod_timer(&priv->stats_timer, jiffies + 5 * HZ); |
| 707 | } |
| 708 | |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 709 | 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] | 710 | { |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 711 | struct p54_hdr *hdr = (struct p54_hdr *) skb->data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 712 | |
| 713 | switch (le16_to_cpu(hdr->type)) { |
| 714 | case P54_CONTROL_TYPE_TXDONE: |
| 715 | p54_rx_frame_sent(dev, skb); |
| 716 | break; |
| 717 | case P54_CONTROL_TYPE_BBP: |
| 718 | break; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 719 | case P54_CONTROL_TYPE_STAT_READBACK: |
| 720 | p54_rx_stats(dev, skb); |
| 721 | break; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 722 | case P54_CONTROL_TYPE_EEPROM_READBACK: |
| 723 | p54_rx_eeprom_readback(dev, skb); |
| 724 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 725 | default: |
| 726 | printk(KERN_DEBUG "%s: not handling 0x%02x type control frame\n", |
| 727 | wiphy_name(dev->wiphy), le16_to_cpu(hdr->type)); |
| 728 | break; |
| 729 | } |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 730 | |
| 731 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | /* returns zero if skb can be reused */ |
| 735 | int p54_rx(struct ieee80211_hw *dev, struct sk_buff *skb) |
| 736 | { |
| 737 | u8 type = le16_to_cpu(*((__le16 *)skb->data)) >> 8; |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 738 | |
| 739 | if (type == 0x80) |
| 740 | return p54_rx_control(dev, skb); |
| 741 | else |
| 742 | return p54_rx_data(dev, skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 743 | } |
| 744 | EXPORT_SYMBOL_GPL(p54_rx); |
| 745 | |
| 746 | /* |
| 747 | * So, the firmware is somewhat stupid and doesn't know what places in its |
| 748 | * memory incoming data should go to. By poking around in the firmware, we |
| 749 | * can find some unused memory to upload our packets to. However, data that we |
| 750 | * want the card to TX needs to stay intact until the card has told us that |
| 751 | * it is done with it. This function finds empty places we can upload to and |
| 752 | * marks allocated areas as reserved if necessary. p54_rx_frame_sent frees |
| 753 | * allocated areas. |
| 754 | */ |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 755 | 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^] | 756 | struct p54_hdr *data, u32 len) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 757 | { |
| 758 | struct p54_common *priv = dev->priv; |
| 759 | struct sk_buff *entry = priv->tx_queue.next; |
| 760 | struct sk_buff *target_skb = NULL; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 761 | struct ieee80211_tx_info *info; |
| 762 | struct memrecord *range; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 763 | u32 last_addr = priv->rx_start; |
| 764 | u32 largest_hole = 0; |
| 765 | u32 target_addr = priv->rx_start; |
| 766 | unsigned long flags; |
| 767 | unsigned int left; |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 768 | len = (len + priv->headroom + priv->tailroom + 3) & ~0x3; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 769 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 770 | if (!skb) |
| 771 | return -EINVAL; |
| 772 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 773 | spin_lock_irqsave(&priv->tx_queue.lock, flags); |
| 774 | left = skb_queue_len(&priv->tx_queue); |
| 775 | while (left--) { |
| 776 | u32 hole_size; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 777 | info = IEEE80211_SKB_CB(entry); |
| 778 | range = (void *)info->rate_driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 779 | hole_size = range->start_addr - last_addr; |
| 780 | if (!target_skb && hole_size >= len) { |
| 781 | target_skb = entry->prev; |
| 782 | hole_size -= len; |
| 783 | target_addr = last_addr; |
| 784 | } |
| 785 | largest_hole = max(largest_hole, hole_size); |
| 786 | last_addr = range->end_addr; |
| 787 | entry = entry->next; |
| 788 | } |
| 789 | if (!target_skb && priv->rx_end - last_addr >= len) { |
| 790 | target_skb = priv->tx_queue.prev; |
| 791 | largest_hole = max(largest_hole, priv->rx_end - last_addr - len); |
| 792 | if (!skb_queue_empty(&priv->tx_queue)) { |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 793 | info = IEEE80211_SKB_CB(target_skb); |
| 794 | range = (void *)info->rate_driver_data; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 795 | target_addr = range->end_addr; |
| 796 | } |
| 797 | } else |
| 798 | largest_hole = max(largest_hole, priv->rx_end - last_addr); |
| 799 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 800 | if (!target_skb) { |
| 801 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 802 | ieee80211_stop_queues(dev); |
| 803 | return -ENOMEM; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 804 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 805 | |
| 806 | info = IEEE80211_SKB_CB(skb); |
| 807 | range = (void *)info->rate_driver_data; |
| 808 | range->start_addr = target_addr; |
| 809 | range->end_addr = target_addr + len; |
| 810 | __skb_queue_after(&priv->tx_queue, target_skb, skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 811 | spin_unlock_irqrestore(&priv->tx_queue.lock, flags); |
| 812 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 813 | if (largest_hole < priv->headroom + sizeof(struct p54_hdr) + |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 814 | 48 + IEEE80211_MAX_RTS_THRESHOLD + priv->tailroom) |
| 815 | ieee80211_stop_queues(dev); |
| 816 | |
Christian Lamparter | 4e416a6 | 2008-09-01 22:48:41 +0200 | [diff] [blame] | 817 | data->req_id = cpu_to_le32(target_addr + priv->headroom); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev, |
| 822 | u16 hdr_flags, u16 len, u16 type, gfp_t memflags) |
| 823 | { |
| 824 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 825 | struct p54_hdr *hdr; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 826 | struct sk_buff *skb; |
| 827 | |
| 828 | skb = __dev_alloc_skb(len + priv->tx_hdr_len, memflags); |
| 829 | if (!skb) |
| 830 | return NULL; |
| 831 | skb_reserve(skb, priv->tx_hdr_len); |
| 832 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 833 | hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr)); |
| 834 | hdr->flags = cpu_to_le16(hdr_flags); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 835 | hdr->len = cpu_to_le16(len - sizeof(*hdr)); |
| 836 | hdr->type = cpu_to_le16(type); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 837 | hdr->tries = hdr->rts_tries = 0; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 838 | |
| 839 | if (unlikely(p54_assign_address(dev, skb, hdr, len))) { |
| 840 | kfree_skb(skb); |
| 841 | return NULL; |
| 842 | } |
| 843 | return skb; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 846 | int p54_read_eeprom(struct ieee80211_hw *dev) |
| 847 | { |
| 848 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 849 | struct p54_hdr *hdr = NULL; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 850 | struct p54_eeprom_lm86 *eeprom_hdr; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 851 | struct sk_buff *skb; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 852 | size_t eeprom_size = 0x2020, offset = 0, blocksize; |
| 853 | int ret = -ENOMEM; |
| 854 | void *eeprom = NULL; |
| 855 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 856 | skb = p54_alloc_skb(dev, 0x8000, sizeof(*hdr) + sizeof(*eeprom_hdr) + |
| 857 | EEPROM_READBACK_LEN, |
| 858 | P54_CONTROL_TYPE_EEPROM_READBACK, GFP_KERNEL); |
| 859 | if (!skb) |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 860 | goto free; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 861 | priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL); |
| 862 | if (!priv->eeprom) |
| 863 | goto free; |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 864 | eeprom = kzalloc(eeprom_size, GFP_KERNEL); |
| 865 | if (!eeprom) |
| 866 | goto free; |
| 867 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 868 | eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb, |
| 869 | sizeof(*eeprom_hdr) + EEPROM_READBACK_LEN); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 870 | |
| 871 | while (eeprom_size) { |
| 872 | blocksize = min(eeprom_size, (size_t)EEPROM_READBACK_LEN); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 873 | eeprom_hdr->offset = cpu_to_le16(offset); |
| 874 | eeprom_hdr->len = cpu_to_le16(blocksize); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 875 | priv->tx(dev, skb, 0); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 876 | |
| 877 | if (!wait_for_completion_interruptible_timeout(&priv->eeprom_comp, HZ)) { |
| 878 | printk(KERN_ERR "%s: device does not respond!\n", |
| 879 | wiphy_name(dev->wiphy)); |
| 880 | ret = -EBUSY; |
| 881 | goto free; |
| 882 | } |
| 883 | |
| 884 | memcpy(eeprom + offset, priv->eeprom, blocksize); |
| 885 | offset += blocksize; |
| 886 | eeprom_size -= blocksize; |
| 887 | } |
| 888 | |
| 889 | ret = p54_parse_eeprom(dev, eeprom, offset); |
| 890 | free: |
| 891 | kfree(priv->eeprom); |
| 892 | priv->eeprom = NULL; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 893 | p54_free_skb(dev, skb); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 894 | kfree(eeprom); |
| 895 | |
| 896 | return ret; |
| 897 | } |
| 898 | EXPORT_SYMBOL_GPL(p54_read_eeprom); |
| 899 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 900 | static int p54_tx(struct ieee80211_hw *dev, struct sk_buff *skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 901 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 902 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 903 | struct ieee80211_tx_queue_stats *current_queue; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 904 | struct p54_common *priv = dev->priv; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 905 | struct p54_hdr *hdr; |
| 906 | struct p54_tx_data *txhdr; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 907 | size_t padding, len; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 908 | int i, j, ridx; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 909 | u8 rate; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 910 | u8 cts_rate = 0x20; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 911 | u8 rc_flags; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 912 | u8 calculated_tries[4]; |
| 913 | u8 nrates = 0, nremaining = 8; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 914 | |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 915 | current_queue = &priv->tx_stats[skb_get_queue_mapping(skb) + 4]; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 916 | if (unlikely(current_queue->len > current_queue->limit)) |
| 917 | return NETDEV_TX_BUSY; |
| 918 | current_queue->len++; |
| 919 | current_queue->count++; |
| 920 | if (current_queue->len == current_queue->limit) |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 921 | ieee80211_stop_queue(dev, skb_get_queue_mapping(skb)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 922 | |
| 923 | padding = (unsigned long)(skb->data - (sizeof(*hdr) + sizeof(*txhdr))) & 3; |
| 924 | len = skb->len; |
| 925 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 926 | txhdr = (struct p54_tx_data *) skb_push(skb, sizeof(*txhdr) + padding); |
| 927 | hdr = (struct p54_hdr *) skb_push(skb, sizeof(*hdr)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 928 | |
| 929 | if (padding) |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 930 | hdr->flags = cpu_to_le16(P54_HDR_FLAG_DATA_ALIGN); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 931 | else |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 932 | hdr->flags = cpu_to_le16(0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 933 | hdr->len = cpu_to_le16(len); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 934 | hdr->type = (info->flags & IEEE80211_TX_CTL_NO_ACK) ? 0 : cpu_to_le16(1); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 935 | hdr->rts_tries = info->control.rates[0].count; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 936 | |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 937 | /* |
| 938 | * we register the rates in perfect order, and |
| 939 | * RTS/CTS won't happen on 5 GHz |
| 940 | */ |
| 941 | cts_rate = info->control.rts_cts_rate_idx; |
| 942 | |
| 943 | memset(&txhdr->rateset, 0, sizeof(txhdr->rateset)); |
| 944 | |
| 945 | /* see how many rates got used */ |
| 946 | for (i = 0; i < 4; i++) { |
| 947 | if (info->control.rates[i].idx < 0) |
| 948 | break; |
| 949 | nrates++; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 950 | } |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 951 | |
| 952 | /* limit tries to 8/nrates per rate */ |
| 953 | for (i = 0; i < nrates; i++) { |
| 954 | /* |
| 955 | * The magic expression here is equivalent to 8/nrates for |
| 956 | * all values that matter, but avoids division and jumps. |
| 957 | * Note that nrates can only take the values 1 through 4. |
| 958 | */ |
| 959 | calculated_tries[i] = min_t(int, ((15 >> nrates) | 1) + 1, |
| 960 | info->control.rates[i].count); |
| 961 | nremaining -= calculated_tries[i]; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 962 | } |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 963 | |
| 964 | /* if there are tries left, distribute from back to front */ |
| 965 | for (i = nrates - 1; nremaining > 0 && i >= 0; i--) { |
| 966 | int tmp = info->control.rates[i].count - calculated_tries[i]; |
| 967 | |
| 968 | if (tmp <= 0) |
| 969 | continue; |
| 970 | /* RC requested more tries at this rate */ |
| 971 | |
| 972 | tmp = min_t(int, tmp, nremaining); |
| 973 | calculated_tries[i] += tmp; |
| 974 | nremaining -= tmp; |
| 975 | } |
| 976 | |
| 977 | ridx = 0; |
| 978 | for (i = 0; i < nrates && ridx < 8; i++) { |
| 979 | /* we register the rates in perfect order */ |
| 980 | rate = info->control.rates[i].idx; |
| 981 | if (info->band == IEEE80211_BAND_5GHZ) |
| 982 | rate += 4; |
| 983 | |
| 984 | /* store the count we actually calculated for TX status */ |
| 985 | info->control.rates[i].count = calculated_tries[i]; |
| 986 | |
| 987 | rc_flags = info->control.rates[i].flags; |
| 988 | if (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) { |
| 989 | rate |= 0x10; |
| 990 | cts_rate |= 0x10; |
| 991 | } |
| 992 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) |
| 993 | rate |= 0x40; |
| 994 | else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) |
| 995 | rate |= 0x20; |
| 996 | for (j = 0; j < calculated_tries[i] && ridx < 8; j++) { |
| 997 | txhdr->rateset[ridx] = rate; |
| 998 | ridx++; |
| 999 | } |
| 1000 | } |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1001 | hdr->tries = ridx; |
| 1002 | txhdr->crypt_offset = 0; |
| 1003 | txhdr->rts_rate_idx = 0; |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1004 | txhdr->key_type = 0; |
| 1005 | txhdr->key_len = 0; |
| 1006 | txhdr->hw_queue = skb_get_queue_mapping(skb) + 4; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1007 | txhdr->backlog = 32; |
| 1008 | memset(txhdr->durations, 0, sizeof(txhdr->durations)); |
Christian Lamparter | aaa1553 | 2008-08-09 19:20:47 -0500 | [diff] [blame] | 1009 | txhdr->tx_antenna = (info->antenna_sel_tx == 0) ? |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1010 | 2 : info->antenna_sel_tx - 1; |
Christian Lamparter | 09adf28 | 2008-09-06 14:25:53 +0200 | [diff] [blame] | 1011 | txhdr->output_power = priv->output_power; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1012 | txhdr->cts_rate = cts_rate; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1013 | if (padding) |
| 1014 | txhdr->align[0] = padding; |
| 1015 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1016 | /* modifies skb->cb and with it info, so must be last! */ |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1017 | if (unlikely(p54_assign_address(dev, skb, hdr, skb->len))) { |
| 1018 | skb_pull(skb, sizeof(*hdr) + sizeof(*txhdr) + padding); |
| 1019 | return NETDEV_TX_BUSY; |
| 1020 | } |
| 1021 | priv->tx(dev, skb, 0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1022 | return 0; |
| 1023 | } |
| 1024 | |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1025 | 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] | 1026 | { |
| 1027 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1028 | struct sk_buff *skb; |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1029 | struct p54_setup_mac *setup; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1030 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1031 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) + |
| 1032 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP, |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1033 | GFP_ATOMIC); |
| 1034 | if (!skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1035 | return -ENOMEM; |
| 1036 | |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1037 | setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup)); |
| 1038 | priv->mac_mode = mode; |
| 1039 | setup->mac_mode = cpu_to_le16(mode); |
| 1040 | memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN); |
Christian Lamparter | e0a58ea | 2008-09-03 22:25:20 +0200 | [diff] [blame] | 1041 | if (!bssid) |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1042 | memset(setup->bssid, ~0, ETH_ALEN); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1043 | else |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1044 | memcpy(setup->bssid, bssid, ETH_ALEN); |
| 1045 | setup->rx_antenna = priv->rx_antenna; |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1046 | if (priv->fw_var < 0x500) { |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1047 | setup->v1.basic_rate_mask = cpu_to_le32(0x15f); |
| 1048 | setup->v1.rx_addr = cpu_to_le32(priv->rx_end); |
| 1049 | setup->v1.max_rx = cpu_to_le16(priv->rx_mtu); |
| 1050 | setup->v1.rxhw = cpu_to_le16(priv->rxhw); |
| 1051 | setup->v1.wakeup_timer = cpu_to_le16(500); |
| 1052 | setup->v1.unalloc0 = cpu_to_le16(0); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1053 | } else { |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1054 | setup->v2.rx_addr = cpu_to_le32(priv->rx_end); |
| 1055 | setup->v2.max_rx = cpu_to_le16(priv->rx_mtu); |
| 1056 | setup->v2.rxhw = cpu_to_le16(priv->rxhw); |
| 1057 | setup->v2.timer = cpu_to_le16(1000); |
| 1058 | setup->v2.truncate = cpu_to_le16(48896); |
| 1059 | setup->v2.basic_rate_mask = cpu_to_le32(0x15f); |
| 1060 | setup->v2.sbss_offset = 0; |
| 1061 | setup->v2.mcast_window = 0; |
| 1062 | setup->v2.rx_rssi_threshold = 0; |
| 1063 | setup->v2.rx_ed_threshold = 0; |
| 1064 | setup->v2.ref_clock = cpu_to_le32(644245094); |
| 1065 | setup->v2.lpf_bandwidth = cpu_to_le16(65535); |
| 1066 | setup->v2.osc_start_delay = cpu_to_le16(65535); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1067 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1068 | priv->tx(dev, skb, 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | static int p54_set_freq(struct ieee80211_hw *dev, __le16 freq) |
| 1073 | { |
| 1074 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1075 | struct sk_buff *skb; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1076 | struct p54_scan *chan; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1077 | unsigned int i; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1078 | void *entry; |
| 1079 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1080 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) + |
| 1081 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN, |
| 1082 | GFP_ATOMIC); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1083 | if (!skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1084 | return -ENOMEM; |
| 1085 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1086 | chan = (struct p54_scan *) skb_put(skb, sizeof(*chan)); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1087 | memset(chan->padding1, 0, sizeof(chan->padding1)); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1088 | chan->mode = cpu_to_le16(P54_SCAN_EXIT); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1089 | chan->dwell = cpu_to_le16(0x0); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1090 | |
| 1091 | for (i = 0; i < priv->iq_autocal_len; i++) { |
| 1092 | if (priv->iq_autocal[i].freq != freq) |
| 1093 | continue; |
| 1094 | |
| 1095 | memcpy(&chan->iq_autocal, &priv->iq_autocal[i], |
| 1096 | sizeof(*priv->iq_autocal)); |
| 1097 | break; |
| 1098 | } |
| 1099 | if (i == priv->iq_autocal_len) |
| 1100 | goto err; |
| 1101 | |
| 1102 | for (i = 0; i < priv->output_limit_len; i++) { |
| 1103 | if (priv->output_limit[i].freq != freq) |
| 1104 | continue; |
| 1105 | |
| 1106 | chan->val_barker = 0x38; |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1107 | chan->val_bpsk = chan->dup_bpsk = |
| 1108 | priv->output_limit[i].val_bpsk; |
| 1109 | chan->val_qpsk = chan->dup_qpsk = |
| 1110 | priv->output_limit[i].val_qpsk; |
| 1111 | chan->val_16qam = chan->dup_16qam = |
| 1112 | priv->output_limit[i].val_16qam; |
| 1113 | chan->val_64qam = chan->dup_64qam = |
| 1114 | priv->output_limit[i].val_64qam; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1115 | break; |
| 1116 | } |
| 1117 | if (i == priv->output_limit_len) |
| 1118 | goto err; |
| 1119 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1120 | entry = priv->curve_data->data; |
| 1121 | for (i = 0; i < priv->curve_data->channels; i++) { |
| 1122 | if (*((__le16 *)entry) != freq) { |
| 1123 | entry += sizeof(__le16); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1124 | entry += sizeof(struct p54_pa_curve_data_sample) * |
| 1125 | priv->curve_data->points_per_channel; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1126 | continue; |
| 1127 | } |
| 1128 | |
| 1129 | entry += sizeof(__le16); |
Christian Lamparter | 154e3af | 2008-08-23 22:15:25 +0200 | [diff] [blame] | 1130 | chan->pa_points_per_curve = |
| 1131 | min(priv->curve_data->points_per_channel, (u8) 8); |
| 1132 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1133 | memcpy(chan->curve_data, entry, sizeof(*chan->curve_data) * |
| 1134 | chan->pa_points_per_curve); |
| 1135 | break; |
| 1136 | } |
| 1137 | |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1138 | if (priv->fw_var < 0x500) { |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1139 | chan->v1.rssical_mul = cpu_to_le16(130); |
| 1140 | chan->v1.rssical_add = cpu_to_le16(0xfe70); |
| 1141 | } else { |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1142 | chan->v2.rssical_mul = cpu_to_le16(130); |
| 1143 | chan->v2.rssical_add = cpu_to_le16(0xfe70); |
| 1144 | chan->v2.basic_rate_mask = cpu_to_le32(0x15f); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1145 | memset(chan->v2.rts_rates, 0, 8); |
Christian Lamparter | 19c19d5 | 2008-09-03 22:25:25 +0200 | [diff] [blame] | 1146 | } |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1147 | priv->tx(dev, skb, 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1148 | return 0; |
| 1149 | |
| 1150 | err: |
| 1151 | printk(KERN_ERR "%s: frequency change failed\n", wiphy_name(dev->wiphy)); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1152 | kfree_skb(skb); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1153 | return -EINVAL; |
| 1154 | } |
| 1155 | |
| 1156 | static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act) |
| 1157 | { |
| 1158 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1159 | struct sk_buff *skb; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1160 | struct p54_led *led; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1161 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1162 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led) + |
| 1163 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_LED, |
| 1164 | GFP_ATOMIC); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1165 | if (!skb) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1166 | return -ENOMEM; |
| 1167 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1168 | led = (struct p54_led *)skb_put(skb, sizeof(*led)); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1169 | led->mode = cpu_to_le16(mode); |
| 1170 | led->led_permanent = cpu_to_le16(link); |
| 1171 | led->led_temporary = cpu_to_le16(act); |
| 1172 | led->duration = cpu_to_le16(1000); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1173 | priv->tx(dev, skb, 1); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1174 | return 0; |
| 1175 | } |
| 1176 | |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1177 | #define P54_SET_QUEUE(queue, ai_fs, cw_min, cw_max, _txop) \ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1178 | do { \ |
| 1179 | queue.aifs = cpu_to_le16(ai_fs); \ |
| 1180 | queue.cwmin = cpu_to_le16(cw_min); \ |
| 1181 | queue.cwmax = cpu_to_le16(cw_max); \ |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1182 | queue.txop = cpu_to_le16(_txop); \ |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1183 | } while(0) |
| 1184 | |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1185 | static int p54_set_edcf(struct ieee80211_hw *dev) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1186 | { |
| 1187 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1188 | struct sk_buff *skb; |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1189 | struct p54_edcf *edcf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1190 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1191 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf) + |
| 1192 | sizeof(struct p54_hdr), P54_CONTROL_TYPE_DCFINIT, |
| 1193 | GFP_ATOMIC); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1194 | if (!skb) |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1195 | return -ENOMEM; |
| 1196 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1197 | edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf)); |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1198 | if (priv->use_short_slot) { |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1199 | edcf->slottime = 9; |
| 1200 | edcf->sifs = 0x10; |
| 1201 | edcf->eofpad = 0x00; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1202 | } else { |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1203 | edcf->slottime = 20; |
| 1204 | edcf->sifs = 0x0a; |
| 1205 | edcf->eofpad = 0x06; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1206 | } |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1207 | /* (see prism54/isl_oid.h for further details) */ |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1208 | edcf->frameburst = cpu_to_le16(0); |
| 1209 | edcf->round_trip_delay = cpu_to_le16(0); |
| 1210 | memset(edcf->mapping, 0, sizeof(edcf->mapping)); |
| 1211 | memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue)); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1212 | priv->tx(dev, skb, 1); |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1213 | return 0; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1216 | static int p54_init_stats(struct ieee80211_hw *dev) |
| 1217 | { |
| 1218 | struct p54_common *priv = dev->priv; |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1219 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1220 | priv->cached_stats = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, |
| 1221 | sizeof(struct p54_hdr) + sizeof(struct p54_statistics), |
| 1222 | P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL); |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1223 | if (!priv->cached_stats) |
| 1224 | return -ENOMEM; |
| 1225 | |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1226 | mod_timer(&priv->stats_timer, jiffies + HZ); |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1230 | static int p54_start(struct ieee80211_hw *dev) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1231 | { |
| 1232 | struct p54_common *priv = dev->priv; |
| 1233 | int err; |
| 1234 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1235 | err = priv->open(dev); |
| 1236 | if (!err) |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1237 | priv->mode = NL80211_IFTYPE_MONITOR; |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1238 | P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47); |
| 1239 | P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94); |
| 1240 | P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0); |
| 1241 | P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0); |
| 1242 | err = p54_set_edcf(dev); |
| 1243 | if (!err) |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1244 | err = p54_init_stats(dev); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1245 | |
| 1246 | return err; |
| 1247 | } |
| 1248 | |
| 1249 | static void p54_stop(struct ieee80211_hw *dev) |
| 1250 | { |
| 1251 | struct p54_common *priv = dev->priv; |
| 1252 | struct sk_buff *skb; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1253 | |
| 1254 | del_timer(&priv->stats_timer); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1255 | p54_free_skb(dev, priv->cached_stats); |
Christian Lamparter | 0f1be97 | 2008-10-15 03:56:20 +0200 | [diff] [blame] | 1256 | priv->cached_stats = NULL; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1257 | while ((skb = skb_dequeue(&priv->tx_queue))) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1258 | kfree_skb(skb); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1259 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1260 | priv->stop(dev); |
Christian Lamparter | a0db663 | 2008-09-06 02:56:04 +0200 | [diff] [blame] | 1261 | priv->tsf_high32 = priv->tsf_low32 = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1262 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | static int p54_add_interface(struct ieee80211_hw *dev, |
| 1266 | struct ieee80211_if_init_conf *conf) |
| 1267 | { |
| 1268 | struct p54_common *priv = dev->priv; |
| 1269 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1270 | if (priv->mode != NL80211_IFTYPE_MONITOR) |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1271 | return -EOPNOTSUPP; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1272 | |
| 1273 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1274 | case NL80211_IFTYPE_STATION: |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1275 | priv->mode = conf->type; |
| 1276 | break; |
| 1277 | default: |
| 1278 | return -EOPNOTSUPP; |
| 1279 | } |
| 1280 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1281 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1282 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1283 | p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1284 | |
| 1285 | switch (conf->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1286 | case NL80211_IFTYPE_STATION: |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1287 | p54_setup_mac(dev, P54_FILTER_TYPE_STATION, NULL); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1288 | break; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1289 | default: |
| 1290 | BUG(); /* impossible */ |
| 1291 | break; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | p54_set_leds(dev, 1, 0, 0); |
| 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | static void p54_remove_interface(struct ieee80211_hw *dev, |
| 1300 | struct ieee80211_if_init_conf *conf) |
| 1301 | { |
| 1302 | struct p54_common *priv = dev->priv; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1303 | priv->mode = NL80211_IFTYPE_MONITOR; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1304 | memset(priv->mac_addr, 0, ETH_ALEN); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1305 | p54_setup_mac(dev, P54_FILTER_TYPE_NONE, NULL); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1308 | static int p54_config(struct ieee80211_hw *dev, u32 changed) |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1309 | { |
| 1310 | int ret; |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1311 | struct p54_common *priv = dev->priv; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 1312 | struct ieee80211_conf *conf = &dev->conf; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1313 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1314 | mutex_lock(&priv->conf_mutex); |
Johannes Berg | 0f4ac38 | 2008-10-09 12:18:04 +0200 | [diff] [blame] | 1315 | priv->rx_antenna = 2; /* automatic */ |
Christian Lamparter | 09adf28 | 2008-09-06 14:25:53 +0200 | [diff] [blame] | 1316 | priv->output_power = conf->power_level << 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1317 | ret = p54_set_freq(dev, cpu_to_le16(conf->channel->center_freq)); |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1318 | if (!ret) |
| 1319 | ret = p54_set_edcf(dev); |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1320 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1321 | return ret; |
| 1322 | } |
| 1323 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 1324 | static int p54_config_interface(struct ieee80211_hw *dev, |
| 1325 | struct ieee80211_vif *vif, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1326 | struct ieee80211_if_conf *conf) |
| 1327 | { |
| 1328 | struct p54_common *priv = dev->priv; |
| 1329 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1330 | mutex_lock(&priv->conf_mutex); |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1331 | p54_setup_mac(dev, P54_FILTER_TYPE_STATION, conf->bssid); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1332 | p54_set_leds(dev, 1, !is_multicast_ether_addr(conf->bssid), 0); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1333 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1334 | mutex_unlock(&priv->conf_mutex); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1335 | return 0; |
| 1336 | } |
| 1337 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1338 | static void p54_configure_filter(struct ieee80211_hw *dev, |
| 1339 | unsigned int changed_flags, |
| 1340 | unsigned int *total_flags, |
| 1341 | int mc_count, struct dev_mc_list *mclist) |
| 1342 | { |
| 1343 | struct p54_common *priv = dev->priv; |
| 1344 | |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 1345 | *total_flags &= FIF_BCN_PRBRESP_PROMISC | |
| 1346 | FIF_PROMISC_IN_BSS | |
| 1347 | FIF_FCSFAIL; |
| 1348 | |
| 1349 | priv->filter_flags = *total_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1350 | |
| 1351 | if (changed_flags & FIF_BCN_PRBRESP_PROMISC) { |
| 1352 | if (*total_flags & FIF_BCN_PRBRESP_PROMISC) |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1353 | p54_setup_mac(dev, priv->mac_mode, NULL); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1354 | else |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1355 | p54_setup_mac(dev, priv->mac_mode, priv->bssid); |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | if (changed_flags & FIF_PROMISC_IN_BSS) { |
| 1359 | if (*total_flags & FIF_PROMISC_IN_BSS) |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1360 | p54_setup_mac(dev, priv->mac_mode | 0x8, NULL); |
Christian Lamparter | 78d57eb | 2008-09-06 02:56:12 +0200 | [diff] [blame] | 1361 | else |
Christian Lamparter | 5e73444 | 2008-10-15 04:07:56 +0200 | [diff] [blame] | 1362 | p54_setup_mac(dev, priv->mac_mode & ~0x8, priv->bssid); |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1363 | } |
| 1364 | } |
| 1365 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1366 | static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1367 | const struct ieee80211_tx_queue_params *params) |
| 1368 | { |
| 1369 | struct p54_common *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1370 | |
John W. Linville | 3df5ee6 | 2008-05-01 17:07:32 -0400 | [diff] [blame] | 1371 | if ((params) && !(queue > 4)) { |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1372 | P54_SET_QUEUE(priv->qos_params[queue], params->aifs, |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 1373 | params->cw_min, params->cw_max, params->txop); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1374 | } else |
| 1375 | return -EINVAL; |
| 1376 | |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1377 | return p54_set_edcf(dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1380 | static int p54_init_xbow_synth(struct ieee80211_hw *dev) |
| 1381 | { |
| 1382 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1383 | struct sk_buff *skb; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1384 | struct p54_xbow_synth *xbow; |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1385 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1386 | skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow) + |
| 1387 | sizeof(struct p54_hdr), |
| 1388 | P54_CONTROL_TYPE_XBOW_SYNTH_CFG, |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1389 | GFP_KERNEL); |
| 1390 | if (!skb) |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1391 | return -ENOMEM; |
| 1392 | |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1393 | xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow)); |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1394 | xbow->magic1 = cpu_to_le16(0x1); |
| 1395 | xbow->magic2 = cpu_to_le16(0x2); |
| 1396 | xbow->freq = cpu_to_le16(5390); |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1397 | memset(xbow->padding, 0, sizeof(xbow->padding)); |
| 1398 | priv->tx(dev, skb, 1); |
Christian Lamparter | 1b99753 | 2008-09-06 14:25:58 +0200 | [diff] [blame] | 1399 | return 0; |
| 1400 | } |
| 1401 | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1402 | static void p54_statistics_timer(unsigned long data) |
| 1403 | { |
| 1404 | struct ieee80211_hw *dev = (struct ieee80211_hw *) data; |
| 1405 | struct p54_common *priv = dev->priv; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1406 | |
| 1407 | BUG_ON(!priv->cached_stats); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1408 | |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1409 | priv->tx(dev, priv->cached_stats, 0); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1410 | } |
| 1411 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1412 | static int p54_get_stats(struct ieee80211_hw *dev, |
| 1413 | struct ieee80211_low_level_stats *stats) |
| 1414 | { |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1415 | struct p54_common *priv = dev->priv; |
| 1416 | |
| 1417 | del_timer(&priv->stats_timer); |
| 1418 | p54_statistics_timer((unsigned long)dev); |
| 1419 | |
| 1420 | if (!wait_for_completion_interruptible_timeout(&priv->stats_comp, HZ)) { |
| 1421 | printk(KERN_ERR "%s: device does not respond!\n", |
| 1422 | wiphy_name(dev->wiphy)); |
| 1423 | return -EBUSY; |
| 1424 | } |
| 1425 | |
| 1426 | memcpy(stats, &priv->stats, sizeof(*stats)); |
| 1427 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1428 | return 0; |
| 1429 | } |
| 1430 | |
| 1431 | static int p54_get_tx_stats(struct ieee80211_hw *dev, |
| 1432 | struct ieee80211_tx_queue_stats *stats) |
| 1433 | { |
| 1434 | struct p54_common *priv = dev->priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1435 | |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 1436 | memcpy(stats, &priv->tx_stats[4], sizeof(stats[0]) * dev->queues); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1437 | |
| 1438 | return 0; |
| 1439 | } |
| 1440 | |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1441 | static void p54_bss_info_changed(struct ieee80211_hw *dev, |
| 1442 | struct ieee80211_vif *vif, |
| 1443 | struct ieee80211_bss_conf *info, |
| 1444 | u32 changed) |
| 1445 | { |
| 1446 | struct p54_common *priv = dev->priv; |
| 1447 | |
| 1448 | if (changed & BSS_CHANGED_ERP_SLOT) { |
| 1449 | priv->use_short_slot = info->use_short_slot; |
Christian Lamparter | 0fdd7c5 | 2008-10-15 03:55:37 +0200 | [diff] [blame] | 1450 | p54_set_edcf(dev); |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1454 | static const struct ieee80211_ops p54_ops = { |
| 1455 | .tx = p54_tx, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1456 | .start = p54_start, |
| 1457 | .stop = p54_stop, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1458 | .add_interface = p54_add_interface, |
| 1459 | .remove_interface = p54_remove_interface, |
| 1460 | .config = p54_config, |
| 1461 | .config_interface = p54_config_interface, |
Christian Lamparter | 40333e4 | 2008-10-08 20:52:22 +0200 | [diff] [blame] | 1462 | .bss_info_changed = p54_bss_info_changed, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 1463 | .configure_filter = p54_configure_filter, |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1464 | .conf_tx = p54_conf_tx, |
| 1465 | .get_stats = p54_get_stats, |
| 1466 | .get_tx_stats = p54_get_tx_stats |
| 1467 | }; |
| 1468 | |
| 1469 | struct ieee80211_hw *p54_init_common(size_t priv_data_len) |
| 1470 | { |
| 1471 | struct ieee80211_hw *dev; |
| 1472 | struct p54_common *priv; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1473 | |
| 1474 | dev = ieee80211_alloc_hw(priv_data_len, &p54_ops); |
| 1475 | if (!dev) |
| 1476 | return NULL; |
| 1477 | |
| 1478 | priv = dev->priv; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1479 | priv->mode = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1480 | skb_queue_head_init(&priv->tx_queue); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1481 | dev->flags = IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING | /* not sure */ |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 1482 | IEEE80211_HW_RX_INCLUDES_FCS | |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1483 | IEEE80211_HW_SIGNAL_DBM | |
| 1484 | IEEE80211_HW_NOISE_DBM; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1485 | |
Johannes Berg | 9477828 | 2008-10-10 13:21:59 +0200 | [diff] [blame] | 1486 | /* |
| 1487 | * XXX: when this driver gets support for any mode that |
| 1488 | * requires beacons (AP, MESH, IBSS) then it must |
| 1489 | * implement IEEE80211_TX_CTL_ASSIGN_SEQ. |
| 1490 | */ |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 1491 | dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION); |
| 1492 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1493 | dev->channel_change_time = 1000; /* TODO: find actual value */ |
Chr | 84df3ed | 2008-08-24 03:15:16 +0200 | [diff] [blame] | 1494 | priv->tx_stats[0].limit = 1; |
| 1495 | priv->tx_stats[1].limit = 1; |
| 1496 | priv->tx_stats[2].limit = 1; |
| 1497 | priv->tx_stats[3].limit = 1; |
| 1498 | priv->tx_stats[4].limit = 5; |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1499 | dev->queues = 1; |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1500 | priv->noise = -94; |
Johannes Berg | c12abae | 2008-10-14 16:56:51 +0200 | [diff] [blame] | 1501 | /* |
| 1502 | * We support at most 8 tries no matter which rate they're at, |
| 1503 | * we cannot support max_rates * max_rate_tries as we set it |
| 1504 | * here, but setting it correctly to 4/2 or so would limit us |
| 1505 | * artificially if the RC algorithm wants just two rates, so |
| 1506 | * let's say 4/7, we'll redistribute it at TX time, see the |
| 1507 | * comments there. |
| 1508 | */ |
| 1509 | dev->max_rates = 4; |
| 1510 | dev->max_rate_tries = 7; |
John W. Linville | 27df605 | 2008-10-22 16:41:55 -0400 | [diff] [blame^] | 1511 | dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 + |
| 1512 | sizeof(struct p54_tx_data); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1513 | |
Larry Finger | 6041e2a | 2008-08-03 17:58:36 -0500 | [diff] [blame] | 1514 | mutex_init(&priv->conf_mutex); |
Christian Lamparter | 7cb7707 | 2008-09-01 22:48:51 +0200 | [diff] [blame] | 1515 | init_completion(&priv->eeprom_comp); |
Christian Lamparter | cc6de66 | 2008-09-06 02:56:23 +0200 | [diff] [blame] | 1516 | init_completion(&priv->stats_comp); |
| 1517 | setup_timer(&priv->stats_timer, p54_statistics_timer, |
| 1518 | (unsigned long)dev); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1519 | |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1520 | return dev; |
| 1521 | } |
| 1522 | EXPORT_SYMBOL_GPL(p54_init_common); |
| 1523 | |
| 1524 | void p54_free_common(struct ieee80211_hw *dev) |
| 1525 | { |
| 1526 | struct p54_common *priv = dev->priv; |
Christian Lamparter | b92f30d | 2008-10-15 04:07:16 +0200 | [diff] [blame] | 1527 | del_timer(&priv->stats_timer); |
| 1528 | kfree_skb(priv->cached_stats); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1529 | kfree(priv->iq_autocal); |
| 1530 | kfree(priv->output_limit); |
| 1531 | kfree(priv->curve_data); |
Michael Wu | eff1a59 | 2007-09-25 18:11:01 -0700 | [diff] [blame] | 1532 | } |
| 1533 | EXPORT_SYMBOL_GPL(p54_free_common); |
| 1534 | |
| 1535 | static int __init p54_init(void) |
| 1536 | { |
| 1537 | return 0; |
| 1538 | } |
| 1539 | |
| 1540 | static void __exit p54_exit(void) |
| 1541 | { |
| 1542 | } |
| 1543 | |
| 1544 | module_init(p54_init); |
| 1545 | module_exit(p54_exit); |