mac80211_if.c 42 KB

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