mac80211_if.c 40 KB

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