mac80211_if.c 41 KB

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