mac80211_if.c 41 KB

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