mac80211_if.c 42 KB

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