mac80211_if.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  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. /**
  258. * This function frees the WL per-device resources.
  259. *
  260. * This function frees resources owned by the WL device pointed to
  261. * by the wl parameter.
  262. *
  263. * precondition: can both be called locked and unlocked
  264. *
  265. */
  266. static void brcms_free(struct brcms_info *wl)
  267. {
  268. struct brcms_timer *t, *next;
  269. /* free ucode data */
  270. if (wl->fw.fw_cnt)
  271. brcms_ucode_data_free(&wl->ucode);
  272. if (wl->irq)
  273. free_irq(wl->irq, wl);
  274. /* kill dpc */
  275. tasklet_kill(&wl->tasklet);
  276. if (wl->pub) {
  277. brcms_debugfs_detach(wl->pub);
  278. brcms_c_module_unregister(wl->pub, "linux", wl);
  279. }
  280. /* free common resources */
  281. if (wl->wlc) {
  282. brcms_c_detach(wl->wlc);
  283. wl->wlc = NULL;
  284. wl->pub = NULL;
  285. }
  286. /* virtual interface deletion is deferred so we cannot spinwait */
  287. /* wait for all pending callbacks to complete */
  288. while (atomic_read(&wl->callbacks) > 0)
  289. schedule();
  290. /* free timers */
  291. for (t = wl->timers; t; t = next) {
  292. next = t->next;
  293. #ifdef DEBUG
  294. kfree(t->name);
  295. #endif
  296. kfree(t);
  297. }
  298. }
  299. /*
  300. * called from both kernel as from this kernel module (error flow on attach)
  301. * precondition: perimeter lock is not acquired.
  302. */
  303. static void brcms_remove(struct bcma_device *pdev)
  304. {
  305. struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
  306. struct brcms_info *wl = hw->priv;
  307. if (wl->wlc) {
  308. brcms_led_unregister(wl);
  309. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
  310. wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
  311. ieee80211_unregister_hw(hw);
  312. }
  313. brcms_free(wl);
  314. bcma_set_drvdata(pdev, NULL);
  315. ieee80211_free_hw(hw);
  316. }
  317. /*
  318. * Precondition: Since this function is called in brcms_pci_probe() context,
  319. * no locking is required.
  320. */
  321. static void brcms_release_fw(struct brcms_info *wl)
  322. {
  323. int i;
  324. for (i = 0; i < MAX_FW_IMAGES; i++) {
  325. release_firmware(wl->fw.fw_bin[i]);
  326. release_firmware(wl->fw.fw_hdr[i]);
  327. }
  328. }
  329. /*
  330. * Precondition: Since this function is called in brcms_pci_probe() context,
  331. * no locking is required.
  332. */
  333. static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
  334. {
  335. int status;
  336. struct device *device = &pdev->dev;
  337. char fw_name[100];
  338. int i;
  339. memset(&wl->fw, 0, sizeof(struct brcms_firmware));
  340. for (i = 0; i < MAX_FW_IMAGES; i++) {
  341. if (brcms_firmwares[i] == NULL)
  342. break;
  343. sprintf(fw_name, "%s-%d.fw", brcms_firmwares[i],
  344. UCODE_LOADER_API_VER);
  345. status = request_firmware(&wl->fw.fw_bin[i], fw_name, device);
  346. if (status) {
  347. wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
  348. KBUILD_MODNAME, fw_name);
  349. return status;
  350. }
  351. sprintf(fw_name, "%s_hdr-%d.fw", brcms_firmwares[i],
  352. UCODE_LOADER_API_VER);
  353. status = request_firmware(&wl->fw.fw_hdr[i], fw_name, device);
  354. if (status) {
  355. wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
  356. KBUILD_MODNAME, fw_name);
  357. return status;
  358. }
  359. wl->fw.hdr_num_entries[i] =
  360. wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
  361. }
  362. wl->fw.fw_cnt = i;
  363. status = brcms_ucode_data_init(wl, &wl->ucode);
  364. brcms_release_fw(wl);
  365. return status;
  366. }
  367. static void brcms_ops_tx(struct ieee80211_hw *hw,
  368. struct ieee80211_tx_control *control,
  369. struct sk_buff *skb)
  370. {
  371. struct brcms_info *wl = hw->priv;
  372. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  373. spin_lock_bh(&wl->lock);
  374. if (!wl->pub->up) {
  375. brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
  376. kfree_skb(skb);
  377. goto done;
  378. }
  379. if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
  380. tx_info->rate_driver_data[0] = control->sta;
  381. done:
  382. spin_unlock_bh(&wl->lock);
  383. }
  384. static int brcms_ops_start(struct ieee80211_hw *hw)
  385. {
  386. struct brcms_info *wl = hw->priv;
  387. bool blocked;
  388. int err;
  389. ieee80211_wake_queues(hw);
  390. spin_lock_bh(&wl->lock);
  391. blocked = brcms_rfkill_set_hw_state(wl);
  392. spin_unlock_bh(&wl->lock);
  393. if (!blocked)
  394. wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
  395. if (!wl->ucode.bcm43xx_bomminor) {
  396. err = brcms_request_fw(wl, wl->wlc->hw->d11core);
  397. if (err) {
  398. brcms_remove(wl->wlc->hw->d11core);
  399. return -ENOENT;
  400. }
  401. }
  402. spin_lock_bh(&wl->lock);
  403. /* avoid acknowledging frames before a non-monitor device is added */
  404. wl->mute_tx = true;
  405. if (!wl->pub->up)
  406. if (!blocked)
  407. err = brcms_up(wl);
  408. else
  409. err = -ERFKILL;
  410. else
  411. err = -ENODEV;
  412. spin_unlock_bh(&wl->lock);
  413. if (err != 0)
  414. brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
  415. __func__, err);
  416. bcma_core_pci_power_save(wl->wlc->hw->d11core->bus, true);
  417. return err;
  418. }
  419. static void brcms_ops_stop(struct ieee80211_hw *hw)
  420. {
  421. struct brcms_info *wl = hw->priv;
  422. int status;
  423. ieee80211_stop_queues(hw);
  424. if (wl->wlc == NULL)
  425. return;
  426. spin_lock_bh(&wl->lock);
  427. status = brcms_c_chipmatch(wl->wlc->hw->d11core);
  428. spin_unlock_bh(&wl->lock);
  429. if (!status) {
  430. brcms_err(wl->wlc->hw->d11core,
  431. "wl: brcms_ops_stop: chipmatch failed\n");
  432. return;
  433. }
  434. bcma_core_pci_power_save(wl->wlc->hw->d11core->bus, false);
  435. /* put driver in down state */
  436. spin_lock_bh(&wl->lock);
  437. brcms_down(wl);
  438. spin_unlock_bh(&wl->lock);
  439. }
  440. static int
  441. brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  442. {
  443. struct brcms_info *wl = hw->priv;
  444. /* Just STA, AP and ADHOC for now */
  445. if (vif->type != NL80211_IFTYPE_STATION &&
  446. vif->type != NL80211_IFTYPE_AP &&
  447. vif->type != NL80211_IFTYPE_ADHOC) {
  448. brcms_err(wl->wlc->hw->d11core,
  449. "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
  450. __func__, vif->type);
  451. return -EOPNOTSUPP;
  452. }
  453. spin_lock_bh(&wl->lock);
  454. wl->mute_tx = false;
  455. brcms_c_mute(wl->wlc, false);
  456. if (vif->type == NL80211_IFTYPE_STATION)
  457. brcms_c_start_station(wl->wlc, vif->addr);
  458. else if (vif->type == NL80211_IFTYPE_AP)
  459. brcms_c_start_ap(wl->wlc, vif->addr, vif->bss_conf.bssid,
  460. vif->bss_conf.ssid, vif->bss_conf.ssid_len);
  461. else if (vif->type == NL80211_IFTYPE_ADHOC)
  462. brcms_c_start_adhoc(wl->wlc, vif->addr);
  463. spin_unlock_bh(&wl->lock);
  464. return 0;
  465. }
  466. static void
  467. brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  468. {
  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, u32 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__, info->assoc ? "" : "dis");
  533. spin_lock_bh(&wl->lock);
  534. brcms_c_associate_upd(wl->wlc, info->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, info->ssid, info->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);
  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__, info->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__, info->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_PROMISC_IN_BSS)
  669. brcms_dbg_info(core, "FIF_PROMISC_IN_BSS\n");
  670. if (changed_flags & FIF_ALLMULTI)
  671. brcms_dbg_info(core, "FIF_ALLMULTI\n");
  672. if (changed_flags & FIF_FCSFAIL)
  673. brcms_dbg_info(core, "FIF_FCSFAIL\n");
  674. if (changed_flags & FIF_CONTROL)
  675. brcms_dbg_info(core, "FIF_CONTROL\n");
  676. if (changed_flags & FIF_OTHER_BSS)
  677. brcms_dbg_info(core, "FIF_OTHER_BSS\n");
  678. if (changed_flags & FIF_PSPOLL)
  679. brcms_dbg_info(core, "FIF_PSPOLL\n");
  680. if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
  681. brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
  682. spin_lock_bh(&wl->lock);
  683. brcms_c_mac_promisc(wl->wlc, *total_flags);
  684. spin_unlock_bh(&wl->lock);
  685. return;
  686. }
  687. static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw)
  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. {
  697. struct brcms_info *wl = hw->priv;
  698. spin_lock_bh(&wl->lock);
  699. brcms_c_scan_stop(wl->wlc);
  700. spin_unlock_bh(&wl->lock);
  701. return;
  702. }
  703. static int
  704. brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
  705. const struct ieee80211_tx_queue_params *params)
  706. {
  707. struct brcms_info *wl = hw->priv;
  708. spin_lock_bh(&wl->lock);
  709. brcms_c_wme_setparams(wl->wlc, queue, params, true);
  710. spin_unlock_bh(&wl->lock);
  711. return 0;
  712. }
  713. static int
  714. brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  715. struct ieee80211_sta *sta)
  716. {
  717. struct brcms_info *wl = hw->priv;
  718. struct scb *scb = &wl->wlc->pri_scb;
  719. brcms_c_init_scb(scb);
  720. wl->pub->global_ampdu = &(scb->scb_ampdu);
  721. wl->pub->global_ampdu->scb = scb;
  722. wl->pub->global_ampdu->max_pdu = 16;
  723. /*
  724. * minstrel_ht initiates addBA on our behalf by calling
  725. * ieee80211_start_tx_ba_session()
  726. */
  727. return 0;
  728. }
  729. static int
  730. brcms_ops_ampdu_action(struct ieee80211_hw *hw,
  731. struct ieee80211_vif *vif,
  732. enum ieee80211_ampdu_mlme_action action,
  733. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  734. u8 buf_size)
  735. {
  736. struct brcms_info *wl = hw->priv;
  737. struct scb *scb = &wl->wlc->pri_scb;
  738. int status;
  739. if (WARN_ON(scb->magic != SCB_MAGIC))
  740. return -EIDRM;
  741. switch (action) {
  742. case IEEE80211_AMPDU_RX_START:
  743. break;
  744. case IEEE80211_AMPDU_RX_STOP:
  745. break;
  746. case IEEE80211_AMPDU_TX_START:
  747. spin_lock_bh(&wl->lock);
  748. status = brcms_c_aggregatable(wl->wlc, tid);
  749. spin_unlock_bh(&wl->lock);
  750. if (!status) {
  751. brcms_err(wl->wlc->hw->d11core,
  752. "START: tid %d is not agg\'able\n", tid);
  753. return -EINVAL;
  754. }
  755. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  756. break;
  757. case IEEE80211_AMPDU_TX_STOP_CONT:
  758. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  759. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  760. spin_lock_bh(&wl->lock);
  761. brcms_c_ampdu_flush(wl->wlc, sta, tid);
  762. spin_unlock_bh(&wl->lock);
  763. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  764. break;
  765. case IEEE80211_AMPDU_TX_OPERATIONAL:
  766. /*
  767. * BA window size from ADDBA response ('buf_size') defines how
  768. * many outstanding MPDUs are allowed for the BA stream by
  769. * recipient and traffic class. 'ampdu_factor' gives maximum
  770. * AMPDU size.
  771. */
  772. spin_lock_bh(&wl->lock);
  773. brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
  774. (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  775. sta->ht_cap.ampdu_factor)) - 1);
  776. spin_unlock_bh(&wl->lock);
  777. /* Power save wakeup */
  778. break;
  779. default:
  780. brcms_err(wl->wlc->hw->d11core,
  781. "%s: Invalid command, ignoring\n", __func__);
  782. }
  783. return 0;
  784. }
  785. static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
  786. {
  787. struct brcms_info *wl = hw->priv;
  788. bool blocked;
  789. spin_lock_bh(&wl->lock);
  790. blocked = brcms_c_check_radio_disabled(wl->wlc);
  791. spin_unlock_bh(&wl->lock);
  792. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
  793. }
  794. static bool brcms_tx_flush_completed(struct brcms_info *wl)
  795. {
  796. bool result;
  797. spin_lock_bh(&wl->lock);
  798. result = brcms_c_tx_flush_completed(wl->wlc);
  799. spin_unlock_bh(&wl->lock);
  800. return result;
  801. }
  802. static void brcms_ops_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
  803. {
  804. struct brcms_info *wl = hw->priv;
  805. int ret;
  806. no_printk("%s: drop = %s\n", __func__, drop ? "true" : "false");
  807. ret = wait_event_timeout(wl->tx_flush_wq,
  808. brcms_tx_flush_completed(wl),
  809. msecs_to_jiffies(BRCMS_FLUSH_TIMEOUT));
  810. brcms_dbg_mac80211(wl->wlc->hw->d11core,
  811. "ret=%d\n", jiffies_to_msecs(ret));
  812. }
  813. static u64 brcms_ops_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  814. {
  815. struct brcms_info *wl = hw->priv;
  816. u64 tsf;
  817. spin_lock_bh(&wl->lock);
  818. tsf = brcms_c_tsf_get(wl->wlc);
  819. spin_unlock_bh(&wl->lock);
  820. return tsf;
  821. }
  822. static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
  823. struct ieee80211_vif *vif, u64 tsf)
  824. {
  825. struct brcms_info *wl = hw->priv;
  826. spin_lock_bh(&wl->lock);
  827. brcms_c_tsf_set(wl->wlc, tsf);
  828. spin_unlock_bh(&wl->lock);
  829. }
  830. static const struct ieee80211_ops brcms_ops = {
  831. .tx = brcms_ops_tx,
  832. .start = brcms_ops_start,
  833. .stop = brcms_ops_stop,
  834. .add_interface = brcms_ops_add_interface,
  835. .remove_interface = brcms_ops_remove_interface,
  836. .config = brcms_ops_config,
  837. .bss_info_changed = brcms_ops_bss_info_changed,
  838. .configure_filter = brcms_ops_configure_filter,
  839. .sw_scan_start = brcms_ops_sw_scan_start,
  840. .sw_scan_complete = brcms_ops_sw_scan_complete,
  841. .conf_tx = brcms_ops_conf_tx,
  842. .sta_add = brcms_ops_sta_add,
  843. .ampdu_action = brcms_ops_ampdu_action,
  844. .rfkill_poll = brcms_ops_rfkill_poll,
  845. .flush = brcms_ops_flush,
  846. .get_tsf = brcms_ops_get_tsf,
  847. .set_tsf = brcms_ops_set_tsf,
  848. };
  849. void brcms_dpc(unsigned long data)
  850. {
  851. struct brcms_info *wl;
  852. wl = (struct brcms_info *) data;
  853. spin_lock_bh(&wl->lock);
  854. /* call the common second level interrupt handler */
  855. if (wl->pub->up) {
  856. if (wl->resched) {
  857. unsigned long flags;
  858. spin_lock_irqsave(&wl->isr_lock, flags);
  859. brcms_c_intrsupd(wl->wlc);
  860. spin_unlock_irqrestore(&wl->isr_lock, flags);
  861. }
  862. wl->resched = brcms_c_dpc(wl->wlc, true);
  863. }
  864. /* brcms_c_dpc() may bring the driver down */
  865. if (!wl->pub->up)
  866. goto done;
  867. /* re-schedule dpc */
  868. if (wl->resched)
  869. tasklet_schedule(&wl->tasklet);
  870. else
  871. /* re-enable interrupts */
  872. brcms_intrson(wl);
  873. done:
  874. spin_unlock_bh(&wl->lock);
  875. wake_up(&wl->tx_flush_wq);
  876. }
  877. static irqreturn_t brcms_isr(int irq, void *dev_id)
  878. {
  879. struct brcms_info *wl;
  880. irqreturn_t ret = IRQ_NONE;
  881. wl = (struct brcms_info *) dev_id;
  882. spin_lock(&wl->isr_lock);
  883. /* call common first level interrupt handler */
  884. if (brcms_c_isr(wl->wlc)) {
  885. /* schedule second level handler */
  886. tasklet_schedule(&wl->tasklet);
  887. ret = IRQ_HANDLED;
  888. }
  889. spin_unlock(&wl->isr_lock);
  890. return ret;
  891. }
  892. /*
  893. * is called in brcms_pci_probe() context, therefore no locking required.
  894. */
  895. static int ieee_hw_rate_init(struct ieee80211_hw *hw)
  896. {
  897. struct brcms_info *wl = hw->priv;
  898. struct brcms_c_info *wlc = wl->wlc;
  899. struct ieee80211_supported_band *band;
  900. int has_5g = 0;
  901. u16 phy_type;
  902. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
  903. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  904. phy_type = brcms_c_get_phy_type(wl->wlc, 0);
  905. if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
  906. band = &wlc->bandstate[BAND_2G_INDEX]->band;
  907. *band = brcms_band_2GHz_nphy_template;
  908. if (phy_type == PHY_TYPE_LCN) {
  909. /* Single stream */
  910. band->ht_cap.mcs.rx_mask[1] = 0;
  911. band->ht_cap.mcs.rx_highest = cpu_to_le16(72);
  912. }
  913. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  914. } else {
  915. return -EPERM;
  916. }
  917. /* Assume all bands use the same phy. True for 11n devices. */
  918. if (wl->pub->_nbands > 1) {
  919. has_5g++;
  920. if (phy_type == PHY_TYPE_N || phy_type == PHY_TYPE_LCN) {
  921. band = &wlc->bandstate[BAND_5G_INDEX]->band;
  922. *band = brcms_band_5GHz_nphy_template;
  923. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  924. } else {
  925. return -EPERM;
  926. }
  927. }
  928. return 0;
  929. }
  930. /*
  931. * is called in brcms_pci_probe() context, therefore no locking required.
  932. */
  933. static int ieee_hw_init(struct ieee80211_hw *hw)
  934. {
  935. hw->flags = IEEE80211_HW_SIGNAL_DBM
  936. /* | IEEE80211_HW_CONNECTION_MONITOR What is this? */
  937. | IEEE80211_HW_REPORTS_TX_ACK_STATUS
  938. | IEEE80211_HW_AMPDU_AGGREGATION;
  939. hw->extra_tx_headroom = brcms_c_get_header_len();
  940. hw->queues = N_TX_QUEUES;
  941. hw->max_rates = 2; /* Primary rate and 1 fallback rate */
  942. /* channel change time is dependent on chip and band */
  943. hw->channel_change_time = 7 * 1000;
  944. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  945. BIT(NL80211_IFTYPE_AP) |
  946. BIT(NL80211_IFTYPE_ADHOC);
  947. /*
  948. * deactivate sending probe responses by ucude, because this will
  949. * cause problems when WPS is used.
  950. *
  951. * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  952. */
  953. hw->rate_control_algorithm = "minstrel_ht";
  954. hw->sta_data_size = 0;
  955. return ieee_hw_rate_init(hw);
  956. }
  957. /**
  958. * attach to the WL device.
  959. *
  960. * Attach to the WL device identified by vendor and device parameters.
  961. * regs is a host accessible memory address pointing to WL device registers.
  962. *
  963. * brcms_attach is not defined as static because in the case where no bus
  964. * is defined, wl_attach will never be called, and thus, gcc will issue
  965. * a warning that this function is defined but not used if we declare
  966. * it as static.
  967. *
  968. *
  969. * is called in brcms_bcma_probe() context, therefore no locking required.
  970. */
  971. static struct brcms_info *brcms_attach(struct bcma_device *pdev)
  972. {
  973. struct brcms_info *wl = NULL;
  974. int unit, err;
  975. struct ieee80211_hw *hw;
  976. u8 perm[ETH_ALEN];
  977. unit = n_adapters_found;
  978. err = 0;
  979. if (unit < 0)
  980. return NULL;
  981. /* allocate private info */
  982. hw = bcma_get_drvdata(pdev);
  983. if (hw != NULL)
  984. wl = hw->priv;
  985. if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
  986. return NULL;
  987. wl->wiphy = hw->wiphy;
  988. atomic_set(&wl->callbacks, 0);
  989. init_waitqueue_head(&wl->tx_flush_wq);
  990. /* setup the bottom half handler */
  991. tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
  992. spin_lock_init(&wl->lock);
  993. spin_lock_init(&wl->isr_lock);
  994. /* common load-time initialization */
  995. wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
  996. if (!wl->wlc) {
  997. wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
  998. KBUILD_MODNAME, err);
  999. goto fail;
  1000. }
  1001. wl->pub = brcms_c_pub(wl->wlc);
  1002. wl->pub->ieee_hw = hw;
  1003. /* register our interrupt handler */
  1004. if (request_irq(pdev->irq, brcms_isr,
  1005. IRQF_SHARED, KBUILD_MODNAME, wl)) {
  1006. wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
  1007. goto fail;
  1008. }
  1009. wl->irq = pdev->irq;
  1010. /* register module */
  1011. brcms_c_module_register(wl->pub, "linux", wl, NULL);
  1012. if (ieee_hw_init(hw)) {
  1013. wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
  1014. __func__);
  1015. goto fail;
  1016. }
  1017. brcms_c_regd_init(wl->wlc);
  1018. memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
  1019. if (WARN_ON(!is_valid_ether_addr(perm)))
  1020. goto fail;
  1021. SET_IEEE80211_PERM_ADDR(hw, perm);
  1022. err = ieee80211_register_hw(hw);
  1023. if (err)
  1024. wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
  1025. "%d\n", __func__, err);
  1026. if (wl->pub->srom_ccode[0] &&
  1027. regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
  1028. wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
  1029. brcms_debugfs_attach(wl->pub);
  1030. brcms_debugfs_create_files(wl->pub);
  1031. n_adapters_found++;
  1032. return wl;
  1033. fail:
  1034. brcms_free(wl);
  1035. return NULL;
  1036. }
  1037. /**
  1038. * determines if a device is a WL device, and if so, attaches it.
  1039. *
  1040. * This function determines if a device pointed to by pdev is a WL device,
  1041. * and if so, performs a brcms_attach() on it.
  1042. *
  1043. * Perimeter lock is initialized in the course of this function.
  1044. */
  1045. static int brcms_bcma_probe(struct bcma_device *pdev)
  1046. {
  1047. struct brcms_info *wl;
  1048. struct ieee80211_hw *hw;
  1049. dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
  1050. pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
  1051. pdev->irq);
  1052. if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
  1053. (pdev->id.id != BCMA_CORE_80211))
  1054. return -ENODEV;
  1055. hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
  1056. if (!hw) {
  1057. pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
  1058. return -ENOMEM;
  1059. }
  1060. SET_IEEE80211_DEV(hw, &pdev->dev);
  1061. bcma_set_drvdata(pdev, hw);
  1062. memset(hw->priv, 0, sizeof(*wl));
  1063. wl = brcms_attach(pdev);
  1064. if (!wl) {
  1065. pr_err("%s: brcms_attach failed!\n", __func__);
  1066. return -ENODEV;
  1067. }
  1068. brcms_led_register(wl);
  1069. return 0;
  1070. }
  1071. static int brcms_suspend(struct bcma_device *pdev)
  1072. {
  1073. struct brcms_info *wl;
  1074. struct ieee80211_hw *hw;
  1075. hw = bcma_get_drvdata(pdev);
  1076. wl = hw->priv;
  1077. if (!wl) {
  1078. pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
  1079. __func__);
  1080. return -ENODEV;
  1081. }
  1082. /* only need to flag hw is down for proper resume */
  1083. spin_lock_bh(&wl->lock);
  1084. wl->pub->hw_up = false;
  1085. spin_unlock_bh(&wl->lock);
  1086. brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
  1087. return 0;
  1088. }
  1089. static int brcms_resume(struct bcma_device *pdev)
  1090. {
  1091. return 0;
  1092. }
  1093. static struct bcma_driver brcms_bcma_driver = {
  1094. .name = KBUILD_MODNAME,
  1095. .probe = brcms_bcma_probe,
  1096. .suspend = brcms_suspend,
  1097. .resume = brcms_resume,
  1098. .remove = brcms_remove,
  1099. .id_table = brcms_coreid_table,
  1100. };
  1101. /**
  1102. * This is the main entry point for the brcmsmac driver.
  1103. *
  1104. * This function is scheduled upon module initialization and
  1105. * does the driver registration, which result in brcms_bcma_probe()
  1106. * call resulting in the driver bringup.
  1107. */
  1108. static void brcms_driver_init(struct work_struct *work)
  1109. {
  1110. int error;
  1111. error = bcma_driver_register(&brcms_bcma_driver);
  1112. if (error)
  1113. pr_err("%s: register returned %d\n", __func__, error);
  1114. }
  1115. static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
  1116. static int __init brcms_module_init(void)
  1117. {
  1118. brcms_debugfs_init();
  1119. if (!schedule_work(&brcms_driver_work))
  1120. return -EBUSY;
  1121. return 0;
  1122. }
  1123. /**
  1124. * This function unloads the brcmsmac driver from the system.
  1125. *
  1126. * This function unconditionally unloads the brcmsmac driver module from the
  1127. * system.
  1128. *
  1129. */
  1130. static void __exit brcms_module_exit(void)
  1131. {
  1132. cancel_work_sync(&brcms_driver_work);
  1133. bcma_driver_unregister(&brcms_bcma_driver);
  1134. brcms_debugfs_exit();
  1135. }
  1136. module_init(brcms_module_init);
  1137. module_exit(brcms_module_exit);
  1138. /*
  1139. * precondition: perimeter lock has been acquired
  1140. */
  1141. void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
  1142. bool state, int prio)
  1143. {
  1144. brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
  1145. }
  1146. /*
  1147. * precondition: perimeter lock has been acquired
  1148. */
  1149. void brcms_init(struct brcms_info *wl)
  1150. {
  1151. brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
  1152. wl->pub->unit);
  1153. brcms_reset(wl);
  1154. brcms_c_init(wl->wlc, wl->mute_tx);
  1155. }
  1156. /*
  1157. * precondition: perimeter lock has been acquired
  1158. */
  1159. uint brcms_reset(struct brcms_info *wl)
  1160. {
  1161. brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
  1162. brcms_c_reset(wl->wlc);
  1163. /* dpc will not be rescheduled */
  1164. wl->resched = false;
  1165. /* inform publicly that interface is down */
  1166. wl->pub->up = false;
  1167. return 0;
  1168. }
  1169. void brcms_fatal_error(struct brcms_info *wl)
  1170. {
  1171. brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
  1172. wl->wlc->pub->unit);
  1173. brcms_reset(wl);
  1174. ieee80211_restart_hw(wl->pub->ieee_hw);
  1175. }
  1176. /*
  1177. * These are interrupt on/off entry points. Disable interrupts
  1178. * during interrupt state transition.
  1179. */
  1180. void brcms_intrson(struct brcms_info *wl)
  1181. {
  1182. unsigned long flags;
  1183. spin_lock_irqsave(&wl->isr_lock, flags);
  1184. brcms_c_intrson(wl->wlc);
  1185. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1186. }
  1187. u32 brcms_intrsoff(struct brcms_info *wl)
  1188. {
  1189. unsigned long flags;
  1190. u32 status;
  1191. spin_lock_irqsave(&wl->isr_lock, flags);
  1192. status = brcms_c_intrsoff(wl->wlc);
  1193. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1194. return status;
  1195. }
  1196. void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
  1197. {
  1198. unsigned long flags;
  1199. spin_lock_irqsave(&wl->isr_lock, flags);
  1200. brcms_c_intrsrestore(wl->wlc, macintmask);
  1201. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1202. }
  1203. /*
  1204. * precondition: perimeter lock has been acquired
  1205. */
  1206. int brcms_up(struct brcms_info *wl)
  1207. {
  1208. int error = 0;
  1209. if (wl->pub->up)
  1210. return 0;
  1211. error = brcms_c_up(wl->wlc);
  1212. return error;
  1213. }
  1214. /*
  1215. * precondition: perimeter lock has been acquired
  1216. */
  1217. void brcms_down(struct brcms_info *wl)
  1218. {
  1219. uint callbacks, ret_val = 0;
  1220. /* call common down function */
  1221. ret_val = brcms_c_down(wl->wlc);
  1222. callbacks = atomic_read(&wl->callbacks) - ret_val;
  1223. /* wait for down callbacks to complete */
  1224. spin_unlock_bh(&wl->lock);
  1225. /* For HIGH_only driver, it's important to actually schedule other work,
  1226. * not just spin wait since everything runs at schedule level
  1227. */
  1228. SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
  1229. spin_lock_bh(&wl->lock);
  1230. }
  1231. /*
  1232. * precondition: perimeter lock is not acquired
  1233. */
  1234. static void _brcms_timer(struct work_struct *work)
  1235. {
  1236. struct brcms_timer *t = container_of(work, struct brcms_timer,
  1237. dly_wrk.work);
  1238. spin_lock_bh(&t->wl->lock);
  1239. if (t->set) {
  1240. if (t->periodic) {
  1241. atomic_inc(&t->wl->callbacks);
  1242. ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
  1243. &t->dly_wrk,
  1244. msecs_to_jiffies(t->ms));
  1245. } else {
  1246. t->set = false;
  1247. }
  1248. t->fn(t->arg);
  1249. }
  1250. atomic_dec(&t->wl->callbacks);
  1251. spin_unlock_bh(&t->wl->lock);
  1252. }
  1253. /*
  1254. * Adds a timer to the list. Caller supplies a timer function.
  1255. * Is called from wlc.
  1256. *
  1257. * precondition: perimeter lock has been acquired
  1258. */
  1259. struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
  1260. void (*fn) (void *arg),
  1261. void *arg, const char *name)
  1262. {
  1263. struct brcms_timer *t;
  1264. t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
  1265. if (!t)
  1266. return NULL;
  1267. INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
  1268. t->wl = wl;
  1269. t->fn = fn;
  1270. t->arg = arg;
  1271. t->next = wl->timers;
  1272. wl->timers = t;
  1273. #ifdef DEBUG
  1274. t->name = kmalloc(strlen(name) + 1, GFP_ATOMIC);
  1275. if (t->name)
  1276. strcpy(t->name, name);
  1277. #endif
  1278. return t;
  1279. }
  1280. /*
  1281. * adds only the kernel timer since it's going to be more accurate
  1282. * as well as it's easier to make it periodic
  1283. *
  1284. * precondition: perimeter lock has been acquired
  1285. */
  1286. void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
  1287. {
  1288. struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
  1289. #ifdef DEBUG
  1290. if (t->set)
  1291. brcms_dbg_info(t->wl->wlc->hw->d11core,
  1292. "%s: Already set. Name: %s, per %d\n",
  1293. __func__, t->name, periodic);
  1294. #endif
  1295. t->ms = ms;
  1296. t->periodic = (bool) periodic;
  1297. if (!t->set) {
  1298. t->set = true;
  1299. atomic_inc(&t->wl->callbacks);
  1300. }
  1301. ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
  1302. }
  1303. /*
  1304. * return true if timer successfully deleted, false if still pending
  1305. *
  1306. * precondition: perimeter lock has been acquired
  1307. */
  1308. bool brcms_del_timer(struct brcms_timer *t)
  1309. {
  1310. if (t->set) {
  1311. t->set = false;
  1312. if (!cancel_delayed_work(&t->dly_wrk))
  1313. return false;
  1314. atomic_dec(&t->wl->callbacks);
  1315. }
  1316. return true;
  1317. }
  1318. /*
  1319. * precondition: perimeter lock has been acquired
  1320. */
  1321. void brcms_free_timer(struct brcms_timer *t)
  1322. {
  1323. struct brcms_info *wl = t->wl;
  1324. struct brcms_timer *tmp;
  1325. /* delete the timer in case it is active */
  1326. brcms_del_timer(t);
  1327. if (wl->timers == t) {
  1328. wl->timers = wl->timers->next;
  1329. #ifdef DEBUG
  1330. kfree(t->name);
  1331. #endif
  1332. kfree(t);
  1333. return;
  1334. }
  1335. tmp = wl->timers;
  1336. while (tmp) {
  1337. if (tmp->next == t) {
  1338. tmp->next = t->next;
  1339. #ifdef DEBUG
  1340. kfree(t->name);
  1341. #endif
  1342. kfree(t);
  1343. return;
  1344. }
  1345. tmp = tmp->next;
  1346. }
  1347. }
  1348. /*
  1349. * precondition: perimeter lock has been acquired
  1350. */
  1351. int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
  1352. {
  1353. int i, entry;
  1354. const u8 *pdata;
  1355. struct firmware_hdr *hdr;
  1356. for (i = 0; i < wl->fw.fw_cnt; i++) {
  1357. hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
  1358. for (entry = 0; entry < wl->fw.hdr_num_entries[i];
  1359. entry++, hdr++) {
  1360. u32 len = le32_to_cpu(hdr->len);
  1361. if (le32_to_cpu(hdr->idx) == idx) {
  1362. pdata = wl->fw.fw_bin[i]->data +
  1363. le32_to_cpu(hdr->offset);
  1364. *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
  1365. if (*pbuf == NULL)
  1366. goto fail;
  1367. return 0;
  1368. }
  1369. }
  1370. }
  1371. brcms_err(wl->wlc->hw->d11core,
  1372. "ERROR: ucode buf tag:%d can not be found!\n", idx);
  1373. *pbuf = NULL;
  1374. fail:
  1375. return -ENODATA;
  1376. }
  1377. /*
  1378. * Precondition: Since this function is called in brcms_bcma_probe() context,
  1379. * no locking is required.
  1380. */
  1381. int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, u32 idx)
  1382. {
  1383. int i, entry;
  1384. const u8 *pdata;
  1385. struct firmware_hdr *hdr;
  1386. for (i = 0; i < wl->fw.fw_cnt; i++) {
  1387. hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
  1388. for (entry = 0; entry < wl->fw.hdr_num_entries[i];
  1389. entry++, hdr++) {
  1390. if (le32_to_cpu(hdr->idx) == idx) {
  1391. pdata = wl->fw.fw_bin[i]->data +
  1392. le32_to_cpu(hdr->offset);
  1393. if (le32_to_cpu(hdr->len) != 4) {
  1394. brcms_err(wl->wlc->hw->d11core,
  1395. "ERROR: fw hdr len\n");
  1396. return -ENOMSG;
  1397. }
  1398. *n_bytes = le32_to_cpu(*((__le32 *) pdata));
  1399. return 0;
  1400. }
  1401. }
  1402. }
  1403. brcms_err(wl->wlc->hw->d11core,
  1404. "ERROR: ucode tag:%d can not be found!\n", idx);
  1405. return -ENOMSG;
  1406. }
  1407. /*
  1408. * precondition: can both be called locked and unlocked
  1409. */
  1410. void brcms_ucode_free_buf(void *p)
  1411. {
  1412. kfree(p);
  1413. }
  1414. /*
  1415. * checks validity of all firmware images loaded from user space
  1416. *
  1417. * Precondition: Since this function is called in brcms_bcma_probe() context,
  1418. * no locking is required.
  1419. */
  1420. int brcms_check_firmwares(struct brcms_info *wl)
  1421. {
  1422. int i;
  1423. int entry;
  1424. int rc = 0;
  1425. const struct firmware *fw;
  1426. const struct firmware *fw_hdr;
  1427. struct firmware_hdr *ucode_hdr;
  1428. for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
  1429. fw = wl->fw.fw_bin[i];
  1430. fw_hdr = wl->fw.fw_hdr[i];
  1431. if (fw == NULL && fw_hdr == NULL) {
  1432. break;
  1433. } else if (fw == NULL || fw_hdr == NULL) {
  1434. wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
  1435. __func__);
  1436. rc = -EBADF;
  1437. } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
  1438. wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
  1439. "size %zu/%zu\n", __func__, fw_hdr->size,
  1440. sizeof(struct firmware_hdr));
  1441. rc = -EBADF;
  1442. } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
  1443. wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
  1444. __func__, fw->size);
  1445. rc = -EBADF;
  1446. } else {
  1447. /* check if ucode section overruns firmware image */
  1448. ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
  1449. for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
  1450. !rc; entry++, ucode_hdr++) {
  1451. if (le32_to_cpu(ucode_hdr->offset) +
  1452. le32_to_cpu(ucode_hdr->len) >
  1453. fw->size) {
  1454. wiphy_err(wl->wiphy,
  1455. "%s: conflicting bin/hdr\n",
  1456. __func__);
  1457. rc = -EBADF;
  1458. }
  1459. }
  1460. }
  1461. }
  1462. if (rc == 0 && wl->fw.fw_cnt != i) {
  1463. wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
  1464. wl->fw.fw_cnt);
  1465. rc = -EBADF;
  1466. }
  1467. return rc;
  1468. }
  1469. /*
  1470. * precondition: perimeter lock has been acquired
  1471. */
  1472. bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
  1473. {
  1474. bool blocked = brcms_c_check_radio_disabled(wl->wlc);
  1475. spin_unlock_bh(&wl->lock);
  1476. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
  1477. if (blocked)
  1478. wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
  1479. spin_lock_bh(&wl->lock);
  1480. return blocked;
  1481. }