mac80211_if.c 41 KB

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