mac80211_if.c 41 KB

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