mac80211_if.c 43 KB

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