fwio.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Firmware I/O code for mac80211 Prism54 drivers
  3. *
  4. * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
  5. * Copyright (c) 2007-2009, Christian Lamparter <chunkeey@web.de>
  6. * Copyright 2008, Johannes Berg <johannes@sipsolutions.net>
  7. *
  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. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
  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. #include <linux/init.h>
  19. #include <linux/slab.h>
  20. #include <linux/firmware.h>
  21. #include <linux/etherdevice.h>
  22. #include <net/mac80211.h>
  23. #include "p54.h"
  24. #include "eeprom.h"
  25. #include "lmac.h"
  26. int p54_parse_firmware(struct ieee80211_hw *dev, const struct firmware *fw)
  27. {
  28. struct p54_common *priv = dev->priv;
  29. struct exp_if *exp_if;
  30. struct bootrec *bootrec;
  31. u32 *data = (u32 *)fw->data;
  32. u32 *end_data = (u32 *)fw->data + (fw->size >> 2);
  33. u8 *fw_version = NULL;
  34. size_t len;
  35. int i;
  36. int maxlen;
  37. if (priv->rx_start)
  38. return 0;
  39. while (data < end_data && *data)
  40. data++;
  41. while (data < end_data && !*data)
  42. data++;
  43. bootrec = (struct bootrec *) data;
  44. while (bootrec->data <= end_data && (bootrec->data +
  45. (len = le32_to_cpu(bootrec->len))) <= end_data) {
  46. u32 code = le32_to_cpu(bootrec->code);
  47. switch (code) {
  48. case BR_CODE_COMPONENT_ID:
  49. priv->fw_interface = be32_to_cpup((__be32 *)
  50. bootrec->data);
  51. switch (priv->fw_interface) {
  52. case FW_LM86:
  53. case FW_LM20:
  54. case FW_LM87: {
  55. char *iftype = (char *)bootrec->data;
  56. printk(KERN_INFO "%s: p54 detected a LM%c%c "
  57. "firmware\n",
  58. wiphy_name(priv->hw->wiphy),
  59. iftype[2], iftype[3]);
  60. break;
  61. }
  62. case FW_FMAC:
  63. default:
  64. printk(KERN_ERR "%s: unsupported firmware\n",
  65. wiphy_name(priv->hw->wiphy));
  66. return -ENODEV;
  67. }
  68. break;
  69. case BR_CODE_COMPONENT_VERSION:
  70. /* 24 bytes should be enough for all firmwares */
  71. if (strnlen((unsigned char *) bootrec->data, 24) < 24)
  72. fw_version = (unsigned char *) bootrec->data;
  73. break;
  74. case BR_CODE_DESCR: {
  75. struct bootrec_desc *desc =
  76. (struct bootrec_desc *)bootrec->data;
  77. priv->rx_start = le32_to_cpu(desc->rx_start);
  78. /* FIXME add sanity checking */
  79. priv->rx_end = le32_to_cpu(desc->rx_end) - 0x3500;
  80. priv->headroom = desc->headroom;
  81. priv->tailroom = desc->tailroom;
  82. priv->privacy_caps = desc->privacy_caps;
  83. priv->rx_keycache_size = desc->rx_keycache_size;
  84. if (le32_to_cpu(bootrec->len) == 11)
  85. priv->rx_mtu = le16_to_cpu(desc->rx_mtu);
  86. else
  87. priv->rx_mtu = (size_t)
  88. 0x620 - priv->tx_hdr_len;
  89. maxlen = priv->tx_hdr_len + /* USB devices */
  90. sizeof(struct p54_rx_data) +
  91. 4 + /* rx alignment */
  92. IEEE80211_MAX_FRAG_THRESHOLD;
  93. if (priv->rx_mtu > maxlen && PAGE_SIZE == 4096) {
  94. printk(KERN_INFO "p54: rx_mtu reduced from %d "
  95. "to %d\n", priv->rx_mtu, maxlen);
  96. priv->rx_mtu = maxlen;
  97. }
  98. break;
  99. }
  100. case BR_CODE_EXPOSED_IF:
  101. exp_if = (struct exp_if *) bootrec->data;
  102. for (i = 0; i < (len * sizeof(*exp_if) / 4); i++)
  103. if (exp_if[i].if_id == cpu_to_le16(IF_ID_LMAC))
  104. priv->fw_var = le16_to_cpu(exp_if[i].variant);
  105. break;
  106. case BR_CODE_DEPENDENT_IF:
  107. break;
  108. case BR_CODE_END_OF_BRA:
  109. case LEGACY_BR_CODE_END_OF_BRA:
  110. end_data = NULL;
  111. break;
  112. default:
  113. break;
  114. }
  115. bootrec = (struct bootrec *)&bootrec->data[len];
  116. }
  117. if (fw_version)
  118. printk(KERN_INFO "%s: FW rev %s - Softmac protocol %x.%x\n",
  119. wiphy_name(priv->hw->wiphy), fw_version,
  120. priv->fw_var >> 8, priv->fw_var & 0xff);
  121. if (priv->fw_var < 0x500)
  122. printk(KERN_INFO "%s: you are using an obsolete firmware. "
  123. "visit http://wireless.kernel.org/en/users/Drivers/p54 "
  124. "and grab one for \"kernel >= 2.6.28\"!\n",
  125. wiphy_name(priv->hw->wiphy));
  126. if (priv->fw_var >= 0x300) {
  127. /* Firmware supports QoS, use it! */
  128. if (priv->fw_var >= 0x500) {
  129. priv->tx_stats[P54_QUEUE_AC_VO].limit = 16;
  130. priv->tx_stats[P54_QUEUE_AC_VI].limit = 16;
  131. priv->tx_stats[P54_QUEUE_AC_BE].limit = 16;
  132. priv->tx_stats[P54_QUEUE_AC_BK].limit = 16;
  133. } else {
  134. priv->tx_stats[P54_QUEUE_AC_VO].limit = 3;
  135. priv->tx_stats[P54_QUEUE_AC_VI].limit = 4;
  136. priv->tx_stats[P54_QUEUE_AC_BE].limit = 3;
  137. priv->tx_stats[P54_QUEUE_AC_BK].limit = 2;
  138. }
  139. priv->hw->queues = P54_QUEUE_AC_NUM;
  140. }
  141. printk(KERN_INFO "%s: cryptographic accelerator "
  142. "WEP:%s, TKIP:%s, CCMP:%s\n", wiphy_name(priv->hw->wiphy),
  143. (priv->privacy_caps & BR_DESC_PRIV_CAP_WEP) ? "YES" :
  144. "no", (priv->privacy_caps & (BR_DESC_PRIV_CAP_TKIP |
  145. BR_DESC_PRIV_CAP_MICHAEL)) ? "YES" : "no",
  146. (priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP) ?
  147. "YES" : "no");
  148. if (priv->rx_keycache_size) {
  149. /*
  150. * NOTE:
  151. *
  152. * The firmware provides at most 255 (0 - 254) slots
  153. * for keys which are then used to offload decryption.
  154. * As a result the 255 entry (aka 0xff) can be used
  155. * safely by the driver to mark keys that didn't fit
  156. * into the full cache. This trick saves us from
  157. * keeping a extra list for uploaded keys.
  158. */
  159. priv->used_rxkeys = kzalloc(BITS_TO_LONGS(
  160. priv->rx_keycache_size), GFP_KERNEL);
  161. if (!priv->used_rxkeys)
  162. return -ENOMEM;
  163. }
  164. return 0;
  165. }
  166. EXPORT_SYMBOL_GPL(p54_parse_firmware);
  167. static struct sk_buff *p54_alloc_skb(struct p54_common *priv, u16 hdr_flags,
  168. u16 payload_len, u16 type, gfp_t memflags)
  169. {
  170. struct p54_hdr *hdr;
  171. struct sk_buff *skb;
  172. size_t frame_len = sizeof(*hdr) + payload_len;
  173. if (frame_len > P54_MAX_CTRL_FRAME_LEN)
  174. return NULL;
  175. if (unlikely(skb_queue_len(&priv->tx_pending) > 64))
  176. return NULL;
  177. skb = __dev_alloc_skb(priv->tx_hdr_len + frame_len, memflags);
  178. if (!skb)
  179. return NULL;
  180. skb_reserve(skb, priv->tx_hdr_len);
  181. hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
  182. hdr->flags = cpu_to_le16(hdr_flags);
  183. hdr->len = cpu_to_le16(payload_len);
  184. hdr->type = cpu_to_le16(type);
  185. hdr->tries = hdr->rts_tries = 0;
  186. return skb;
  187. }
  188. int p54_download_eeprom(struct p54_common *priv, void *buf,
  189. u16 offset, u16 len)
  190. {
  191. struct p54_eeprom_lm86 *eeprom_hdr;
  192. struct sk_buff *skb;
  193. size_t eeprom_hdr_size;
  194. int ret = 0;
  195. if (priv->fw_var >= 0x509)
  196. eeprom_hdr_size = sizeof(*eeprom_hdr);
  197. else
  198. eeprom_hdr_size = 0x4;
  199. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL, eeprom_hdr_size +
  200. len, P54_CONTROL_TYPE_EEPROM_READBACK,
  201. GFP_KERNEL);
  202. if (unlikely(!skb))
  203. return -ENOMEM;
  204. mutex_lock(&priv->eeprom_mutex);
  205. priv->eeprom = buf;
  206. eeprom_hdr = (struct p54_eeprom_lm86 *) skb_put(skb,
  207. eeprom_hdr_size + len);
  208. if (priv->fw_var < 0x509) {
  209. eeprom_hdr->v1.offset = cpu_to_le16(offset);
  210. eeprom_hdr->v1.len = cpu_to_le16(len);
  211. } else {
  212. eeprom_hdr->v2.offset = cpu_to_le32(offset);
  213. eeprom_hdr->v2.len = cpu_to_le16(len);
  214. eeprom_hdr->v2.magic2 = 0xf;
  215. memcpy(eeprom_hdr->v2.magic, (const char *)"LOCK", 4);
  216. }
  217. p54_tx(priv, skb);
  218. if (!wait_for_completion_interruptible_timeout(
  219. &priv->eeprom_comp, HZ)) {
  220. printk(KERN_ERR "%s: device does not respond!\n",
  221. wiphy_name(priv->hw->wiphy));
  222. ret = -EBUSY;
  223. }
  224. priv->eeprom = NULL;
  225. mutex_unlock(&priv->eeprom_mutex);
  226. return ret;
  227. }
  228. int p54_update_beacon_tim(struct p54_common *priv, u16 aid, bool set)
  229. {
  230. struct sk_buff *skb;
  231. struct p54_tim *tim;
  232. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*tim),
  233. P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
  234. if (unlikely(!skb))
  235. return -ENOMEM;
  236. tim = (struct p54_tim *) skb_put(skb, sizeof(*tim));
  237. tim->count = 1;
  238. tim->entry[0] = cpu_to_le16(set ? (aid | 0x8000) : aid);
  239. p54_tx(priv, skb);
  240. return 0;
  241. }
  242. int p54_sta_unlock(struct p54_common *priv, u8 *addr)
  243. {
  244. struct sk_buff *skb;
  245. struct p54_sta_unlock *sta;
  246. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*sta),
  247. P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
  248. if (unlikely(!skb))
  249. return -ENOMEM;
  250. sta = (struct p54_sta_unlock *)skb_put(skb, sizeof(*sta));
  251. memcpy(sta->addr, addr, ETH_ALEN);
  252. p54_tx(priv, skb);
  253. return 0;
  254. }
  255. int p54_tx_cancel(struct p54_common *priv, __le32 req_id)
  256. {
  257. struct sk_buff *skb;
  258. struct p54_txcancel *cancel;
  259. u32 _req_id = le32_to_cpu(req_id);
  260. if (unlikely(_req_id < priv->rx_start || _req_id > priv->rx_end))
  261. return -EINVAL;
  262. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*cancel),
  263. P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
  264. if (unlikely(!skb))
  265. return -ENOMEM;
  266. cancel = (struct p54_txcancel *)skb_put(skb, sizeof(*cancel));
  267. cancel->req_id = req_id;
  268. p54_tx(priv, skb);
  269. return 0;
  270. }
  271. int p54_setup_mac(struct p54_common *priv)
  272. {
  273. struct sk_buff *skb;
  274. struct p54_setup_mac *setup;
  275. u16 mode;
  276. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup),
  277. P54_CONTROL_TYPE_SETUP, GFP_ATOMIC);
  278. if (!skb)
  279. return -ENOMEM;
  280. setup = (struct p54_setup_mac *) skb_put(skb, sizeof(*setup));
  281. if (!(priv->hw->conf.flags & IEEE80211_CONF_IDLE)) {
  282. switch (priv->mode) {
  283. case NL80211_IFTYPE_STATION:
  284. mode = P54_FILTER_TYPE_STATION;
  285. break;
  286. case NL80211_IFTYPE_AP:
  287. mode = P54_FILTER_TYPE_AP;
  288. break;
  289. case NL80211_IFTYPE_ADHOC:
  290. case NL80211_IFTYPE_MESH_POINT:
  291. mode = P54_FILTER_TYPE_IBSS;
  292. break;
  293. case NL80211_IFTYPE_MONITOR:
  294. mode = P54_FILTER_TYPE_PROMISCUOUS;
  295. break;
  296. default:
  297. mode = P54_FILTER_TYPE_HIBERNATE;
  298. break;
  299. }
  300. /*
  301. * "TRANSPARENT and PROMISCUOUS are mutually exclusive"
  302. * STSW45X0C LMAC API - page 12
  303. */
  304. if (((priv->filter_flags & FIF_PROMISC_IN_BSS) ||
  305. (priv->filter_flags & FIF_OTHER_BSS)) &&
  306. (mode != P54_FILTER_TYPE_PROMISCUOUS))
  307. mode |= P54_FILTER_TYPE_TRANSPARENT;
  308. } else {
  309. mode = P54_FILTER_TYPE_HIBERNATE;
  310. }
  311. setup->mac_mode = cpu_to_le16(mode);
  312. memcpy(setup->mac_addr, priv->mac_addr, ETH_ALEN);
  313. memcpy(setup->bssid, priv->bssid, ETH_ALEN);
  314. setup->rx_antenna = 2 & priv->rx_diversity_mask; /* automatic */
  315. setup->rx_align = 0;
  316. if (priv->fw_var < 0x500) {
  317. setup->v1.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  318. memset(setup->v1.rts_rates, 0, 8);
  319. setup->v1.rx_addr = cpu_to_le32(priv->rx_end);
  320. setup->v1.max_rx = cpu_to_le16(priv->rx_mtu);
  321. setup->v1.rxhw = cpu_to_le16(priv->rxhw);
  322. setup->v1.wakeup_timer = cpu_to_le16(priv->wakeup_timer);
  323. setup->v1.unalloc0 = cpu_to_le16(0);
  324. } else {
  325. setup->v2.rx_addr = cpu_to_le32(priv->rx_end);
  326. setup->v2.max_rx = cpu_to_le16(priv->rx_mtu);
  327. setup->v2.rxhw = cpu_to_le16(priv->rxhw);
  328. setup->v2.timer = cpu_to_le16(priv->wakeup_timer);
  329. setup->v2.truncate = cpu_to_le16(48896);
  330. setup->v2.basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  331. setup->v2.sbss_offset = 0;
  332. setup->v2.mcast_window = 0;
  333. setup->v2.rx_rssi_threshold = 0;
  334. setup->v2.rx_ed_threshold = 0;
  335. setup->v2.ref_clock = cpu_to_le32(644245094);
  336. setup->v2.lpf_bandwidth = cpu_to_le16(65535);
  337. setup->v2.osc_start_delay = cpu_to_le16(65535);
  338. }
  339. p54_tx(priv, skb);
  340. return 0;
  341. }
  342. int p54_scan(struct p54_common *priv, u16 mode, u16 dwell)
  343. {
  344. struct sk_buff *skb;
  345. struct p54_hdr *hdr;
  346. struct p54_scan_head *head;
  347. struct p54_iq_autocal_entry *iq_autocal;
  348. union p54_scan_body_union *body;
  349. struct p54_scan_tail_rate *rate;
  350. struct pda_rssi_cal_entry *rssi;
  351. unsigned int i;
  352. void *entry;
  353. int band = priv->hw->conf.channel->band;
  354. __le16 freq = cpu_to_le16(priv->hw->conf.channel->center_freq);
  355. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*head) +
  356. 2 + sizeof(*iq_autocal) + sizeof(*body) +
  357. sizeof(*rate) + 2 * sizeof(*rssi),
  358. P54_CONTROL_TYPE_SCAN, GFP_ATOMIC);
  359. if (!skb)
  360. return -ENOMEM;
  361. head = (struct p54_scan_head *) skb_put(skb, sizeof(*head));
  362. memset(head->scan_params, 0, sizeof(head->scan_params));
  363. head->mode = cpu_to_le16(mode);
  364. head->dwell = cpu_to_le16(dwell);
  365. head->freq = freq;
  366. if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
  367. __le16 *pa_power_points = (__le16 *) skb_put(skb, 2);
  368. *pa_power_points = cpu_to_le16(0x0c);
  369. }
  370. iq_autocal = (void *) skb_put(skb, sizeof(*iq_autocal));
  371. for (i = 0; i < priv->iq_autocal_len; i++) {
  372. if (priv->iq_autocal[i].freq != freq)
  373. continue;
  374. memcpy(iq_autocal, &priv->iq_autocal[i].params,
  375. sizeof(struct p54_iq_autocal_entry));
  376. break;
  377. }
  378. if (i == priv->iq_autocal_len)
  379. goto err;
  380. if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW)
  381. body = (void *) skb_put(skb, sizeof(body->longbow));
  382. else
  383. body = (void *) skb_put(skb, sizeof(body->normal));
  384. for (i = 0; i < priv->output_limit->entries; i++) {
  385. __le16 *entry_freq = (void *) (priv->output_limit->data +
  386. priv->output_limit->entry_size * i);
  387. if (*entry_freq != freq)
  388. continue;
  389. if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
  390. memcpy(&body->longbow.power_limits,
  391. (void *) entry_freq + sizeof(__le16),
  392. priv->output_limit->entry_size);
  393. } else {
  394. struct pda_channel_output_limit *limits =
  395. (void *) entry_freq;
  396. body->normal.val_barker = 0x38;
  397. body->normal.val_bpsk = body->normal.dup_bpsk =
  398. limits->val_bpsk;
  399. body->normal.val_qpsk = body->normal.dup_qpsk =
  400. limits->val_qpsk;
  401. body->normal.val_16qam = body->normal.dup_16qam =
  402. limits->val_16qam;
  403. body->normal.val_64qam = body->normal.dup_64qam =
  404. limits->val_64qam;
  405. }
  406. break;
  407. }
  408. if (i == priv->output_limit->entries)
  409. goto err;
  410. entry = (void *)(priv->curve_data->data + priv->curve_data->offset);
  411. for (i = 0; i < priv->curve_data->entries; i++) {
  412. if (*((__le16 *)entry) != freq) {
  413. entry += priv->curve_data->entry_size;
  414. continue;
  415. }
  416. if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
  417. memcpy(&body->longbow.curve_data,
  418. (void *) entry + sizeof(__le16),
  419. priv->curve_data->entry_size);
  420. } else {
  421. struct p54_scan_body *chan = &body->normal;
  422. struct pda_pa_curve_data *curve_data =
  423. (void *) priv->curve_data->data;
  424. entry += sizeof(__le16);
  425. chan->pa_points_per_curve = 8;
  426. memset(chan->curve_data, 0, sizeof(*chan->curve_data));
  427. memcpy(chan->curve_data, entry,
  428. sizeof(struct p54_pa_curve_data_sample) *
  429. min((u8)8, curve_data->points_per_channel));
  430. }
  431. break;
  432. }
  433. if (i == priv->curve_data->entries)
  434. goto err;
  435. if ((priv->fw_var >= 0x500) && (priv->fw_var < 0x509)) {
  436. rate = (void *) skb_put(skb, sizeof(*rate));
  437. rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  438. for (i = 0; i < sizeof(rate->rts_rates); i++)
  439. rate->rts_rates[i] = i;
  440. }
  441. rssi = (struct pda_rssi_cal_entry *) skb_put(skb, sizeof(*rssi));
  442. rssi->mul = cpu_to_le16(priv->rssical_db[band].mul);
  443. rssi->add = cpu_to_le16(priv->rssical_db[band].add);
  444. if (priv->rxhw == PDR_SYNTH_FRONTEND_LONGBOW) {
  445. /* Longbow frontend needs ever more */
  446. rssi = (void *) skb_put(skb, sizeof(*rssi));
  447. rssi->mul = cpu_to_le16(priv->rssical_db[band].longbow_unkn);
  448. rssi->add = cpu_to_le16(priv->rssical_db[band].longbow_unk2);
  449. }
  450. if (priv->fw_var >= 0x509) {
  451. rate = (void *) skb_put(skb, sizeof(*rate));
  452. rate->basic_rate_mask = cpu_to_le32(priv->basic_rate_mask);
  453. for (i = 0; i < sizeof(rate->rts_rates); i++)
  454. rate->rts_rates[i] = i;
  455. }
  456. hdr = (struct p54_hdr *) skb->data;
  457. hdr->len = cpu_to_le16(skb->len - sizeof(*hdr));
  458. p54_tx(priv, skb);
  459. return 0;
  460. err:
  461. printk(KERN_ERR "%s: frequency change to channel %d failed.\n",
  462. wiphy_name(priv->hw->wiphy), ieee80211_frequency_to_channel(
  463. priv->hw->conf.channel->center_freq));
  464. dev_kfree_skb_any(skb);
  465. return -EINVAL;
  466. }
  467. int p54_set_leds(struct p54_common *priv)
  468. {
  469. struct sk_buff *skb;
  470. struct p54_led *led;
  471. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led),
  472. P54_CONTROL_TYPE_LED, GFP_ATOMIC);
  473. if (unlikely(!skb))
  474. return -ENOMEM;
  475. led = (struct p54_led *) skb_put(skb, sizeof(*led));
  476. led->flags = cpu_to_le16(0x0003);
  477. led->mask[0] = led->mask[1] = cpu_to_le16(priv->softled_state);
  478. led->delay[0] = cpu_to_le16(1);
  479. led->delay[1] = cpu_to_le16(0);
  480. p54_tx(priv, skb);
  481. return 0;
  482. }
  483. int p54_set_edcf(struct p54_common *priv)
  484. {
  485. struct sk_buff *skb;
  486. struct p54_edcf *edcf;
  487. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf),
  488. P54_CONTROL_TYPE_DCFINIT, GFP_ATOMIC);
  489. if (unlikely(!skb))
  490. return -ENOMEM;
  491. edcf = (struct p54_edcf *)skb_put(skb, sizeof(*edcf));
  492. if (priv->use_short_slot) {
  493. edcf->slottime = 9;
  494. edcf->sifs = 0x10;
  495. edcf->eofpad = 0x00;
  496. } else {
  497. edcf->slottime = 20;
  498. edcf->sifs = 0x0a;
  499. edcf->eofpad = 0x06;
  500. }
  501. /* (see prism54/isl_oid.h for further details) */
  502. edcf->frameburst = cpu_to_le16(0);
  503. edcf->round_trip_delay = cpu_to_le16(0);
  504. edcf->flags = 0;
  505. memset(edcf->mapping, 0, sizeof(edcf->mapping));
  506. memcpy(edcf->queue, priv->qos_params, sizeof(edcf->queue));
  507. p54_tx(priv, skb);
  508. return 0;
  509. }
  510. int p54_set_ps(struct p54_common *priv)
  511. {
  512. struct sk_buff *skb;
  513. struct p54_psm *psm;
  514. unsigned int i;
  515. u16 mode;
  516. if (priv->hw->conf.flags & IEEE80211_CONF_PS &&
  517. !priv->powersave_override)
  518. mode = P54_PSM | P54_PSM_BEACON_TIMEOUT | P54_PSM_DTIM |
  519. P54_PSM_CHECKSUM | P54_PSM_MCBC;
  520. else
  521. mode = P54_PSM_CAM;
  522. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*psm),
  523. P54_CONTROL_TYPE_PSM, GFP_ATOMIC);
  524. if (!skb)
  525. return -ENOMEM;
  526. psm = (struct p54_psm *)skb_put(skb, sizeof(*psm));
  527. psm->mode = cpu_to_le16(mode);
  528. psm->aid = cpu_to_le16(priv->aid);
  529. for (i = 0; i < ARRAY_SIZE(psm->intervals); i++) {
  530. psm->intervals[i].interval =
  531. cpu_to_le16(priv->hw->conf.listen_interval);
  532. psm->intervals[i].periods = cpu_to_le16(1);
  533. }
  534. psm->beacon_rssi_skip_max = 200;
  535. psm->rssi_delta_threshold = 0;
  536. psm->nr = 1;
  537. psm->exclude[0] = WLAN_EID_TIM;
  538. p54_tx(priv, skb);
  539. return 0;
  540. }
  541. int p54_init_xbow_synth(struct p54_common *priv)
  542. {
  543. struct sk_buff *skb;
  544. struct p54_xbow_synth *xbow;
  545. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow),
  546. P54_CONTROL_TYPE_XBOW_SYNTH_CFG, GFP_KERNEL);
  547. if (unlikely(!skb))
  548. return -ENOMEM;
  549. xbow = (struct p54_xbow_synth *)skb_put(skb, sizeof(*xbow));
  550. xbow->magic1 = cpu_to_le16(0x1);
  551. xbow->magic2 = cpu_to_le16(0x2);
  552. xbow->freq = cpu_to_le16(5390);
  553. memset(xbow->padding, 0, sizeof(xbow->padding));
  554. p54_tx(priv, skb);
  555. return 0;
  556. }
  557. int p54_upload_key(struct p54_common *priv, u8 algo, int slot, u8 idx, u8 len,
  558. u8 *addr, u8* key)
  559. {
  560. struct sk_buff *skb;
  561. struct p54_keycache *rxkey;
  562. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey),
  563. P54_CONTROL_TYPE_RX_KEYCACHE, GFP_KERNEL);
  564. if (unlikely(!skb))
  565. return -ENOMEM;
  566. rxkey = (struct p54_keycache *)skb_put(skb, sizeof(*rxkey));
  567. rxkey->entry = slot;
  568. rxkey->key_id = idx;
  569. rxkey->key_type = algo;
  570. if (addr)
  571. memcpy(rxkey->mac, addr, ETH_ALEN);
  572. else
  573. memset(rxkey->mac, ~0, ETH_ALEN);
  574. switch (algo) {
  575. case P54_CRYPTO_WEP:
  576. case P54_CRYPTO_AESCCMP:
  577. rxkey->key_len = min_t(u8, 16, len);
  578. memcpy(rxkey->key, key, rxkey->key_len);
  579. break;
  580. case P54_CRYPTO_TKIPMICHAEL:
  581. rxkey->key_len = 24;
  582. memcpy(rxkey->key, key, 16);
  583. memcpy(&(rxkey->key[16]), &(key
  584. [NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY]), 8);
  585. break;
  586. case P54_CRYPTO_NONE:
  587. rxkey->key_len = 0;
  588. memset(rxkey->key, 0, sizeof(rxkey->key));
  589. break;
  590. default:
  591. printk(KERN_ERR "%s: invalid cryptographic algorithm: %d\n",
  592. wiphy_name(priv->hw->wiphy), algo);
  593. dev_kfree_skb(skb);
  594. return -EINVAL;
  595. }
  596. p54_tx(priv, skb);
  597. return 0;
  598. }
  599. int p54_fetch_statistics(struct p54_common *priv)
  600. {
  601. struct ieee80211_tx_info *txinfo;
  602. struct p54_tx_info *p54info;
  603. struct sk_buff *skb;
  604. skb = p54_alloc_skb(priv, P54_HDR_FLAG_CONTROL,
  605. sizeof(struct p54_statistics),
  606. P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
  607. if (!skb)
  608. return -ENOMEM;
  609. /*
  610. * The statistic feedback causes some extra headaches here, if it
  611. * is not to crash/corrupt the firmware data structures.
  612. *
  613. * Unlike all other Control Get OIDs we can not use helpers like
  614. * skb_put to reserve the space for the data we're requesting.
  615. * Instead the extra frame length -which will hold the results later-
  616. * will only be told to the p54_assign_address, so that following
  617. * frames won't be placed into the allegedly empty area.
  618. */
  619. txinfo = IEEE80211_SKB_CB(skb);
  620. p54info = (void *) txinfo->rate_driver_data;
  621. p54info->extra_len = sizeof(struct p54_statistics);
  622. p54_tx(priv, skb);
  623. return 0;
  624. }