mac80211_if.c 41 KB

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