mac80211_if.c 42 KB

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