mac80211_if.c 40 KB

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