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