mac80211_if.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  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. "/*(DEBLOBBED)*/",
  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_SUPPORTED_DEVICE("Broadcom 802.11n WLAN cards");
  80. MODULE_LICENSE("Dual BSD/GPL");
  81. /* This needs to be adjusted when brcms_firmwares changes */
  82. /*(DEBLOBBED)*/
  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, S_IRUGO | S_IWUSR);
  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. */
  264. static void brcms_free(struct brcms_info *wl)
  265. {
  266. struct brcms_timer *t, *next;
  267. /* free ucode data */
  268. if (wl->fw.fw_cnt)
  269. brcms_ucode_data_free(&wl->ucode);
  270. if (wl->irq)
  271. free_irq(wl->irq, wl);
  272. /* kill dpc */
  273. tasklet_kill(&wl->tasklet);
  274. if (wl->pub) {
  275. brcms_debugfs_detach(wl->pub);
  276. brcms_c_module_unregister(wl->pub, "linux", wl);
  277. }
  278. /* free common resources */
  279. if (wl->wlc) {
  280. brcms_c_detach(wl->wlc);
  281. wl->wlc = NULL;
  282. wl->pub = NULL;
  283. }
  284. /* virtual interface deletion is deferred so we cannot spinwait */
  285. /* wait for all pending callbacks to complete */
  286. while (atomic_read(&wl->callbacks) > 0)
  287. schedule();
  288. /* free timers */
  289. for (t = wl->timers; t; t = next) {
  290. next = t->next;
  291. #ifdef DEBUG
  292. kfree(t->name);
  293. #endif
  294. kfree(t);
  295. }
  296. }
  297. /*
  298. * called from both kernel as from this kernel module (error flow on attach)
  299. * precondition: perimeter lock is not acquired.
  300. */
  301. static void brcms_remove(struct bcma_device *pdev)
  302. {
  303. struct ieee80211_hw *hw = bcma_get_drvdata(pdev);
  304. struct brcms_info *wl = hw->priv;
  305. if (wl->wlc) {
  306. brcms_led_unregister(wl);
  307. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, false);
  308. wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
  309. ieee80211_unregister_hw(hw);
  310. }
  311. brcms_free(wl);
  312. bcma_set_drvdata(pdev, NULL);
  313. ieee80211_free_hw(hw);
  314. }
  315. /*
  316. * Precondition: Since this function is called in brcms_pci_probe() context,
  317. * no locking is required.
  318. */
  319. static void brcms_release_fw(struct brcms_info *wl)
  320. {
  321. int i;
  322. for (i = 0; i < MAX_FW_IMAGES; i++) {
  323. release_firmware(wl->fw.fw_bin[i]);
  324. release_firmware(wl->fw.fw_hdr[i]);
  325. }
  326. }
  327. /*
  328. * Precondition: Since this function is called in brcms_pci_probe() context,
  329. * no locking is required.
  330. */
  331. static int brcms_request_fw(struct brcms_info *wl, struct bcma_device *pdev)
  332. {
  333. int status;
  334. struct device *device = &pdev->dev;
  335. char fw_name[100];
  336. int i;
  337. memset(&wl->fw, 0, sizeof(struct brcms_firmware));
  338. for (i = 0; i < MAX_FW_IMAGES; i++) {
  339. if (brcms_firmwares[i] == NULL)
  340. break;
  341. sprintf(fw_name, "/*(DEBLOBBED)*/", brcms_firmwares[i],
  342. UCODE_LOADER_API_VER);
  343. status = reject_firmware(&wl->fw.fw_bin[i], fw_name, device);
  344. if (status) {
  345. wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
  346. KBUILD_MODNAME, fw_name);
  347. return status;
  348. }
  349. sprintf(fw_name, "/*(DEBLOBBED)*/", brcms_firmwares[i],
  350. UCODE_LOADER_API_VER);
  351. status = reject_firmware(&wl->fw.fw_hdr[i], fw_name, device);
  352. if (status) {
  353. wiphy_err(wl->wiphy, "%s: fail to load firmware %s\n",
  354. KBUILD_MODNAME, fw_name);
  355. return status;
  356. }
  357. wl->fw.hdr_num_entries[i] =
  358. wl->fw.fw_hdr[i]->size / (sizeof(struct firmware_hdr));
  359. }
  360. wl->fw.fw_cnt = i;
  361. status = brcms_ucode_data_init(wl, &wl->ucode);
  362. brcms_release_fw(wl);
  363. return status;
  364. }
  365. static void brcms_ops_tx(struct ieee80211_hw *hw,
  366. struct ieee80211_tx_control *control,
  367. struct sk_buff *skb)
  368. {
  369. struct brcms_info *wl = hw->priv;
  370. struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
  371. spin_lock_bh(&wl->lock);
  372. if (!wl->pub->up) {
  373. brcms_err(wl->wlc->hw->d11core, "ops->tx called while down\n");
  374. kfree_skb(skb);
  375. goto done;
  376. }
  377. if (brcms_c_sendpkt_mac80211(wl->wlc, skb, hw))
  378. tx_info->rate_driver_data[0] = control->sta;
  379. done:
  380. spin_unlock_bh(&wl->lock);
  381. }
  382. static int brcms_ops_start(struct ieee80211_hw *hw)
  383. {
  384. struct brcms_info *wl = hw->priv;
  385. bool blocked;
  386. int err;
  387. if (!wl->ucode.bcm43xx_bomminor) {
  388. err = brcms_request_fw(wl, wl->wlc->hw->d11core);
  389. if (err)
  390. return -ENOENT;
  391. }
  392. ieee80211_wake_queues(hw);
  393. spin_lock_bh(&wl->lock);
  394. blocked = brcms_rfkill_set_hw_state(wl);
  395. spin_unlock_bh(&wl->lock);
  396. if (!blocked)
  397. wiphy_rfkill_stop_polling(wl->pub->ieee_hw->wiphy);
  398. spin_lock_bh(&wl->lock);
  399. /* avoid acknowledging frames before a non-monitor device is added */
  400. wl->mute_tx = true;
  401. if (!wl->pub->up)
  402. if (!blocked)
  403. err = brcms_up(wl);
  404. else
  405. err = -ERFKILL;
  406. else
  407. err = -ENODEV;
  408. spin_unlock_bh(&wl->lock);
  409. if (err != 0)
  410. brcms_err(wl->wlc->hw->d11core, "%s: brcms_up() returned %d\n",
  411. __func__, err);
  412. bcma_core_pci_power_save(wl->wlc->hw->d11core->bus, true);
  413. return err;
  414. }
  415. static void brcms_ops_stop(struct ieee80211_hw *hw)
  416. {
  417. struct brcms_info *wl = hw->priv;
  418. int status;
  419. ieee80211_stop_queues(hw);
  420. if (wl->wlc == NULL)
  421. return;
  422. spin_lock_bh(&wl->lock);
  423. status = brcms_c_chipmatch(wl->wlc->hw->d11core);
  424. spin_unlock_bh(&wl->lock);
  425. if (!status) {
  426. brcms_err(wl->wlc->hw->d11core,
  427. "wl: brcms_ops_stop: chipmatch failed\n");
  428. return;
  429. }
  430. bcma_core_pci_power_save(wl->wlc->hw->d11core->bus, false);
  431. /* put driver in down state */
  432. spin_lock_bh(&wl->lock);
  433. brcms_down(wl);
  434. spin_unlock_bh(&wl->lock);
  435. }
  436. static int
  437. brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  438. {
  439. struct brcms_info *wl = hw->priv;
  440. /* Just STA, AP and ADHOC for now */
  441. if (vif->type != NL80211_IFTYPE_STATION &&
  442. vif->type != NL80211_IFTYPE_AP &&
  443. vif->type != NL80211_IFTYPE_ADHOC) {
  444. brcms_err(wl->wlc->hw->d11core,
  445. "%s: Attempt to add type %d, only STA, AP and AdHoc for now\n",
  446. __func__, vif->type);
  447. return -EOPNOTSUPP;
  448. }
  449. spin_lock_bh(&wl->lock);
  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->bss_conf.ssid, vif->bss_conf.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. }
  466. static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
  467. {
  468. struct ieee80211_conf *conf = &hw->conf;
  469. struct brcms_info *wl = hw->priv;
  470. struct bcma_device *core = wl->wlc->hw->d11core;
  471. int err = 0;
  472. int new_int;
  473. spin_lock_bh(&wl->lock);
  474. if (changed & IEEE80211_CONF_CHANGE_LISTEN_INTERVAL) {
  475. brcms_c_set_beacon_listen_interval(wl->wlc,
  476. conf->listen_interval);
  477. }
  478. if (changed & IEEE80211_CONF_CHANGE_MONITOR)
  479. brcms_dbg_info(core, "%s: change monitor mode: %s\n",
  480. __func__, conf->flags & IEEE80211_CONF_MONITOR ?
  481. "true" : "false");
  482. if (changed & IEEE80211_CONF_CHANGE_PS)
  483. brcms_err(core, "%s: change power-save mode: %s (implement)\n",
  484. __func__, conf->flags & IEEE80211_CONF_PS ?
  485. "true" : "false");
  486. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  487. err = brcms_c_set_tx_power(wl->wlc, conf->power_level);
  488. if (err < 0) {
  489. brcms_err(core, "%s: Error setting power_level\n",
  490. __func__);
  491. goto config_out;
  492. }
  493. new_int = brcms_c_get_tx_power(wl->wlc);
  494. if (new_int != conf->power_level)
  495. brcms_err(core,
  496. "%s: Power level req != actual, %d %d\n",
  497. __func__, conf->power_level,
  498. new_int);
  499. }
  500. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  501. if (conf->chandef.width == NL80211_CHAN_WIDTH_20 ||
  502. conf->chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
  503. err = brcms_c_set_channel(wl->wlc,
  504. conf->chandef.chan->hw_value);
  505. else
  506. err = -ENOTSUPP;
  507. }
  508. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  509. err = brcms_c_set_rate_limit(wl->wlc,
  510. conf->short_frame_max_tx_count,
  511. conf->long_frame_max_tx_count);
  512. config_out:
  513. spin_unlock_bh(&wl->lock);
  514. return err;
  515. }
  516. static void
  517. brcms_ops_bss_info_changed(struct ieee80211_hw *hw,
  518. struct ieee80211_vif *vif,
  519. struct ieee80211_bss_conf *info, u32 changed)
  520. {
  521. struct brcms_info *wl = hw->priv;
  522. struct bcma_device *core = wl->wlc->hw->d11core;
  523. if (changed & BSS_CHANGED_ASSOC) {
  524. /* association status changed (associated/disassociated)
  525. * also implies a change in the AID.
  526. */
  527. brcms_err(core, "%s: %s: %sassociated\n", KBUILD_MODNAME,
  528. __func__, info->assoc ? "" : "dis");
  529. spin_lock_bh(&wl->lock);
  530. brcms_c_associate_upd(wl->wlc, info->assoc);
  531. spin_unlock_bh(&wl->lock);
  532. }
  533. if (changed & BSS_CHANGED_ERP_SLOT) {
  534. s8 val;
  535. /* slot timing changed */
  536. if (info->use_short_slot)
  537. val = 1;
  538. else
  539. val = 0;
  540. spin_lock_bh(&wl->lock);
  541. brcms_c_set_shortslot_override(wl->wlc, val);
  542. spin_unlock_bh(&wl->lock);
  543. }
  544. if (changed & BSS_CHANGED_HT) {
  545. /* 802.11n parameters changed */
  546. u16 mode = info->ht_operation_mode;
  547. spin_lock_bh(&wl->lock);
  548. brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_CFG,
  549. mode & IEEE80211_HT_OP_MODE_PROTECTION);
  550. brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_NONGF,
  551. mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  552. brcms_c_protection_upd(wl->wlc, BRCMS_PROT_N_OBSS,
  553. mode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT);
  554. spin_unlock_bh(&wl->lock);
  555. }
  556. if (changed & BSS_CHANGED_BASIC_RATES) {
  557. struct ieee80211_supported_band *bi;
  558. u32 br_mask, i;
  559. u16 rate;
  560. struct brcm_rateset rs;
  561. int error;
  562. /* retrieve the current rates */
  563. spin_lock_bh(&wl->lock);
  564. brcms_c_get_current_rateset(wl->wlc, &rs);
  565. spin_unlock_bh(&wl->lock);
  566. br_mask = info->basic_rates;
  567. bi = hw->wiphy->bands[brcms_c_get_curband(wl->wlc)];
  568. for (i = 0; i < bi->n_bitrates; i++) {
  569. /* convert to internal rate value */
  570. rate = (bi->bitrates[i].bitrate << 1) / 10;
  571. /* set/clear basic rate flag */
  572. brcms_set_basic_rate(&rs, rate, br_mask & 1);
  573. br_mask >>= 1;
  574. }
  575. /* update the rate set */
  576. spin_lock_bh(&wl->lock);
  577. error = brcms_c_set_rateset(wl->wlc, &rs);
  578. spin_unlock_bh(&wl->lock);
  579. if (error)
  580. brcms_err(core, "changing basic rates failed: %d\n",
  581. error);
  582. }
  583. if (changed & BSS_CHANGED_BEACON_INT) {
  584. /* Beacon interval changed */
  585. spin_lock_bh(&wl->lock);
  586. brcms_c_set_beacon_period(wl->wlc, info->beacon_int);
  587. spin_unlock_bh(&wl->lock);
  588. }
  589. if (changed & BSS_CHANGED_BSSID) {
  590. /* BSSID changed, for whatever reason (IBSS and managed mode) */
  591. spin_lock_bh(&wl->lock);
  592. brcms_c_set_addrmatch(wl->wlc, RCM_BSSID_OFFSET, info->bssid);
  593. spin_unlock_bh(&wl->lock);
  594. }
  595. if (changed & BSS_CHANGED_SSID) {
  596. /* BSSID changed, for whatever reason (IBSS and managed mode) */
  597. spin_lock_bh(&wl->lock);
  598. brcms_c_set_ssid(wl->wlc, info->ssid, info->ssid_len);
  599. spin_unlock_bh(&wl->lock);
  600. }
  601. if (changed & BSS_CHANGED_BEACON) {
  602. /* Beacon data changed, retrieve new beacon (beaconing modes) */
  603. struct sk_buff *beacon;
  604. u16 tim_offset = 0;
  605. spin_lock_bh(&wl->lock);
  606. beacon = ieee80211_beacon_get_tim(hw, vif, &tim_offset, NULL);
  607. brcms_c_set_new_beacon(wl->wlc, beacon, tim_offset,
  608. info->dtim_period);
  609. spin_unlock_bh(&wl->lock);
  610. }
  611. if (changed & BSS_CHANGED_AP_PROBE_RESP) {
  612. struct sk_buff *probe_resp;
  613. spin_lock_bh(&wl->lock);
  614. probe_resp = ieee80211_proberesp_get(hw, vif);
  615. brcms_c_set_new_probe_resp(wl->wlc, probe_resp);
  616. spin_unlock_bh(&wl->lock);
  617. }
  618. if (changed & BSS_CHANGED_BEACON_ENABLED) {
  619. /* Beaconing should be enabled/disabled (beaconing modes) */
  620. brcms_err(core, "%s: Beacon enabled: %s\n", __func__,
  621. info->enable_beacon ? "true" : "false");
  622. if (info->enable_beacon &&
  623. hw->wiphy->flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) {
  624. brcms_c_enable_probe_resp(wl->wlc, true);
  625. } else {
  626. brcms_c_enable_probe_resp(wl->wlc, false);
  627. }
  628. }
  629. if (changed & BSS_CHANGED_CQM) {
  630. /* Connection quality monitor config changed */
  631. brcms_err(core, "%s: cqm change: threshold %d, hys %d "
  632. " (implement)\n", __func__, info->cqm_rssi_thold,
  633. info->cqm_rssi_hyst);
  634. }
  635. if (changed & BSS_CHANGED_IBSS) {
  636. /* IBSS join status changed */
  637. brcms_err(core, "%s: IBSS joined: %s (implement)\n",
  638. __func__, info->ibss_joined ? "true" : "false");
  639. }
  640. if (changed & BSS_CHANGED_ARP_FILTER) {
  641. /* Hardware ARP filter address list or state changed */
  642. brcms_err(core, "%s: arp filtering: %d addresses"
  643. " (implement)\n", __func__, info->arp_addr_cnt);
  644. }
  645. if (changed & BSS_CHANGED_QOS) {
  646. /*
  647. * QoS for this association was enabled/disabled.
  648. * Note that it is only ever disabled for station mode.
  649. */
  650. brcms_err(core, "%s: qos enabled: %s (implement)\n",
  651. __func__, info->qos ? "true" : "false");
  652. }
  653. return;
  654. }
  655. static void
  656. brcms_ops_configure_filter(struct ieee80211_hw *hw,
  657. unsigned int changed_flags,
  658. unsigned int *total_flags, u64 multicast)
  659. {
  660. struct brcms_info *wl = hw->priv;
  661. struct bcma_device *core = wl->wlc->hw->d11core;
  662. changed_flags &= MAC_FILTERS;
  663. *total_flags &= MAC_FILTERS;
  664. if (changed_flags & FIF_ALLMULTI)
  665. brcms_dbg_info(core, "FIF_ALLMULTI\n");
  666. if (changed_flags & FIF_FCSFAIL)
  667. brcms_dbg_info(core, "FIF_FCSFAIL\n");
  668. if (changed_flags & FIF_CONTROL)
  669. brcms_dbg_info(core, "FIF_CONTROL\n");
  670. if (changed_flags & FIF_OTHER_BSS)
  671. brcms_dbg_info(core, "FIF_OTHER_BSS\n");
  672. if (changed_flags & FIF_PSPOLL)
  673. brcms_dbg_info(core, "FIF_PSPOLL\n");
  674. if (changed_flags & FIF_BCN_PRBRESP_PROMISC)
  675. brcms_dbg_info(core, "FIF_BCN_PRBRESP_PROMISC\n");
  676. spin_lock_bh(&wl->lock);
  677. brcms_c_mac_promisc(wl->wlc, *total_flags);
  678. spin_unlock_bh(&wl->lock);
  679. return;
  680. }
  681. static void brcms_ops_sw_scan_start(struct ieee80211_hw *hw,
  682. struct ieee80211_vif *vif,
  683. const u8 *mac_addr)
  684. {
  685. struct brcms_info *wl = hw->priv;
  686. spin_lock_bh(&wl->lock);
  687. brcms_c_scan_start(wl->wlc);
  688. spin_unlock_bh(&wl->lock);
  689. return;
  690. }
  691. static void brcms_ops_sw_scan_complete(struct ieee80211_hw *hw,
  692. struct ieee80211_vif *vif)
  693. {
  694. struct brcms_info *wl = hw->priv;
  695. spin_lock_bh(&wl->lock);
  696. brcms_c_scan_stop(wl->wlc);
  697. spin_unlock_bh(&wl->lock);
  698. return;
  699. }
  700. static int
  701. brcms_ops_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
  702. const struct ieee80211_tx_queue_params *params)
  703. {
  704. struct brcms_info *wl = hw->priv;
  705. spin_lock_bh(&wl->lock);
  706. brcms_c_wme_setparams(wl->wlc, queue, params, true);
  707. spin_unlock_bh(&wl->lock);
  708. return 0;
  709. }
  710. static int
  711. brcms_ops_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  712. struct ieee80211_sta *sta)
  713. {
  714. struct brcms_info *wl = hw->priv;
  715. struct scb *scb = &wl->wlc->pri_scb;
  716. brcms_c_init_scb(scb);
  717. wl->pub->global_ampdu = &(scb->scb_ampdu);
  718. wl->pub->global_ampdu->scb = scb;
  719. wl->pub->global_ampdu->max_pdu = 16;
  720. /*
  721. * minstrel_ht initiates addBA on our behalf by calling
  722. * ieee80211_start_tx_ba_session()
  723. */
  724. return 0;
  725. }
  726. static int
  727. brcms_ops_ampdu_action(struct ieee80211_hw *hw,
  728. struct ieee80211_vif *vif,
  729. struct ieee80211_ampdu_params *params)
  730. {
  731. struct brcms_info *wl = hw->priv;
  732. struct scb *scb = &wl->wlc->pri_scb;
  733. int status;
  734. struct ieee80211_sta *sta = params->sta;
  735. enum ieee80211_ampdu_mlme_action action = params->action;
  736. u16 tid = params->tid;
  737. u8 buf_size = params->buf_size;
  738. if (WARN_ON(scb->magic != SCB_MAGIC))
  739. return -EIDRM;
  740. switch (action) {
  741. case IEEE80211_AMPDU_RX_START:
  742. break;
  743. case IEEE80211_AMPDU_RX_STOP:
  744. break;
  745. case IEEE80211_AMPDU_TX_START:
  746. spin_lock_bh(&wl->lock);
  747. status = brcms_c_aggregatable(wl->wlc, tid);
  748. spin_unlock_bh(&wl->lock);
  749. if (!status) {
  750. brcms_err(wl->wlc->hw->d11core,
  751. "START: tid %d is not agg\'able\n", tid);
  752. return -EINVAL;
  753. }
  754. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  755. break;
  756. case IEEE80211_AMPDU_TX_STOP_CONT:
  757. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  758. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  759. spin_lock_bh(&wl->lock);
  760. brcms_c_ampdu_flush(wl->wlc, sta, tid);
  761. spin_unlock_bh(&wl->lock);
  762. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  763. break;
  764. case IEEE80211_AMPDU_TX_OPERATIONAL:
  765. /*
  766. * BA window size from ADDBA response ('buf_size') defines how
  767. * many outstanding MPDUs are allowed for the BA stream by
  768. * recipient and traffic class. 'ampdu_factor' gives maximum
  769. * AMPDU size.
  770. */
  771. spin_lock_bh(&wl->lock);
  772. brcms_c_ampdu_tx_operational(wl->wlc, tid, buf_size,
  773. (1 << (IEEE80211_HT_MAX_AMPDU_FACTOR +
  774. sta->ht_cap.ampdu_factor)) - 1);
  775. spin_unlock_bh(&wl->lock);
  776. /* Power save wakeup */
  777. break;
  778. default:
  779. brcms_err(wl->wlc->hw->d11core,
  780. "%s: Invalid command, ignoring\n", __func__);
  781. }
  782. return 0;
  783. }
  784. static void brcms_ops_rfkill_poll(struct ieee80211_hw *hw)
  785. {
  786. struct brcms_info *wl = hw->priv;
  787. bool blocked;
  788. spin_lock_bh(&wl->lock);
  789. blocked = brcms_c_check_radio_disabled(wl->wlc);
  790. spin_unlock_bh(&wl->lock);
  791. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
  792. }
  793. static bool brcms_tx_flush_completed(struct brcms_info *wl)
  794. {
  795. bool result;
  796. spin_lock_bh(&wl->lock);
  797. result = brcms_c_tx_flush_completed(wl->wlc);
  798. spin_unlock_bh(&wl->lock);
  799. return result;
  800. }
  801. static void brcms_ops_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  802. 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[NL80211_BAND_2GHZ] = NULL;
  903. hw->wiphy->bands[NL80211_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[NL80211_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[NL80211_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. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  936. ieee80211_hw_set(hw, SIGNAL_DBM);
  937. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  938. hw->extra_tx_headroom = brcms_c_get_header_len();
  939. hw->queues = N_TX_QUEUES;
  940. hw->max_rates = 2; /* Primary rate and 1 fallback rate */
  941. /* channel change time is dependent on chip and band */
  942. hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  943. BIT(NL80211_IFTYPE_AP) |
  944. BIT(NL80211_IFTYPE_ADHOC);
  945. /*
  946. * deactivate sending probe responses by ucude, because this will
  947. * cause problems when WPS is used.
  948. *
  949. * hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
  950. */
  951. hw->rate_control_algorithm = "minstrel_ht";
  952. hw->sta_data_size = 0;
  953. return ieee_hw_rate_init(hw);
  954. }
  955. /**
  956. * attach to the WL device.
  957. *
  958. * Attach to the WL device identified by vendor and device parameters.
  959. * regs is a host accessible memory address pointing to WL device registers.
  960. *
  961. * is called in brcms_bcma_probe() context, therefore no locking required.
  962. */
  963. static struct brcms_info *brcms_attach(struct bcma_device *pdev)
  964. {
  965. struct brcms_info *wl = NULL;
  966. int unit, err;
  967. struct ieee80211_hw *hw;
  968. u8 perm[ETH_ALEN];
  969. unit = n_adapters_found;
  970. err = 0;
  971. if (unit < 0)
  972. return NULL;
  973. /* allocate private info */
  974. hw = bcma_get_drvdata(pdev);
  975. if (hw != NULL)
  976. wl = hw->priv;
  977. if (WARN_ON(hw == NULL) || WARN_ON(wl == NULL))
  978. return NULL;
  979. wl->wiphy = hw->wiphy;
  980. atomic_set(&wl->callbacks, 0);
  981. init_waitqueue_head(&wl->tx_flush_wq);
  982. /* setup the bottom half handler */
  983. tasklet_init(&wl->tasklet, brcms_dpc, (unsigned long) wl);
  984. spin_lock_init(&wl->lock);
  985. spin_lock_init(&wl->isr_lock);
  986. /* common load-time initialization */
  987. wl->wlc = brcms_c_attach((void *)wl, pdev, unit, false, &err);
  988. if (!wl->wlc) {
  989. wiphy_err(wl->wiphy, "%s: attach() failed with code %d\n",
  990. KBUILD_MODNAME, err);
  991. goto fail;
  992. }
  993. wl->pub = brcms_c_pub(wl->wlc);
  994. wl->pub->ieee_hw = hw;
  995. /* register our interrupt handler */
  996. if (request_irq(pdev->irq, brcms_isr,
  997. IRQF_SHARED, KBUILD_MODNAME, wl)) {
  998. wiphy_err(wl->wiphy, "wl%d: request_irq() failed\n", unit);
  999. goto fail;
  1000. }
  1001. wl->irq = pdev->irq;
  1002. /* register module */
  1003. brcms_c_module_register(wl->pub, "linux", wl, NULL);
  1004. if (ieee_hw_init(hw)) {
  1005. wiphy_err(wl->wiphy, "wl%d: %s: ieee_hw_init failed!\n", unit,
  1006. __func__);
  1007. goto fail;
  1008. }
  1009. brcms_c_regd_init(wl->wlc);
  1010. memcpy(perm, &wl->pub->cur_etheraddr, ETH_ALEN);
  1011. if (WARN_ON(!is_valid_ether_addr(perm)))
  1012. goto fail;
  1013. SET_IEEE80211_PERM_ADDR(hw, perm);
  1014. err = ieee80211_register_hw(hw);
  1015. if (err)
  1016. wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
  1017. "%d\n", __func__, err);
  1018. if (wl->pub->srom_ccode[0] &&
  1019. regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
  1020. wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
  1021. brcms_debugfs_attach(wl->pub);
  1022. brcms_debugfs_create_files(wl->pub);
  1023. n_adapters_found++;
  1024. return wl;
  1025. fail:
  1026. brcms_free(wl);
  1027. return NULL;
  1028. }
  1029. /**
  1030. * determines if a device is a WL device, and if so, attaches it.
  1031. *
  1032. * This function determines if a device pointed to by pdev is a WL device,
  1033. * and if so, performs a brcms_attach() on it.
  1034. *
  1035. * Perimeter lock is initialized in the course of this function.
  1036. */
  1037. static int brcms_bcma_probe(struct bcma_device *pdev)
  1038. {
  1039. struct brcms_info *wl;
  1040. struct ieee80211_hw *hw;
  1041. dev_info(&pdev->dev, "mfg %x core %x rev %d class %d irq %d\n",
  1042. pdev->id.manuf, pdev->id.id, pdev->id.rev, pdev->id.class,
  1043. pdev->irq);
  1044. if ((pdev->id.manuf != BCMA_MANUF_BCM) ||
  1045. (pdev->id.id != BCMA_CORE_80211))
  1046. return -ENODEV;
  1047. hw = ieee80211_alloc_hw(sizeof(struct brcms_info), &brcms_ops);
  1048. if (!hw) {
  1049. pr_err("%s: ieee80211_alloc_hw failed\n", __func__);
  1050. return -ENOMEM;
  1051. }
  1052. SET_IEEE80211_DEV(hw, &pdev->dev);
  1053. bcma_set_drvdata(pdev, hw);
  1054. memset(hw->priv, 0, sizeof(*wl));
  1055. wl = brcms_attach(pdev);
  1056. if (!wl) {
  1057. pr_err("%s: brcms_attach failed!\n", __func__);
  1058. return -ENODEV;
  1059. }
  1060. brcms_led_register(wl);
  1061. return 0;
  1062. }
  1063. static int brcms_suspend(struct bcma_device *pdev)
  1064. {
  1065. struct brcms_info *wl;
  1066. struct ieee80211_hw *hw;
  1067. hw = bcma_get_drvdata(pdev);
  1068. wl = hw->priv;
  1069. if (!wl) {
  1070. pr_err("%s: %s: no driver private struct!\n", KBUILD_MODNAME,
  1071. __func__);
  1072. return -ENODEV;
  1073. }
  1074. /* only need to flag hw is down for proper resume */
  1075. spin_lock_bh(&wl->lock);
  1076. wl->pub->hw_up = false;
  1077. spin_unlock_bh(&wl->lock);
  1078. brcms_dbg_info(wl->wlc->hw->d11core, "brcms_suspend ok\n");
  1079. return 0;
  1080. }
  1081. static int brcms_resume(struct bcma_device *pdev)
  1082. {
  1083. return 0;
  1084. }
  1085. static struct bcma_driver brcms_bcma_driver = {
  1086. .name = KBUILD_MODNAME,
  1087. .probe = brcms_bcma_probe,
  1088. .suspend = brcms_suspend,
  1089. .resume = brcms_resume,
  1090. .remove = brcms_remove,
  1091. .id_table = brcms_coreid_table,
  1092. };
  1093. /**
  1094. * This is the main entry point for the brcmsmac driver.
  1095. *
  1096. * This function is scheduled upon module initialization and
  1097. * does the driver registration, which result in brcms_bcma_probe()
  1098. * call resulting in the driver bringup.
  1099. */
  1100. static void brcms_driver_init(struct work_struct *work)
  1101. {
  1102. int error;
  1103. error = bcma_driver_register(&brcms_bcma_driver);
  1104. if (error)
  1105. pr_err("%s: register returned %d\n", __func__, error);
  1106. }
  1107. static DECLARE_WORK(brcms_driver_work, brcms_driver_init);
  1108. static int __init brcms_module_init(void)
  1109. {
  1110. brcms_debugfs_init();
  1111. if (!schedule_work(&brcms_driver_work))
  1112. return -EBUSY;
  1113. return 0;
  1114. }
  1115. /**
  1116. * This function unloads the brcmsmac driver from the system.
  1117. *
  1118. * This function unconditionally unloads the brcmsmac driver module from the
  1119. * system.
  1120. *
  1121. */
  1122. static void __exit brcms_module_exit(void)
  1123. {
  1124. cancel_work_sync(&brcms_driver_work);
  1125. bcma_driver_unregister(&brcms_bcma_driver);
  1126. brcms_debugfs_exit();
  1127. }
  1128. module_init(brcms_module_init);
  1129. module_exit(brcms_module_exit);
  1130. /*
  1131. * precondition: perimeter lock has been acquired
  1132. */
  1133. void brcms_txflowcontrol(struct brcms_info *wl, struct brcms_if *wlif,
  1134. bool state, int prio)
  1135. {
  1136. brcms_err(wl->wlc->hw->d11core, "Shouldn't be here %s\n", __func__);
  1137. }
  1138. /*
  1139. * precondition: perimeter lock has been acquired
  1140. */
  1141. void brcms_init(struct brcms_info *wl)
  1142. {
  1143. brcms_dbg_info(wl->wlc->hw->d11core, "Initializing wl%d\n",
  1144. wl->pub->unit);
  1145. brcms_reset(wl);
  1146. brcms_c_init(wl->wlc, wl->mute_tx);
  1147. }
  1148. /*
  1149. * precondition: perimeter lock has been acquired
  1150. */
  1151. uint brcms_reset(struct brcms_info *wl)
  1152. {
  1153. brcms_dbg_info(wl->wlc->hw->d11core, "Resetting wl%d\n", wl->pub->unit);
  1154. brcms_c_reset(wl->wlc);
  1155. /* dpc will not be rescheduled */
  1156. wl->resched = false;
  1157. /* inform publicly that interface is down */
  1158. wl->pub->up = false;
  1159. return 0;
  1160. }
  1161. void brcms_fatal_error(struct brcms_info *wl)
  1162. {
  1163. brcms_err(wl->wlc->hw->d11core, "wl%d: fatal error, reinitializing\n",
  1164. wl->wlc->pub->unit);
  1165. brcms_reset(wl);
  1166. ieee80211_restart_hw(wl->pub->ieee_hw);
  1167. }
  1168. /*
  1169. * These are interrupt on/off entry points. Disable interrupts
  1170. * during interrupt state transition.
  1171. */
  1172. void brcms_intrson(struct brcms_info *wl)
  1173. {
  1174. unsigned long flags;
  1175. spin_lock_irqsave(&wl->isr_lock, flags);
  1176. brcms_c_intrson(wl->wlc);
  1177. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1178. }
  1179. u32 brcms_intrsoff(struct brcms_info *wl)
  1180. {
  1181. unsigned long flags;
  1182. u32 status;
  1183. spin_lock_irqsave(&wl->isr_lock, flags);
  1184. status = brcms_c_intrsoff(wl->wlc);
  1185. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1186. return status;
  1187. }
  1188. void brcms_intrsrestore(struct brcms_info *wl, u32 macintmask)
  1189. {
  1190. unsigned long flags;
  1191. spin_lock_irqsave(&wl->isr_lock, flags);
  1192. brcms_c_intrsrestore(wl->wlc, macintmask);
  1193. spin_unlock_irqrestore(&wl->isr_lock, flags);
  1194. }
  1195. /*
  1196. * precondition: perimeter lock has been acquired
  1197. */
  1198. int brcms_up(struct brcms_info *wl)
  1199. {
  1200. int error = 0;
  1201. if (wl->pub->up)
  1202. return 0;
  1203. error = brcms_c_up(wl->wlc);
  1204. return error;
  1205. }
  1206. /*
  1207. * precondition: perimeter lock has been acquired
  1208. */
  1209. void brcms_down(struct brcms_info *wl)
  1210. {
  1211. uint callbacks, ret_val = 0;
  1212. /* call common down function */
  1213. ret_val = brcms_c_down(wl->wlc);
  1214. callbacks = atomic_read(&wl->callbacks) - ret_val;
  1215. /* wait for down callbacks to complete */
  1216. spin_unlock_bh(&wl->lock);
  1217. /* For HIGH_only driver, it's important to actually schedule other work,
  1218. * not just spin wait since everything runs at schedule level
  1219. */
  1220. SPINWAIT((atomic_read(&wl->callbacks) > callbacks), 100 * 1000);
  1221. spin_lock_bh(&wl->lock);
  1222. }
  1223. /*
  1224. * precondition: perimeter lock is not acquired
  1225. */
  1226. static void _brcms_timer(struct work_struct *work)
  1227. {
  1228. struct brcms_timer *t = container_of(work, struct brcms_timer,
  1229. dly_wrk.work);
  1230. spin_lock_bh(&t->wl->lock);
  1231. if (t->set) {
  1232. if (t->periodic) {
  1233. atomic_inc(&t->wl->callbacks);
  1234. ieee80211_queue_delayed_work(t->wl->pub->ieee_hw,
  1235. &t->dly_wrk,
  1236. msecs_to_jiffies(t->ms));
  1237. } else {
  1238. t->set = false;
  1239. }
  1240. t->fn(t->arg);
  1241. }
  1242. atomic_dec(&t->wl->callbacks);
  1243. spin_unlock_bh(&t->wl->lock);
  1244. }
  1245. /*
  1246. * Adds a timer to the list. Caller supplies a timer function.
  1247. * Is called from wlc.
  1248. *
  1249. * precondition: perimeter lock has been acquired
  1250. */
  1251. struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
  1252. void (*fn) (void *arg),
  1253. void *arg, const char *name)
  1254. {
  1255. struct brcms_timer *t;
  1256. t = kzalloc(sizeof(struct brcms_timer), GFP_ATOMIC);
  1257. if (!t)
  1258. return NULL;
  1259. INIT_DELAYED_WORK(&t->dly_wrk, _brcms_timer);
  1260. t->wl = wl;
  1261. t->fn = fn;
  1262. t->arg = arg;
  1263. t->next = wl->timers;
  1264. wl->timers = t;
  1265. #ifdef DEBUG
  1266. t->name = kstrdup(name, GFP_ATOMIC);
  1267. #endif
  1268. return t;
  1269. }
  1270. /*
  1271. * adds only the kernel timer since it's going to be more accurate
  1272. * as well as it's easier to make it periodic
  1273. *
  1274. * precondition: perimeter lock has been acquired
  1275. */
  1276. void brcms_add_timer(struct brcms_timer *t, uint ms, int periodic)
  1277. {
  1278. struct ieee80211_hw *hw = t->wl->pub->ieee_hw;
  1279. #ifdef DEBUG
  1280. if (t->set)
  1281. brcms_dbg_info(t->wl->wlc->hw->d11core,
  1282. "%s: Already set. Name: %s, per %d\n",
  1283. __func__, t->name, periodic);
  1284. #endif
  1285. t->ms = ms;
  1286. t->periodic = (bool) periodic;
  1287. if (!t->set) {
  1288. t->set = true;
  1289. atomic_inc(&t->wl->callbacks);
  1290. }
  1291. ieee80211_queue_delayed_work(hw, &t->dly_wrk, msecs_to_jiffies(ms));
  1292. }
  1293. /*
  1294. * return true if timer successfully deleted, false if still pending
  1295. *
  1296. * precondition: perimeter lock has been acquired
  1297. */
  1298. bool brcms_del_timer(struct brcms_timer *t)
  1299. {
  1300. if (t->set) {
  1301. t->set = false;
  1302. if (!cancel_delayed_work(&t->dly_wrk))
  1303. return false;
  1304. atomic_dec(&t->wl->callbacks);
  1305. }
  1306. return true;
  1307. }
  1308. /*
  1309. * precondition: perimeter lock has been acquired
  1310. */
  1311. void brcms_free_timer(struct brcms_timer *t)
  1312. {
  1313. struct brcms_info *wl = t->wl;
  1314. struct brcms_timer *tmp;
  1315. /* delete the timer in case it is active */
  1316. brcms_del_timer(t);
  1317. if (wl->timers == t) {
  1318. wl->timers = wl->timers->next;
  1319. #ifdef DEBUG
  1320. kfree(t->name);
  1321. #endif
  1322. kfree(t);
  1323. return;
  1324. }
  1325. tmp = wl->timers;
  1326. while (tmp) {
  1327. if (tmp->next == t) {
  1328. tmp->next = t->next;
  1329. #ifdef DEBUG
  1330. kfree(t->name);
  1331. #endif
  1332. kfree(t);
  1333. return;
  1334. }
  1335. tmp = tmp->next;
  1336. }
  1337. }
  1338. /*
  1339. * precondition: perimeter lock has been acquired
  1340. */
  1341. int brcms_ucode_init_buf(struct brcms_info *wl, void **pbuf, u32 idx)
  1342. {
  1343. int i, entry;
  1344. const u8 *pdata;
  1345. struct firmware_hdr *hdr;
  1346. for (i = 0; i < wl->fw.fw_cnt; i++) {
  1347. hdr = (struct firmware_hdr *)wl->fw.fw_hdr[i]->data;
  1348. for (entry = 0; entry < wl->fw.hdr_num_entries[i];
  1349. entry++, hdr++) {
  1350. u32 len = le32_to_cpu(hdr->len);
  1351. if (le32_to_cpu(hdr->idx) == idx) {
  1352. pdata = wl->fw.fw_bin[i]->data +
  1353. le32_to_cpu(hdr->offset);
  1354. *pbuf = kmemdup(pdata, len, GFP_ATOMIC);
  1355. if (*pbuf == NULL)
  1356. goto fail;
  1357. return 0;
  1358. }
  1359. }
  1360. }
  1361. brcms_err(wl->wlc->hw->d11core,
  1362. "ERROR: ucode buf tag:%d can not be found!\n", idx);
  1363. *pbuf = NULL;
  1364. fail:
  1365. return -ENODATA;
  1366. }
  1367. /*
  1368. * Precondition: Since this function is called in brcms_bcma_probe() context,
  1369. * no locking is required.
  1370. */
  1371. int brcms_ucode_init_uint(struct brcms_info *wl, size_t *n_bytes, 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. if (le32_to_cpu(hdr->idx) == idx) {
  1381. pdata = wl->fw.fw_bin[i]->data +
  1382. le32_to_cpu(hdr->offset);
  1383. if (le32_to_cpu(hdr->len) != 4) {
  1384. brcms_err(wl->wlc->hw->d11core,
  1385. "ERROR: fw hdr len\n");
  1386. return -ENOMSG;
  1387. }
  1388. *n_bytes = le32_to_cpu(*((__le32 *) pdata));
  1389. return 0;
  1390. }
  1391. }
  1392. }
  1393. brcms_err(wl->wlc->hw->d11core,
  1394. "ERROR: ucode tag:%d can not be found!\n", idx);
  1395. return -ENOMSG;
  1396. }
  1397. /*
  1398. * precondition: can both be called locked and unlocked
  1399. */
  1400. void brcms_ucode_free_buf(void *p)
  1401. {
  1402. kfree(p);
  1403. }
  1404. /*
  1405. * checks validity of all firmware images loaded from user space
  1406. *
  1407. * Precondition: Since this function is called in brcms_bcma_probe() context,
  1408. * no locking is required.
  1409. */
  1410. int brcms_check_firmwares(struct brcms_info *wl)
  1411. {
  1412. int i;
  1413. int entry;
  1414. int rc = 0;
  1415. const struct firmware *fw;
  1416. const struct firmware *fw_hdr;
  1417. struct firmware_hdr *ucode_hdr;
  1418. for (i = 0; i < MAX_FW_IMAGES && rc == 0; i++) {
  1419. fw = wl->fw.fw_bin[i];
  1420. fw_hdr = wl->fw.fw_hdr[i];
  1421. if (fw == NULL && fw_hdr == NULL) {
  1422. break;
  1423. } else if (fw == NULL || fw_hdr == NULL) {
  1424. wiphy_err(wl->wiphy, "%s: invalid bin/hdr fw\n",
  1425. __func__);
  1426. rc = -EBADF;
  1427. } else if (fw_hdr->size % sizeof(struct firmware_hdr)) {
  1428. wiphy_err(wl->wiphy, "%s: non integral fw hdr file "
  1429. "size %zu/%zu\n", __func__, fw_hdr->size,
  1430. sizeof(struct firmware_hdr));
  1431. rc = -EBADF;
  1432. } else if (fw->size < MIN_FW_SIZE || fw->size > MAX_FW_SIZE) {
  1433. wiphy_err(wl->wiphy, "%s: out of bounds fw file size %zu\n",
  1434. __func__, fw->size);
  1435. rc = -EBADF;
  1436. } else {
  1437. /* check if ucode section overruns firmware image */
  1438. ucode_hdr = (struct firmware_hdr *)fw_hdr->data;
  1439. for (entry = 0; entry < wl->fw.hdr_num_entries[i] &&
  1440. !rc; entry++, ucode_hdr++) {
  1441. if (le32_to_cpu(ucode_hdr->offset) +
  1442. le32_to_cpu(ucode_hdr->len) >
  1443. fw->size) {
  1444. wiphy_err(wl->wiphy,
  1445. "%s: conflicting bin/hdr\n",
  1446. __func__);
  1447. rc = -EBADF;
  1448. }
  1449. }
  1450. }
  1451. }
  1452. if (rc == 0 && wl->fw.fw_cnt != i) {
  1453. wiphy_err(wl->wiphy, "%s: invalid fw_cnt=%d\n", __func__,
  1454. wl->fw.fw_cnt);
  1455. rc = -EBADF;
  1456. }
  1457. return rc;
  1458. }
  1459. /*
  1460. * precondition: perimeter lock has been acquired
  1461. */
  1462. bool brcms_rfkill_set_hw_state(struct brcms_info *wl)
  1463. {
  1464. bool blocked = brcms_c_check_radio_disabled(wl->wlc);
  1465. spin_unlock_bh(&wl->lock);
  1466. wiphy_rfkill_set_hw_state(wl->pub->ieee_hw->wiphy, blocked);
  1467. if (blocked)
  1468. wiphy_rfkill_start_polling(wl->pub->ieee_hw->wiphy);
  1469. spin_lock_bh(&wl->lock);
  1470. return blocked;
  1471. }