mac80211_if.c 40 KB

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