fwio.c 20 KB

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