mac80211_if.c 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. * Copyright (c) 2013 Hauke Mehrtens <hauke@hauke-m.de>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  12. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  14. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #define __UNDEF_NO_VERSION__
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/etherdevice.h>
  20. #include <linux/sched.h>
  21. #include <linux/firmware.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/module.h>
  24. #include <linux/bcma/bcma.h>
  25. #include <net/mac80211.h>
  26. #include <defs.h>
  27. #include "phy/phy_int.h"
  28. #include "d11.h"
  29. #include "channel.h"
  30. #include "scb.h"
  31. #include "pub.h"
  32. #include "ucode_loader.h"
  33. #include "mac80211_if.h"
  34. #include "main.h"
  35. #include "debug.h"
  36. #include "led.h"
  37. #define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */
  38. #define BRCMS_FLUSH_TIMEOUT 500 /* msec */
  39. /* Flags we support */
  40. #define MAC_FILTERS (FIF_PROMISC_IN_BSS | \
  41. FIF_ALLMULTI | \
  42. FIF_FCSFAIL | \
  43. FIF_CONTROL | \
  44. FIF_OTHER_BSS | \
  45. FIF_BCN_PRBRESP_PROMISC | \
  46. FIF_PSPOLL)
  47. #define CHAN2GHZ(channel, freqency, chflags) { \
  48. .band = IEEE80211_BAND_2GHZ, \
  49. .center_freq = (freqency), \
  50. .hw_value = (channel), \
  51. .flags = chflags, \
  52. .max_antenna_gain = 0, \
  53. .max_power = 19, \
  54. }
  55. #define CHAN5GHZ(channel, chflags) { \
  56. .band = IEEE80211_BAND_5GHZ, \
  57. .center_freq = 5000 + 5*(channel), \
  58. .hw_value = (channel), \
  59. .flags = chflags, \
  60. .max_antenna_gain = 0, \
  61. .max_power = 21, \
  62. }
  63. #define RATE(rate100m, _flags) { \
  64. .bitrate = (rate100m), \
  65. .flags = (_flags), \
  66. .hw_value = (rate100m / 5), \
  67. }
  68. struct firmware_hdr {
  69. __le32 offset;
  70. __le32 len;
  71. __le32 idx;
  72. };
  73. static const char * const brcms_firmwares[MAX_FW_IMAGES] = {
  74. "brcm/bcm43xx",
  75. NULL
  76. };
  77. static int n_adapters_found;
  78. MODULE_AUTHOR("Broadcom Corporation");
  79. MODULE_DESCRIPTION("Broadcom 802.11n wireless LAN driver.");
  80. MODULE_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
  81. MODULE_LICENSE("Dual BSD/GPL");
  82. /* This needs to be adjusted when brcms_firmwares changes */
  83. MODULE_FIRMWARE("brcm/bcm43xx-0.fw");
  84. MODULE_FIRMWARE("brcm/bcm43xx_hdr-0.fw");
  85. /* recognized BCMA Core IDs */
  86. static struct bcma_device_id brcms_coreid_table[] = {
  87. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 17, BCMA_ANY_CLASS),
  88. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 23, BCMA_ANY_CLASS),
  89. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 24, BCMA_ANY_CLASS),
  90. BCMA_CORETABLE_END
  91. };
  92. MODULE_DEVICE_TABLE(bcma, brcms_coreid_table);
  93. #if defined(CONFIG_BRCMDBG)
  94. /*
  95. * Module parameter for setting the debug message level. Available
  96. * flags are specified by the BRCM_DL_* macros in
  97. * drivers/net/wireless/brcm80211/include/defs.h.
  98. */
  99. module_param_named(debug, brcm_msg_level, uint, S_IRUGO | S_IWUSR);
  100. #endif
  101. static struct ieee80211_channel brcms_2ghz_chantable[] = {
  102. CHAN2GHZ(1, 2412, IEEE80211_CHAN_NO_HT40MINUS),
  103. CHAN2GHZ(2, 2417, IEEE80211_CHAN_NO_HT40MINUS),
  104. CHAN2GHZ(3, 2422, IEEE80211_CHAN_NO_HT40MINUS),
  105. CHAN2GHZ(4, 2427, IEEE80211_CHAN_NO_HT40MINUS),
  106. CHAN2GHZ(5, 2432, 0),
  107. CHAN2GHZ(6, 2437, 0),
  108. CHAN2GHZ(7, 2442, 0),
  109. CHAN2GHZ(8, 2447, IEEE80211_CHAN_NO_HT40PLUS),
  110. CHAN2GHZ(9, 2452, IEEE80211_CHAN_NO_HT40PLUS),
  111. CHAN2GHZ(10, 2457, IEEE80211_CHAN_NO_HT40PLUS),
  112. CHAN2GHZ(11, 2462, IEEE80211_CHAN_NO_HT40PLUS),
  113. CHAN2GHZ(12, 2467,
  114. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
  115. IEEE80211_CHAN_NO_HT40PLUS),
  116. CHAN2GHZ(13, 2472,
  117. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
  118. IEEE80211_CHAN_NO_HT40PLUS),
  119. CHAN2GHZ(14, 2484,
  120. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_IBSS |
  121. IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS |
  122. IEEE80211_CHAN_NO_OFDM)
  123. };
  124. static struct ieee80211_channel brcms_5ghz_nphy_chantable[] = {
  125. /* UNII-1 */
  126. CHAN5GHZ(36, IEEE80211_CHAN_NO_HT40MINUS),
  127. CHAN5GHZ(40, IEEE80211_CHAN_NO_HT40PLUS),
  128. CHAN5GHZ(44, IEEE80211_CHAN_NO_HT40MINUS),
  129. CHAN5GHZ(48, IEEE80211_CHAN_NO_HT40PLUS),
  130. /* UNII-2 */
  131. CHAN5GHZ(52,
  132. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  133. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  134. CHAN5GHZ(56,
  135. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  136. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  137. CHAN5GHZ(60,
  138. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  139. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  140. CHAN5GHZ(64,
  141. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  142. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  143. /* MID */
  144. CHAN5GHZ(100,
  145. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  146. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  147. CHAN5GHZ(104,
  148. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  149. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  150. CHAN5GHZ(108,
  151. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  152. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  153. CHAN5GHZ(112,
  154. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  155. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  156. CHAN5GHZ(116,
  157. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  158. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  159. CHAN5GHZ(120,
  160. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  161. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  162. CHAN5GHZ(124,
  163. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  164. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  165. CHAN5GHZ(128,
  166. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  167. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  168. CHAN5GHZ(132,
  169. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  170. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40MINUS),
  171. CHAN5GHZ(136,
  172. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  173. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS),
  174. CHAN5GHZ(140,
  175. IEEE80211_CHAN_RADAR | IEEE80211_CHAN_NO_IBSS |
  176. IEEE80211_CHAN_PASSIVE_SCAN | IEEE80211_CHAN_NO_HT40PLUS |
  177. IEEE80211_CHAN_NO_HT40MINUS),
  178. /* UNII-3 */
  179. CHAN5GHZ(149, IEEE80211_CHAN_NO_HT40MINUS),
  180. CHAN5GHZ(153, IEEE80211_CHAN_NO_HT40PLUS),
  181. CHAN5GHZ(157, IEEE80211_CHAN_NO_HT40MINUS),
  182. CHAN5GHZ(161, IEEE80211_CHAN_NO_HT40PLUS),
  183. CHAN5GHZ(165, IEEE80211_CHAN_NO_HT40PLUS | IEEE80211_CHAN_NO_HT40MINUS)
  184. };
  185. /*
  186. * The rate table is used for both 2.4G and 5G rates. The
  187. * latter being a subset as it does not support CCK rates.
  188. */
  189. static struct ieee80211_rate legacy_ratetable[] = {
  190. RATE(10, 0),
  191. RATE(20, IEEE80211_RATE_SHORT_PREAMBLE),
  192. RATE(55, IEEE80211_RATE_SHORT_PREAMBLE),
  193. RATE(110, IEEE80211_RATE_SHORT_PREAMBLE),
  194. RATE(60, 0),
  195. RATE(90, 0),
  196. RATE(120, 0),
  197. RATE(180, 0),
  198. RATE(240, 0),
  199. RATE(360, 0),
  200. RATE(480, 0),
  201. RATE(540, 0),
  202. };
  203. static const struct ieee80211_supported_band brcms_band_2GHz_nphy_template = {
  204. .band = IEEE80211_BAND_2GHZ,
  205. .channels = brcms_2ghz_chantable,
  206. .n_channels = ARRAY_SIZE(brcms_2ghz_chantable),
  207. .bitrates = legacy_ratetable,
  208. .n_bitrates = ARRAY_SIZE(legacy_ratetable),
  209. .ht_cap = {
  210. /* from include/linux/ieee80211.h */
  211. .cap = IEEE80211_HT_CAP_GRN_FLD |
  212. IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40,
  213. .ht_supported = true,
  214. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
  215. .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
  216. .mcs = {
  217. /* placeholders for now */
  218. .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
  219. .rx_highest = cpu_to_le16(500),
  220. .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
  221. }
  222. };
  223. static const struct ieee80211_supported_band brcms_band_5GHz_nphy_template = {
  224. .band = IEEE80211_BAND_5GHZ,
  225. .channels = brcms_5ghz_nphy_chantable,
  226. .n_channels = ARRAY_SIZE(brcms_5ghz_nphy_chantable),
  227. .bitrates = legacy_ratetable + BRCMS_LEGACY_5G_RATE_OFFSET,
  228. .n_bitrates = ARRAY_SIZE(legacy_ratetable) -
  229. BRCMS_LEGACY_5G_RATE_OFFSET,
  230. .ht_cap = {
  231. .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
  232. IEEE80211_HT_CAP_SGI_40,
  233. .ht_supported = true,
  234. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K,
  235. .ampdu_density = AMPDU_DEF_MPDU_DENSITY,
  236. .mcs = {
  237. /* placeholders for now */
  238. .rx_mask = {0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0},
  239. .rx_highest = cpu_to_le16(500),
  240. .tx_params = IEEE80211_HT_MCS_TX_DEFINED}
  241. }
  242. };
  243. /* flags the given rate in rateset as requested */
  244. static void brcms_set_basic_rate(struct brcm_rateset *rs, u16 rate, bool is_br)
  245. {
  246. u32 i;
  247. for (i = 0; i < rs->count; i++) {
  248. if (rate != (rs->rates[i] & 0x7f))
  249. continue;
  250. if (is_br)
  251. rs->rates[i] |= BRCMS_RATE_FLAG;
  252. else
  253. rs->rates[i] &= BRCMS_RATE_MASK;
  254. return;
  255. }
  256. }
  257. static void brcms_ops_tx(struct ieee80211_hw *hw,
  258. struct ieee80211_tx_control *control,
  259. struct sk_buff *skb)
  260. {
  261. struct brcms_info *wl = hw->priv;
  262. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  263. spin_lock_bh(&wl->lock);
  264. if (!wl->pub->up) {
  265. brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
  266. kfree_skb(skb);
  267. goto done;
  268. }
  269. if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
  270. tx_info->rate_driver_data[0] = control->sta;
  271. done:
  272. spin_unlock_bh(&wl->lock);
  273. }
  274. static int brcms_ops_start(struct ieee80211_hw *hw)
  275. {
  276. struct brcms_info *wl = hw->priv;
  277. bool blocked;
  278. int err;
  279. ieee80211_wake_queues(hw);
  280. spin_lock_bh(&wl->lock);
  281. blocked = brcms_rfkill_set_hw_state(wl);
  282. spin_unlock_bh(&wl->lock);
  283. if (!blocked)
  284. wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
  285. spin_lock_bh(&wl->lock);
  286. /* avoid acknowledging frames before a non-monitor device is added */
  287. wl->mute_tx = true;
  288. if (!wl->pub->up)
  289. if (!blocked)
  290. err = brcms_up(wl);
  291. else
  292. err = -ERFKILL;
  293. else
  294. err = -ENODEV;
  295. spin_unlock_bh(&wl->lock);
  296. if (err != 0)
  297. brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
  298. __func__, err);
  299. return err;
  300. }
  301. static void brcms_ops_stop(struct ieee80211_hw *hw)
  302. {
  303. struct brcms_info *wl = hw->priv;
  304. int status;
  305. ieee80211_stop_queues(hw);
  306. if (wl->wlc == NULL)
  307. return;
  308. spin_lock_bh(&wl->lock);
  309. status = brcms_c_chipmatch(wl->wlc->hw->d11core);
  310. spin_unlock_bh(&wl->lock);
  311. if (!status) {
  312. brcms_err(wl->wlc->hw->d11core,
  313. "wl: brcms_ops_stop: chipmatch failed\n");
  314. return;
  315. }
  316. /* put driver in down state */
  317. spin_lock_bh(&wl->lock);
  318. brcms_down(wl);
  319. spin_unlock_bh(&wl->lock);
  320. }
  321. static int
  322. brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  323. {
  324. struct brcms_info *wl = hw->priv;
  325. /* Just STA, AP and ADHOC for now */
  326. if (vif->type != NL80211_IFTYPE_STATION &&
  327. vif->type != NL80211_IFTYPE_AP &&
  328. vif->type != NL80211_IFTYPE_ADHOC) {
  329. brcms_err(wl->wlc->hw->d11core,
  330. "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
  331. __func__, vif->type);
  332. return -EOPNOTSUPP;
  333. }
  334. spin_lock_bh(&wl->lock);
  335. wl->mute_tx = false;
  336. brcms_c_mute(wl->wlc, false);
  337. if (vif->type == NL80211_IFTYPE_STATION)
  338. brcms_c_start_station(wl->wlc, vif->addr);
  339. else if (vif->type == NL80211_IFTYPE_AP)
  340. brcms_c_start_ap(wl->wlc, vif->addr, vif->bss_conf.bssid,
  341. vif->bss_conf.ssid, vif->bss_conf.ssid_len);
  342. else if (vif->type == NL80211_IFTYPE_ADHOC)
  343. brcms_c_start_adhoc(wl->wlc, vif->addr);
  344. spin_unlock_bh(&wl->lock);
  345. return 0;
  346. }
  347. static void
  348. brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  349. {
  350. }
  351. static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
  352. {
  353. struct ieee80211_conf *conf = &hw->conf;
  354. struct brcms_info *wl = hw->priv;
  355. struct bcma_device *core = wl->wlc->hw->d11core;
  356. int err = 0;
  357. int new_int;
  358. spin_lock_bh(&wl->lock);
  359. if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
  360. brcms_c_set_beacon_listen_interval(wl->wlc,
  361. conf->listen_interval);
  362. }
  363. if (changed & IEEE80211_CONF_CHANGE_MONITOR)
  364. brcms_dbg_info(core, "%s: change monitor mode: %s\n",
  365. __func__, conf->flags & IEEE80211_CONF_MONITOR ?
  366. "true" : "false");
  367. if (changed & IEEE80211_CONF_CHANGE_PS)
  368. brcms_err(core, "%s: change power-save mode: %s (implement)\n",
  369. __func__, conf->flags & IEEE80211_CONF_PS ?
  370. "true" : "false");
  371. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  372. err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
  373. if (err < 0) {
  374. brcms_err(core, "%s: Error setting power_level\n",
  375. __func__);
  376. goto config_out;
  377. }
  378. new_int = brcms_c_get_tx_power(wl->wlc);
  379. if (new_int != conf->power_level)
  380. brcms_err(core,
  381. "%s: Power level req != actual, %d %d\n",
  382. __func__, conf->power_level,
  383. new_int);
  384. }
  385. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  386. if (conf->chandef.width == NL80211_CHAN_WIDTH_20 ||
  387. conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  388. err = brcms_c_set_channel(wl->wlc,
  389. conf->chandef.chan->hw_value);
  390. else
  391. err = -ENOTSUPP;
  392. }
  393. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  394. err = brcms_c_set_rate_limit(wl->wlc,
  395. conf->short_frame_max_tx_count,
  396. conf->long_frame_max_tx_count);
  397. config_out:
  398. spin_unlock_bh(&wl->lock);
  399. return err;
  400. }
  401. static void
  402. brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
  403. struct ieee80211_vif *vif,
  404. struct ieee80211_bss_conf *info, u32 changed)
  405. {
  406. struct brcms_info *wl = hw->priv;
  407. struct bcma_device *core = wl->wlc->hw->d11core;
  408. if (changed & BSS_CHANGED_ASSOC) {
  409. /* association status changed (associated/disassociated)
  410. * also implies a change in the AID.
  411. */
  412. brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
  413. __func__, info->assoc ? "" : "dis");
  414. spin_lock_bh(&wl->lock);
  415. brcms_c_associate_upd(wl->wlc, info->assoc);
  416. spin_unlock_bh(&wl->lock);
  417. }
  418. if (changed & BSS_CHANGED_ERP_SLOT) {
  419. s8 val;
  420. /* slot timing changed */
  421. if (info->use_short_slot)
  422. val = 1;
  423. else
  424. val = 0;
  425. spin_lock_bh(&wl->lock);
  426. brcms_c_set_shortslot_override(wl->wlc, val);
  427. spin_unlock_bh(&wl->lock);
  428. }
  429. if (changed & BSS_CHANGED_HT) {
  430. /* 802.11n parameters changed */
  431. u16 mode = info->ht_operation_mode;
  432. spin_lock_bh(&wl->lock);
  433. brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
  434. mode & IEEE80211_HT_OP_MODE_PROTECTION);
  435. brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
  436. mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  437. brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
  438. mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
  439. spin_unlock_bh(&wl->lock);
  440. }
  441. if (changed & BSS_CHANGED_BASIC_RATES) {
  442. struct ieee80211_supported_band *bi;
  443. u32 br_mask, i;
  444. u16 rate;
  445. struct brcm_rateset rs;
  446. int error;
  447. /* retrieve the current rates */
  448. spin_lock_bh(&wl->lock);
  449. brcms_c_get_current_rateset(wl->wlc, &rs);
  450. spin_unlock_bh(&wl->lock);
  451. br_mask = info->basic_rates;
  452. bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
  453. for (i = 0; i < bi->n_bitrates; i++) {
  454. /* convert to internal rate value */
  455. rate = (bi->bitrates[i].bitrate << 1) / 10;
  456. /* set/clear basic rate flag */
  457. brcms_set_basic_rate(&rs, rate, br_mask & 1);
  458. br_mask >>= 1;
  459. }
  460. /* update the rate set */
  461. spin_lock_bh(&wl->lock);
  462. error = brcms_c_set_rateset(wl->wlc, &rs);
  463. spin_unlock_bh(&wl->lock);
  464. if (error)
  465. brcms_err(core, "changing basic rates failed: %d\n",
  466. error);
  467. }
  468. if (changed & BSS_CHANGED_BEACON_INT) {
  469. /* Beacon interval changed */
  470. spin_lock_bh(&wl->lock);
  471. brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
  472. spin_unlock_bh(&wl->lock);
  473. }
  474. if (changed & BSS_CHANGED_BSSID) {
  475. /* BSSID changed, for whatever reason (IBSS and managed mode) */
  476. spin_lock_bh(&wl->lock);
  477. brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
  478. spin_unlock_bh(&wl->lock);
  479. }
  480. if (changed & BSS_CHANGED_SSID) {
  481. /* BSSID changed, for whatever reason (IBSS and managed mode) */
  482. spin_lock_bh(&wl->lock);
  483. brcms_c_set_ssid(wl->wlc, info->ssid, info->ssid_len);
  484. spin_unlock_bh(&wl->lock);
  485. }
  486. if (changed & BSS_CHANGED_BEACON) {
  487. /* Beacon data changed, retrieve new beacon (beaconing modes) */
  488. struct sk_buff *beacon;
  489. u16 tim_offset = 0;
  490. spin_lock_bh(&wl->lock);
  491. beacon = ieee80211_beacon_get_tim(hw, vif, &tim_offset, NULL);
  492. brcms_c_set_new_beacon(wl->wlc, beacon, tim_offset,
  493. info->dtim_period);
  494. spin_unlock_bh(&wl->lock);
  495. }
  496. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  497. struct sk_buff *probe_resp;
  498. spin_lock_bh(&wl->lock);
  499. probe_resp = ieee80211_proberesp_get(hw, vif);
  500. brcms_c_set_new_probe_resp(wl->wlc, probe_resp);
  501. spin_unlock_bh(&wl->lock);
  502. }
  503. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  504. /* Beaconing should be enabled/disabled (beaconing modes) */
  505. brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
  506. info->enable_beacon ? "true" : "false");
  507. if (info->enable_beacon &&
  508. hw->wiphy->flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) {
  509. brcms_c_enable_probe_resp(wl->wlc, true);
  510. } else {
  511. brcms_c_enable_probe_resp(wl->wlc, false);
  512. }
  513. }
  514. if (changed & BSS_CHANGED_CQM) {
  515. /* Connection quality monitor config changed */
  516. brcms_err(core, "%s: cqm change: threshold %d, hys %d "
  517. " (implement)\n", __func__, info->cqm_rssi_thold,
  518. info->cqm_rssi_hyst);
  519. }
  520. if (changed & BSS_CHANGED_IBSS) {
  521. /* IBSS join status changed */
  522. brcms_err(core, "%s: IBSS joined: %s (implement)\n",
  523. __func__, info->ibss_joined ? "true" : "false");
  524. }
  525. if (changed & BSS_CHANGED_ARP_FILTER) {
  526. /* Hardware ARP filter address list or state changed */
  527. brcms_err(core, "%s: arp filtering: %d addresses"
  528. " (implement)\n", __func__, info->arp_addr_cnt);
  529. }
  530. if (changed & BSS_CHANGED_QOS) {
  531. /*
  532. * QoS for this association was enabled/disabled.
  533. * Note that it is only ever disabled for station mode.
  534. */
  535. brcms_err(core, "%s: qos enabled: %s (implement)\n",
  536. __func__, info->qos ? "true" : "false");
  537. }
  538. return;
  539. }
  540. static void
  541. brcms_ops_configure_filter(struct ieee80211_hw *hw,
  542. unsigned int changed_flags,
  543. unsigned int *total_flags, u64 multicast)
  544. {
  545. struct brcms_info *wl = hw->priv;
  546. struct bcma_device *core = wl->wlc->hw->d11core;
  547. changed_flags &= MAC_FILTERS;
  548. *total_flags &= MAC_FILTERS;
  549. if (changed_flags & FIF_PROMISC_IN_BSS)
  550. brcms_dbg_info(core, "FIF_PROMISC_IN_BSS\n");
  551. if (changed_flags & FIF_ALLMULTI)
  552. brcms_dbg_info(core, "FIF_ALLMULTI\n");
  553. if (changed_flags & FIF_FCSFAIL)
  554. brcms_dbg_info(core, "FIF_FCSFAIL\n");
  555. if (changed_flags & FIF_CONTROL)
  556. brcms_dbg_info(core, "FIF_CONTROL\n");
  557. if (changed_flags & FIF_OTHER_BSS)
  558. brcms_dbg_info(core, "FIF_OTHER_BSS\n");
  559. if (changed_flags & FIF_PSPOLL)
  560. brcms_dbg_info(core, "FIF_PSPOLL\n");
  561. if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
  562. brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
  563. spin_lock_bh(&wl->lock);
  564. brcms_c_mac_promisc(wl->wlc, *total_flags);
  565. spin_unlock_bh(&wl->lock);
  566. return;
  567. }
  568. static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
  569. {
  570. struct brcms_info *wl = hw->priv;
  571. spin_lock_bh(&wl->lock);
  572. brcms_c_scan_start(wl->wlc);
  573. spin_unlock_bh(&wl->lock);
  574. return;
  575. }
  576. static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw)
  577. {
  578. struct brcms_info *wl = hw->priv;
  579. spin_lock_bh(&wl->lock);
  580. brcms_c_scan_stop(wl->wlc);
  581. spin_unlock_bh(&wl->lock);
  582. return;
  583. }
  584. static int
  585. brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
  586. const struct ieee80211_tx_queue_params *params)
  587. {
  588. struct brcms_info *wl = hw->priv;
  589. spin_lock_bh(&wl->lock);
  590. brcms_c_wme_setparams(wl->wlc, queue, params, true);
  591. spin_unlock_bh(&wl->lock);
  592. return 0;
  593. }
  594. static int
  595. brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  596. struct ieee80211_sta *sta)
  597. {
  598. struct brcms_info *wl = hw->priv;
  599. struct scb *scb = &wl->wlc->pri_scb;
  600. brcms_c_init_scb(scb);
  601. wl->pub->global_ampdu = &(scb->scb_ampdu);
  602. wl->pub->global_ampdu->scb = scb;
  603. wl->pub->global_ampdu->max_pdu = 16;
  604. /*
  605. * minstrel_ht initiates addBA on our behalf by calling
  606. * ieee80211_start_tx_ba_session()
  607. */
  608. return 0;
  609. }
  610. static int
  611. brcms_ops_ampdu_action(struct ieee80211_hw *hw,
  612. struct ieee80211_vif *vif,
  613. enum ieee80211_ampdu_mlme_action action,
  614. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  615. u8 buf_size)
  616. {
  617. struct brcms_info *wl = hw->priv;
  618. struct scb *scb = &wl->wlc->pri_scb;
  619. int status;
  620. if (WARN_ON(scb->magic != SCB_MAGIC))
  621. return -EIDRM;
  622. switch (action) {
  623. case IEEE80211_AMPDU_RX_START:
  624. break;
  625. case IEEE80211_AMPDU_RX_STOP:
  626. break;
  627. case IEEE80211_AMPDU_TX_START:
  628. spin_lock_bh(&wl->lock);
  629. status = brcms_c_aggregatable(wl->wlc, tid);
  630. spin_unlock_bh(&wl->lock);
  631. if (!status) {
  632. brcms_err(wl->wlc->hw->d11core,
  633. "START: tid %d is not agg\'able\n", tid);
  634. return -EINVAL;
  635. }
  636. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  637. break;
  638. case IEEE80211_AMPDU_TX_STOP_CONT:
  639. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  640. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  641. spin_lock_bh(&wl->lock);
  642. brcms_c_ampdu_flush(wl->wlc, sta, tid);
  643. spin_unlock_bh(&wl->lock);
  644. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  645. break;
  646. case IEEE80211_AMPDU_TX_OPERATIONAL:
  647. /*
  648. * BA window size from ADDBA response ('buf_size') defines how
  649. * many outstanding MPDUs are allowed for the BA stream by
  650. * recipient and traffic class. 'ampdu_factor' gives maximum
  651. * AMPDU size.
  652. */
  653. spin_lock_bh(&wl->lock);
  654. brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
  655. (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  656. sta->ht_cap.ampdu_factor)) - 1);
  657. spin_unlock_bh(&wl->lock);
  658. /* Power save wakeup */
  659. break;
  660. default:
  661. brcms_err(wl->wlc->hw->d11core,
  662. "%s: Invalid command, ignoring\n", __func__);
  663. }
  664. return 0;
  665. }
  666. static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
  667. {
  668. struct brcms_info *wl = hw->priv;
  669. bool blocked;
  670. spin_lock_bh(&wl->lock);
  671. blocked = brcms_c_check_radio_disabled(wl->wlc);
  672. spin_unlock_bh(&wl->lock);
  673. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
  674. }
  675. static bool brcms_tx_flush_completed(struct brcms_info *wl)
  676. {
  677. bool result;
  678. spin_lock_bh(&wl->lock);
  679. result = brcms_c_tx_flush_completed(wl->wlc);
  680. spin_unlock_bh(&wl->lock);
  681. return result;
  682. }
  683. static void brcms_ops_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  684. {
  685. struct brcms_info *wl = hw->priv;
  686. int ret;
  687. no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
  688. ret = wait_event_timeout(wl->tx_flush_wq,
  689. brcms_tx_flush_completed(wl),
  690. msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT));
  691. brcms_dbg_mac80211(wl->wlc->hw->d11core,
  692. "ret=%d\n", jiffies_to_msecs(ret));
  693. }
  694. static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  695. {
  696. struct brcms_info *wl = hw->priv;
  697. u64 tsf;
  698. spin_lock_bh(&wl->lock);
  699. tsf = brcms_c_tsf_get(wl->wlc);
  700. spin_unlock_bh(&wl->lock);
  701. return tsf;
  702. }
  703. static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
  704. struct ieee80211_vif *vif, u64 tsf)
  705. {
  706. struct brcms_info *wl = hw->priv;
  707. spin_lock_bh(&wl->lock);
  708. brcms_c_tsf_set(wl->wlc, tsf);
  709. spin_unlock_bh(&wl->lock);
  710. }
  711. static const struct ieee80211_ops brcms_ops = {
  712. .tx = brcms_ops_tx,
  713. .start = brcms_ops_start,
  714. .stop = brcms_ops_stop,
  715. .add_interface = brcms_ops_add_interface,
  716. .remove_interface = brcms_ops_remove_interface,
  717. .config = brcms_ops_config,
  718. .bss_info_changed = brcms_ops_bss_info_changed,
  719. .configure_filter = brcms_ops_configure_filter,
  720. .sw_scan_start = brcms_ops_sw_scan_start,
  721. .sw_scan_complete = brcms_ops_sw_scan_complete,
  722. .conf_tx = brcms_ops_conf_tx,
  723. .sta_add = brcms_ops_sta_add,
  724. .ampdu_action = brcms_ops_ampdu_action,
  725. .rfkill_poll = brcms_ops_rfkill_poll,
  726. .flush = brcms_ops_flush,
  727. .get_tsf = brcms_ops_get_tsf,
  728. .set_tsf = brcms_ops_set_tsf,
  729. };
  730. void brcms_dpc(unsigned long data)
  731. {
  732. struct brcms_info *wl;
  733. wl = (struct brcms_info *) data;
  734. spin_lock_bh(&wl->lock);
  735. /* call the common second level interrupt handler */
  736. if (wl->pub->up) {
  737. if (wl->resched) {
  738. unsigned long flags;
  739. spin_lock_irqsave(&wl->isr_lock, flags);
  740. brcms_c_intrsupd(wl->wlc);
  741. spin_unlock_irqrestore(&wl->isr_lock, flags);
  742. }
  743. wl->resched = brcms_c_dpc(wl->wlc, true);
  744. }
  745. /* brcms_c_dpc() may bring the driver down */
  746. if (!wl->pub->up)
  747. goto done;
  748. /* re-schedule dpc */
  749. if (wl->resched)
  750. tasklet_schedule(&wl->tasklet);
  751. else
  752. /* re-enable interrupts */
  753. brcms_intrson(wl);
  754. done:
  755. spin_unlock_bh(&wl->lock);
  756. wake_up(&wl->tx_flush_wq);
  757. }
  758. /*
  759. * Precondition: Since this function is called in brcms_pci_probe() context,
  760. * no locking is required.
  761. */
  762. static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
  763. {
  764. int status;
  765. struct device *device = &pdev->dev;
  766. char fw_name[100];
  767. int i;
  768. memset(&wl->fw, 0, sizeof(struct brcms_firmware));
  769. for (i = 0; i < MAX_FW_IMAGES; i++) {
  770. if (brcms_firmwares[i] == NULL)
  771. break;
  772. sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
  773. UCODE_LOADER_API_VER);
  774. status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
  775. if (status) {
  776. wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
  777. KBUILD_MODNAME, fw_name);
  778. return status;
  779. }
  780. sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
  781. UCODE_LOADER_API_VER);
  782. status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
  783. if (status) {
  784. wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
  785. KBUILD_MODNAME, fw_name);
  786. return status;
  787. }
  788. wl->fw.hdr_num_entries[i] =
  789. wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
  790. }
  791. wl->fw.fw_cnt = i;
  792. return brcms_ucode_data_init(wl, &wl->ucode);
  793. }
  794. /*
  795. * Precondition: Since this function is called in brcms_pci_probe() context,
  796. * no locking is required.
  797. */
  798. static void brcms_release_fw(struct brcms_info *wl)
  799. {
  800. int i;
  801. for (i = 0; i < MAX_FW_IMAGES; i++) {
  802. release_firmware(wl->fw.fw_bin[i]);
  803. release_firmware(wl->fw.fw_hdr[i]);
  804. }
  805. }
  806. /**
  807. * This function frees the WL per-device resources.
  808. *
  809. * This function frees resources owned by the WL device pointed to
  810. * by the wl parameter.
  811. *
  812. * precondition: can both be called locked and unlocked
  813. *
  814. */
  815. static void brcms_free(struct brcms_info *wl)
  816. {
  817. struct brcms_timer *t, *next;
  818. /* free ucode data */
  819. if (wl->fw.fw_cnt)
  820. brcms_ucode_data_free(&wl->ucode);
  821. if (wl->irq)
  822. free_irq(wl->irq, wl);
  823. /* kill dpc */
  824. tasklet_kill(&wl->tasklet);
  825. if (wl->pub) {
  826. brcms_debugfs_detach(wl->pub);
  827. brcms_c_module_unregister(wl->pub, "linux", wl);
  828. }
  829. /* free common resources */
  830. if (wl->wlc) {
  831. brcms_c_detach(wl->wlc);
  832. wl->wlc = NULL;
  833. wl->pub = NULL;
  834. }
  835. /* virtual interface deletion is deferred so we cannot spinwait */
  836. /* wait for all pending callbacks to complete */
  837. while (atomic_read(&wl->callbacks) > 0)
  838. schedule();
  839. /* free timers */
  840. for (t = wl->timers; t; t = next) {
  841. next = t->next;
  842. #ifdef DEBUG
  843. kfree(t->name);
  844. #endif
  845. kfree(t);
  846. }
  847. }
  848. /*
  849. * called from both kernel as from this kernel module (error flow on attach)
  850. * precondition: perimeter lock is not acquired.
  851. */
  852. static void brcms_remove(struct bcma_device *pdev)
  853. {
  854. struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
  855. struct brcms_info *wl = hw->priv;
  856. if (wl->wlc) {
  857. brcms_led_unregister(wl);
  858. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
  859. wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
  860. ieee80211_unregister_hw(hw);
  861. }
  862. brcms_free(wl);
  863. bcma_set_drvdata(pdev, NULL);
  864. ieee80211_free_hw(hw);
  865. }
  866. static irqreturn_t brcms_isr(int irq, void *dev_id)
  867. {
  868. struct brcms_info *wl;
  869. irqreturn_t ret = IRQ_NONE;
  870. wl = (struct brcms_info *) dev_id;
  871. spin_lock(&wl->isr_lock);
  872. /* call common first level interrupt handler */
  873. if (brcms_c_isr(wl->wlc)) {
  874. /* schedule second level handler */
  875. tasklet_schedule(&wl->tasklet);
  876. ret = IRQ_HANDLED;
  877. }
  878. spin_unlock(&wl->isr_lock);
  879. return ret;
  880. }
  881. /*
  882. * is called in brcms_pci_probe() context, therefore no locking required.
  883. */
  884. static int ieee_hw_rate_init(struct ieee80211_hw *hw)
  885. {
  886. struct brcms_info *wl = hw->priv;
  887. struct brcms_c_info *wlc = wl->wlc;
  888. struct ieee80211_supported_band *band;
  889. int has_5g = 0;
  890. u16 phy_type;
  891. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
  892. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  893. phy_type = brcms_c_get_phy_type(wl->wlc, 0);
  894. if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
  895. band = &wlc->bandstate[BAND_2G_INDEX]->band;
  896. *band = brcms_band_2GHz_nphy_template;
  897. if (phy_type == PHY_TYPE_LCN) {
  898. /* Single stream */
  899. band->ht_cap.mcs.rx_mask[1] = 0;
  900. band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
  901. }
  902. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  903. } else {
  904. return -EPERM;
  905. }
  906. /* Assume all bands use the same phy. True for 11n devices. */
  907. if (wl->pub->_nbands > 1) {
  908. has_5g++;
  909. if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
  910. band = &wlc->bandstate[BAND_5G_INDEX]->band;
  911. *band = brcms_band_5GHz_nphy_template;
  912. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  913. } else {
  914. return -EPERM;
  915. }
  916. }
  917. return 0;
  918. }
  919. /*
  920. * is called in brcms_pci_probe() context, therefore no locking required.
  921. */
  922. static int ieee_hw_init(struct ieee80211_hw *hw)
  923. {
  924. hw->flags = IEEE80211_HW_SIGNAL_DBM
  925. /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
  926. | IEEE80211_HW_REPORTS_TX_ACK_STATUS
  927. | IEEE80211_HW_AMPDU_AGGREGATION;
  928. hw->extra_tx_headroom = brcms_c_get_header_len();
  929. hw->queues = N_TX_QUEUES;
  930. hw->max_rates = 2; /* Primary rate and 1 fallback rate */
  931. /* channel change time is dependent on chip and band */
  932. hw->channel_change_time = 7 * 1000;
  933. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  934. BIT(NL80211_IFTYPE_AP) |
  935. BIT(NL80211_IFTYPE_ADHOC);
  936. /*
  937. * deactivate sending probe responses by ucude, because this will
  938. * cause problems when WPS is used.
  939. *
  940. * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  941. */
  942. hw->rate_control_algorithm = "minstrel_ht";
  943. hw->sta_data_size = 0;
  944. return ieee_hw_rate_init(hw);
  945. }
  946. /**
  947. * attach to the WL device.
  948. *
  949. * Attach to the WL device identified by vendor and device parameters.
  950. * regs is a host accessible memory address pointing to WL device registers.
  951. *
  952. * brcms_attach is not defined as static because in the case where no bus
  953. * is defined, wl_attach will never be called, and thus, gcc will issue
  954. * a warning that this function is defined but not used if we declare
  955. * it as static.
  956. *
  957. *
  958. * is called in brcms_bcma_probe() context, therefore no locking required.
  959. */
  960. static struct brcms_info *brcms_attach(struct bcma_device *pdev)
  961. {
  962. struct brcms_info *wl = NULL;
  963. int unit, err;
  964. struct ieee80211_hw *hw;
  965. u8 perm[ETH_ALEN];
  966. unit = n_adapters_found;
  967. err = 0;
  968. if (unit < 0)
  969. return NULL;
  970. /* allocate private info */
  971. hw = bcma_get_drvdata(pdev);
  972. if (hw != NULL)
  973. wl = hw->priv;
  974. if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
  975. return NULL;
  976. wl->wiphy = hw->wiphy;
  977. atomic_set(&wl->callbacks, 0);
  978. init_waitqueue_head(&wl->tx_flush_wq);
  979. /* setup the bottom half handler */
  980. tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
  981. spin_lock_init(&wl->lock);
  982. spin_lock_init(&wl->isr_lock);
  983. /* prepare ucode */
  984. if (brcms_request_fw(wl, pdev) < 0) {
  985. wiphy_err(wl->wiphy, "%s: Failed to find firmware usually in "
  986. "%s\n", KBUILD_MODNAME, "/lib/firmware/brcm");
  987. brcms_release_fw(wl);
  988. brcms_remove(pdev);
  989. return NULL;
  990. }
  991. /* common load-time initialization */
  992. wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
  993. brcms_release_fw(wl);
  994. if (!wl->wlc) {
  995. wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
  996. KBUILD_MODNAME, err);
  997. goto fail;
  998. }
  999. wl->pub = brcms_c_pub(wl->wlc);
  1000. wl->pub->ieee_hw = hw;
  1001. /* register our interrupt handler */
  1002. if (request_irq(pdev->irq, brcms_isr,
  1003. IRQF_SHARED, KBUILD_MODNAME, wl)) {
  1004. wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
  1005. goto fail;
  1006. }
  1007. wl->irq = pdev->irq;
  1008. /* register module */
  1009. brcms_c_module_register(wl->pub, "linux", wl, NULL);
  1010. if (ieee_hw_init(hw)) {
  1011. wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
  1012. __func__);
  1013. goto fail;
  1014. }
  1015. brcms_c_regd_init(wl->wlc);
  1016. memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
  1017. if (WARN_ON(!is_valid_ether_addr(perm)))
  1018. goto fail;
  1019. SET_IEEE80211_PERM_ADDR(hw, perm);
  1020. err = ieee80211_register_hw(hw);
  1021. if (err)
  1022. wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
  1023. "%d\n", __func__, err);
  1024. if (wl->pub->srom_ccode[0] &&
  1025. regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
  1026. wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
  1027. brcms_debugfs_attach(wl->pub);
  1028. brcms_debugfs_create_files(wl->pub);
  1029. n_adapters_found++;
  1030. return wl;
  1031. fail:
  1032. brcms_free(wl);
  1033. return NULL;
  1034. }
  1035. /**
  1036. * determines if a device is a WL device, and if so, attaches it.
  1037. *
  1038. * This function determines if a device pointed to by pdev is a WL device,
  1039. * and if so, performs a brcms_attach() on it.
  1040. *
  1041. * Perimeter lock is initialized in the course of this function.
  1042. */
  1043. static int brcms_bcma_probe(struct bcma_device *pdev)
  1044. {
  1045. struct brcms_info *wl;
  1046. struct ieee80211_hw *hw;
  1047. dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
  1048. pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
  1049. pdev->irq);
  1050. if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
  1051. (pdev->id.id != BCMA_CORE_80211))
  1052. return -ENODEV;
  1053. hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
  1054. if (!hw) {
  1055. pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
  1056. return -ENOMEM;
  1057. }
  1058. SET_IEEE80211_DEV(hw, &pdev->dev);
  1059. bcma_set_drvdata(pdev, hw);
  1060. memset(hw->priv, 0, sizeof(*wl));
  1061. wl = brcms_attach(pdev);
  1062. if (!wl) {
  1063. pr_err("%s: brcms_attach failed!\n", __func__);
  1064. return -ENODEV;
  1065. }
  1066. brcms_led_register(wl);
  1067. return 0;
  1068. }
  1069. static int brcms_suspend(struct bcma_device *pdev)
  1070. {
  1071. struct brcms_info *wl;
  1072. struct ieee80211_hw *hw;
  1073. hw = bcma_get_drvdata(pdev);
  1074. wl = hw->priv;
  1075. if (!wl) {
  1076. pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
  1077. __func__);
  1078. return -ENODEV;
  1079. }
  1080. /* only need to flag hw is down for proper resume */
  1081. spin_lock_bh(&wl->lock);
  1082. wl->pub->hw_up = false;
  1083. spin_unlock_bh(&wl->lock);
  1084. brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
  1085. return 0;
  1086. }
  1087. static int brcms_resume(struct bcma_device *pdev)
  1088. {
  1089. return 0;
  1090. }
  1091. static struct bcma_driver brcms_bcma_driver = {
  1092. .name = KBUILD_MODNAME,
  1093. .probe = brcms_bcma_probe,
  1094. .suspend = brcms_suspend,
  1095. .resume = brcms_resume,
  1096. .remove = brcms_remove,
  1097. .id_table = brcms_coreid_table,
  1098. };
  1099. /**
  1100. * This is the main entry point for the brcmsmac driver.
  1101. *
  1102. * This function is scheduled upon module initialization and
  1103. * does the driver registration, which result in brcms_bcma_probe()
  1104. * call resulting in the driver bringup.
  1105. */
  1106. static void brcms_driver_init(struct work_struct *work)
  1107. {
  1108. int error;
  1109. error = bcma_driver_register(&brcms_bcma_driver);
  1110. if (error)
  1111. pr_err("%s: register returned %d\n", __func__, error);
  1112. }
  1113. static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
  1114. static int __init brcms_module_init(void)
  1115. {
  1116. brcms_debugfs_init();
  1117. if (!schedule_work(&brcms_driver_work))
  1118. return -EBUSY;
  1119. return 0;
  1120. }
  1121. /**
  1122. * This function unloads the brcmsmac driver from the system.
  1123. *
  1124. * This function unconditionally unloads the brcmsmac driver module from the
  1125. * system.
  1126. *
  1127. */
  1128. static void __exit brcms_module_exit(void)
  1129. {
  1130. cancel_work_sync(&brcms_driver_work);
  1131. bcma_driver_unregister(&brcms_bcma_driver);
  1132. brcms_debugfs_exit();
  1133. }
  1134. module_init(brcms_module_init);
  1135. module_exit(brcms_module_exit);
  1136. /*
  1137. * precondition: perimeter lock has been acquired
  1138. */
  1139. void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
  1140. bool state, int prio)
  1141. {
  1142. brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
  1143. }
  1144. /*
  1145. * precondition: perimeter lock has been acquired
  1146. */
  1147. void brcms_init(struct brcms_info *wl)
  1148. {
  1149. brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
  1150. wl->pub->unit);
  1151. brcms_reset(wl);
  1152. brcms_c_init(wl->wlc, wl->mute_tx);
  1153. }
  1154. /*
  1155. * precondition: perimeter lock has been acquired
  1156. */
  1157. uint brcms_reset(struct brcms_info *wl)
  1158. {
  1159. brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
  1160. brcms_c_reset(wl->wlc);
  1161. /* dpc will not be rescheduled */
  1162. wl->resched = false;
  1163. /* inform publicly that interface is down */
  1164. wl->pub->up = false;
  1165. return 0;
  1166. }
  1167. void brcms_fatal_error(struct brcms_info *wl)
  1168. {
  1169. brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
  1170. wl->wlc->pub->unit);
  1171. brcms_reset(wl);
  1172. ieee80211_restart_hw(wl->pub->ieee_hw);
  1173. }
  1174. /*
  1175. * These are interrupt on/off entry points. Disable interrupts
  1176. * during interrupt state transition.
  1177. */
  1178. void brcms_intrson(struct brcms_info *wl)
  1179. {
  1180. unsigned long flags;
  1181. spin_lock_irqsave(&wl->isr_lock, flags);
  1182. brcms_c_intrson(wl->wlc);
  1183. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1184. }
  1185. u32 brcms_intrsoff(struct brcms_info *wl)
  1186. {
  1187. unsigned long flags;
  1188. u32 status;
  1189. spin_lock_irqsave(&wl->isr_lock, flags);
  1190. status = brcms_c_intrsoff(wl->wlc);
  1191. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1192. return status;
  1193. }
  1194. void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
  1195. {
  1196. unsigned long flags;
  1197. spin_lock_irqsave(&wl->isr_lock, flags);
  1198. brcms_c_intrsrestore(wl->wlc, macintmask);
  1199. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1200. }
  1201. /*
  1202. * precondition: perimeter lock has been acquired
  1203. */
  1204. int brcms_up(struct brcms_info *wl)
  1205. {
  1206. int error = 0;
  1207. if (wl->pub->up)
  1208. return 0;
  1209. error = brcms_c_up(wl->wlc);
  1210. return error;
  1211. }
  1212. /*
  1213. * precondition: perimeter lock has been acquired
  1214. */
  1215. void brcms_down(struct brcms_info *wl)
  1216. {
  1217. uint callbacks, ret_val = 0;
  1218. /* call common down function */
  1219. ret_val = brcms_c_down(wl->wlc);
  1220. callbacks = atomic_read(&wl->callbacks) - ret_val;
  1221. /* wait for down callbacks to complete */
  1222. spin_unlock_bh(&wl->lock);
  1223. /* For HIGH_only driver, it's important to actually schedule other work,
  1224. * not just spin wait since everything runs at schedule level
  1225. */
  1226. SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
  1227. spin_lock_bh(&wl->lock);
  1228. }
  1229. /*
  1230. * precondition: perimeter lock is not acquired
  1231. */
  1232. static void _brcms_timer(struct work_struct *work)
  1233. {
  1234. struct brcms_timer *t = container_of(work, struct brcms_timer,
  1235. dly_wrk.work);
  1236. spin_lock_bh(&t->wl->lock);
  1237. if (t->set) {
  1238. if (t->periodic) {
  1239. atomic_inc(&t->wl->callbacks);
  1240. ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
  1241. &t->dly_wrk,
  1242. msecs_to_jiffies(t->ms));
  1243. } else {
  1244. t->set = false;
  1245. }
  1246. t->fn(t->arg);
  1247. }
  1248. atomic_dec(&t->wl->callbacks);
  1249. spin_unlock_bh(&t->wl->lock);
  1250. }
  1251. /*
  1252. * Adds a timer to the list. Caller supplies a timer function.
  1253. * Is called from wlc.
  1254. *
  1255. * precondition: perimeter lock has been acquired
  1256. */
  1257. struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
  1258. void (*fn) (void *arg),
  1259. void *arg, const char *name)
  1260. {
  1261. struct brcms_timer *t;
  1262. t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
  1263. if (!t)
  1264. return NULL;
  1265. INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
  1266. t->wl = wl;
  1267. t->fn = fn;
  1268. t->arg = arg;
  1269. t->next = wl->timers;
  1270. wl->timers = t;
  1271. #ifdef DEBUG
  1272. t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
  1273. if (t->name)
  1274. strcpy(t->name, name);
  1275. #endif
  1276. return t;
  1277. }
  1278. /*
  1279. * adds only the kernel timer since it's going to be more accurate
  1280. * as well as it's easier to make it periodic
  1281. *
  1282. * precondition: perimeter lock has been acquired
  1283. */
  1284. void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
  1285. {
  1286. struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
  1287. #ifdef DEBUG
  1288. if (t->set)
  1289. brcms_dbg_info(t->wl->wlc->hw->d11core,
  1290. "%s: Already set. Name: %s, per %d\n",
  1291. __func__, t->name, periodic);
  1292. #endif
  1293. t->ms = ms;
  1294. t->periodic = (bool) periodic;
  1295. if (!t->set) {
  1296. t->set = true;
  1297. atomic_inc(&t->wl->callbacks);
  1298. }
  1299. ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
  1300. }
  1301. /*
  1302. * return true if timer successfully deleted, false if still pending
  1303. *
  1304. * precondition: perimeter lock has been acquired
  1305. */
  1306. bool brcms_del_timer(struct brcms_timer *t)
  1307. {
  1308. if (t->set) {
  1309. t->set = false;
  1310. if (!cancel_delayed_work(&t->dly_wrk))
  1311. return false;
  1312. atomic_dec(&t->wl->callbacks);
  1313. }
  1314. return true;
  1315. }
  1316. /*
  1317. * precondition: perimeter lock has been acquired
  1318. */
  1319. void brcms_free_timer(struct brcms_timer *t)
  1320. {
  1321. struct brcms_info *wl = t->wl;
  1322. struct brcms_timer *tmp;
  1323. /* delete the timer in case it is active */
  1324. brcms_del_timer(t);
  1325. if (wl->timers == t) {
  1326. wl->timers = wl->timers->next;
  1327. #ifdef DEBUG
  1328. kfree(t->name);
  1329. #endif
  1330. kfree(t);
  1331. return;
  1332. }
  1333. tmp = wl->timers;
  1334. while (tmp) {
  1335. if (tmp->next == t) {
  1336. tmp->next = t->next;
  1337. #ifdef DEBUG
  1338. kfree(t->name);
  1339. #endif
  1340. kfree(t);
  1341. return;
  1342. }
  1343. tmp = tmp->next;
  1344. }
  1345. }
  1346. /*
  1347. * precondition: perimeter lock has been acquired
  1348. */
  1349. int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
  1350. {
  1351. int i, entry;
  1352. const u8 *pdata;
  1353. struct firmware_hdr *hdr;
  1354. for (i = 0; i < wl->fw.fw_cnt; i++) {
  1355. hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
  1356. for (entry = 0; entry < wl->fw.hdr_num_entries[i];
  1357. entry++, hdr++) {
  1358. u32 len = le32_to_cpu(hdr->len);
  1359. if (le32_to_cpu(hdr->idx) == idx) {
  1360. pdata = wl->fw.fw_bin[i]->data +
  1361. le32_to_cpu(hdr->offset);
  1362. *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
  1363. if (*pbuf == NULL)
  1364. goto fail;
  1365. return 0;
  1366. }
  1367. }
  1368. }
  1369. brcms_err(wl->wlc->hw->d11core,
  1370. "ERROR: ucode buf tag:%d can not be found!\n", idx);
  1371. *pbuf = NULL;
  1372. fail:
  1373. return -ENODATA;
  1374. }
  1375. /*
  1376. * Precondition: Since this function is called in brcms_bcma_probe() context,
  1377. * no locking is required.
  1378. */
  1379. int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
  1380. {
  1381. int i, entry;
  1382. const u8 *pdata;
  1383. struct firmware_hdr *hdr;
  1384. for (i = 0; i < wl->fw.fw_cnt; i++) {
  1385. hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
  1386. for (entry = 0; entry < wl->fw.hdr_num_entries[i];
  1387. entry++, hdr++) {
  1388. if (le32_to_cpu(hdr->idx) == idx) {
  1389. pdata = wl->fw.fw_bin[i]->data +
  1390. le32_to_cpu(hdr->offset);
  1391. if (le32_to_cpu(hdr->len) != 4) {
  1392. brcms_err(wl->wlc->hw->d11core,
  1393. "ERROR: fw hdr len\n");
  1394. return -ENOMSG;
  1395. }
  1396. *n_bytes = le32_to_cpu(*((__le32 *) pdata));
  1397. return 0;
  1398. }
  1399. }
  1400. }
  1401. brcms_err(wl->wlc->hw->d11core,
  1402. "ERROR: ucode tag:%d can not be found!\n", idx);
  1403. return -ENOMSG;
  1404. }
  1405. /*
  1406. * precondition: can both be called locked and unlocked
  1407. */
  1408. void brcms_ucode_free_buf(void *p)
  1409. {
  1410. kfree(p);
  1411. }
  1412. /*
  1413. * checks validity of all firmware images loaded from user space
  1414. *
  1415. * Precondition: Since this function is called in brcms_bcma_probe() context,
  1416. * no locking is required.
  1417. */
  1418. int brcms_check_firmwares(struct brcms_info *wl)
  1419. {
  1420. int i;
  1421. int entry;
  1422. int rc = 0;
  1423. const struct firmware *fw;
  1424. const struct firmware *fw_hdr;
  1425. struct firmware_hdr *ucode_hdr;
  1426. for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
  1427. fw = wl->fw.fw_bin[i];
  1428. fw_hdr = wl->fw.fw_hdr[i];
  1429. if (fw == NULL && fw_hdr == NULL) {
  1430. break;
  1431. } else if (fw == NULL || fw_hdr == NULL) {
  1432. wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
  1433. __func__);
  1434. rc = -EBADF;
  1435. } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
  1436. wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
  1437. "size %zu/%zu\n", __func__, fw_hdr->size,
  1438. sizeof(struct firmware_hdr));
  1439. rc = -EBADF;
  1440. } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
  1441. wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
  1442. __func__, fw->size);
  1443. rc = -EBADF;
  1444. } else {
  1445. /* check if ucode section overruns firmware image */
  1446. ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
  1447. for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
  1448. !rc; entry++, ucode_hdr++) {
  1449. if (le32_to_cpu(ucode_hdr->offset) +
  1450. le32_to_cpu(ucode_hdr->len) >
  1451. fw->size) {
  1452. wiphy_err(wl->wiphy,
  1453. "%s: conflicting bin/hdr\n",
  1454. __func__);
  1455. rc = -EBADF;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. if (rc == 0 && wl->fw.fw_cnt != i) {
  1461. wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
  1462. wl->fw.fw_cnt);
  1463. rc = -EBADF;
  1464. }
  1465. return rc;
  1466. }
  1467. /*
  1468. * precondition: perimeter lock has been acquired
  1469. */
  1470. bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
  1471. {
  1472. bool blocked = brcms_c_check_radio_disabled(wl->wlc);
  1473. spin_unlock_bh(&wl->lock);
  1474. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
  1475. if (blocked)
  1476. wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
  1477. spin_lock_bh(&wl->lock);
  1478. return blocked;
  1479. }