mac80211_if.c 41 KB

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