mac80211_if.c 41 KB

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