mac80211_if.c 41 KB

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