main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * mac80211 glue 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 "lmac.h"
  25. static int modparam_nohwcrypt;
  26. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  27. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  28. MODULE_AUTHOR("Michael Wu <flamingice@sourmilk.net>");
  29. MODULE_DESCRIPTION("Softmac Prism54 common code");
  30. MODULE_LICENSE("GPL");
  31. MODULE_ALIAS("prism54common");
  32. static int p54_sta_add_remove(struct ieee80211_hw *hw,
  33. struct ieee80211_vif *vif,
  34. struct ieee80211_sta *sta)
  35. {
  36. struct p54_common *priv = hw->priv;
  37. /*
  38. * Notify the firmware that we don't want or we don't
  39. * need to buffer frames for this station anymore.
  40. */
  41. p54_sta_unlock(priv, sta->addr);
  42. return 0;
  43. }
  44. static void p54_sta_notify(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
  45. enum sta_notify_cmd notify_cmd,
  46. struct ieee80211_sta *sta)
  47. {
  48. struct p54_common *priv = dev->priv;
  49. switch (notify_cmd) {
  50. case STA_NOTIFY_AWAKE:
  51. /* update the firmware's filter table */
  52. p54_sta_unlock(priv, sta->addr);
  53. break;
  54. default:
  55. break;
  56. }
  57. }
  58. static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
  59. bool set)
  60. {
  61. struct p54_common *priv = dev->priv;
  62. return p54_update_beacon_tim(priv, sta->aid, set);
  63. }
  64. u8 *p54_find_ie(struct sk_buff *skb, u8 ie)
  65. {
  66. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  67. u8 *pos, *end;
  68. if (skb->len <= sizeof(mgmt))
  69. return NULL;
  70. pos = (u8 *)mgmt->u.beacon.variable;
  71. end = skb->data + skb->len;
  72. while (pos < end) {
  73. if (pos + 2 + pos[1] > end)
  74. return NULL;
  75. if (pos[0] == ie)
  76. return pos;
  77. pos += 2 + pos[1];
  78. }
  79. return NULL;
  80. }
  81. static int p54_beacon_format_ie_tim(struct sk_buff *skb)
  82. {
  83. /*
  84. * the good excuse for this mess is ... the firmware.
  85. * The dummy TIM MUST be at the end of the beacon frame,
  86. * because it'll be overwritten!
  87. */
  88. u8 *tim;
  89. u8 dtim_len;
  90. u8 dtim_period;
  91. u8 *next;
  92. tim = p54_find_ie(skb, WLAN_EID_TIM);
  93. if (!tim)
  94. return 0;
  95. dtim_len = tim[1];
  96. dtim_period = tim[3];
  97. next = tim + 2 + dtim_len;
  98. if (dtim_len < 3)
  99. return -EINVAL;
  100. memmove(tim, next, skb_tail_pointer(skb) - next);
  101. tim = skb_tail_pointer(skb) - (dtim_len + 2);
  102. /* add the dummy at the end */
  103. tim[0] = WLAN_EID_TIM;
  104. tim[1] = 3;
  105. tim[2] = 0;
  106. tim[3] = dtim_period;
  107. tim[4] = 0;
  108. if (dtim_len > 3)
  109. skb_trim(skb, skb->len - (dtim_len - 3));
  110. return 0;
  111. }
  112. static int p54_beacon_update(struct p54_common *priv,
  113. struct ieee80211_vif *vif)
  114. {
  115. struct sk_buff *beacon;
  116. int ret;
  117. beacon = ieee80211_beacon_get(priv->hw, vif);
  118. if (!beacon)
  119. return -ENOMEM;
  120. ret = p54_beacon_format_ie_tim(beacon);
  121. if (ret)
  122. return ret;
  123. /*
  124. * During operation, the firmware takes care of beaconing.
  125. * The driver only needs to upload a new beacon template, once
  126. * the template was changed by the stack or userspace.
  127. *
  128. * LMAC API 3.2.2 also specifies that the driver does not need
  129. * to cancel the old beacon template by hand, instead the firmware
  130. * will release the previous one through the feedback mechanism.
  131. */
  132. p54_tx_80211(priv->hw, beacon);
  133. priv->tsf_high32 = 0;
  134. priv->tsf_low32 = 0;
  135. return 0;
  136. }
  137. static int p54_start(struct ieee80211_hw *dev)
  138. {
  139. struct p54_common *priv = dev->priv;
  140. int err;
  141. mutex_lock(&priv->conf_mutex);
  142. err = priv->open(dev);
  143. if (err)
  144. goto out;
  145. P54_SET_QUEUE(priv->qos_params[0], 0x0002, 0x0003, 0x0007, 47);
  146. P54_SET_QUEUE(priv->qos_params[1], 0x0002, 0x0007, 0x000f, 94);
  147. P54_SET_QUEUE(priv->qos_params[2], 0x0003, 0x000f, 0x03ff, 0);
  148. P54_SET_QUEUE(priv->qos_params[3], 0x0007, 0x000f, 0x03ff, 0);
  149. err = p54_set_edcf(priv);
  150. if (err)
  151. goto out;
  152. memset(priv->bssid, ~0, ETH_ALEN);
  153. priv->mode = NL80211_IFTYPE_MONITOR;
  154. err = p54_setup_mac(priv);
  155. if (err) {
  156. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  157. goto out;
  158. }
  159. ieee80211_queue_delayed_work(dev, &priv->work, 0);
  160. priv->softled_state = 0;
  161. err = p54_set_leds(priv);
  162. out:
  163. mutex_unlock(&priv->conf_mutex);
  164. return err;
  165. }
  166. static void p54_stop(struct ieee80211_hw *dev)
  167. {
  168. struct p54_common *priv = dev->priv;
  169. int i;
  170. mutex_lock(&priv->conf_mutex);
  171. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  172. priv->softled_state = 0;
  173. p54_set_leds(priv);
  174. cancel_delayed_work_sync(&priv->work);
  175. priv->stop(dev);
  176. skb_queue_purge(&priv->tx_pending);
  177. skb_queue_purge(&priv->tx_queue);
  178. for (i = 0; i < P54_QUEUE_NUM; i++) {
  179. priv->tx_stats[i].count = 0;
  180. priv->tx_stats[i].len = 0;
  181. }
  182. priv->beacon_req_id = cpu_to_le32(0);
  183. priv->tsf_high32 = priv->tsf_low32 = 0;
  184. mutex_unlock(&priv->conf_mutex);
  185. }
  186. static int p54_add_interface(struct ieee80211_hw *dev,
  187. struct ieee80211_vif *vif)
  188. {
  189. struct p54_common *priv = dev->priv;
  190. mutex_lock(&priv->conf_mutex);
  191. if (priv->mode != NL80211_IFTYPE_MONITOR) {
  192. mutex_unlock(&priv->conf_mutex);
  193. return -EOPNOTSUPP;
  194. }
  195. priv->vif = vif;
  196. switch (vif->type) {
  197. case NL80211_IFTYPE_STATION:
  198. case NL80211_IFTYPE_ADHOC:
  199. case NL80211_IFTYPE_AP:
  200. case NL80211_IFTYPE_MESH_POINT:
  201. priv->mode = vif->type;
  202. break;
  203. default:
  204. mutex_unlock(&priv->conf_mutex);
  205. return -EOPNOTSUPP;
  206. }
  207. memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
  208. p54_setup_mac(priv);
  209. mutex_unlock(&priv->conf_mutex);
  210. return 0;
  211. }
  212. static void p54_remove_interface(struct ieee80211_hw *dev,
  213. struct ieee80211_vif *vif)
  214. {
  215. struct p54_common *priv = dev->priv;
  216. mutex_lock(&priv->conf_mutex);
  217. priv->vif = NULL;
  218. /*
  219. * LMAC API 3.2.2 states that any active beacon template must be
  220. * canceled by the driver before attempting a mode transition.
  221. */
  222. if (le32_to_cpu(priv->beacon_req_id) != 0) {
  223. p54_tx_cancel(priv, priv->beacon_req_id);
  224. wait_for_completion_interruptible_timeout(&priv->beacon_comp, HZ);
  225. }
  226. priv->mode = NL80211_IFTYPE_MONITOR;
  227. memset(priv->mac_addr, 0, ETH_ALEN);
  228. memset(priv->bssid, 0, ETH_ALEN);
  229. p54_setup_mac(priv);
  230. mutex_unlock(&priv->conf_mutex);
  231. }
  232. static int p54_config(struct ieee80211_hw *dev, u32 changed)
  233. {
  234. int ret = 0;
  235. struct p54_common *priv = dev->priv;
  236. struct ieee80211_conf *conf = &dev->conf;
  237. mutex_lock(&priv->conf_mutex);
  238. if (changed & IEEE80211_CONF_CHANGE_POWER)
  239. priv->output_power = conf->power_level << 2;
  240. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  241. ret = p54_scan(priv, P54_SCAN_EXIT, 0);
  242. if (ret)
  243. goto out;
  244. }
  245. if (changed & IEEE80211_CONF_CHANGE_PS) {
  246. ret = p54_set_ps(priv);
  247. if (ret)
  248. goto out;
  249. }
  250. if (changed & IEEE80211_CONF_CHANGE_IDLE) {
  251. ret = p54_setup_mac(priv);
  252. if (ret)
  253. goto out;
  254. }
  255. out:
  256. mutex_unlock(&priv->conf_mutex);
  257. return ret;
  258. }
  259. static u64 p54_prepare_multicast(struct ieee80211_hw *dev,
  260. struct netdev_hw_addr_list *mc_list)
  261. {
  262. struct p54_common *priv = dev->priv;
  263. struct netdev_hw_addr *ha;
  264. int i;
  265. BUILD_BUG_ON(ARRAY_SIZE(priv->mc_maclist) !=
  266. ARRAY_SIZE(((struct p54_group_address_table *)NULL)->mac_list));
  267. /*
  268. * The first entry is reserved for the global broadcast MAC.
  269. * Otherwise the firmware will drop it and ARP will no longer work.
  270. */
  271. i = 1;
  272. priv->mc_maclist_num = netdev_hw_addr_list_count(mc_list) + i;
  273. netdev_hw_addr_list_for_each(ha, mc_list) {
  274. memcpy(&priv->mc_maclist[i], ha->addr, ETH_ALEN);
  275. i++;
  276. if (i >= ARRAY_SIZE(priv->mc_maclist))
  277. break;
  278. }
  279. return 1; /* update */
  280. }
  281. static void p54_configure_filter(struct ieee80211_hw *dev,
  282. unsigned int changed_flags,
  283. unsigned int *total_flags,
  284. u64 multicast)
  285. {
  286. struct p54_common *priv = dev->priv;
  287. *total_flags &= FIF_PROMISC_IN_BSS |
  288. FIF_ALLMULTI |
  289. FIF_OTHER_BSS;
  290. priv->filter_flags = *total_flags;
  291. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS))
  292. p54_setup_mac(priv);
  293. if (changed_flags & FIF_ALLMULTI || multicast)
  294. p54_set_groupfilter(priv);
  295. }
  296. static int p54_conf_tx(struct ieee80211_hw *dev, u16 queue,
  297. const struct ieee80211_tx_queue_params *params)
  298. {
  299. struct p54_common *priv = dev->priv;
  300. int ret;
  301. mutex_lock(&priv->conf_mutex);
  302. if (queue < dev->queues) {
  303. P54_SET_QUEUE(priv->qos_params[queue], params->aifs,
  304. params->cw_min, params->cw_max, params->txop);
  305. ret = p54_set_edcf(priv);
  306. } else
  307. ret = -EINVAL;
  308. mutex_unlock(&priv->conf_mutex);
  309. return ret;
  310. }
  311. static void p54_work(struct work_struct *work)
  312. {
  313. struct p54_common *priv = container_of(work, struct p54_common,
  314. work.work);
  315. if (unlikely(priv->mode == NL80211_IFTYPE_UNSPECIFIED))
  316. return ;
  317. /*
  318. * TODO: walk through tx_queue and do the following tasks
  319. * 1. initiate bursts.
  320. * 2. cancel stuck frames / reset the device if necessary.
  321. */
  322. p54_fetch_statistics(priv);
  323. }
  324. static int p54_get_stats(struct ieee80211_hw *dev,
  325. struct ieee80211_low_level_stats *stats)
  326. {
  327. struct p54_common *priv = dev->priv;
  328. memcpy(stats, &priv->stats, sizeof(*stats));
  329. return 0;
  330. }
  331. static void p54_bss_info_changed(struct ieee80211_hw *dev,
  332. struct ieee80211_vif *vif,
  333. struct ieee80211_bss_conf *info,
  334. u32 changed)
  335. {
  336. struct p54_common *priv = dev->priv;
  337. mutex_lock(&priv->conf_mutex);
  338. if (changed & BSS_CHANGED_BSSID) {
  339. memcpy(priv->bssid, info->bssid, ETH_ALEN);
  340. p54_setup_mac(priv);
  341. }
  342. if (changed & BSS_CHANGED_BEACON) {
  343. p54_scan(priv, P54_SCAN_EXIT, 0);
  344. p54_setup_mac(priv);
  345. p54_beacon_update(priv, vif);
  346. p54_set_edcf(priv);
  347. }
  348. if (changed & (BSS_CHANGED_ERP_SLOT | BSS_CHANGED_BEACON)) {
  349. priv->use_short_slot = info->use_short_slot;
  350. p54_set_edcf(priv);
  351. }
  352. if (changed & BSS_CHANGED_BASIC_RATES) {
  353. if (dev->conf.channel->band == IEEE80211_BAND_5GHZ)
  354. priv->basic_rate_mask = (info->basic_rates << 4);
  355. else
  356. priv->basic_rate_mask = info->basic_rates;
  357. p54_setup_mac(priv);
  358. if (priv->fw_var >= 0x500)
  359. p54_scan(priv, P54_SCAN_EXIT, 0);
  360. }
  361. if (changed & BSS_CHANGED_ASSOC) {
  362. if (info->assoc) {
  363. priv->aid = info->aid;
  364. priv->wakeup_timer = info->beacon_int *
  365. info->dtim_period * 5;
  366. p54_setup_mac(priv);
  367. } else {
  368. priv->wakeup_timer = 500;
  369. priv->aid = 0;
  370. }
  371. }
  372. mutex_unlock(&priv->conf_mutex);
  373. }
  374. static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
  375. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  376. struct ieee80211_key_conf *key)
  377. {
  378. struct p54_common *priv = dev->priv;
  379. int slot, ret = 0;
  380. u8 algo = 0;
  381. u8 *addr = NULL;
  382. if (modparam_nohwcrypt)
  383. return -EOPNOTSUPP;
  384. mutex_lock(&priv->conf_mutex);
  385. if (cmd == SET_KEY) {
  386. switch (key->cipher) {
  387. case WLAN_CIPHER_SUITE_TKIP:
  388. if (!(priv->privacy_caps & (BR_DESC_PRIV_CAP_MICHAEL |
  389. BR_DESC_PRIV_CAP_TKIP))) {
  390. ret = -EOPNOTSUPP;
  391. goto out_unlock;
  392. }
  393. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  394. algo = P54_CRYPTO_TKIPMICHAEL;
  395. break;
  396. case WLAN_CIPHER_SUITE_WEP40:
  397. case WLAN_CIPHER_SUITE_WEP104:
  398. if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_WEP)) {
  399. ret = -EOPNOTSUPP;
  400. goto out_unlock;
  401. }
  402. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  403. algo = P54_CRYPTO_WEP;
  404. break;
  405. case WLAN_CIPHER_SUITE_CCMP:
  406. if (!(priv->privacy_caps & BR_DESC_PRIV_CAP_AESCCMP)) {
  407. ret = -EOPNOTSUPP;
  408. goto out_unlock;
  409. }
  410. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  411. algo = P54_CRYPTO_AESCCMP;
  412. break;
  413. default:
  414. ret = -EOPNOTSUPP;
  415. goto out_unlock;
  416. }
  417. slot = bitmap_find_free_region(priv->used_rxkeys,
  418. priv->rx_keycache_size, 0);
  419. if (slot < 0) {
  420. /*
  421. * The device supports the chosen algorithm, but the
  422. * firmware does not provide enough key slots to store
  423. * all of them.
  424. * But encryption offload for outgoing frames is always
  425. * possible, so we just pretend that the upload was
  426. * successful and do the decryption in software.
  427. */
  428. /* mark the key as invalid. */
  429. key->hw_key_idx = 0xff;
  430. goto out_unlock;
  431. }
  432. } else {
  433. slot = key->hw_key_idx;
  434. if (slot == 0xff) {
  435. /* This key was not uploaded into the rx key cache. */
  436. goto out_unlock;
  437. }
  438. bitmap_release_region(priv->used_rxkeys, slot, 0);
  439. algo = 0;
  440. }
  441. if (sta)
  442. addr = sta->addr;
  443. ret = p54_upload_key(priv, algo, slot, key->keyidx,
  444. key->keylen, addr, key->key);
  445. if (ret) {
  446. bitmap_release_region(priv->used_rxkeys, slot, 0);
  447. ret = -EOPNOTSUPP;
  448. goto out_unlock;
  449. }
  450. key->hw_key_idx = slot;
  451. out_unlock:
  452. mutex_unlock(&priv->conf_mutex);
  453. return ret;
  454. }
  455. static int p54_get_survey(struct ieee80211_hw *dev, int idx,
  456. struct survey_info *survey)
  457. {
  458. struct p54_common *priv = dev->priv;
  459. struct ieee80211_conf *conf = &dev->conf;
  460. if (idx != 0)
  461. return -ENOENT;
  462. survey->channel = conf->channel;
  463. survey->filled = SURVEY_INFO_NOISE_DBM;
  464. survey->noise = clamp_t(s8, priv->noise, -128, 127);
  465. return 0;
  466. }
  467. static unsigned int p54_flush_count(struct p54_common *priv)
  468. {
  469. unsigned int total = 0, i;
  470. BUILD_BUG_ON(P54_QUEUE_NUM > ARRAY_SIZE(priv->tx_stats));
  471. /*
  472. * Because the firmware has the sole control over any frames
  473. * in the P54_QUEUE_BEACON or P54_QUEUE_SCAN queues, they
  474. * don't really count as pending or active.
  475. */
  476. for (i = P54_QUEUE_MGMT; i < P54_QUEUE_NUM; i++)
  477. total += priv->tx_stats[i].len;
  478. return total;
  479. }
  480. static void p54_flush(struct ieee80211_hw *dev, bool drop)
  481. {
  482. struct p54_common *priv = dev->priv;
  483. unsigned int total, i;
  484. /*
  485. * Currently, it wouldn't really matter if we wait for one second
  486. * or 15 minutes. But once someone gets around and completes the
  487. * TODOs [ancel stuck frames / reset device] in p54_work, it will
  488. * suddenly make sense to wait that long.
  489. */
  490. i = P54_STATISTICS_UPDATE * 2 / 20;
  491. /*
  492. * In this case no locking is required because as we speak the
  493. * queues have already been stopped and no new frames can sneak
  494. * up from behind.
  495. */
  496. while ((total = p54_flush_count(priv) && i--)) {
  497. /* waste time */
  498. msleep(20);
  499. }
  500. WARN(total, "tx flush timeout, unresponsive firmware");
  501. }
  502. static void p54_set_coverage_class(struct ieee80211_hw *dev, u8 coverage_class)
  503. {
  504. struct p54_common *priv = dev->priv;
  505. mutex_lock(&priv->conf_mutex);
  506. /* support all coverage class values as in 802.11-2007 Table 7-27 */
  507. priv->coverage_class = clamp_t(u8, coverage_class, 0, 31);
  508. p54_set_edcf(priv);
  509. mutex_unlock(&priv->conf_mutex);
  510. }
  511. static const struct ieee80211_ops p54_ops = {
  512. .tx = p54_tx_80211,
  513. .start = p54_start,
  514. .stop = p54_stop,
  515. .add_interface = p54_add_interface,
  516. .remove_interface = p54_remove_interface,
  517. .set_tim = p54_set_tim,
  518. .sta_notify = p54_sta_notify,
  519. .sta_add = p54_sta_add_remove,
  520. .sta_remove = p54_sta_add_remove,
  521. .set_key = p54_set_key,
  522. .config = p54_config,
  523. .flush = p54_flush,
  524. .bss_info_changed = p54_bss_info_changed,
  525. .prepare_multicast = p54_prepare_multicast,
  526. .configure_filter = p54_configure_filter,
  527. .conf_tx = p54_conf_tx,
  528. .get_stats = p54_get_stats,
  529. .get_survey = p54_get_survey,
  530. .set_coverage_class = p54_set_coverage_class,
  531. };
  532. struct ieee80211_hw *p54_init_common(size_t priv_data_len)
  533. {
  534. struct ieee80211_hw *dev;
  535. struct p54_common *priv;
  536. dev = ieee80211_alloc_hw(priv_data_len, &p54_ops);
  537. if (!dev)
  538. return NULL;
  539. priv = dev->priv;
  540. priv->hw = dev;
  541. priv->mode = NL80211_IFTYPE_UNSPECIFIED;
  542. priv->basic_rate_mask = 0x15f;
  543. spin_lock_init(&priv->tx_stats_lock);
  544. skb_queue_head_init(&priv->tx_queue);
  545. skb_queue_head_init(&priv->tx_pending);
  546. dev->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  547. IEEE80211_HW_SIGNAL_DBM |
  548. IEEE80211_HW_SUPPORTS_PS |
  549. IEEE80211_HW_PS_NULLFUNC_STACK |
  550. IEEE80211_HW_BEACON_FILTER |
  551. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  552. dev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  553. BIT(NL80211_IFTYPE_ADHOC) |
  554. BIT(NL80211_IFTYPE_AP) |
  555. BIT(NL80211_IFTYPE_MESH_POINT);
  556. dev->channel_change_time = 1000; /* TODO: find actual value */
  557. priv->beacon_req_id = cpu_to_le32(0);
  558. priv->tx_stats[P54_QUEUE_BEACON].limit = 1;
  559. priv->tx_stats[P54_QUEUE_FWSCAN].limit = 1;
  560. priv->tx_stats[P54_QUEUE_MGMT].limit = 3;
  561. priv->tx_stats[P54_QUEUE_CAB].limit = 3;
  562. priv->tx_stats[P54_QUEUE_DATA].limit = 5;
  563. dev->queues = 1;
  564. priv->noise = -94;
  565. /*
  566. * We support at most 8 tries no matter which rate they're at,
  567. * we cannot support max_rates * max_rate_tries as we set it
  568. * here, but setting it correctly to 4/2 or so would limit us
  569. * artificially if the RC algorithm wants just two rates, so
  570. * let's say 4/7, we'll redistribute it at TX time, see the
  571. * comments there.
  572. */
  573. dev->max_rates = 4;
  574. dev->max_rate_tries = 7;
  575. dev->extra_tx_headroom = sizeof(struct p54_hdr) + 4 +
  576. sizeof(struct p54_tx_data);
  577. /*
  578. * For now, disable PS by default because it affects
  579. * link stability significantly.
  580. */
  581. dev->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  582. mutex_init(&priv->conf_mutex);
  583. mutex_init(&priv->eeprom_mutex);
  584. init_completion(&priv->eeprom_comp);
  585. init_completion(&priv->beacon_comp);
  586. INIT_DELAYED_WORK(&priv->work, p54_work);
  587. memset(&priv->mc_maclist[0], ~0, ETH_ALEN);
  588. return dev;
  589. }
  590. EXPORT_SYMBOL_GPL(p54_init_common);
  591. int p54_register_common(struct ieee80211_hw *dev, struct device *pdev)
  592. {
  593. struct p54_common __maybe_unused *priv = dev->priv;
  594. int err;
  595. err = ieee80211_register_hw(dev);
  596. if (err) {
  597. dev_err(pdev, "Cannot register device (%d).\n", err);
  598. return err;
  599. }
  600. #ifdef CONFIG_P54_LEDS
  601. err = p54_init_leds(priv);
  602. if (err)
  603. return err;
  604. #endif /* CONFIG_P54_LEDS */
  605. dev_info(pdev, "is registered as '%s'\n", wiphy_name(dev->wiphy));
  606. return 0;
  607. }
  608. EXPORT_SYMBOL_GPL(p54_register_common);
  609. void p54_free_common(struct ieee80211_hw *dev)
  610. {
  611. struct p54_common *priv = dev->priv;
  612. unsigned int i;
  613. for (i = 0; i < IEEE80211_NUM_BANDS; i++)
  614. kfree(priv->band_table[i]);
  615. kfree(priv->iq_autocal);
  616. kfree(priv->output_limit);
  617. kfree(priv->curve_data);
  618. kfree(priv->rssi_db);
  619. kfree(priv->used_rxkeys);
  620. priv->iq_autocal = NULL;
  621. priv->output_limit = NULL;
  622. priv->curve_data = NULL;
  623. priv->rssi_db = NULL;
  624. priv->used_rxkeys = NULL;
  625. ieee80211_free_hw(dev);
  626. }
  627. EXPORT_SYMBOL_GPL(p54_free_common);
  628. void p54_unregister_common(struct ieee80211_hw *dev)
  629. {
  630. struct p54_common *priv = dev->priv;
  631. #ifdef CONFIG_P54_LEDS
  632. p54_unregister_leds(priv);
  633. #endif /* CONFIG_P54_LEDS */
  634. ieee80211_unregister_hw(dev);
  635. mutex_destroy(&priv->conf_mutex);
  636. mutex_destroy(&priv->eeprom_mutex);
  637. }
  638. EXPORT_SYMBOL_GPL(p54_unregister_common);