fwio.c 20 KB

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