mac80211_if.c 41 KB

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