fwio.c 21 KB

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