main.c 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793
  1. /*
  2. *
  3. * Broadcom B43legacy wireless driver
  4. *
  5. * Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
  6. * Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
  7. * Copyright (c) 2005, 2006 Michael Buesch <mb@bu3sch.de>
  8. * Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
  9. * Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  10. * Copyright (c) 2007 Larry Finger <Larry.Finger@lwfinger.net>
  11. *
  12. * Some parts of the code in this file are derived from the ipw2200
  13. * driver Copyright(c) 2003 - 2004 Intel Corporation.
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; see the file COPYING. If not, write to
  26. * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  27. * Boston, MA 02110-1301, USA.
  28. *
  29. */
  30. #include <linux/delay.h>
  31. #include <linux/init.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/if_arp.h>
  34. #include <linux/etherdevice.h>
  35. #include <linux/version.h>
  36. #include <linux/firmware.h>
  37. #include <linux/wireless.h>
  38. #include <linux/workqueue.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/dma-mapping.h>
  41. #include <net/dst.h>
  42. #include <asm/unaligned.h>
  43. #include "b43legacy.h"
  44. #include "main.h"
  45. #include "debugfs.h"
  46. #include "phy.h"
  47. #include "dma.h"
  48. #include "pio.h"
  49. #include "sysfs.h"
  50. #include "xmit.h"
  51. #include "radio.h"
  52. MODULE_DESCRIPTION("Broadcom B43legacy wireless driver");
  53. MODULE_AUTHOR("Martin Langer");
  54. MODULE_AUTHOR("Stefano Brivio");
  55. MODULE_AUTHOR("Michael Buesch");
  56. MODULE_LICENSE("GPL");
  57. #if defined(CONFIG_B43LEGACY_DMA) && defined(CONFIG_B43LEGACY_PIO)
  58. static int modparam_pio;
  59. module_param_named(pio, modparam_pio, int, 0444);
  60. MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
  61. #elif defined(CONFIG_B43LEGACY_DMA)
  62. # define modparam_pio 0
  63. #elif defined(CONFIG_B43LEGACY_PIO)
  64. # define modparam_pio 1
  65. #endif
  66. static int modparam_bad_frames_preempt;
  67. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  68. MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames"
  69. " Preemption");
  70. static char modparam_fwpostfix[16];
  71. module_param_string(fwpostfix, modparam_fwpostfix, 16, 0444);
  72. MODULE_PARM_DESC(fwpostfix, "Postfix for the firmware files to load.");
  73. /* The following table supports BCM4301, BCM4303 and BCM4306/2 devices. */
  74. static const struct ssb_device_id b43legacy_ssb_tbl[] = {
  75. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 2),
  76. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 4),
  77. SSB_DEVTABLE_END
  78. };
  79. MODULE_DEVICE_TABLE(ssb, b43legacy_ssb_tbl);
  80. /* Channel and ratetables are shared for all devices.
  81. * They can't be const, because ieee80211 puts some precalculated
  82. * data in there. This data is the same for all devices, so we don't
  83. * get concurrency issues */
  84. #define RATETAB_ENT(_rateid, _flags) \
  85. { \
  86. .rate = B43legacy_RATE_TO_100KBPS(_rateid), \
  87. .val = (_rateid), \
  88. .val2 = (_rateid), \
  89. .flags = (_flags), \
  90. }
  91. static struct ieee80211_rate __b43legacy_ratetable[] = {
  92. RATETAB_ENT(B43legacy_CCK_RATE_1MB, IEEE80211_RATE_CCK),
  93. RATETAB_ENT(B43legacy_CCK_RATE_2MB, IEEE80211_RATE_CCK_2),
  94. RATETAB_ENT(B43legacy_CCK_RATE_5MB, IEEE80211_RATE_CCK_2),
  95. RATETAB_ENT(B43legacy_CCK_RATE_11MB, IEEE80211_RATE_CCK_2),
  96. RATETAB_ENT(B43legacy_OFDM_RATE_6MB, IEEE80211_RATE_OFDM),
  97. RATETAB_ENT(B43legacy_OFDM_RATE_9MB, IEEE80211_RATE_OFDM),
  98. RATETAB_ENT(B43legacy_OFDM_RATE_12MB, IEEE80211_RATE_OFDM),
  99. RATETAB_ENT(B43legacy_OFDM_RATE_18MB, IEEE80211_RATE_OFDM),
  100. RATETAB_ENT(B43legacy_OFDM_RATE_24MB, IEEE80211_RATE_OFDM),
  101. RATETAB_ENT(B43legacy_OFDM_RATE_36MB, IEEE80211_RATE_OFDM),
  102. RATETAB_ENT(B43legacy_OFDM_RATE_48MB, IEEE80211_RATE_OFDM),
  103. RATETAB_ENT(B43legacy_OFDM_RATE_54MB, IEEE80211_RATE_OFDM),
  104. };
  105. #define b43legacy_a_ratetable (__b43legacy_ratetable + 4)
  106. #define b43legacy_a_ratetable_size 8
  107. #define b43legacy_b_ratetable (__b43legacy_ratetable + 0)
  108. #define b43legacy_b_ratetable_size 4
  109. #define b43legacy_g_ratetable (__b43legacy_ratetable + 0)
  110. #define b43legacy_g_ratetable_size 12
  111. #define CHANTAB_ENT(_chanid, _freq) \
  112. { \
  113. .chan = (_chanid), \
  114. .freq = (_freq), \
  115. .val = (_chanid), \
  116. .flag = IEEE80211_CHAN_W_SCAN | \
  117. IEEE80211_CHAN_W_ACTIVE_SCAN | \
  118. IEEE80211_CHAN_W_IBSS, \
  119. .power_level = 0x0A, \
  120. .antenna_max = 0xFF, \
  121. }
  122. static struct ieee80211_channel b43legacy_bg_chantable[] = {
  123. CHANTAB_ENT(1, 2412),
  124. CHANTAB_ENT(2, 2417),
  125. CHANTAB_ENT(3, 2422),
  126. CHANTAB_ENT(4, 2427),
  127. CHANTAB_ENT(5, 2432),
  128. CHANTAB_ENT(6, 2437),
  129. CHANTAB_ENT(7, 2442),
  130. CHANTAB_ENT(8, 2447),
  131. CHANTAB_ENT(9, 2452),
  132. CHANTAB_ENT(10, 2457),
  133. CHANTAB_ENT(11, 2462),
  134. CHANTAB_ENT(12, 2467),
  135. CHANTAB_ENT(13, 2472),
  136. CHANTAB_ENT(14, 2484),
  137. };
  138. #define b43legacy_bg_chantable_size ARRAY_SIZE(b43legacy_bg_chantable)
  139. static void b43legacy_wireless_core_exit(struct b43legacy_wldev *dev);
  140. static int b43legacy_wireless_core_init(struct b43legacy_wldev *dev);
  141. static void b43legacy_wireless_core_stop(struct b43legacy_wldev *dev);
  142. static int b43legacy_wireless_core_start(struct b43legacy_wldev *dev);
  143. static int b43legacy_ratelimit(struct b43legacy_wl *wl)
  144. {
  145. if (!wl || !wl->current_dev)
  146. return 1;
  147. if (b43legacy_status(wl->current_dev) < B43legacy_STAT_STARTED)
  148. return 1;
  149. /* We are up and running.
  150. * Ratelimit the messages to avoid DoS over the net. */
  151. return net_ratelimit();
  152. }
  153. void b43legacyinfo(struct b43legacy_wl *wl, const char *fmt, ...)
  154. {
  155. va_list args;
  156. if (!b43legacy_ratelimit(wl))
  157. return;
  158. va_start(args, fmt);
  159. printk(KERN_INFO "b43legacy-%s: ",
  160. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  161. vprintk(fmt, args);
  162. va_end(args);
  163. }
  164. void b43legacyerr(struct b43legacy_wl *wl, const char *fmt, ...)
  165. {
  166. va_list args;
  167. if (!b43legacy_ratelimit(wl))
  168. return;
  169. va_start(args, fmt);
  170. printk(KERN_ERR "b43legacy-%s ERROR: ",
  171. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  172. vprintk(fmt, args);
  173. va_end(args);
  174. }
  175. void b43legacywarn(struct b43legacy_wl *wl, const char *fmt, ...)
  176. {
  177. va_list args;
  178. if (!b43legacy_ratelimit(wl))
  179. return;
  180. va_start(args, fmt);
  181. printk(KERN_WARNING "b43legacy-%s warning: ",
  182. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  183. vprintk(fmt, args);
  184. va_end(args);
  185. }
  186. #if B43legacy_DEBUG
  187. void b43legacydbg(struct b43legacy_wl *wl, const char *fmt, ...)
  188. {
  189. va_list args;
  190. va_start(args, fmt);
  191. printk(KERN_DEBUG "b43legacy-%s debug: ",
  192. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  193. vprintk(fmt, args);
  194. va_end(args);
  195. }
  196. #endif /* DEBUG */
  197. static void b43legacy_ram_write(struct b43legacy_wldev *dev, u16 offset,
  198. u32 val)
  199. {
  200. u32 status;
  201. B43legacy_WARN_ON(offset % 4 != 0);
  202. status = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  203. if (status & B43legacy_SBF_XFER_REG_BYTESWAP)
  204. val = swab32(val);
  205. b43legacy_write32(dev, B43legacy_MMIO_RAM_CONTROL, offset);
  206. mmiowb();
  207. b43legacy_write32(dev, B43legacy_MMIO_RAM_DATA, val);
  208. }
  209. static inline
  210. void b43legacy_shm_control_word(struct b43legacy_wldev *dev,
  211. u16 routing, u16 offset)
  212. {
  213. u32 control;
  214. /* "offset" is the WORD offset. */
  215. control = routing;
  216. control <<= 16;
  217. control |= offset;
  218. b43legacy_write32(dev, B43legacy_MMIO_SHM_CONTROL, control);
  219. }
  220. u32 b43legacy_shm_read32(struct b43legacy_wldev *dev,
  221. u16 routing, u16 offset)
  222. {
  223. u32 ret;
  224. if (routing == B43legacy_SHM_SHARED) {
  225. B43legacy_WARN_ON((offset & 0x0001) != 0);
  226. if (offset & 0x0003) {
  227. /* Unaligned access */
  228. b43legacy_shm_control_word(dev, routing, offset >> 2);
  229. ret = b43legacy_read16(dev,
  230. B43legacy_MMIO_SHM_DATA_UNALIGNED);
  231. ret <<= 16;
  232. b43legacy_shm_control_word(dev, routing,
  233. (offset >> 2) + 1);
  234. ret |= b43legacy_read16(dev, B43legacy_MMIO_SHM_DATA);
  235. return ret;
  236. }
  237. offset >>= 2;
  238. }
  239. b43legacy_shm_control_word(dev, routing, offset);
  240. ret = b43legacy_read32(dev, B43legacy_MMIO_SHM_DATA);
  241. return ret;
  242. }
  243. u16 b43legacy_shm_read16(struct b43legacy_wldev *dev,
  244. u16 routing, u16 offset)
  245. {
  246. u16 ret;
  247. if (routing == B43legacy_SHM_SHARED) {
  248. B43legacy_WARN_ON((offset & 0x0001) != 0);
  249. if (offset & 0x0003) {
  250. /* Unaligned access */
  251. b43legacy_shm_control_word(dev, routing, offset >> 2);
  252. ret = b43legacy_read16(dev,
  253. B43legacy_MMIO_SHM_DATA_UNALIGNED);
  254. return ret;
  255. }
  256. offset >>= 2;
  257. }
  258. b43legacy_shm_control_word(dev, routing, offset);
  259. ret = b43legacy_read16(dev, B43legacy_MMIO_SHM_DATA);
  260. return ret;
  261. }
  262. void b43legacy_shm_write32(struct b43legacy_wldev *dev,
  263. u16 routing, u16 offset,
  264. u32 value)
  265. {
  266. if (routing == B43legacy_SHM_SHARED) {
  267. B43legacy_WARN_ON((offset & 0x0001) != 0);
  268. if (offset & 0x0003) {
  269. /* Unaligned access */
  270. b43legacy_shm_control_word(dev, routing, offset >> 2);
  271. mmiowb();
  272. b43legacy_write16(dev,
  273. B43legacy_MMIO_SHM_DATA_UNALIGNED,
  274. (value >> 16) & 0xffff);
  275. mmiowb();
  276. b43legacy_shm_control_word(dev, routing,
  277. (offset >> 2) + 1);
  278. mmiowb();
  279. b43legacy_write16(dev, B43legacy_MMIO_SHM_DATA,
  280. value & 0xffff);
  281. return;
  282. }
  283. offset >>= 2;
  284. }
  285. b43legacy_shm_control_word(dev, routing, offset);
  286. mmiowb();
  287. b43legacy_write32(dev, B43legacy_MMIO_SHM_DATA, value);
  288. }
  289. void b43legacy_shm_write16(struct b43legacy_wldev *dev, u16 routing, u16 offset,
  290. u16 value)
  291. {
  292. if (routing == B43legacy_SHM_SHARED) {
  293. B43legacy_WARN_ON((offset & 0x0001) != 0);
  294. if (offset & 0x0003) {
  295. /* Unaligned access */
  296. b43legacy_shm_control_word(dev, routing, offset >> 2);
  297. mmiowb();
  298. b43legacy_write16(dev,
  299. B43legacy_MMIO_SHM_DATA_UNALIGNED,
  300. value);
  301. return;
  302. }
  303. offset >>= 2;
  304. }
  305. b43legacy_shm_control_word(dev, routing, offset);
  306. mmiowb();
  307. b43legacy_write16(dev, B43legacy_MMIO_SHM_DATA, value);
  308. }
  309. /* Read HostFlags */
  310. u32 b43legacy_hf_read(struct b43legacy_wldev *dev)
  311. {
  312. u32 ret;
  313. ret = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  314. B43legacy_SHM_SH_HOSTFHI);
  315. ret <<= 16;
  316. ret |= b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  317. B43legacy_SHM_SH_HOSTFLO);
  318. return ret;
  319. }
  320. /* Write HostFlags */
  321. void b43legacy_hf_write(struct b43legacy_wldev *dev, u32 value)
  322. {
  323. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  324. B43legacy_SHM_SH_HOSTFLO,
  325. (value & 0x0000FFFF));
  326. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  327. B43legacy_SHM_SH_HOSTFHI,
  328. ((value & 0xFFFF0000) >> 16));
  329. }
  330. void b43legacy_tsf_read(struct b43legacy_wldev *dev, u64 *tsf)
  331. {
  332. /* We need to be careful. As we read the TSF from multiple
  333. * registers, we should take care of register overflows.
  334. * In theory, the whole tsf read process should be atomic.
  335. * We try to be atomic here, by restaring the read process,
  336. * if any of the high registers changed (overflew).
  337. */
  338. if (dev->dev->id.revision >= 3) {
  339. u32 low;
  340. u32 high;
  341. u32 high2;
  342. do {
  343. high = b43legacy_read32(dev,
  344. B43legacy_MMIO_REV3PLUS_TSF_HIGH);
  345. low = b43legacy_read32(dev,
  346. B43legacy_MMIO_REV3PLUS_TSF_LOW);
  347. high2 = b43legacy_read32(dev,
  348. B43legacy_MMIO_REV3PLUS_TSF_HIGH);
  349. } while (unlikely(high != high2));
  350. *tsf = high;
  351. *tsf <<= 32;
  352. *tsf |= low;
  353. } else {
  354. u64 tmp;
  355. u16 v0;
  356. u16 v1;
  357. u16 v2;
  358. u16 v3;
  359. u16 test1;
  360. u16 test2;
  361. u16 test3;
  362. do {
  363. v3 = b43legacy_read16(dev, B43legacy_MMIO_TSF_3);
  364. v2 = b43legacy_read16(dev, B43legacy_MMIO_TSF_2);
  365. v1 = b43legacy_read16(dev, B43legacy_MMIO_TSF_1);
  366. v0 = b43legacy_read16(dev, B43legacy_MMIO_TSF_0);
  367. test3 = b43legacy_read16(dev, B43legacy_MMIO_TSF_3);
  368. test2 = b43legacy_read16(dev, B43legacy_MMIO_TSF_2);
  369. test1 = b43legacy_read16(dev, B43legacy_MMIO_TSF_1);
  370. } while (v3 != test3 || v2 != test2 || v1 != test1);
  371. *tsf = v3;
  372. *tsf <<= 48;
  373. tmp = v2;
  374. tmp <<= 32;
  375. *tsf |= tmp;
  376. tmp = v1;
  377. tmp <<= 16;
  378. *tsf |= tmp;
  379. *tsf |= v0;
  380. }
  381. }
  382. static void b43legacy_time_lock(struct b43legacy_wldev *dev)
  383. {
  384. u32 status;
  385. status = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  386. status |= B43legacy_SBF_TIME_UPDATE;
  387. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, status);
  388. mmiowb();
  389. }
  390. static void b43legacy_time_unlock(struct b43legacy_wldev *dev)
  391. {
  392. u32 status;
  393. status = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  394. status &= ~B43legacy_SBF_TIME_UPDATE;
  395. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, status);
  396. }
  397. static void b43legacy_tsf_write_locked(struct b43legacy_wldev *dev, u64 tsf)
  398. {
  399. /* Be careful with the in-progress timer.
  400. * First zero out the low register, so we have a full
  401. * register-overflow duration to complete the operation.
  402. */
  403. if (dev->dev->id.revision >= 3) {
  404. u32 lo = (tsf & 0x00000000FFFFFFFFULL);
  405. u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
  406. b43legacy_write32(dev, B43legacy_MMIO_REV3PLUS_TSF_LOW, 0);
  407. mmiowb();
  408. b43legacy_write32(dev, B43legacy_MMIO_REV3PLUS_TSF_HIGH,
  409. hi);
  410. mmiowb();
  411. b43legacy_write32(dev, B43legacy_MMIO_REV3PLUS_TSF_LOW,
  412. lo);
  413. } else {
  414. u16 v0 = (tsf & 0x000000000000FFFFULL);
  415. u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
  416. u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
  417. u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
  418. b43legacy_write16(dev, B43legacy_MMIO_TSF_0, 0);
  419. mmiowb();
  420. b43legacy_write16(dev, B43legacy_MMIO_TSF_3, v3);
  421. mmiowb();
  422. b43legacy_write16(dev, B43legacy_MMIO_TSF_2, v2);
  423. mmiowb();
  424. b43legacy_write16(dev, B43legacy_MMIO_TSF_1, v1);
  425. mmiowb();
  426. b43legacy_write16(dev, B43legacy_MMIO_TSF_0, v0);
  427. }
  428. }
  429. void b43legacy_tsf_write(struct b43legacy_wldev *dev, u64 tsf)
  430. {
  431. b43legacy_time_lock(dev);
  432. b43legacy_tsf_write_locked(dev, tsf);
  433. b43legacy_time_unlock(dev);
  434. }
  435. static
  436. void b43legacy_macfilter_set(struct b43legacy_wldev *dev,
  437. u16 offset, const u8 *mac)
  438. {
  439. static const u8 zero_addr[ETH_ALEN] = { 0 };
  440. u16 data;
  441. if (!mac)
  442. mac = zero_addr;
  443. offset |= 0x0020;
  444. b43legacy_write16(dev, B43legacy_MMIO_MACFILTER_CONTROL, offset);
  445. data = mac[0];
  446. data |= mac[1] << 8;
  447. b43legacy_write16(dev, B43legacy_MMIO_MACFILTER_DATA, data);
  448. data = mac[2];
  449. data |= mac[3] << 8;
  450. b43legacy_write16(dev, B43legacy_MMIO_MACFILTER_DATA, data);
  451. data = mac[4];
  452. data |= mac[5] << 8;
  453. b43legacy_write16(dev, B43legacy_MMIO_MACFILTER_DATA, data);
  454. }
  455. static void b43legacy_write_mac_bssid_templates(struct b43legacy_wldev *dev)
  456. {
  457. static const u8 zero_addr[ETH_ALEN] = { 0 };
  458. const u8 *mac = dev->wl->mac_addr;
  459. const u8 *bssid = dev->wl->bssid;
  460. u8 mac_bssid[ETH_ALEN * 2];
  461. int i;
  462. u32 tmp;
  463. if (!bssid)
  464. bssid = zero_addr;
  465. if (!mac)
  466. mac = zero_addr;
  467. b43legacy_macfilter_set(dev, B43legacy_MACFILTER_BSSID, bssid);
  468. memcpy(mac_bssid, mac, ETH_ALEN);
  469. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  470. /* Write our MAC address and BSSID to template ram */
  471. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32)) {
  472. tmp = (u32)(mac_bssid[i + 0]);
  473. tmp |= (u32)(mac_bssid[i + 1]) << 8;
  474. tmp |= (u32)(mac_bssid[i + 2]) << 16;
  475. tmp |= (u32)(mac_bssid[i + 3]) << 24;
  476. b43legacy_ram_write(dev, 0x20 + i, tmp);
  477. b43legacy_ram_write(dev, 0x78 + i, tmp);
  478. b43legacy_ram_write(dev, 0x478 + i, tmp);
  479. }
  480. }
  481. static void b43legacy_upload_card_macaddress(struct b43legacy_wldev *dev)
  482. {
  483. b43legacy_write_mac_bssid_templates(dev);
  484. b43legacy_macfilter_set(dev, B43legacy_MACFILTER_SELF,
  485. dev->wl->mac_addr);
  486. }
  487. static void b43legacy_set_slot_time(struct b43legacy_wldev *dev,
  488. u16 slot_time)
  489. {
  490. /* slot_time is in usec. */
  491. if (dev->phy.type != B43legacy_PHYTYPE_G)
  492. return;
  493. b43legacy_write16(dev, 0x684, 510 + slot_time);
  494. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x0010,
  495. slot_time);
  496. }
  497. static void b43legacy_short_slot_timing_enable(struct b43legacy_wldev *dev)
  498. {
  499. b43legacy_set_slot_time(dev, 9);
  500. dev->short_slot = 1;
  501. }
  502. static void b43legacy_short_slot_timing_disable(struct b43legacy_wldev *dev)
  503. {
  504. b43legacy_set_slot_time(dev, 20);
  505. dev->short_slot = 0;
  506. }
  507. /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
  508. * Returns the _previously_ enabled IRQ mask.
  509. */
  510. static inline u32 b43legacy_interrupt_enable(struct b43legacy_wldev *dev,
  511. u32 mask)
  512. {
  513. u32 old_mask;
  514. old_mask = b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_MASK);
  515. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_MASK, old_mask |
  516. mask);
  517. return old_mask;
  518. }
  519. /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
  520. * Returns the _previously_ enabled IRQ mask.
  521. */
  522. static inline u32 b43legacy_interrupt_disable(struct b43legacy_wldev *dev,
  523. u32 mask)
  524. {
  525. u32 old_mask;
  526. old_mask = b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_MASK);
  527. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
  528. return old_mask;
  529. }
  530. /* Synchronize IRQ top- and bottom-half.
  531. * IRQs must be masked before calling this.
  532. * This must not be called with the irq_lock held.
  533. */
  534. static void b43legacy_synchronize_irq(struct b43legacy_wldev *dev)
  535. {
  536. synchronize_irq(dev->dev->irq);
  537. tasklet_kill(&dev->isr_tasklet);
  538. }
  539. /* DummyTransmission function, as documented on
  540. * http://bcm-specs.sipsolutions.net/DummyTransmission
  541. */
  542. void b43legacy_dummy_transmission(struct b43legacy_wldev *dev)
  543. {
  544. struct b43legacy_phy *phy = &dev->phy;
  545. unsigned int i;
  546. unsigned int max_loop;
  547. u16 value;
  548. u32 buffer[5] = {
  549. 0x00000000,
  550. 0x00D40000,
  551. 0x00000000,
  552. 0x01000000,
  553. 0x00000000,
  554. };
  555. switch (phy->type) {
  556. case B43legacy_PHYTYPE_B:
  557. case B43legacy_PHYTYPE_G:
  558. max_loop = 0xFA;
  559. buffer[0] = 0x000B846E;
  560. break;
  561. default:
  562. B43legacy_BUG_ON(1);
  563. return;
  564. }
  565. for (i = 0; i < 5; i++)
  566. b43legacy_ram_write(dev, i * 4, buffer[i]);
  567. /* dummy read follows */
  568. b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  569. b43legacy_write16(dev, 0x0568, 0x0000);
  570. b43legacy_write16(dev, 0x07C0, 0x0000);
  571. b43legacy_write16(dev, 0x050C, 0x0000);
  572. b43legacy_write16(dev, 0x0508, 0x0000);
  573. b43legacy_write16(dev, 0x050A, 0x0000);
  574. b43legacy_write16(dev, 0x054C, 0x0000);
  575. b43legacy_write16(dev, 0x056A, 0x0014);
  576. b43legacy_write16(dev, 0x0568, 0x0826);
  577. b43legacy_write16(dev, 0x0500, 0x0000);
  578. b43legacy_write16(dev, 0x0502, 0x0030);
  579. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  580. b43legacy_radio_write16(dev, 0x0051, 0x0017);
  581. for (i = 0x00; i < max_loop; i++) {
  582. value = b43legacy_read16(dev, 0x050E);
  583. if (value & 0x0080)
  584. break;
  585. udelay(10);
  586. }
  587. for (i = 0x00; i < 0x0A; i++) {
  588. value = b43legacy_read16(dev, 0x050E);
  589. if (value & 0x0400)
  590. break;
  591. udelay(10);
  592. }
  593. for (i = 0x00; i < 0x0A; i++) {
  594. value = b43legacy_read16(dev, 0x0690);
  595. if (!(value & 0x0100))
  596. break;
  597. udelay(10);
  598. }
  599. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  600. b43legacy_radio_write16(dev, 0x0051, 0x0037);
  601. }
  602. /* Turn the Analog ON/OFF */
  603. static void b43legacy_switch_analog(struct b43legacy_wldev *dev, int on)
  604. {
  605. b43legacy_write16(dev, B43legacy_MMIO_PHY0, on ? 0 : 0xF4);
  606. }
  607. void b43legacy_wireless_core_reset(struct b43legacy_wldev *dev, u32 flags)
  608. {
  609. u32 tmslow;
  610. u32 macctl;
  611. flags |= B43legacy_TMSLOW_PHYCLKEN;
  612. flags |= B43legacy_TMSLOW_PHYRESET;
  613. ssb_device_enable(dev->dev, flags);
  614. msleep(2); /* Wait for the PLL to turn on. */
  615. /* Now take the PHY out of Reset again */
  616. tmslow = ssb_read32(dev->dev, SSB_TMSLOW);
  617. tmslow |= SSB_TMSLOW_FGC;
  618. tmslow &= ~B43legacy_TMSLOW_PHYRESET;
  619. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  620. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  621. msleep(1);
  622. tmslow &= ~SSB_TMSLOW_FGC;
  623. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  624. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  625. msleep(1);
  626. /* Turn Analog ON */
  627. b43legacy_switch_analog(dev, 1);
  628. macctl = b43legacy_read32(dev, B43legacy_MMIO_MACCTL);
  629. macctl &= ~B43legacy_MACCTL_GMODE;
  630. if (flags & B43legacy_TMSLOW_GMODE) {
  631. macctl |= B43legacy_MACCTL_GMODE;
  632. dev->phy.gmode = 1;
  633. } else
  634. dev->phy.gmode = 0;
  635. macctl |= B43legacy_MACCTL_IHR_ENABLED;
  636. b43legacy_write32(dev, B43legacy_MMIO_MACCTL, macctl);
  637. }
  638. static void handle_irq_transmit_status(struct b43legacy_wldev *dev)
  639. {
  640. u32 v0;
  641. u32 v1;
  642. u16 tmp;
  643. struct b43legacy_txstatus stat;
  644. while (1) {
  645. v0 = b43legacy_read32(dev, B43legacy_MMIO_XMITSTAT_0);
  646. if (!(v0 & 0x00000001))
  647. break;
  648. v1 = b43legacy_read32(dev, B43legacy_MMIO_XMITSTAT_1);
  649. stat.cookie = (v0 >> 16);
  650. stat.seq = (v1 & 0x0000FFFF);
  651. stat.phy_stat = ((v1 & 0x00FF0000) >> 16);
  652. tmp = (v0 & 0x0000FFFF);
  653. stat.frame_count = ((tmp & 0xF000) >> 12);
  654. stat.rts_count = ((tmp & 0x0F00) >> 8);
  655. stat.supp_reason = ((tmp & 0x001C) >> 2);
  656. stat.pm_indicated = !!(tmp & 0x0080);
  657. stat.intermediate = !!(tmp & 0x0040);
  658. stat.for_ampdu = !!(tmp & 0x0020);
  659. stat.acked = !!(tmp & 0x0002);
  660. b43legacy_handle_txstatus(dev, &stat);
  661. }
  662. }
  663. static void drain_txstatus_queue(struct b43legacy_wldev *dev)
  664. {
  665. u32 dummy;
  666. if (dev->dev->id.revision < 5)
  667. return;
  668. /* Read all entries from the microcode TXstatus FIFO
  669. * and throw them away.
  670. */
  671. while (1) {
  672. dummy = b43legacy_read32(dev, B43legacy_MMIO_XMITSTAT_0);
  673. if (!(dummy & 0x00000001))
  674. break;
  675. dummy = b43legacy_read32(dev, B43legacy_MMIO_XMITSTAT_1);
  676. }
  677. }
  678. static u32 b43legacy_jssi_read(struct b43legacy_wldev *dev)
  679. {
  680. u32 val = 0;
  681. val = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED, 0x40A);
  682. val <<= 16;
  683. val |= b43legacy_shm_read16(dev, B43legacy_SHM_SHARED, 0x408);
  684. return val;
  685. }
  686. static void b43legacy_jssi_write(struct b43legacy_wldev *dev, u32 jssi)
  687. {
  688. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x408,
  689. (jssi & 0x0000FFFF));
  690. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x40A,
  691. (jssi & 0xFFFF0000) >> 16);
  692. }
  693. static void b43legacy_generate_noise_sample(struct b43legacy_wldev *dev)
  694. {
  695. b43legacy_jssi_write(dev, 0x7F7F7F7F);
  696. b43legacy_write32(dev, B43legacy_MMIO_STATUS2_BITFIELD,
  697. b43legacy_read32(dev,
  698. B43legacy_MMIO_STATUS2_BITFIELD)
  699. | (1 << 4));
  700. B43legacy_WARN_ON(dev->noisecalc.channel_at_start !=
  701. dev->phy.channel);
  702. }
  703. static void b43legacy_calculate_link_quality(struct b43legacy_wldev *dev)
  704. {
  705. /* Top half of Link Quality calculation. */
  706. if (dev->noisecalc.calculation_running)
  707. return;
  708. dev->noisecalc.channel_at_start = dev->phy.channel;
  709. dev->noisecalc.calculation_running = 1;
  710. dev->noisecalc.nr_samples = 0;
  711. b43legacy_generate_noise_sample(dev);
  712. }
  713. static void handle_irq_noise(struct b43legacy_wldev *dev)
  714. {
  715. struct b43legacy_phy *phy = &dev->phy;
  716. u16 tmp;
  717. u8 noise[4];
  718. u8 i;
  719. u8 j;
  720. s32 average;
  721. /* Bottom half of Link Quality calculation. */
  722. B43legacy_WARN_ON(!dev->noisecalc.calculation_running);
  723. if (dev->noisecalc.channel_at_start != phy->channel)
  724. goto drop_calculation;
  725. *((__le32 *)noise) = cpu_to_le32(b43legacy_jssi_read(dev));
  726. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  727. noise[2] == 0x7F || noise[3] == 0x7F)
  728. goto generate_new;
  729. /* Get the noise samples. */
  730. B43legacy_WARN_ON(dev->noisecalc.nr_samples >= 8);
  731. i = dev->noisecalc.nr_samples;
  732. noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  733. noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  734. noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  735. noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  736. dev->noisecalc.samples[i][0] = phy->nrssi_lt[noise[0]];
  737. dev->noisecalc.samples[i][1] = phy->nrssi_lt[noise[1]];
  738. dev->noisecalc.samples[i][2] = phy->nrssi_lt[noise[2]];
  739. dev->noisecalc.samples[i][3] = phy->nrssi_lt[noise[3]];
  740. dev->noisecalc.nr_samples++;
  741. if (dev->noisecalc.nr_samples == 8) {
  742. /* Calculate the Link Quality by the noise samples. */
  743. average = 0;
  744. for (i = 0; i < 8; i++) {
  745. for (j = 0; j < 4; j++)
  746. average += dev->noisecalc.samples[i][j];
  747. }
  748. average /= (8 * 4);
  749. average *= 125;
  750. average += 64;
  751. average /= 128;
  752. tmp = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  753. 0x40C);
  754. tmp = (tmp / 128) & 0x1F;
  755. if (tmp >= 8)
  756. average += 2;
  757. else
  758. average -= 25;
  759. if (tmp == 8)
  760. average -= 72;
  761. else
  762. average -= 48;
  763. dev->stats.link_noise = average;
  764. drop_calculation:
  765. dev->noisecalc.calculation_running = 0;
  766. return;
  767. }
  768. generate_new:
  769. b43legacy_generate_noise_sample(dev);
  770. }
  771. static void handle_irq_tbtt_indication(struct b43legacy_wldev *dev)
  772. {
  773. if (b43legacy_is_mode(dev->wl, IEEE80211_IF_TYPE_AP)) {
  774. /* TODO: PS TBTT */
  775. } else {
  776. if (1/*FIXME: the last PSpoll frame was sent successfully */)
  777. b43legacy_power_saving_ctl_bits(dev, -1, -1);
  778. }
  779. dev->reg124_set_0x4 = 0;
  780. if (b43legacy_is_mode(dev->wl, IEEE80211_IF_TYPE_IBSS))
  781. dev->reg124_set_0x4 = 1;
  782. }
  783. static void handle_irq_atim_end(struct b43legacy_wldev *dev)
  784. {
  785. if (!dev->reg124_set_0x4) /*FIXME rename this variable*/
  786. return;
  787. b43legacy_write32(dev, B43legacy_MMIO_STATUS2_BITFIELD,
  788. b43legacy_read32(dev, B43legacy_MMIO_STATUS2_BITFIELD)
  789. | 0x4);
  790. }
  791. static void handle_irq_pmq(struct b43legacy_wldev *dev)
  792. {
  793. u32 tmp;
  794. /* TODO: AP mode. */
  795. while (1) {
  796. tmp = b43legacy_read32(dev, B43legacy_MMIO_PS_STATUS);
  797. if (!(tmp & 0x00000008))
  798. break;
  799. }
  800. /* 16bit write is odd, but correct. */
  801. b43legacy_write16(dev, B43legacy_MMIO_PS_STATUS, 0x0002);
  802. }
  803. static void b43legacy_write_template_common(struct b43legacy_wldev *dev,
  804. const u8 *data, u16 size,
  805. u16 ram_offset,
  806. u16 shm_size_offset, u8 rate)
  807. {
  808. u32 i;
  809. u32 tmp;
  810. struct b43legacy_plcp_hdr4 plcp;
  811. plcp.data = 0;
  812. b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  813. b43legacy_ram_write(dev, ram_offset, le32_to_cpu(plcp.data));
  814. ram_offset += sizeof(u32);
  815. /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
  816. * So leave the first two bytes of the next write blank.
  817. */
  818. tmp = (u32)(data[0]) << 16;
  819. tmp |= (u32)(data[1]) << 24;
  820. b43legacy_ram_write(dev, ram_offset, tmp);
  821. ram_offset += sizeof(u32);
  822. for (i = 2; i < size; i += sizeof(u32)) {
  823. tmp = (u32)(data[i + 0]);
  824. if (i + 1 < size)
  825. tmp |= (u32)(data[i + 1]) << 8;
  826. if (i + 2 < size)
  827. tmp |= (u32)(data[i + 2]) << 16;
  828. if (i + 3 < size)
  829. tmp |= (u32)(data[i + 3]) << 24;
  830. b43legacy_ram_write(dev, ram_offset + i - 2, tmp);
  831. }
  832. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, shm_size_offset,
  833. size + sizeof(struct b43legacy_plcp_hdr6));
  834. }
  835. static void b43legacy_write_beacon_template(struct b43legacy_wldev *dev,
  836. u16 ram_offset,
  837. u16 shm_size_offset, u8 rate)
  838. {
  839. int len;
  840. const u8 *data;
  841. B43legacy_WARN_ON(!dev->cached_beacon);
  842. len = min((size_t)dev->cached_beacon->len,
  843. 0x200 - sizeof(struct b43legacy_plcp_hdr6));
  844. data = (const u8 *)(dev->cached_beacon->data);
  845. b43legacy_write_template_common(dev, data,
  846. len, ram_offset,
  847. shm_size_offset, rate);
  848. }
  849. static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev,
  850. u16 shm_offset, u16 size,
  851. u8 rate)
  852. {
  853. struct b43legacy_plcp_hdr4 plcp;
  854. u32 tmp;
  855. __le16 dur;
  856. plcp.data = 0;
  857. b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  858. dur = ieee80211_generic_frame_duration(dev->wl->hw,
  859. dev->wl->if_id,
  860. size,
  861. B43legacy_RATE_TO_100KBPS(rate));
  862. /* Write PLCP in two parts and timing for packet transfer */
  863. tmp = le32_to_cpu(plcp.data);
  864. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, shm_offset,
  865. tmp & 0xFFFF);
  866. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, shm_offset + 2,
  867. tmp >> 16);
  868. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, shm_offset + 6,
  869. le16_to_cpu(dur));
  870. }
  871. /* Instead of using custom probe response template, this function
  872. * just patches custom beacon template by:
  873. * 1) Changing packet type
  874. * 2) Patching duration field
  875. * 3) Stripping TIM
  876. */
  877. static u8 *b43legacy_generate_probe_resp(struct b43legacy_wldev *dev,
  878. u16 *dest_size, u8 rate)
  879. {
  880. const u8 *src_data;
  881. u8 *dest_data;
  882. u16 src_size;
  883. u16 elem_size;
  884. u16 src_pos;
  885. u16 dest_pos;
  886. __le16 dur;
  887. struct ieee80211_hdr *hdr;
  888. B43legacy_WARN_ON(!dev->cached_beacon);
  889. src_size = dev->cached_beacon->len;
  890. src_data = (const u8 *)dev->cached_beacon->data;
  891. if (unlikely(src_size < 0x24)) {
  892. b43legacydbg(dev->wl, "b43legacy_generate_probe_resp: "
  893. "invalid beacon\n");
  894. return NULL;
  895. }
  896. dest_data = kmalloc(src_size, GFP_ATOMIC);
  897. if (unlikely(!dest_data))
  898. return NULL;
  899. /* 0x24 is offset of first variable-len Information-Element
  900. * in beacon frame.
  901. */
  902. memcpy(dest_data, src_data, 0x24);
  903. src_pos = 0x24;
  904. dest_pos = 0x24;
  905. for (; src_pos < src_size - 2; src_pos += elem_size) {
  906. elem_size = src_data[src_pos + 1] + 2;
  907. if (src_data[src_pos] != 0x05) { /* TIM */
  908. memcpy(dest_data + dest_pos, src_data + src_pos,
  909. elem_size);
  910. dest_pos += elem_size;
  911. }
  912. }
  913. *dest_size = dest_pos;
  914. hdr = (struct ieee80211_hdr *)dest_data;
  915. /* Set the frame control. */
  916. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  917. IEEE80211_STYPE_PROBE_RESP);
  918. dur = ieee80211_generic_frame_duration(dev->wl->hw,
  919. dev->wl->if_id,
  920. *dest_size,
  921. B43legacy_RATE_TO_100KBPS(rate));
  922. hdr->duration_id = dur;
  923. return dest_data;
  924. }
  925. static void b43legacy_write_probe_resp_template(struct b43legacy_wldev *dev,
  926. u16 ram_offset,
  927. u16 shm_size_offset, u8 rate)
  928. {
  929. u8 *probe_resp_data;
  930. u16 size;
  931. B43legacy_WARN_ON(!dev->cached_beacon);
  932. size = dev->cached_beacon->len;
  933. probe_resp_data = b43legacy_generate_probe_resp(dev, &size, rate);
  934. if (unlikely(!probe_resp_data))
  935. return;
  936. /* Looks like PLCP headers plus packet timings are stored for
  937. * all possible basic rates
  938. */
  939. b43legacy_write_probe_resp_plcp(dev, 0x31A, size,
  940. B43legacy_CCK_RATE_1MB);
  941. b43legacy_write_probe_resp_plcp(dev, 0x32C, size,
  942. B43legacy_CCK_RATE_2MB);
  943. b43legacy_write_probe_resp_plcp(dev, 0x33E, size,
  944. B43legacy_CCK_RATE_5MB);
  945. b43legacy_write_probe_resp_plcp(dev, 0x350, size,
  946. B43legacy_CCK_RATE_11MB);
  947. size = min((size_t)size,
  948. 0x200 - sizeof(struct b43legacy_plcp_hdr6));
  949. b43legacy_write_template_common(dev, probe_resp_data,
  950. size, ram_offset,
  951. shm_size_offset, rate);
  952. kfree(probe_resp_data);
  953. }
  954. static int b43legacy_refresh_cached_beacon(struct b43legacy_wldev *dev,
  955. struct sk_buff *beacon)
  956. {
  957. if (dev->cached_beacon)
  958. kfree_skb(dev->cached_beacon);
  959. dev->cached_beacon = beacon;
  960. return 0;
  961. }
  962. static void b43legacy_update_templates(struct b43legacy_wldev *dev)
  963. {
  964. u32 status;
  965. B43legacy_WARN_ON(!dev->cached_beacon);
  966. b43legacy_write_beacon_template(dev, 0x68, 0x18,
  967. B43legacy_CCK_RATE_1MB);
  968. b43legacy_write_beacon_template(dev, 0x468, 0x1A,
  969. B43legacy_CCK_RATE_1MB);
  970. b43legacy_write_probe_resp_template(dev, 0x268, 0x4A,
  971. B43legacy_CCK_RATE_11MB);
  972. status = b43legacy_read32(dev, B43legacy_MMIO_STATUS2_BITFIELD);
  973. status |= 0x03;
  974. b43legacy_write32(dev, B43legacy_MMIO_STATUS2_BITFIELD, status);
  975. }
  976. static void b43legacy_refresh_templates(struct b43legacy_wldev *dev,
  977. struct sk_buff *beacon)
  978. {
  979. int err;
  980. err = b43legacy_refresh_cached_beacon(dev, beacon);
  981. if (unlikely(err))
  982. return;
  983. b43legacy_update_templates(dev);
  984. }
  985. static void b43legacy_set_ssid(struct b43legacy_wldev *dev,
  986. const u8 *ssid, u8 ssid_len)
  987. {
  988. u32 tmp;
  989. u16 i;
  990. u16 len;
  991. len = min((u16)ssid_len, (u16)0x100);
  992. for (i = 0; i < len; i += sizeof(u32)) {
  993. tmp = (u32)(ssid[i + 0]);
  994. if (i + 1 < len)
  995. tmp |= (u32)(ssid[i + 1]) << 8;
  996. if (i + 2 < len)
  997. tmp |= (u32)(ssid[i + 2]) << 16;
  998. if (i + 3 < len)
  999. tmp |= (u32)(ssid[i + 3]) << 24;
  1000. b43legacy_shm_write32(dev, B43legacy_SHM_SHARED,
  1001. 0x380 + i, tmp);
  1002. }
  1003. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  1004. 0x48, len);
  1005. }
  1006. static void b43legacy_set_beacon_int(struct b43legacy_wldev *dev,
  1007. u16 beacon_int)
  1008. {
  1009. b43legacy_time_lock(dev);
  1010. if (dev->dev->id.revision >= 3)
  1011. b43legacy_write32(dev, 0x188, (beacon_int << 16));
  1012. else {
  1013. b43legacy_write16(dev, 0x606, (beacon_int >> 6));
  1014. b43legacy_write16(dev, 0x610, beacon_int);
  1015. }
  1016. b43legacy_time_unlock(dev);
  1017. }
  1018. static void handle_irq_beacon(struct b43legacy_wldev *dev)
  1019. {
  1020. u32 status;
  1021. if (!b43legacy_is_mode(dev->wl, IEEE80211_IF_TYPE_AP))
  1022. return;
  1023. dev->irq_savedstate &= ~B43legacy_IRQ_BEACON;
  1024. status = b43legacy_read32(dev, B43legacy_MMIO_STATUS2_BITFIELD);
  1025. if (!dev->cached_beacon || ((status & 0x1) && (status & 0x2))) {
  1026. /* ACK beacon IRQ. */
  1027. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_REASON,
  1028. B43legacy_IRQ_BEACON);
  1029. dev->irq_savedstate |= B43legacy_IRQ_BEACON;
  1030. if (dev->cached_beacon)
  1031. kfree_skb(dev->cached_beacon);
  1032. dev->cached_beacon = NULL;
  1033. return;
  1034. }
  1035. if (!(status & 0x1)) {
  1036. b43legacy_write_beacon_template(dev, 0x68, 0x18,
  1037. B43legacy_CCK_RATE_1MB);
  1038. status |= 0x1;
  1039. b43legacy_write32(dev, B43legacy_MMIO_STATUS2_BITFIELD,
  1040. status);
  1041. }
  1042. if (!(status & 0x2)) {
  1043. b43legacy_write_beacon_template(dev, 0x468, 0x1A,
  1044. B43legacy_CCK_RATE_1MB);
  1045. status |= 0x2;
  1046. b43legacy_write32(dev, B43legacy_MMIO_STATUS2_BITFIELD,
  1047. status);
  1048. }
  1049. }
  1050. static void handle_irq_ucode_debug(struct b43legacy_wldev *dev)
  1051. {
  1052. }
  1053. /* Interrupt handler bottom-half */
  1054. static void b43legacy_interrupt_tasklet(struct b43legacy_wldev *dev)
  1055. {
  1056. u32 reason;
  1057. u32 dma_reason[ARRAY_SIZE(dev->dma_reason)];
  1058. u32 merged_dma_reason = 0;
  1059. int i;
  1060. unsigned long flags;
  1061. spin_lock_irqsave(&dev->wl->irq_lock, flags);
  1062. B43legacy_WARN_ON(b43legacy_status(dev) <
  1063. B43legacy_STAT_INITIALIZED);
  1064. reason = dev->irq_reason;
  1065. for (i = 0; i < ARRAY_SIZE(dma_reason); i++) {
  1066. dma_reason[i] = dev->dma_reason[i];
  1067. merged_dma_reason |= dma_reason[i];
  1068. }
  1069. if (unlikely(reason & B43legacy_IRQ_MAC_TXERR))
  1070. b43legacyerr(dev->wl, "MAC transmission error\n");
  1071. if (unlikely(reason & B43legacy_IRQ_PHY_TXERR)) {
  1072. b43legacyerr(dev->wl, "PHY transmission error\n");
  1073. rmb();
  1074. if (unlikely(atomic_dec_and_test(&dev->phy.txerr_cnt))) {
  1075. b43legacyerr(dev->wl, "Too many PHY TX errors, "
  1076. "restarting the controller\n");
  1077. b43legacy_controller_restart(dev, "PHY TX errors");
  1078. }
  1079. }
  1080. if (unlikely(merged_dma_reason & (B43legacy_DMAIRQ_FATALMASK |
  1081. B43legacy_DMAIRQ_NONFATALMASK))) {
  1082. if (merged_dma_reason & B43legacy_DMAIRQ_FATALMASK) {
  1083. b43legacyerr(dev->wl, "Fatal DMA error: "
  1084. "0x%08X, 0x%08X, 0x%08X, "
  1085. "0x%08X, 0x%08X, 0x%08X\n",
  1086. dma_reason[0], dma_reason[1],
  1087. dma_reason[2], dma_reason[3],
  1088. dma_reason[4], dma_reason[5]);
  1089. b43legacy_controller_restart(dev, "DMA error");
  1090. mmiowb();
  1091. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1092. return;
  1093. }
  1094. if (merged_dma_reason & B43legacy_DMAIRQ_NONFATALMASK)
  1095. b43legacyerr(dev->wl, "DMA error: "
  1096. "0x%08X, 0x%08X, 0x%08X, "
  1097. "0x%08X, 0x%08X, 0x%08X\n",
  1098. dma_reason[0], dma_reason[1],
  1099. dma_reason[2], dma_reason[3],
  1100. dma_reason[4], dma_reason[5]);
  1101. }
  1102. if (unlikely(reason & B43legacy_IRQ_UCODE_DEBUG))
  1103. handle_irq_ucode_debug(dev);
  1104. if (reason & B43legacy_IRQ_TBTT_INDI)
  1105. handle_irq_tbtt_indication(dev);
  1106. if (reason & B43legacy_IRQ_ATIM_END)
  1107. handle_irq_atim_end(dev);
  1108. if (reason & B43legacy_IRQ_BEACON)
  1109. handle_irq_beacon(dev);
  1110. if (reason & B43legacy_IRQ_PMQ)
  1111. handle_irq_pmq(dev);
  1112. if (reason & B43legacy_IRQ_TXFIFO_FLUSH_OK)
  1113. ;/*TODO*/
  1114. if (reason & B43legacy_IRQ_NOISESAMPLE_OK)
  1115. handle_irq_noise(dev);
  1116. /* Check the DMA reason registers for received data. */
  1117. if (dma_reason[0] & B43legacy_DMAIRQ_RX_DONE) {
  1118. if (b43legacy_using_pio(dev))
  1119. b43legacy_pio_rx(dev->pio.queue0);
  1120. else
  1121. b43legacy_dma_rx(dev->dma.rx_ring0);
  1122. }
  1123. B43legacy_WARN_ON(dma_reason[1] & B43legacy_DMAIRQ_RX_DONE);
  1124. B43legacy_WARN_ON(dma_reason[2] & B43legacy_DMAIRQ_RX_DONE);
  1125. if (dma_reason[3] & B43legacy_DMAIRQ_RX_DONE) {
  1126. if (b43legacy_using_pio(dev))
  1127. b43legacy_pio_rx(dev->pio.queue3);
  1128. else
  1129. b43legacy_dma_rx(dev->dma.rx_ring3);
  1130. }
  1131. B43legacy_WARN_ON(dma_reason[4] & B43legacy_DMAIRQ_RX_DONE);
  1132. B43legacy_WARN_ON(dma_reason[5] & B43legacy_DMAIRQ_RX_DONE);
  1133. if (reason & B43legacy_IRQ_TX_OK)
  1134. handle_irq_transmit_status(dev);
  1135. b43legacy_interrupt_enable(dev, dev->irq_savedstate);
  1136. mmiowb();
  1137. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1138. }
  1139. static void pio_irq_workaround(struct b43legacy_wldev *dev,
  1140. u16 base, int queueidx)
  1141. {
  1142. u16 rxctl;
  1143. rxctl = b43legacy_read16(dev, base + B43legacy_PIO_RXCTL);
  1144. if (rxctl & B43legacy_PIO_RXCTL_DATAAVAILABLE)
  1145. dev->dma_reason[queueidx] |= B43legacy_DMAIRQ_RX_DONE;
  1146. else
  1147. dev->dma_reason[queueidx] &= ~B43legacy_DMAIRQ_RX_DONE;
  1148. }
  1149. static void b43legacy_interrupt_ack(struct b43legacy_wldev *dev, u32 reason)
  1150. {
  1151. if (b43legacy_using_pio(dev) &&
  1152. (dev->dev->id.revision < 3) &&
  1153. (!(reason & B43legacy_IRQ_PIO_WORKAROUND))) {
  1154. /* Apply a PIO specific workaround to the dma_reasons */
  1155. pio_irq_workaround(dev, B43legacy_MMIO_PIO1_BASE, 0);
  1156. pio_irq_workaround(dev, B43legacy_MMIO_PIO2_BASE, 1);
  1157. pio_irq_workaround(dev, B43legacy_MMIO_PIO3_BASE, 2);
  1158. pio_irq_workaround(dev, B43legacy_MMIO_PIO4_BASE, 3);
  1159. }
  1160. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_REASON, reason);
  1161. b43legacy_write32(dev, B43legacy_MMIO_DMA0_REASON,
  1162. dev->dma_reason[0]);
  1163. b43legacy_write32(dev, B43legacy_MMIO_DMA1_REASON,
  1164. dev->dma_reason[1]);
  1165. b43legacy_write32(dev, B43legacy_MMIO_DMA2_REASON,
  1166. dev->dma_reason[2]);
  1167. b43legacy_write32(dev, B43legacy_MMIO_DMA3_REASON,
  1168. dev->dma_reason[3]);
  1169. b43legacy_write32(dev, B43legacy_MMIO_DMA4_REASON,
  1170. dev->dma_reason[4]);
  1171. b43legacy_write32(dev, B43legacy_MMIO_DMA5_REASON,
  1172. dev->dma_reason[5]);
  1173. }
  1174. /* Interrupt handler top-half */
  1175. static irqreturn_t b43legacy_interrupt_handler(int irq, void *dev_id)
  1176. {
  1177. irqreturn_t ret = IRQ_NONE;
  1178. struct b43legacy_wldev *dev = dev_id;
  1179. u32 reason;
  1180. if (!dev)
  1181. return IRQ_NONE;
  1182. spin_lock(&dev->wl->irq_lock);
  1183. if (b43legacy_status(dev) < B43legacy_STAT_STARTED)
  1184. goto out;
  1185. reason = b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_REASON);
  1186. if (reason == 0xffffffff) /* shared IRQ */
  1187. goto out;
  1188. ret = IRQ_HANDLED;
  1189. reason &= b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_MASK);
  1190. if (!reason)
  1191. goto out;
  1192. dev->dma_reason[0] = b43legacy_read32(dev,
  1193. B43legacy_MMIO_DMA0_REASON)
  1194. & 0x0001DC00;
  1195. dev->dma_reason[1] = b43legacy_read32(dev,
  1196. B43legacy_MMIO_DMA1_REASON)
  1197. & 0x0000DC00;
  1198. dev->dma_reason[2] = b43legacy_read32(dev,
  1199. B43legacy_MMIO_DMA2_REASON)
  1200. & 0x0000DC00;
  1201. dev->dma_reason[3] = b43legacy_read32(dev,
  1202. B43legacy_MMIO_DMA3_REASON)
  1203. & 0x0001DC00;
  1204. dev->dma_reason[4] = b43legacy_read32(dev,
  1205. B43legacy_MMIO_DMA4_REASON)
  1206. & 0x0000DC00;
  1207. dev->dma_reason[5] = b43legacy_read32(dev,
  1208. B43legacy_MMIO_DMA5_REASON)
  1209. & 0x0000DC00;
  1210. b43legacy_interrupt_ack(dev, reason);
  1211. /* disable all IRQs. They are enabled again in the bottom half. */
  1212. dev->irq_savedstate = b43legacy_interrupt_disable(dev,
  1213. B43legacy_IRQ_ALL);
  1214. /* save the reason code and call our bottom half. */
  1215. dev->irq_reason = reason;
  1216. tasklet_schedule(&dev->isr_tasklet);
  1217. out:
  1218. mmiowb();
  1219. spin_unlock(&dev->wl->irq_lock);
  1220. return ret;
  1221. }
  1222. static void b43legacy_release_firmware(struct b43legacy_wldev *dev)
  1223. {
  1224. release_firmware(dev->fw.ucode);
  1225. dev->fw.ucode = NULL;
  1226. release_firmware(dev->fw.pcm);
  1227. dev->fw.pcm = NULL;
  1228. release_firmware(dev->fw.initvals);
  1229. dev->fw.initvals = NULL;
  1230. release_firmware(dev->fw.initvals_band);
  1231. dev->fw.initvals_band = NULL;
  1232. }
  1233. static void b43legacy_print_fw_helptext(struct b43legacy_wl *wl)
  1234. {
  1235. b43legacyerr(wl, "You must go to http://linuxwireless.org/en/users/"
  1236. "Drivers/b43#devicefirmware "
  1237. "and download the correct firmware (version 3).\n");
  1238. }
  1239. static int do_request_fw(struct b43legacy_wldev *dev,
  1240. const char *name,
  1241. const struct firmware **fw)
  1242. {
  1243. char path[sizeof(modparam_fwpostfix) + 32];
  1244. struct b43legacy_fw_header *hdr;
  1245. u32 size;
  1246. int err;
  1247. if (!name)
  1248. return 0;
  1249. snprintf(path, ARRAY_SIZE(path),
  1250. "b43legacy%s/%s.fw",
  1251. modparam_fwpostfix, name);
  1252. err = request_firmware(fw, path, dev->dev->dev);
  1253. if (err) {
  1254. b43legacyerr(dev->wl, "Firmware file \"%s\" not found "
  1255. "or load failed.\n", path);
  1256. return err;
  1257. }
  1258. if ((*fw)->size < sizeof(struct b43legacy_fw_header))
  1259. goto err_format;
  1260. hdr = (struct b43legacy_fw_header *)((*fw)->data);
  1261. switch (hdr->type) {
  1262. case B43legacy_FW_TYPE_UCODE:
  1263. case B43legacy_FW_TYPE_PCM:
  1264. size = be32_to_cpu(hdr->size);
  1265. if (size != (*fw)->size - sizeof(struct b43legacy_fw_header))
  1266. goto err_format;
  1267. /* fallthrough */
  1268. case B43legacy_FW_TYPE_IV:
  1269. if (hdr->ver != 1)
  1270. goto err_format;
  1271. break;
  1272. default:
  1273. goto err_format;
  1274. }
  1275. return err;
  1276. err_format:
  1277. b43legacyerr(dev->wl, "Firmware file \"%s\" format error.\n", path);
  1278. return -EPROTO;
  1279. }
  1280. static int b43legacy_request_firmware(struct b43legacy_wldev *dev)
  1281. {
  1282. struct b43legacy_firmware *fw = &dev->fw;
  1283. const u8 rev = dev->dev->id.revision;
  1284. const char *filename;
  1285. u32 tmshigh;
  1286. int err;
  1287. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  1288. if (!fw->ucode) {
  1289. if (rev == 2)
  1290. filename = "ucode2";
  1291. else if (rev == 4)
  1292. filename = "ucode4";
  1293. else
  1294. filename = "ucode5";
  1295. err = do_request_fw(dev, filename, &fw->ucode);
  1296. if (err)
  1297. goto err_load;
  1298. }
  1299. if (!fw->pcm) {
  1300. if (rev < 5)
  1301. filename = "pcm4";
  1302. else
  1303. filename = "pcm5";
  1304. err = do_request_fw(dev, filename, &fw->pcm);
  1305. if (err)
  1306. goto err_load;
  1307. }
  1308. if (!fw->initvals) {
  1309. switch (dev->phy.type) {
  1310. case B43legacy_PHYTYPE_G:
  1311. if ((rev >= 5) && (rev <= 10))
  1312. filename = "b0g0initvals5";
  1313. else if (rev == 2 || rev == 4)
  1314. filename = "b0g0initvals2";
  1315. else
  1316. goto err_no_initvals;
  1317. break;
  1318. default:
  1319. goto err_no_initvals;
  1320. }
  1321. err = do_request_fw(dev, filename, &fw->initvals);
  1322. if (err)
  1323. goto err_load;
  1324. }
  1325. if (!fw->initvals_band) {
  1326. switch (dev->phy.type) {
  1327. case B43legacy_PHYTYPE_G:
  1328. if ((rev >= 5) && (rev <= 10))
  1329. filename = "b0g0bsinitvals5";
  1330. else if (rev >= 11)
  1331. filename = NULL;
  1332. else if (rev == 2 || rev == 4)
  1333. filename = NULL;
  1334. else
  1335. goto err_no_initvals;
  1336. break;
  1337. default:
  1338. goto err_no_initvals;
  1339. }
  1340. err = do_request_fw(dev, filename, &fw->initvals_band);
  1341. if (err)
  1342. goto err_load;
  1343. }
  1344. return 0;
  1345. err_load:
  1346. b43legacy_print_fw_helptext(dev->wl);
  1347. goto error;
  1348. err_no_initvals:
  1349. err = -ENODEV;
  1350. b43legacyerr(dev->wl, "No Initial Values firmware file for PHY %u, "
  1351. "core rev %u\n", dev->phy.type, rev);
  1352. goto error;
  1353. error:
  1354. b43legacy_release_firmware(dev);
  1355. return err;
  1356. }
  1357. static int b43legacy_upload_microcode(struct b43legacy_wldev *dev)
  1358. {
  1359. const size_t hdr_len = sizeof(struct b43legacy_fw_header);
  1360. const __be32 *data;
  1361. unsigned int i;
  1362. unsigned int len;
  1363. u16 fwrev;
  1364. u16 fwpatch;
  1365. u16 fwdate;
  1366. u16 fwtime;
  1367. u32 tmp;
  1368. int err = 0;
  1369. /* Upload Microcode. */
  1370. data = (__be32 *) (dev->fw.ucode->data + hdr_len);
  1371. len = (dev->fw.ucode->size - hdr_len) / sizeof(__be32);
  1372. b43legacy_shm_control_word(dev,
  1373. B43legacy_SHM_UCODE |
  1374. B43legacy_SHM_AUTOINC_W,
  1375. 0x0000);
  1376. for (i = 0; i < len; i++) {
  1377. b43legacy_write32(dev, B43legacy_MMIO_SHM_DATA,
  1378. be32_to_cpu(data[i]));
  1379. udelay(10);
  1380. }
  1381. if (dev->fw.pcm) {
  1382. /* Upload PCM data. */
  1383. data = (__be32 *) (dev->fw.pcm->data + hdr_len);
  1384. len = (dev->fw.pcm->size - hdr_len) / sizeof(__be32);
  1385. b43legacy_shm_control_word(dev, B43legacy_SHM_HW, 0x01EA);
  1386. b43legacy_write32(dev, B43legacy_MMIO_SHM_DATA, 0x00004000);
  1387. /* No need for autoinc bit in SHM_HW */
  1388. b43legacy_shm_control_word(dev, B43legacy_SHM_HW, 0x01EB);
  1389. for (i = 0; i < len; i++) {
  1390. b43legacy_write32(dev, B43legacy_MMIO_SHM_DATA,
  1391. be32_to_cpu(data[i]));
  1392. udelay(10);
  1393. }
  1394. }
  1395. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_REASON,
  1396. B43legacy_IRQ_ALL);
  1397. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, 0x00020402);
  1398. /* Wait for the microcode to load and respond */
  1399. i = 0;
  1400. while (1) {
  1401. tmp = b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_REASON);
  1402. if (tmp == B43legacy_IRQ_MAC_SUSPENDED)
  1403. break;
  1404. i++;
  1405. if (i >= B43legacy_IRQWAIT_MAX_RETRIES) {
  1406. b43legacyerr(dev->wl, "Microcode not responding\n");
  1407. b43legacy_print_fw_helptext(dev->wl);
  1408. err = -ENODEV;
  1409. goto out;
  1410. }
  1411. udelay(10);
  1412. }
  1413. /* dummy read follows */
  1414. b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_REASON);
  1415. /* Get and check the revisions. */
  1416. fwrev = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1417. B43legacy_SHM_SH_UCODEREV);
  1418. fwpatch = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1419. B43legacy_SHM_SH_UCODEPATCH);
  1420. fwdate = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1421. B43legacy_SHM_SH_UCODEDATE);
  1422. fwtime = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1423. B43legacy_SHM_SH_UCODETIME);
  1424. if (fwrev > 0x128) {
  1425. b43legacyerr(dev->wl, "YOU ARE TRYING TO LOAD V4 FIRMWARE."
  1426. " Only firmware from binary drivers version 3.x"
  1427. " is supported. You must change your firmware"
  1428. " files.\n");
  1429. b43legacy_print_fw_helptext(dev->wl);
  1430. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, 0);
  1431. err = -EOPNOTSUPP;
  1432. goto out;
  1433. }
  1434. b43legacydbg(dev->wl, "Loading firmware version 0x%X, patch level %u "
  1435. "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n", fwrev, fwpatch,
  1436. (fwdate >> 12) & 0xF, (fwdate >> 8) & 0xF, fwdate & 0xFF,
  1437. (fwtime >> 11) & 0x1F, (fwtime >> 5) & 0x3F, fwtime & 0x1F);
  1438. dev->fw.rev = fwrev;
  1439. dev->fw.patch = fwpatch;
  1440. out:
  1441. return err;
  1442. }
  1443. static int b43legacy_write_initvals(struct b43legacy_wldev *dev,
  1444. const struct b43legacy_iv *ivals,
  1445. size_t count,
  1446. size_t array_size)
  1447. {
  1448. const struct b43legacy_iv *iv;
  1449. u16 offset;
  1450. size_t i;
  1451. bool bit32;
  1452. BUILD_BUG_ON(sizeof(struct b43legacy_iv) != 6);
  1453. iv = ivals;
  1454. for (i = 0; i < count; i++) {
  1455. if (array_size < sizeof(iv->offset_size))
  1456. goto err_format;
  1457. array_size -= sizeof(iv->offset_size);
  1458. offset = be16_to_cpu(iv->offset_size);
  1459. bit32 = !!(offset & B43legacy_IV_32BIT);
  1460. offset &= B43legacy_IV_OFFSET_MASK;
  1461. if (offset >= 0x1000)
  1462. goto err_format;
  1463. if (bit32) {
  1464. u32 value;
  1465. if (array_size < sizeof(iv->data.d32))
  1466. goto err_format;
  1467. array_size -= sizeof(iv->data.d32);
  1468. value = be32_to_cpu(get_unaligned(&iv->data.d32));
  1469. b43legacy_write32(dev, offset, value);
  1470. iv = (const struct b43legacy_iv *)((const uint8_t *)iv +
  1471. sizeof(__be16) +
  1472. sizeof(__be32));
  1473. } else {
  1474. u16 value;
  1475. if (array_size < sizeof(iv->data.d16))
  1476. goto err_format;
  1477. array_size -= sizeof(iv->data.d16);
  1478. value = be16_to_cpu(iv->data.d16);
  1479. b43legacy_write16(dev, offset, value);
  1480. iv = (const struct b43legacy_iv *)((const uint8_t *)iv +
  1481. sizeof(__be16) +
  1482. sizeof(__be16));
  1483. }
  1484. }
  1485. if (array_size)
  1486. goto err_format;
  1487. return 0;
  1488. err_format:
  1489. b43legacyerr(dev->wl, "Initial Values Firmware file-format error.\n");
  1490. b43legacy_print_fw_helptext(dev->wl);
  1491. return -EPROTO;
  1492. }
  1493. static int b43legacy_upload_initvals(struct b43legacy_wldev *dev)
  1494. {
  1495. const size_t hdr_len = sizeof(struct b43legacy_fw_header);
  1496. const struct b43legacy_fw_header *hdr;
  1497. struct b43legacy_firmware *fw = &dev->fw;
  1498. const struct b43legacy_iv *ivals;
  1499. size_t count;
  1500. int err;
  1501. hdr = (const struct b43legacy_fw_header *)(fw->initvals->data);
  1502. ivals = (const struct b43legacy_iv *)(fw->initvals->data + hdr_len);
  1503. count = be32_to_cpu(hdr->size);
  1504. err = b43legacy_write_initvals(dev, ivals, count,
  1505. fw->initvals->size - hdr_len);
  1506. if (err)
  1507. goto out;
  1508. if (fw->initvals_band) {
  1509. hdr = (const struct b43legacy_fw_header *)
  1510. (fw->initvals_band->data);
  1511. ivals = (const struct b43legacy_iv *)(fw->initvals_band->data
  1512. + hdr_len);
  1513. count = be32_to_cpu(hdr->size);
  1514. err = b43legacy_write_initvals(dev, ivals, count,
  1515. fw->initvals_band->size - hdr_len);
  1516. if (err)
  1517. goto out;
  1518. }
  1519. out:
  1520. return err;
  1521. }
  1522. /* Initialize the GPIOs
  1523. * http://bcm-specs.sipsolutions.net/GPIO
  1524. */
  1525. static int b43legacy_gpio_init(struct b43legacy_wldev *dev)
  1526. {
  1527. struct ssb_bus *bus = dev->dev->bus;
  1528. struct ssb_device *gpiodev, *pcidev = NULL;
  1529. u32 mask;
  1530. u32 set;
  1531. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD,
  1532. b43legacy_read32(dev,
  1533. B43legacy_MMIO_STATUS_BITFIELD)
  1534. & 0xFFFF3FFF);
  1535. b43legacy_write16(dev, B43legacy_MMIO_GPIO_MASK,
  1536. b43legacy_read16(dev,
  1537. B43legacy_MMIO_GPIO_MASK)
  1538. | 0x000F);
  1539. mask = 0x0000001F;
  1540. set = 0x0000000F;
  1541. if (dev->dev->bus->chip_id == 0x4301) {
  1542. mask |= 0x0060;
  1543. set |= 0x0060;
  1544. }
  1545. if (dev->dev->bus->sprom.boardflags_lo & B43legacy_BFL_PACTRL) {
  1546. b43legacy_write16(dev, B43legacy_MMIO_GPIO_MASK,
  1547. b43legacy_read16(dev,
  1548. B43legacy_MMIO_GPIO_MASK)
  1549. | 0x0200);
  1550. mask |= 0x0200;
  1551. set |= 0x0200;
  1552. }
  1553. if (dev->dev->id.revision >= 2)
  1554. mask |= 0x0010; /* FIXME: This is redundant. */
  1555. #ifdef CONFIG_SSB_DRIVER_PCICORE
  1556. pcidev = bus->pcicore.dev;
  1557. #endif
  1558. gpiodev = bus->chipco.dev ? : pcidev;
  1559. if (!gpiodev)
  1560. return 0;
  1561. ssb_write32(gpiodev, B43legacy_GPIO_CONTROL,
  1562. (ssb_read32(gpiodev, B43legacy_GPIO_CONTROL)
  1563. & mask) | set);
  1564. return 0;
  1565. }
  1566. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  1567. static void b43legacy_gpio_cleanup(struct b43legacy_wldev *dev)
  1568. {
  1569. struct ssb_bus *bus = dev->dev->bus;
  1570. struct ssb_device *gpiodev, *pcidev = NULL;
  1571. #ifdef CONFIG_SSB_DRIVER_PCICORE
  1572. pcidev = bus->pcicore.dev;
  1573. #endif
  1574. gpiodev = bus->chipco.dev ? : pcidev;
  1575. if (!gpiodev)
  1576. return;
  1577. ssb_write32(gpiodev, B43legacy_GPIO_CONTROL, 0);
  1578. }
  1579. /* http://bcm-specs.sipsolutions.net/EnableMac */
  1580. void b43legacy_mac_enable(struct b43legacy_wldev *dev)
  1581. {
  1582. dev->mac_suspended--;
  1583. B43legacy_WARN_ON(dev->mac_suspended < 0);
  1584. B43legacy_WARN_ON(irqs_disabled());
  1585. if (dev->mac_suspended == 0) {
  1586. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD,
  1587. b43legacy_read32(dev,
  1588. B43legacy_MMIO_STATUS_BITFIELD)
  1589. | B43legacy_SBF_MAC_ENABLED);
  1590. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_REASON,
  1591. B43legacy_IRQ_MAC_SUSPENDED);
  1592. /* the next two are dummy reads */
  1593. b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  1594. b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_REASON);
  1595. b43legacy_power_saving_ctl_bits(dev, -1, -1);
  1596. /* Re-enable IRQs. */
  1597. spin_lock_irq(&dev->wl->irq_lock);
  1598. b43legacy_interrupt_enable(dev, dev->irq_savedstate);
  1599. spin_unlock_irq(&dev->wl->irq_lock);
  1600. }
  1601. }
  1602. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  1603. void b43legacy_mac_suspend(struct b43legacy_wldev *dev)
  1604. {
  1605. int i;
  1606. u32 tmp;
  1607. might_sleep();
  1608. B43legacy_WARN_ON(irqs_disabled());
  1609. B43legacy_WARN_ON(dev->mac_suspended < 0);
  1610. if (dev->mac_suspended == 0) {
  1611. /* Mask IRQs before suspending MAC. Otherwise
  1612. * the MAC stays busy and won't suspend. */
  1613. spin_lock_irq(&dev->wl->irq_lock);
  1614. tmp = b43legacy_interrupt_disable(dev, B43legacy_IRQ_ALL);
  1615. spin_unlock_irq(&dev->wl->irq_lock);
  1616. b43legacy_synchronize_irq(dev);
  1617. dev->irq_savedstate = tmp;
  1618. b43legacy_power_saving_ctl_bits(dev, -1, 1);
  1619. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD,
  1620. b43legacy_read32(dev,
  1621. B43legacy_MMIO_STATUS_BITFIELD)
  1622. & ~B43legacy_SBF_MAC_ENABLED);
  1623. b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_REASON);
  1624. for (i = 40; i; i--) {
  1625. tmp = b43legacy_read32(dev,
  1626. B43legacy_MMIO_GEN_IRQ_REASON);
  1627. if (tmp & B43legacy_IRQ_MAC_SUSPENDED)
  1628. goto out;
  1629. msleep(1);
  1630. }
  1631. b43legacyerr(dev->wl, "MAC suspend failed\n");
  1632. }
  1633. out:
  1634. dev->mac_suspended++;
  1635. }
  1636. static void b43legacy_adjust_opmode(struct b43legacy_wldev *dev)
  1637. {
  1638. struct b43legacy_wl *wl = dev->wl;
  1639. u32 ctl;
  1640. u16 cfp_pretbtt;
  1641. ctl = b43legacy_read32(dev, B43legacy_MMIO_MACCTL);
  1642. /* Reset status to STA infrastructure mode. */
  1643. ctl &= ~B43legacy_MACCTL_AP;
  1644. ctl &= ~B43legacy_MACCTL_KEEP_CTL;
  1645. ctl &= ~B43legacy_MACCTL_KEEP_BADPLCP;
  1646. ctl &= ~B43legacy_MACCTL_KEEP_BAD;
  1647. ctl &= ~B43legacy_MACCTL_PROMISC;
  1648. ctl &= ~B43legacy_MACCTL_BEACPROMISC;
  1649. ctl |= B43legacy_MACCTL_INFRA;
  1650. if (b43legacy_is_mode(wl, IEEE80211_IF_TYPE_AP))
  1651. ctl |= B43legacy_MACCTL_AP;
  1652. else if (b43legacy_is_mode(wl, IEEE80211_IF_TYPE_IBSS))
  1653. ctl &= ~B43legacy_MACCTL_INFRA;
  1654. if (wl->filter_flags & FIF_CONTROL)
  1655. ctl |= B43legacy_MACCTL_KEEP_CTL;
  1656. if (wl->filter_flags & FIF_FCSFAIL)
  1657. ctl |= B43legacy_MACCTL_KEEP_BAD;
  1658. if (wl->filter_flags & FIF_PLCPFAIL)
  1659. ctl |= B43legacy_MACCTL_KEEP_BADPLCP;
  1660. if (wl->filter_flags & FIF_PROMISC_IN_BSS)
  1661. ctl |= B43legacy_MACCTL_PROMISC;
  1662. if (wl->filter_flags & FIF_BCN_PRBRESP_PROMISC)
  1663. ctl |= B43legacy_MACCTL_BEACPROMISC;
  1664. /* Workaround: On old hardware the HW-MAC-address-filter
  1665. * doesn't work properly, so always run promisc in filter
  1666. * it in software. */
  1667. if (dev->dev->id.revision <= 4)
  1668. ctl |= B43legacy_MACCTL_PROMISC;
  1669. b43legacy_write32(dev, B43legacy_MMIO_MACCTL, ctl);
  1670. cfp_pretbtt = 2;
  1671. if ((ctl & B43legacy_MACCTL_INFRA) &&
  1672. !(ctl & B43legacy_MACCTL_AP)) {
  1673. if (dev->dev->bus->chip_id == 0x4306 &&
  1674. dev->dev->bus->chip_rev == 3)
  1675. cfp_pretbtt = 100;
  1676. else
  1677. cfp_pretbtt = 50;
  1678. }
  1679. b43legacy_write16(dev, 0x612, cfp_pretbtt);
  1680. }
  1681. static void b43legacy_rate_memory_write(struct b43legacy_wldev *dev,
  1682. u16 rate,
  1683. int is_ofdm)
  1684. {
  1685. u16 offset;
  1686. if (is_ofdm) {
  1687. offset = 0x480;
  1688. offset += (b43legacy_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  1689. } else {
  1690. offset = 0x4C0;
  1691. offset += (b43legacy_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  1692. }
  1693. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, offset + 0x20,
  1694. b43legacy_shm_read16(dev,
  1695. B43legacy_SHM_SHARED, offset));
  1696. }
  1697. static void b43legacy_rate_memory_init(struct b43legacy_wldev *dev)
  1698. {
  1699. switch (dev->phy.type) {
  1700. case B43legacy_PHYTYPE_G:
  1701. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_6MB, 1);
  1702. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_12MB, 1);
  1703. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_18MB, 1);
  1704. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_24MB, 1);
  1705. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_36MB, 1);
  1706. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_48MB, 1);
  1707. b43legacy_rate_memory_write(dev, B43legacy_OFDM_RATE_54MB, 1);
  1708. /* fallthrough */
  1709. case B43legacy_PHYTYPE_B:
  1710. b43legacy_rate_memory_write(dev, B43legacy_CCK_RATE_1MB, 0);
  1711. b43legacy_rate_memory_write(dev, B43legacy_CCK_RATE_2MB, 0);
  1712. b43legacy_rate_memory_write(dev, B43legacy_CCK_RATE_5MB, 0);
  1713. b43legacy_rate_memory_write(dev, B43legacy_CCK_RATE_11MB, 0);
  1714. break;
  1715. default:
  1716. B43legacy_BUG_ON(1);
  1717. }
  1718. }
  1719. /* Set the TX-Antenna for management frames sent by firmware. */
  1720. static void b43legacy_mgmtframe_txantenna(struct b43legacy_wldev *dev,
  1721. int antenna)
  1722. {
  1723. u16 ant = 0;
  1724. u16 tmp;
  1725. switch (antenna) {
  1726. case B43legacy_ANTENNA0:
  1727. ant |= B43legacy_TX4_PHY_ANT0;
  1728. break;
  1729. case B43legacy_ANTENNA1:
  1730. ant |= B43legacy_TX4_PHY_ANT1;
  1731. break;
  1732. case B43legacy_ANTENNA_AUTO:
  1733. ant |= B43legacy_TX4_PHY_ANTLAST;
  1734. break;
  1735. default:
  1736. B43legacy_BUG_ON(1);
  1737. }
  1738. /* FIXME We also need to set the other flags of the PHY control
  1739. * field somewhere. */
  1740. /* For Beacons */
  1741. tmp = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1742. B43legacy_SHM_SH_BEACPHYCTL);
  1743. tmp = (tmp & ~B43legacy_TX4_PHY_ANT) | ant;
  1744. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  1745. B43legacy_SHM_SH_BEACPHYCTL, tmp);
  1746. /* For ACK/CTS */
  1747. tmp = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1748. B43legacy_SHM_SH_ACKCTSPHYCTL);
  1749. tmp = (tmp & ~B43legacy_TX4_PHY_ANT) | ant;
  1750. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  1751. B43legacy_SHM_SH_ACKCTSPHYCTL, tmp);
  1752. /* For Probe Resposes */
  1753. tmp = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1754. B43legacy_SHM_SH_PRPHYCTL);
  1755. tmp = (tmp & ~B43legacy_TX4_PHY_ANT) | ant;
  1756. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  1757. B43legacy_SHM_SH_PRPHYCTL, tmp);
  1758. }
  1759. /* This is the opposite of b43legacy_chip_init() */
  1760. static void b43legacy_chip_exit(struct b43legacy_wldev *dev)
  1761. {
  1762. b43legacy_radio_turn_off(dev, 1);
  1763. b43legacy_leds_exit(dev);
  1764. b43legacy_gpio_cleanup(dev);
  1765. /* firmware is released later */
  1766. }
  1767. /* Initialize the chip
  1768. * http://bcm-specs.sipsolutions.net/ChipInit
  1769. */
  1770. static int b43legacy_chip_init(struct b43legacy_wldev *dev)
  1771. {
  1772. struct b43legacy_phy *phy = &dev->phy;
  1773. int err;
  1774. int tmp;
  1775. u32 value32;
  1776. u16 value16;
  1777. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD,
  1778. B43legacy_SBF_CORE_READY
  1779. | B43legacy_SBF_400);
  1780. err = b43legacy_request_firmware(dev);
  1781. if (err)
  1782. goto out;
  1783. err = b43legacy_upload_microcode(dev);
  1784. if (err)
  1785. goto out; /* firmware is released later */
  1786. err = b43legacy_gpio_init(dev);
  1787. if (err)
  1788. goto out; /* firmware is released later */
  1789. b43legacy_leds_init(dev);
  1790. err = b43legacy_upload_initvals(dev);
  1791. if (err)
  1792. goto err_leds_exit;
  1793. b43legacy_radio_turn_on(dev);
  1794. b43legacy_write16(dev, 0x03E6, 0x0000);
  1795. err = b43legacy_phy_init(dev);
  1796. if (err)
  1797. goto err_radio_off;
  1798. /* Select initial Interference Mitigation. */
  1799. tmp = phy->interfmode;
  1800. phy->interfmode = B43legacy_INTERFMODE_NONE;
  1801. b43legacy_radio_set_interference_mitigation(dev, tmp);
  1802. b43legacy_phy_set_antenna_diversity(dev);
  1803. b43legacy_mgmtframe_txantenna(dev, B43legacy_ANTENNA_DEFAULT);
  1804. if (phy->type == B43legacy_PHYTYPE_B) {
  1805. value16 = b43legacy_read16(dev, 0x005E);
  1806. value16 |= 0x0004;
  1807. b43legacy_write16(dev, 0x005E, value16);
  1808. }
  1809. b43legacy_write32(dev, 0x0100, 0x01000000);
  1810. if (dev->dev->id.revision < 5)
  1811. b43legacy_write32(dev, 0x010C, 0x01000000);
  1812. value32 = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  1813. value32 &= ~B43legacy_SBF_MODE_NOTADHOC;
  1814. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, value32);
  1815. value32 = b43legacy_read32(dev, B43legacy_MMIO_STATUS_BITFIELD);
  1816. value32 |= B43legacy_SBF_MODE_NOTADHOC;
  1817. b43legacy_write32(dev, B43legacy_MMIO_STATUS_BITFIELD, value32);
  1818. if (b43legacy_using_pio(dev)) {
  1819. b43legacy_write32(dev, 0x0210, 0x00000100);
  1820. b43legacy_write32(dev, 0x0230, 0x00000100);
  1821. b43legacy_write32(dev, 0x0250, 0x00000100);
  1822. b43legacy_write32(dev, 0x0270, 0x00000100);
  1823. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x0034,
  1824. 0x0000);
  1825. }
  1826. /* Probe Response Timeout value */
  1827. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  1828. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x0074, 0x0000);
  1829. /* Initially set the wireless operation mode. */
  1830. b43legacy_adjust_opmode(dev);
  1831. if (dev->dev->id.revision < 3) {
  1832. b43legacy_write16(dev, 0x060E, 0x0000);
  1833. b43legacy_write16(dev, 0x0610, 0x8000);
  1834. b43legacy_write16(dev, 0x0604, 0x0000);
  1835. b43legacy_write16(dev, 0x0606, 0x0200);
  1836. } else {
  1837. b43legacy_write32(dev, 0x0188, 0x80000000);
  1838. b43legacy_write32(dev, 0x018C, 0x02000000);
  1839. }
  1840. b43legacy_write32(dev, B43legacy_MMIO_GEN_IRQ_REASON, 0x00004000);
  1841. b43legacy_write32(dev, B43legacy_MMIO_DMA0_IRQ_MASK, 0x0001DC00);
  1842. b43legacy_write32(dev, B43legacy_MMIO_DMA1_IRQ_MASK, 0x0000DC00);
  1843. b43legacy_write32(dev, B43legacy_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  1844. b43legacy_write32(dev, B43legacy_MMIO_DMA3_IRQ_MASK, 0x0001DC00);
  1845. b43legacy_write32(dev, B43legacy_MMIO_DMA4_IRQ_MASK, 0x0000DC00);
  1846. b43legacy_write32(dev, B43legacy_MMIO_DMA5_IRQ_MASK, 0x0000DC00);
  1847. value32 = ssb_read32(dev->dev, SSB_TMSLOW);
  1848. value32 |= 0x00100000;
  1849. ssb_write32(dev->dev, SSB_TMSLOW, value32);
  1850. b43legacy_write16(dev, B43legacy_MMIO_POWERUP_DELAY,
  1851. dev->dev->bus->chipco.fast_pwrup_delay);
  1852. /* PHY TX errors counter. */
  1853. atomic_set(&phy->txerr_cnt, B43legacy_PHY_TX_BADNESS_LIMIT);
  1854. B43legacy_WARN_ON(err != 0);
  1855. b43legacydbg(dev->wl, "Chip initialized\n");
  1856. out:
  1857. return err;
  1858. err_radio_off:
  1859. b43legacy_radio_turn_off(dev, 1);
  1860. err_leds_exit:
  1861. b43legacy_leds_exit(dev);
  1862. b43legacy_gpio_cleanup(dev);
  1863. goto out;
  1864. }
  1865. static void b43legacy_periodic_every120sec(struct b43legacy_wldev *dev)
  1866. {
  1867. struct b43legacy_phy *phy = &dev->phy;
  1868. if (phy->type != B43legacy_PHYTYPE_G || phy->rev < 2)
  1869. return;
  1870. b43legacy_mac_suspend(dev);
  1871. b43legacy_phy_lo_g_measure(dev);
  1872. b43legacy_mac_enable(dev);
  1873. }
  1874. static void b43legacy_periodic_every60sec(struct b43legacy_wldev *dev)
  1875. {
  1876. b43legacy_phy_lo_mark_all_unused(dev);
  1877. if (dev->dev->bus->sprom.boardflags_lo & B43legacy_BFL_RSSI) {
  1878. b43legacy_mac_suspend(dev);
  1879. b43legacy_calc_nrssi_slope(dev);
  1880. b43legacy_mac_enable(dev);
  1881. }
  1882. }
  1883. static void b43legacy_periodic_every30sec(struct b43legacy_wldev *dev)
  1884. {
  1885. /* Update device statistics. */
  1886. b43legacy_calculate_link_quality(dev);
  1887. }
  1888. static void b43legacy_periodic_every15sec(struct b43legacy_wldev *dev)
  1889. {
  1890. b43legacy_phy_xmitpower(dev); /* FIXME: unless scanning? */
  1891. atomic_set(&dev->phy.txerr_cnt, B43legacy_PHY_TX_BADNESS_LIMIT);
  1892. wmb();
  1893. }
  1894. static void do_periodic_work(struct b43legacy_wldev *dev)
  1895. {
  1896. unsigned int state;
  1897. state = dev->periodic_state;
  1898. if (state % 8 == 0)
  1899. b43legacy_periodic_every120sec(dev);
  1900. if (state % 4 == 0)
  1901. b43legacy_periodic_every60sec(dev);
  1902. if (state % 2 == 0)
  1903. b43legacy_periodic_every30sec(dev);
  1904. b43legacy_periodic_every15sec(dev);
  1905. }
  1906. /* Periodic work locking policy:
  1907. * The whole periodic work handler is protected by
  1908. * wl->mutex. If another lock is needed somewhere in the
  1909. * pwork callchain, it's aquired in-place, where it's needed.
  1910. */
  1911. static void b43legacy_periodic_work_handler(struct work_struct *work)
  1912. {
  1913. struct b43legacy_wldev *dev = container_of(work, struct b43legacy_wldev,
  1914. periodic_work.work);
  1915. struct b43legacy_wl *wl = dev->wl;
  1916. unsigned long delay;
  1917. mutex_lock(&wl->mutex);
  1918. if (unlikely(b43legacy_status(dev) != B43legacy_STAT_STARTED))
  1919. goto out;
  1920. if (b43legacy_debug(dev, B43legacy_DBG_PWORK_STOP))
  1921. goto out_requeue;
  1922. do_periodic_work(dev);
  1923. dev->periodic_state++;
  1924. out_requeue:
  1925. if (b43legacy_debug(dev, B43legacy_DBG_PWORK_FAST))
  1926. delay = msecs_to_jiffies(50);
  1927. else
  1928. delay = round_jiffies_relative(HZ * 15);
  1929. queue_delayed_work(wl->hw->workqueue, &dev->periodic_work, delay);
  1930. out:
  1931. mutex_unlock(&wl->mutex);
  1932. }
  1933. static void b43legacy_periodic_tasks_setup(struct b43legacy_wldev *dev)
  1934. {
  1935. struct delayed_work *work = &dev->periodic_work;
  1936. dev->periodic_state = 0;
  1937. INIT_DELAYED_WORK(work, b43legacy_periodic_work_handler);
  1938. queue_delayed_work(dev->wl->hw->workqueue, work, 0);
  1939. }
  1940. /* Validate access to the chip (SHM) */
  1941. static int b43legacy_validate_chipaccess(struct b43legacy_wldev *dev)
  1942. {
  1943. u32 value;
  1944. u32 shm_backup;
  1945. shm_backup = b43legacy_shm_read32(dev, B43legacy_SHM_SHARED, 0);
  1946. b43legacy_shm_write32(dev, B43legacy_SHM_SHARED, 0, 0xAA5555AA);
  1947. if (b43legacy_shm_read32(dev, B43legacy_SHM_SHARED, 0) !=
  1948. 0xAA5555AA)
  1949. goto error;
  1950. b43legacy_shm_write32(dev, B43legacy_SHM_SHARED, 0, 0x55AAAA55);
  1951. if (b43legacy_shm_read32(dev, B43legacy_SHM_SHARED, 0) !=
  1952. 0x55AAAA55)
  1953. goto error;
  1954. b43legacy_shm_write32(dev, B43legacy_SHM_SHARED, 0, shm_backup);
  1955. value = b43legacy_read32(dev, B43legacy_MMIO_MACCTL);
  1956. if ((value | B43legacy_MACCTL_GMODE) !=
  1957. (B43legacy_MACCTL_GMODE | B43legacy_MACCTL_IHR_ENABLED))
  1958. goto error;
  1959. value = b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_REASON);
  1960. if (value)
  1961. goto error;
  1962. return 0;
  1963. error:
  1964. b43legacyerr(dev->wl, "Failed to validate the chipaccess\n");
  1965. return -ENODEV;
  1966. }
  1967. static void b43legacy_security_init(struct b43legacy_wldev *dev)
  1968. {
  1969. dev->max_nr_keys = (dev->dev->id.revision >= 5) ? 58 : 20;
  1970. B43legacy_WARN_ON(dev->max_nr_keys > ARRAY_SIZE(dev->key));
  1971. dev->ktp = b43legacy_shm_read16(dev, B43legacy_SHM_SHARED,
  1972. 0x0056);
  1973. /* KTP is a word address, but we address SHM bytewise.
  1974. * So multiply by two.
  1975. */
  1976. dev->ktp *= 2;
  1977. if (dev->dev->id.revision >= 5)
  1978. /* Number of RCMTA address slots */
  1979. b43legacy_write16(dev, B43legacy_MMIO_RCMTA_COUNT,
  1980. dev->max_nr_keys - 8);
  1981. }
  1982. static int b43legacy_rng_read(struct hwrng *rng, u32 *data)
  1983. {
  1984. struct b43legacy_wl *wl = (struct b43legacy_wl *)rng->priv;
  1985. unsigned long flags;
  1986. /* Don't take wl->mutex here, as it could deadlock with
  1987. * hwrng internal locking. It's not needed to take
  1988. * wl->mutex here, anyway. */
  1989. spin_lock_irqsave(&wl->irq_lock, flags);
  1990. *data = b43legacy_read16(wl->current_dev, B43legacy_MMIO_RNG);
  1991. spin_unlock_irqrestore(&wl->irq_lock, flags);
  1992. return (sizeof(u16));
  1993. }
  1994. static void b43legacy_rng_exit(struct b43legacy_wl *wl)
  1995. {
  1996. if (wl->rng_initialized)
  1997. hwrng_unregister(&wl->rng);
  1998. }
  1999. static int b43legacy_rng_init(struct b43legacy_wl *wl)
  2000. {
  2001. int err;
  2002. snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
  2003. "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
  2004. wl->rng.name = wl->rng_name;
  2005. wl->rng.data_read = b43legacy_rng_read;
  2006. wl->rng.priv = (unsigned long)wl;
  2007. wl->rng_initialized = 1;
  2008. err = hwrng_register(&wl->rng);
  2009. if (err) {
  2010. wl->rng_initialized = 0;
  2011. b43legacyerr(wl, "Failed to register the random "
  2012. "number generator (%d)\n", err);
  2013. }
  2014. return err;
  2015. }
  2016. static int b43legacy_op_tx(struct ieee80211_hw *hw,
  2017. struct sk_buff *skb,
  2018. struct ieee80211_tx_control *ctl)
  2019. {
  2020. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2021. struct b43legacy_wldev *dev = wl->current_dev;
  2022. int err = -ENODEV;
  2023. unsigned long flags;
  2024. if (unlikely(!dev))
  2025. goto out;
  2026. if (unlikely(b43legacy_status(dev) < B43legacy_STAT_STARTED))
  2027. goto out;
  2028. /* DMA-TX is done without a global lock. */
  2029. if (b43legacy_using_pio(dev)) {
  2030. spin_lock_irqsave(&wl->irq_lock, flags);
  2031. err = b43legacy_pio_tx(dev, skb, ctl);
  2032. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2033. } else
  2034. err = b43legacy_dma_tx(dev, skb, ctl);
  2035. out:
  2036. if (unlikely(err))
  2037. return NETDEV_TX_BUSY;
  2038. return NETDEV_TX_OK;
  2039. }
  2040. static int b43legacy_op_conf_tx(struct ieee80211_hw *hw,
  2041. int queue,
  2042. const struct ieee80211_tx_queue_params *params)
  2043. {
  2044. return 0;
  2045. }
  2046. static int b43legacy_op_get_tx_stats(struct ieee80211_hw *hw,
  2047. struct ieee80211_tx_queue_stats *stats)
  2048. {
  2049. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2050. struct b43legacy_wldev *dev = wl->current_dev;
  2051. unsigned long flags;
  2052. int err = -ENODEV;
  2053. if (!dev)
  2054. goto out;
  2055. spin_lock_irqsave(&wl->irq_lock, flags);
  2056. if (likely(b43legacy_status(dev) >= B43legacy_STAT_STARTED)) {
  2057. if (b43legacy_using_pio(dev))
  2058. b43legacy_pio_get_tx_stats(dev, stats);
  2059. else
  2060. b43legacy_dma_get_tx_stats(dev, stats);
  2061. err = 0;
  2062. }
  2063. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2064. out:
  2065. return err;
  2066. }
  2067. static int b43legacy_op_get_stats(struct ieee80211_hw *hw,
  2068. struct ieee80211_low_level_stats *stats)
  2069. {
  2070. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2071. unsigned long flags;
  2072. spin_lock_irqsave(&wl->irq_lock, flags);
  2073. memcpy(stats, &wl->ieee_stats, sizeof(*stats));
  2074. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2075. return 0;
  2076. }
  2077. static const char *phymode_to_string(unsigned int phymode)
  2078. {
  2079. switch (phymode) {
  2080. case B43legacy_PHYMODE_B:
  2081. return "B";
  2082. case B43legacy_PHYMODE_G:
  2083. return "G";
  2084. default:
  2085. B43legacy_BUG_ON(1);
  2086. }
  2087. return "";
  2088. }
  2089. static int find_wldev_for_phymode(struct b43legacy_wl *wl,
  2090. unsigned int phymode,
  2091. struct b43legacy_wldev **dev,
  2092. bool *gmode)
  2093. {
  2094. struct b43legacy_wldev *d;
  2095. list_for_each_entry(d, &wl->devlist, list) {
  2096. if (d->phy.possible_phymodes & phymode) {
  2097. /* Ok, this device supports the PHY-mode.
  2098. * Set the gmode bit. */
  2099. *gmode = 1;
  2100. *dev = d;
  2101. return 0;
  2102. }
  2103. }
  2104. return -ESRCH;
  2105. }
  2106. static void b43legacy_put_phy_into_reset(struct b43legacy_wldev *dev)
  2107. {
  2108. struct ssb_device *sdev = dev->dev;
  2109. u32 tmslow;
  2110. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2111. tmslow &= ~B43legacy_TMSLOW_GMODE;
  2112. tmslow |= B43legacy_TMSLOW_PHYRESET;
  2113. tmslow |= SSB_TMSLOW_FGC;
  2114. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2115. msleep(1);
  2116. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2117. tmslow &= ~SSB_TMSLOW_FGC;
  2118. tmslow |= B43legacy_TMSLOW_PHYRESET;
  2119. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2120. msleep(1);
  2121. }
  2122. /* Expects wl->mutex locked */
  2123. static int b43legacy_switch_phymode(struct b43legacy_wl *wl,
  2124. unsigned int new_mode)
  2125. {
  2126. struct b43legacy_wldev *up_dev;
  2127. struct b43legacy_wldev *down_dev;
  2128. int err;
  2129. bool gmode = 0;
  2130. int prev_status;
  2131. err = find_wldev_for_phymode(wl, new_mode, &up_dev, &gmode);
  2132. if (err) {
  2133. b43legacyerr(wl, "Could not find a device for %s-PHY mode\n",
  2134. phymode_to_string(new_mode));
  2135. return err;
  2136. }
  2137. if ((up_dev == wl->current_dev) &&
  2138. (!!wl->current_dev->phy.gmode == !!gmode))
  2139. /* This device is already running. */
  2140. return 0;
  2141. b43legacydbg(wl, "Reconfiguring PHYmode to %s-PHY\n",
  2142. phymode_to_string(new_mode));
  2143. down_dev = wl->current_dev;
  2144. prev_status = b43legacy_status(down_dev);
  2145. /* Shutdown the currently running core. */
  2146. if (prev_status >= B43legacy_STAT_STARTED)
  2147. b43legacy_wireless_core_stop(down_dev);
  2148. if (prev_status >= B43legacy_STAT_INITIALIZED)
  2149. b43legacy_wireless_core_exit(down_dev);
  2150. if (down_dev != up_dev)
  2151. /* We switch to a different core, so we put PHY into
  2152. * RESET on the old core. */
  2153. b43legacy_put_phy_into_reset(down_dev);
  2154. /* Now start the new core. */
  2155. up_dev->phy.gmode = gmode;
  2156. if (prev_status >= B43legacy_STAT_INITIALIZED) {
  2157. err = b43legacy_wireless_core_init(up_dev);
  2158. if (err) {
  2159. b43legacyerr(wl, "Fatal: Could not initialize device"
  2160. " for newly selected %s-PHY mode\n",
  2161. phymode_to_string(new_mode));
  2162. goto init_failure;
  2163. }
  2164. }
  2165. if (prev_status >= B43legacy_STAT_STARTED) {
  2166. err = b43legacy_wireless_core_start(up_dev);
  2167. if (err) {
  2168. b43legacyerr(wl, "Fatal: Coult not start device for "
  2169. "newly selected %s-PHY mode\n",
  2170. phymode_to_string(new_mode));
  2171. b43legacy_wireless_core_exit(up_dev);
  2172. goto init_failure;
  2173. }
  2174. }
  2175. B43legacy_WARN_ON(b43legacy_status(up_dev) != prev_status);
  2176. b43legacy_shm_write32(up_dev, B43legacy_SHM_SHARED, 0x003E, 0);
  2177. wl->current_dev = up_dev;
  2178. return 0;
  2179. init_failure:
  2180. /* Whoops, failed to init the new core. No core is operating now. */
  2181. wl->current_dev = NULL;
  2182. return err;
  2183. }
  2184. static int b43legacy_antenna_from_ieee80211(u8 antenna)
  2185. {
  2186. switch (antenna) {
  2187. case 0: /* default/diversity */
  2188. return B43legacy_ANTENNA_DEFAULT;
  2189. case 1: /* Antenna 0 */
  2190. return B43legacy_ANTENNA0;
  2191. case 2: /* Antenna 1 */
  2192. return B43legacy_ANTENNA1;
  2193. default:
  2194. return B43legacy_ANTENNA_DEFAULT;
  2195. }
  2196. }
  2197. static int b43legacy_op_dev_config(struct ieee80211_hw *hw,
  2198. struct ieee80211_conf *conf)
  2199. {
  2200. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2201. struct b43legacy_wldev *dev;
  2202. struct b43legacy_phy *phy;
  2203. unsigned long flags;
  2204. unsigned int new_phymode = 0xFFFF;
  2205. int antenna_tx;
  2206. int antenna_rx;
  2207. int err = 0;
  2208. u32 savedirqs;
  2209. antenna_tx = b43legacy_antenna_from_ieee80211(conf->antenna_sel_tx);
  2210. antenna_rx = b43legacy_antenna_from_ieee80211(conf->antenna_sel_rx);
  2211. mutex_lock(&wl->mutex);
  2212. /* Switch the PHY mode (if necessary). */
  2213. switch (conf->phymode) {
  2214. case MODE_IEEE80211B:
  2215. new_phymode = B43legacy_PHYMODE_B;
  2216. break;
  2217. case MODE_IEEE80211G:
  2218. new_phymode = B43legacy_PHYMODE_G;
  2219. break;
  2220. default:
  2221. B43legacy_WARN_ON(1);
  2222. }
  2223. err = b43legacy_switch_phymode(wl, new_phymode);
  2224. if (err)
  2225. goto out_unlock_mutex;
  2226. dev = wl->current_dev;
  2227. phy = &dev->phy;
  2228. /* Disable IRQs while reconfiguring the device.
  2229. * This makes it possible to drop the spinlock throughout
  2230. * the reconfiguration process. */
  2231. spin_lock_irqsave(&wl->irq_lock, flags);
  2232. if (b43legacy_status(dev) < B43legacy_STAT_STARTED) {
  2233. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2234. goto out_unlock_mutex;
  2235. }
  2236. savedirqs = b43legacy_interrupt_disable(dev, B43legacy_IRQ_ALL);
  2237. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2238. b43legacy_synchronize_irq(dev);
  2239. /* Switch to the requested channel.
  2240. * The firmware takes care of races with the TX handler. */
  2241. if (conf->channel_val != phy->channel)
  2242. b43legacy_radio_selectchannel(dev, conf->channel_val, 0);
  2243. /* Enable/Disable ShortSlot timing. */
  2244. if ((!!(conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME))
  2245. != dev->short_slot) {
  2246. B43legacy_WARN_ON(phy->type != B43legacy_PHYTYPE_G);
  2247. if (conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME)
  2248. b43legacy_short_slot_timing_enable(dev);
  2249. else
  2250. b43legacy_short_slot_timing_disable(dev);
  2251. }
  2252. dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  2253. /* Adjust the desired TX power level. */
  2254. if (conf->power_level != 0) {
  2255. if (conf->power_level != phy->power_level) {
  2256. phy->power_level = conf->power_level;
  2257. b43legacy_phy_xmitpower(dev);
  2258. }
  2259. }
  2260. /* Antennas for RX and management frame TX. */
  2261. b43legacy_mgmtframe_txantenna(dev, antenna_tx);
  2262. /* Update templates for AP mode. */
  2263. if (b43legacy_is_mode(wl, IEEE80211_IF_TYPE_AP))
  2264. b43legacy_set_beacon_int(dev, conf->beacon_int);
  2265. if (!!conf->radio_enabled != phy->radio_on) {
  2266. if (conf->radio_enabled) {
  2267. b43legacy_radio_turn_on(dev);
  2268. b43legacyinfo(dev->wl, "Radio turned on by software\n");
  2269. if (!dev->radio_hw_enable)
  2270. b43legacyinfo(dev->wl, "The hardware RF-kill"
  2271. " button still turns the radio"
  2272. " physically off. Press the"
  2273. " button to turn it on.\n");
  2274. } else {
  2275. b43legacy_radio_turn_off(dev, 0);
  2276. b43legacyinfo(dev->wl, "Radio turned off by"
  2277. " software\n");
  2278. }
  2279. }
  2280. spin_lock_irqsave(&wl->irq_lock, flags);
  2281. b43legacy_interrupt_enable(dev, savedirqs);
  2282. mmiowb();
  2283. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2284. out_unlock_mutex:
  2285. mutex_unlock(&wl->mutex);
  2286. return err;
  2287. }
  2288. static void b43legacy_op_configure_filter(struct ieee80211_hw *hw,
  2289. unsigned int changed,
  2290. unsigned int *fflags,
  2291. int mc_count,
  2292. struct dev_addr_list *mc_list)
  2293. {
  2294. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2295. struct b43legacy_wldev *dev = wl->current_dev;
  2296. unsigned long flags;
  2297. if (!dev) {
  2298. *fflags = 0;
  2299. return;
  2300. }
  2301. spin_lock_irqsave(&wl->irq_lock, flags);
  2302. *fflags &= FIF_PROMISC_IN_BSS |
  2303. FIF_ALLMULTI |
  2304. FIF_FCSFAIL |
  2305. FIF_PLCPFAIL |
  2306. FIF_CONTROL |
  2307. FIF_OTHER_BSS |
  2308. FIF_BCN_PRBRESP_PROMISC;
  2309. changed &= FIF_PROMISC_IN_BSS |
  2310. FIF_ALLMULTI |
  2311. FIF_FCSFAIL |
  2312. FIF_PLCPFAIL |
  2313. FIF_CONTROL |
  2314. FIF_OTHER_BSS |
  2315. FIF_BCN_PRBRESP_PROMISC;
  2316. wl->filter_flags = *fflags;
  2317. if (changed && b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED)
  2318. b43legacy_adjust_opmode(dev);
  2319. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2320. }
  2321. static int b43legacy_op_config_interface(struct ieee80211_hw *hw,
  2322. int if_id,
  2323. struct ieee80211_if_conf *conf)
  2324. {
  2325. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2326. struct b43legacy_wldev *dev = wl->current_dev;
  2327. unsigned long flags;
  2328. if (!dev)
  2329. return -ENODEV;
  2330. mutex_lock(&wl->mutex);
  2331. spin_lock_irqsave(&wl->irq_lock, flags);
  2332. B43legacy_WARN_ON(wl->if_id != if_id);
  2333. if (conf->bssid)
  2334. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  2335. else
  2336. memset(wl->bssid, 0, ETH_ALEN);
  2337. if (b43legacy_status(dev) >= B43legacy_STAT_INITIALIZED) {
  2338. if (b43legacy_is_mode(wl, IEEE80211_IF_TYPE_AP)) {
  2339. B43legacy_WARN_ON(conf->type != IEEE80211_IF_TYPE_AP);
  2340. b43legacy_set_ssid(dev, conf->ssid, conf->ssid_len);
  2341. if (conf->beacon)
  2342. b43legacy_refresh_templates(dev, conf->beacon);
  2343. }
  2344. b43legacy_write_mac_bssid_templates(dev);
  2345. }
  2346. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2347. mutex_unlock(&wl->mutex);
  2348. return 0;
  2349. }
  2350. /* Locking: wl->mutex */
  2351. static void b43legacy_wireless_core_stop(struct b43legacy_wldev *dev)
  2352. {
  2353. struct b43legacy_wl *wl = dev->wl;
  2354. unsigned long flags;
  2355. if (b43legacy_status(dev) < B43legacy_STAT_STARTED)
  2356. return;
  2357. /* Disable and sync interrupts. We must do this before than
  2358. * setting the status to INITIALIZED, as the interrupt handler
  2359. * won't care about IRQs then. */
  2360. spin_lock_irqsave(&wl->irq_lock, flags);
  2361. dev->irq_savedstate = b43legacy_interrupt_disable(dev,
  2362. B43legacy_IRQ_ALL);
  2363. b43legacy_read32(dev, B43legacy_MMIO_GEN_IRQ_MASK); /* flush */
  2364. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2365. b43legacy_synchronize_irq(dev);
  2366. b43legacy_set_status(dev, B43legacy_STAT_INITIALIZED);
  2367. mutex_unlock(&wl->mutex);
  2368. /* Must unlock as it would otherwise deadlock. No races here.
  2369. * Cancel the possibly running self-rearming periodic work. */
  2370. cancel_delayed_work_sync(&dev->periodic_work);
  2371. mutex_lock(&wl->mutex);
  2372. ieee80211_stop_queues(wl->hw); /* FIXME this could cause a deadlock */
  2373. b43legacy_mac_suspend(dev);
  2374. free_irq(dev->dev->irq, dev);
  2375. b43legacydbg(wl, "Wireless interface stopped\n");
  2376. }
  2377. /* Locking: wl->mutex */
  2378. static int b43legacy_wireless_core_start(struct b43legacy_wldev *dev)
  2379. {
  2380. int err;
  2381. B43legacy_WARN_ON(b43legacy_status(dev) != B43legacy_STAT_INITIALIZED);
  2382. drain_txstatus_queue(dev);
  2383. err = request_irq(dev->dev->irq, b43legacy_interrupt_handler,
  2384. IRQF_SHARED, KBUILD_MODNAME, dev);
  2385. if (err) {
  2386. b43legacyerr(dev->wl, "Cannot request IRQ-%d\n",
  2387. dev->dev->irq);
  2388. goto out;
  2389. }
  2390. /* We are ready to run. */
  2391. b43legacy_set_status(dev, B43legacy_STAT_STARTED);
  2392. /* Start data flow (TX/RX) */
  2393. b43legacy_mac_enable(dev);
  2394. b43legacy_interrupt_enable(dev, dev->irq_savedstate);
  2395. ieee80211_start_queues(dev->wl->hw);
  2396. /* Start maintenance work */
  2397. b43legacy_periodic_tasks_setup(dev);
  2398. b43legacydbg(dev->wl, "Wireless interface started\n");
  2399. out:
  2400. return err;
  2401. }
  2402. /* Get PHY and RADIO versioning numbers */
  2403. static int b43legacy_phy_versioning(struct b43legacy_wldev *dev)
  2404. {
  2405. struct b43legacy_phy *phy = &dev->phy;
  2406. u32 tmp;
  2407. u8 analog_type;
  2408. u8 phy_type;
  2409. u8 phy_rev;
  2410. u16 radio_manuf;
  2411. u16 radio_ver;
  2412. u16 radio_rev;
  2413. int unsupported = 0;
  2414. /* Get PHY versioning */
  2415. tmp = b43legacy_read16(dev, B43legacy_MMIO_PHY_VER);
  2416. analog_type = (tmp & B43legacy_PHYVER_ANALOG)
  2417. >> B43legacy_PHYVER_ANALOG_SHIFT;
  2418. phy_type = (tmp & B43legacy_PHYVER_TYPE) >> B43legacy_PHYVER_TYPE_SHIFT;
  2419. phy_rev = (tmp & B43legacy_PHYVER_VERSION);
  2420. switch (phy_type) {
  2421. case B43legacy_PHYTYPE_B:
  2422. if (phy_rev != 2 && phy_rev != 4
  2423. && phy_rev != 6 && phy_rev != 7)
  2424. unsupported = 1;
  2425. break;
  2426. case B43legacy_PHYTYPE_G:
  2427. if (phy_rev > 8)
  2428. unsupported = 1;
  2429. break;
  2430. default:
  2431. unsupported = 1;
  2432. };
  2433. if (unsupported) {
  2434. b43legacyerr(dev->wl, "FOUND UNSUPPORTED PHY "
  2435. "(Analog %u, Type %u, Revision %u)\n",
  2436. analog_type, phy_type, phy_rev);
  2437. return -EOPNOTSUPP;
  2438. }
  2439. b43legacydbg(dev->wl, "Found PHY: Analog %u, Type %u, Revision %u\n",
  2440. analog_type, phy_type, phy_rev);
  2441. /* Get RADIO versioning */
  2442. if (dev->dev->bus->chip_id == 0x4317) {
  2443. if (dev->dev->bus->chip_rev == 0)
  2444. tmp = 0x3205017F;
  2445. else if (dev->dev->bus->chip_rev == 1)
  2446. tmp = 0x4205017F;
  2447. else
  2448. tmp = 0x5205017F;
  2449. } else {
  2450. b43legacy_write16(dev, B43legacy_MMIO_RADIO_CONTROL,
  2451. B43legacy_RADIOCTL_ID);
  2452. tmp = b43legacy_read16(dev, B43legacy_MMIO_RADIO_DATA_HIGH);
  2453. tmp <<= 16;
  2454. b43legacy_write16(dev, B43legacy_MMIO_RADIO_CONTROL,
  2455. B43legacy_RADIOCTL_ID);
  2456. tmp |= b43legacy_read16(dev, B43legacy_MMIO_RADIO_DATA_LOW);
  2457. }
  2458. radio_manuf = (tmp & 0x00000FFF);
  2459. radio_ver = (tmp & 0x0FFFF000) >> 12;
  2460. radio_rev = (tmp & 0xF0000000) >> 28;
  2461. switch (phy_type) {
  2462. case B43legacy_PHYTYPE_B:
  2463. if ((radio_ver & 0xFFF0) != 0x2050)
  2464. unsupported = 1;
  2465. break;
  2466. case B43legacy_PHYTYPE_G:
  2467. if (radio_ver != 0x2050)
  2468. unsupported = 1;
  2469. break;
  2470. default:
  2471. B43legacy_BUG_ON(1);
  2472. }
  2473. if (unsupported) {
  2474. b43legacyerr(dev->wl, "FOUND UNSUPPORTED RADIO "
  2475. "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
  2476. radio_manuf, radio_ver, radio_rev);
  2477. return -EOPNOTSUPP;
  2478. }
  2479. b43legacydbg(dev->wl, "Found Radio: Manuf 0x%X, Version 0x%X,"
  2480. " Revision %u\n", radio_manuf, radio_ver, radio_rev);
  2481. phy->radio_manuf = radio_manuf;
  2482. phy->radio_ver = radio_ver;
  2483. phy->radio_rev = radio_rev;
  2484. phy->analog = analog_type;
  2485. phy->type = phy_type;
  2486. phy->rev = phy_rev;
  2487. return 0;
  2488. }
  2489. static void setup_struct_phy_for_init(struct b43legacy_wldev *dev,
  2490. struct b43legacy_phy *phy)
  2491. {
  2492. struct b43legacy_lopair *lo;
  2493. int i;
  2494. memset(phy->minlowsig, 0xFF, sizeof(phy->minlowsig));
  2495. memset(phy->minlowsigpos, 0, sizeof(phy->minlowsigpos));
  2496. /* Flags */
  2497. phy->locked = 0;
  2498. /* Assume the radio is enabled. If it's not enabled, the state will
  2499. * immediately get fixed on the first periodic work run. */
  2500. dev->radio_hw_enable = 1;
  2501. phy->savedpctlreg = 0xFFFF;
  2502. phy->aci_enable = 0;
  2503. phy->aci_wlan_automatic = 0;
  2504. phy->aci_hw_rssi = 0;
  2505. lo = phy->_lo_pairs;
  2506. if (lo)
  2507. memset(lo, 0, sizeof(struct b43legacy_lopair) *
  2508. B43legacy_LO_COUNT);
  2509. phy->max_lb_gain = 0;
  2510. phy->trsw_rx_gain = 0;
  2511. /* Set default attenuation values. */
  2512. phy->bbatt = b43legacy_default_baseband_attenuation(dev);
  2513. phy->rfatt = b43legacy_default_radio_attenuation(dev);
  2514. phy->txctl1 = b43legacy_default_txctl1(dev);
  2515. phy->txpwr_offset = 0;
  2516. /* NRSSI */
  2517. phy->nrssislope = 0;
  2518. for (i = 0; i < ARRAY_SIZE(phy->nrssi); i++)
  2519. phy->nrssi[i] = -1000;
  2520. for (i = 0; i < ARRAY_SIZE(phy->nrssi_lt); i++)
  2521. phy->nrssi_lt[i] = i;
  2522. phy->lofcal = 0xFFFF;
  2523. phy->initval = 0xFFFF;
  2524. spin_lock_init(&phy->lock);
  2525. phy->interfmode = B43legacy_INTERFMODE_NONE;
  2526. phy->channel = 0xFF;
  2527. }
  2528. static void setup_struct_wldev_for_init(struct b43legacy_wldev *dev)
  2529. {
  2530. /* Flags */
  2531. dev->reg124_set_0x4 = 0;
  2532. /* Stats */
  2533. memset(&dev->stats, 0, sizeof(dev->stats));
  2534. setup_struct_phy_for_init(dev, &dev->phy);
  2535. /* IRQ related flags */
  2536. dev->irq_reason = 0;
  2537. memset(dev->dma_reason, 0, sizeof(dev->dma_reason));
  2538. dev->irq_savedstate = B43legacy_IRQ_MASKTEMPLATE;
  2539. dev->mac_suspended = 1;
  2540. /* Noise calculation context */
  2541. memset(&dev->noisecalc, 0, sizeof(dev->noisecalc));
  2542. }
  2543. static void b43legacy_imcfglo_timeouts_workaround(struct b43legacy_wldev *dev)
  2544. {
  2545. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2546. struct ssb_bus *bus = dev->dev->bus;
  2547. u32 tmp;
  2548. if (bus->pcicore.dev &&
  2549. bus->pcicore.dev->id.coreid == SSB_DEV_PCI &&
  2550. bus->pcicore.dev->id.revision <= 5) {
  2551. /* IMCFGLO timeouts workaround. */
  2552. tmp = ssb_read32(dev->dev, SSB_IMCFGLO);
  2553. tmp &= ~SSB_IMCFGLO_REQTO;
  2554. tmp &= ~SSB_IMCFGLO_SERTO;
  2555. switch (bus->bustype) {
  2556. case SSB_BUSTYPE_PCI:
  2557. case SSB_BUSTYPE_PCMCIA:
  2558. tmp |= 0x32;
  2559. break;
  2560. case SSB_BUSTYPE_SSB:
  2561. tmp |= 0x53;
  2562. break;
  2563. }
  2564. ssb_write32(dev->dev, SSB_IMCFGLO, tmp);
  2565. }
  2566. #endif /* CONFIG_SSB_DRIVER_PCICORE */
  2567. }
  2568. /* Write the short and long frame retry limit values. */
  2569. static void b43legacy_set_retry_limits(struct b43legacy_wldev *dev,
  2570. unsigned int short_retry,
  2571. unsigned int long_retry)
  2572. {
  2573. /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
  2574. * the chip-internal counter. */
  2575. short_retry = min(short_retry, (unsigned int)0xF);
  2576. long_retry = min(long_retry, (unsigned int)0xF);
  2577. b43legacy_shm_write16(dev, B43legacy_SHM_WIRELESS, 0x0006, short_retry);
  2578. b43legacy_shm_write16(dev, B43legacy_SHM_WIRELESS, 0x0007, long_retry);
  2579. }
  2580. /* Shutdown a wireless core */
  2581. /* Locking: wl->mutex */
  2582. static void b43legacy_wireless_core_exit(struct b43legacy_wldev *dev)
  2583. {
  2584. struct b43legacy_wl *wl = dev->wl;
  2585. struct b43legacy_phy *phy = &dev->phy;
  2586. B43legacy_WARN_ON(b43legacy_status(dev) > B43legacy_STAT_INITIALIZED);
  2587. if (b43legacy_status(dev) != B43legacy_STAT_INITIALIZED)
  2588. return;
  2589. b43legacy_set_status(dev, B43legacy_STAT_UNINIT);
  2590. mutex_unlock(&wl->mutex);
  2591. /* Must unlock as it would otherwise deadlock. No races here.
  2592. * Cancel possibly pending workqueues. */
  2593. cancel_work_sync(&dev->restart_work);
  2594. mutex_lock(&wl->mutex);
  2595. mutex_unlock(&dev->wl->mutex);
  2596. b43legacy_rfkill_exit(dev);
  2597. mutex_lock(&dev->wl->mutex);
  2598. b43legacy_rng_exit(dev->wl);
  2599. b43legacy_pio_free(dev);
  2600. b43legacy_dma_free(dev);
  2601. b43legacy_chip_exit(dev);
  2602. b43legacy_radio_turn_off(dev, 1);
  2603. b43legacy_switch_analog(dev, 0);
  2604. if (phy->dyn_tssi_tbl)
  2605. kfree(phy->tssi2dbm);
  2606. kfree(phy->lo_control);
  2607. phy->lo_control = NULL;
  2608. ssb_device_disable(dev->dev, 0);
  2609. ssb_bus_may_powerdown(dev->dev->bus);
  2610. }
  2611. static void prepare_phy_data_for_init(struct b43legacy_wldev *dev)
  2612. {
  2613. struct b43legacy_phy *phy = &dev->phy;
  2614. int i;
  2615. /* Set default attenuation values. */
  2616. phy->bbatt = b43legacy_default_baseband_attenuation(dev);
  2617. phy->rfatt = b43legacy_default_radio_attenuation(dev);
  2618. phy->txctl1 = b43legacy_default_txctl1(dev);
  2619. phy->txctl2 = 0xFFFF;
  2620. phy->txpwr_offset = 0;
  2621. /* NRSSI */
  2622. phy->nrssislope = 0;
  2623. for (i = 0; i < ARRAY_SIZE(phy->nrssi); i++)
  2624. phy->nrssi[i] = -1000;
  2625. for (i = 0; i < ARRAY_SIZE(phy->nrssi_lt); i++)
  2626. phy->nrssi_lt[i] = i;
  2627. phy->lofcal = 0xFFFF;
  2628. phy->initval = 0xFFFF;
  2629. phy->aci_enable = 0;
  2630. phy->aci_wlan_automatic = 0;
  2631. phy->aci_hw_rssi = 0;
  2632. phy->antenna_diversity = 0xFFFF;
  2633. memset(phy->minlowsig, 0xFF, sizeof(phy->minlowsig));
  2634. memset(phy->minlowsigpos, 0, sizeof(phy->minlowsigpos));
  2635. /* Flags */
  2636. phy->calibrated = 0;
  2637. phy->locked = 0;
  2638. if (phy->_lo_pairs)
  2639. memset(phy->_lo_pairs, 0,
  2640. sizeof(struct b43legacy_lopair) * B43legacy_LO_COUNT);
  2641. memset(phy->loopback_gain, 0, sizeof(phy->loopback_gain));
  2642. }
  2643. /* Initialize a wireless core */
  2644. static int b43legacy_wireless_core_init(struct b43legacy_wldev *dev)
  2645. {
  2646. struct b43legacy_wl *wl = dev->wl;
  2647. struct ssb_bus *bus = dev->dev->bus;
  2648. struct b43legacy_phy *phy = &dev->phy;
  2649. struct ssb_sprom *sprom = &dev->dev->bus->sprom;
  2650. int err;
  2651. u32 hf;
  2652. u32 tmp;
  2653. B43legacy_WARN_ON(b43legacy_status(dev) != B43legacy_STAT_UNINIT);
  2654. err = ssb_bus_powerup(bus, 0);
  2655. if (err)
  2656. goto out;
  2657. if (!ssb_device_is_enabled(dev->dev)) {
  2658. tmp = phy->gmode ? B43legacy_TMSLOW_GMODE : 0;
  2659. b43legacy_wireless_core_reset(dev, tmp);
  2660. }
  2661. if ((phy->type == B43legacy_PHYTYPE_B) ||
  2662. (phy->type == B43legacy_PHYTYPE_G)) {
  2663. phy->_lo_pairs = kzalloc(sizeof(struct b43legacy_lopair)
  2664. * B43legacy_LO_COUNT,
  2665. GFP_KERNEL);
  2666. if (!phy->_lo_pairs)
  2667. return -ENOMEM;
  2668. }
  2669. setup_struct_wldev_for_init(dev);
  2670. err = b43legacy_phy_init_tssi2dbm_table(dev);
  2671. if (err)
  2672. goto err_kfree_lo_control;
  2673. /* Enable IRQ routing to this device. */
  2674. ssb_pcicore_dev_irqvecs_enable(&bus->pcicore, dev->dev);
  2675. b43legacy_imcfglo_timeouts_workaround(dev);
  2676. prepare_phy_data_for_init(dev);
  2677. b43legacy_phy_calibrate(dev);
  2678. err = b43legacy_chip_init(dev);
  2679. if (err)
  2680. goto err_kfree_tssitbl;
  2681. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  2682. B43legacy_SHM_SH_WLCOREREV,
  2683. dev->dev->id.revision);
  2684. hf = b43legacy_hf_read(dev);
  2685. if (phy->type == B43legacy_PHYTYPE_G) {
  2686. hf |= B43legacy_HF_SYMW;
  2687. if (phy->rev == 1)
  2688. hf |= B43legacy_HF_GDCW;
  2689. if (sprom->boardflags_lo & B43legacy_BFL_PACTRL)
  2690. hf |= B43legacy_HF_OFDMPABOOST;
  2691. } else if (phy->type == B43legacy_PHYTYPE_B) {
  2692. hf |= B43legacy_HF_SYMW;
  2693. if (phy->rev >= 2 && phy->radio_ver == 0x2050)
  2694. hf &= ~B43legacy_HF_GDCW;
  2695. }
  2696. b43legacy_hf_write(dev, hf);
  2697. b43legacy_set_retry_limits(dev,
  2698. B43legacy_DEFAULT_SHORT_RETRY_LIMIT,
  2699. B43legacy_DEFAULT_LONG_RETRY_LIMIT);
  2700. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  2701. 0x0044, 3);
  2702. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  2703. 0x0046, 2);
  2704. /* Disable sending probe responses from firmware.
  2705. * Setting the MaxTime to one usec will always trigger
  2706. * a timeout, so we never send any probe resp.
  2707. * A timeout of zero is infinite. */
  2708. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED,
  2709. B43legacy_SHM_SH_PRMAXTIME, 1);
  2710. b43legacy_rate_memory_init(dev);
  2711. /* Minimum Contention Window */
  2712. if (phy->type == B43legacy_PHYTYPE_B)
  2713. b43legacy_shm_write16(dev, B43legacy_SHM_WIRELESS,
  2714. 0x0003, 31);
  2715. else
  2716. b43legacy_shm_write16(dev, B43legacy_SHM_WIRELESS,
  2717. 0x0003, 15);
  2718. /* Maximum Contention Window */
  2719. b43legacy_shm_write16(dev, B43legacy_SHM_WIRELESS,
  2720. 0x0004, 1023);
  2721. do {
  2722. if (b43legacy_using_pio(dev))
  2723. err = b43legacy_pio_init(dev);
  2724. else {
  2725. err = b43legacy_dma_init(dev);
  2726. if (!err)
  2727. b43legacy_qos_init(dev);
  2728. }
  2729. } while (err == -EAGAIN);
  2730. if (err)
  2731. goto err_chip_exit;
  2732. b43legacy_write16(dev, 0x0612, 0x0050);
  2733. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x0416, 0x0050);
  2734. b43legacy_shm_write16(dev, B43legacy_SHM_SHARED, 0x0414, 0x01F4);
  2735. ssb_bus_powerup(bus, 1); /* Enable dynamic PCTL */
  2736. memset(wl->bssid, 0, ETH_ALEN);
  2737. memset(wl->mac_addr, 0, ETH_ALEN);
  2738. b43legacy_upload_card_macaddress(dev);
  2739. b43legacy_security_init(dev);
  2740. b43legacy_rfkill_init(dev);
  2741. b43legacy_rng_init(wl);
  2742. b43legacy_set_status(dev, B43legacy_STAT_INITIALIZED);
  2743. out:
  2744. return err;
  2745. err_chip_exit:
  2746. b43legacy_chip_exit(dev);
  2747. err_kfree_tssitbl:
  2748. if (phy->dyn_tssi_tbl)
  2749. kfree(phy->tssi2dbm);
  2750. err_kfree_lo_control:
  2751. kfree(phy->lo_control);
  2752. phy->lo_control = NULL;
  2753. ssb_bus_may_powerdown(bus);
  2754. B43legacy_WARN_ON(b43legacy_status(dev) != B43legacy_STAT_UNINIT);
  2755. return err;
  2756. }
  2757. static int b43legacy_op_add_interface(struct ieee80211_hw *hw,
  2758. struct ieee80211_if_init_conf *conf)
  2759. {
  2760. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2761. struct b43legacy_wldev *dev;
  2762. unsigned long flags;
  2763. int err = -EOPNOTSUPP;
  2764. /* TODO: allow WDS/AP devices to coexist */
  2765. if (conf->type != IEEE80211_IF_TYPE_AP &&
  2766. conf->type != IEEE80211_IF_TYPE_STA &&
  2767. conf->type != IEEE80211_IF_TYPE_WDS &&
  2768. conf->type != IEEE80211_IF_TYPE_IBSS)
  2769. return -EOPNOTSUPP;
  2770. mutex_lock(&wl->mutex);
  2771. if (wl->operating)
  2772. goto out_mutex_unlock;
  2773. b43legacydbg(wl, "Adding Interface type %d\n", conf->type);
  2774. dev = wl->current_dev;
  2775. wl->operating = 1;
  2776. wl->if_id = conf->if_id;
  2777. wl->if_type = conf->type;
  2778. memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
  2779. spin_lock_irqsave(&wl->irq_lock, flags);
  2780. b43legacy_adjust_opmode(dev);
  2781. b43legacy_upload_card_macaddress(dev);
  2782. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2783. err = 0;
  2784. out_mutex_unlock:
  2785. mutex_unlock(&wl->mutex);
  2786. return err;
  2787. }
  2788. static void b43legacy_op_remove_interface(struct ieee80211_hw *hw,
  2789. struct ieee80211_if_init_conf *conf)
  2790. {
  2791. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2792. struct b43legacy_wldev *dev = wl->current_dev;
  2793. unsigned long flags;
  2794. b43legacydbg(wl, "Removing Interface type %d\n", conf->type);
  2795. mutex_lock(&wl->mutex);
  2796. B43legacy_WARN_ON(!wl->operating);
  2797. B43legacy_WARN_ON(wl->if_id != conf->if_id);
  2798. wl->operating = 0;
  2799. spin_lock_irqsave(&wl->irq_lock, flags);
  2800. b43legacy_adjust_opmode(dev);
  2801. memset(wl->mac_addr, 0, ETH_ALEN);
  2802. b43legacy_upload_card_macaddress(dev);
  2803. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2804. mutex_unlock(&wl->mutex);
  2805. }
  2806. static int b43legacy_op_start(struct ieee80211_hw *hw)
  2807. {
  2808. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2809. struct b43legacy_wldev *dev = wl->current_dev;
  2810. int did_init = 0;
  2811. int err = 0;
  2812. mutex_lock(&wl->mutex);
  2813. if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED) {
  2814. err = b43legacy_wireless_core_init(dev);
  2815. if (err)
  2816. goto out_mutex_unlock;
  2817. did_init = 1;
  2818. }
  2819. if (b43legacy_status(dev) < B43legacy_STAT_STARTED) {
  2820. err = b43legacy_wireless_core_start(dev);
  2821. if (err) {
  2822. if (did_init)
  2823. b43legacy_wireless_core_exit(dev);
  2824. goto out_mutex_unlock;
  2825. }
  2826. }
  2827. out_mutex_unlock:
  2828. mutex_unlock(&wl->mutex);
  2829. return err;
  2830. }
  2831. static void b43legacy_op_stop(struct ieee80211_hw *hw)
  2832. {
  2833. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2834. struct b43legacy_wldev *dev = wl->current_dev;
  2835. mutex_lock(&wl->mutex);
  2836. if (b43legacy_status(dev) >= B43legacy_STAT_STARTED)
  2837. b43legacy_wireless_core_stop(dev);
  2838. b43legacy_wireless_core_exit(dev);
  2839. mutex_unlock(&wl->mutex);
  2840. }
  2841. static int b43legacy_op_set_retry_limit(struct ieee80211_hw *hw,
  2842. u32 short_retry_limit,
  2843. u32 long_retry_limit)
  2844. {
  2845. struct b43legacy_wl *wl = hw_to_b43legacy_wl(hw);
  2846. struct b43legacy_wldev *dev;
  2847. int err = 0;
  2848. mutex_lock(&wl->mutex);
  2849. dev = wl->current_dev;
  2850. if (unlikely(!dev ||
  2851. (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED))) {
  2852. err = -ENODEV;
  2853. goto out_unlock;
  2854. }
  2855. b43legacy_set_retry_limits(dev, short_retry_limit, long_retry_limit);
  2856. out_unlock:
  2857. mutex_unlock(&wl->mutex);
  2858. return err;
  2859. }
  2860. static const struct ieee80211_ops b43legacy_hw_ops = {
  2861. .tx = b43legacy_op_tx,
  2862. .conf_tx = b43legacy_op_conf_tx,
  2863. .add_interface = b43legacy_op_add_interface,
  2864. .remove_interface = b43legacy_op_remove_interface,
  2865. .config = b43legacy_op_dev_config,
  2866. .config_interface = b43legacy_op_config_interface,
  2867. .configure_filter = b43legacy_op_configure_filter,
  2868. .get_stats = b43legacy_op_get_stats,
  2869. .get_tx_stats = b43legacy_op_get_tx_stats,
  2870. .start = b43legacy_op_start,
  2871. .stop = b43legacy_op_stop,
  2872. .set_retry_limit = b43legacy_op_set_retry_limit,
  2873. };
  2874. /* Hard-reset the chip. Do not call this directly.
  2875. * Use b43legacy_controller_restart()
  2876. */
  2877. static void b43legacy_chip_reset(struct work_struct *work)
  2878. {
  2879. struct b43legacy_wldev *dev =
  2880. container_of(work, struct b43legacy_wldev, restart_work);
  2881. struct b43legacy_wl *wl = dev->wl;
  2882. int err = 0;
  2883. int prev_status;
  2884. mutex_lock(&wl->mutex);
  2885. prev_status = b43legacy_status(dev);
  2886. /* Bring the device down... */
  2887. if (prev_status >= B43legacy_STAT_STARTED)
  2888. b43legacy_wireless_core_stop(dev);
  2889. if (prev_status >= B43legacy_STAT_INITIALIZED)
  2890. b43legacy_wireless_core_exit(dev);
  2891. /* ...and up again. */
  2892. if (prev_status >= B43legacy_STAT_INITIALIZED) {
  2893. err = b43legacy_wireless_core_init(dev);
  2894. if (err)
  2895. goto out;
  2896. }
  2897. if (prev_status >= B43legacy_STAT_STARTED) {
  2898. err = b43legacy_wireless_core_start(dev);
  2899. if (err) {
  2900. b43legacy_wireless_core_exit(dev);
  2901. goto out;
  2902. }
  2903. }
  2904. out:
  2905. mutex_unlock(&wl->mutex);
  2906. if (err)
  2907. b43legacyerr(wl, "Controller restart FAILED\n");
  2908. else
  2909. b43legacyinfo(wl, "Controller restarted\n");
  2910. }
  2911. static int b43legacy_setup_modes(struct b43legacy_wldev *dev,
  2912. int have_bphy,
  2913. int have_gphy)
  2914. {
  2915. struct ieee80211_hw *hw = dev->wl->hw;
  2916. struct ieee80211_hw_mode *mode;
  2917. struct b43legacy_phy *phy = &dev->phy;
  2918. int cnt = 0;
  2919. int err;
  2920. phy->possible_phymodes = 0;
  2921. for (; 1; cnt++) {
  2922. if (have_bphy) {
  2923. B43legacy_WARN_ON(cnt >= B43legacy_MAX_PHYHWMODES);
  2924. mode = &phy->hwmodes[cnt];
  2925. mode->mode = MODE_IEEE80211B;
  2926. mode->num_channels = b43legacy_bg_chantable_size;
  2927. mode->channels = b43legacy_bg_chantable;
  2928. mode->num_rates = b43legacy_b_ratetable_size;
  2929. mode->rates = b43legacy_b_ratetable;
  2930. err = ieee80211_register_hwmode(hw, mode);
  2931. if (err)
  2932. return err;
  2933. phy->possible_phymodes |= B43legacy_PHYMODE_B;
  2934. have_bphy = 0;
  2935. continue;
  2936. }
  2937. if (have_gphy) {
  2938. B43legacy_WARN_ON(cnt >= B43legacy_MAX_PHYHWMODES);
  2939. mode = &phy->hwmodes[cnt];
  2940. mode->mode = MODE_IEEE80211G;
  2941. mode->num_channels = b43legacy_bg_chantable_size;
  2942. mode->channels = b43legacy_bg_chantable;
  2943. mode->num_rates = b43legacy_g_ratetable_size;
  2944. mode->rates = b43legacy_g_ratetable;
  2945. err = ieee80211_register_hwmode(hw, mode);
  2946. if (err)
  2947. return err;
  2948. phy->possible_phymodes |= B43legacy_PHYMODE_G;
  2949. have_gphy = 0;
  2950. continue;
  2951. }
  2952. break;
  2953. }
  2954. return 0;
  2955. }
  2956. static void b43legacy_wireless_core_detach(struct b43legacy_wldev *dev)
  2957. {
  2958. /* We release firmware that late to not be required to re-request
  2959. * is all the time when we reinit the core. */
  2960. b43legacy_release_firmware(dev);
  2961. }
  2962. static int b43legacy_wireless_core_attach(struct b43legacy_wldev *dev)
  2963. {
  2964. struct b43legacy_wl *wl = dev->wl;
  2965. struct ssb_bus *bus = dev->dev->bus;
  2966. struct pci_dev *pdev = bus->host_pci;
  2967. int err;
  2968. int have_bphy = 0;
  2969. int have_gphy = 0;
  2970. u32 tmp;
  2971. /* Do NOT do any device initialization here.
  2972. * Do it in wireless_core_init() instead.
  2973. * This function is for gathering basic information about the HW, only.
  2974. * Also some structs may be set up here. But most likely you want to
  2975. * have that in core_init(), too.
  2976. */
  2977. err = ssb_bus_powerup(bus, 0);
  2978. if (err) {
  2979. b43legacyerr(wl, "Bus powerup failed\n");
  2980. goto out;
  2981. }
  2982. /* Get the PHY type. */
  2983. if (dev->dev->id.revision >= 5) {
  2984. u32 tmshigh;
  2985. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  2986. have_gphy = !!(tmshigh & B43legacy_TMSHIGH_GPHY);
  2987. if (!have_gphy)
  2988. have_bphy = 1;
  2989. } else if (dev->dev->id.revision == 4)
  2990. have_gphy = 1;
  2991. else
  2992. have_bphy = 1;
  2993. dev->phy.gmode = (have_gphy || have_bphy);
  2994. tmp = dev->phy.gmode ? B43legacy_TMSLOW_GMODE : 0;
  2995. b43legacy_wireless_core_reset(dev, tmp);
  2996. err = b43legacy_phy_versioning(dev);
  2997. if (err)
  2998. goto err_powerdown;
  2999. /* Check if this device supports multiband. */
  3000. if (!pdev ||
  3001. (pdev->device != 0x4312 &&
  3002. pdev->device != 0x4319 &&
  3003. pdev->device != 0x4324)) {
  3004. /* No multiband support. */
  3005. have_bphy = 0;
  3006. have_gphy = 0;
  3007. switch (dev->phy.type) {
  3008. case B43legacy_PHYTYPE_B:
  3009. have_bphy = 1;
  3010. break;
  3011. case B43legacy_PHYTYPE_G:
  3012. have_gphy = 1;
  3013. break;
  3014. default:
  3015. B43legacy_BUG_ON(1);
  3016. }
  3017. }
  3018. dev->phy.gmode = (have_gphy || have_bphy);
  3019. tmp = dev->phy.gmode ? B43legacy_TMSLOW_GMODE : 0;
  3020. b43legacy_wireless_core_reset(dev, tmp);
  3021. err = b43legacy_validate_chipaccess(dev);
  3022. if (err)
  3023. goto err_powerdown;
  3024. err = b43legacy_setup_modes(dev, have_bphy, have_gphy);
  3025. if (err)
  3026. goto err_powerdown;
  3027. /* Now set some default "current_dev" */
  3028. if (!wl->current_dev)
  3029. wl->current_dev = dev;
  3030. INIT_WORK(&dev->restart_work, b43legacy_chip_reset);
  3031. b43legacy_radio_turn_off(dev, 1);
  3032. b43legacy_switch_analog(dev, 0);
  3033. ssb_device_disable(dev->dev, 0);
  3034. ssb_bus_may_powerdown(bus);
  3035. out:
  3036. return err;
  3037. err_powerdown:
  3038. ssb_bus_may_powerdown(bus);
  3039. return err;
  3040. }
  3041. static void b43legacy_one_core_detach(struct ssb_device *dev)
  3042. {
  3043. struct b43legacy_wldev *wldev;
  3044. struct b43legacy_wl *wl;
  3045. wldev = ssb_get_drvdata(dev);
  3046. wl = wldev->wl;
  3047. cancel_work_sync(&wldev->restart_work);
  3048. b43legacy_debugfs_remove_device(wldev);
  3049. b43legacy_wireless_core_detach(wldev);
  3050. list_del(&wldev->list);
  3051. wl->nr_devs--;
  3052. ssb_set_drvdata(dev, NULL);
  3053. kfree(wldev);
  3054. }
  3055. static int b43legacy_one_core_attach(struct ssb_device *dev,
  3056. struct b43legacy_wl *wl)
  3057. {
  3058. struct b43legacy_wldev *wldev;
  3059. struct pci_dev *pdev;
  3060. int err = -ENOMEM;
  3061. if (!list_empty(&wl->devlist)) {
  3062. /* We are not the first core on this chip. */
  3063. pdev = dev->bus->host_pci;
  3064. /* Only special chips support more than one wireless
  3065. * core, although some of the other chips have more than
  3066. * one wireless core as well. Check for this and
  3067. * bail out early.
  3068. */
  3069. if (!pdev ||
  3070. ((pdev->device != 0x4321) &&
  3071. (pdev->device != 0x4313) &&
  3072. (pdev->device != 0x431A))) {
  3073. b43legacydbg(wl, "Ignoring unconnected 802.11 core\n");
  3074. return -ENODEV;
  3075. }
  3076. }
  3077. wldev = kzalloc(sizeof(*wldev), GFP_KERNEL);
  3078. if (!wldev)
  3079. goto out;
  3080. wldev->dev = dev;
  3081. wldev->wl = wl;
  3082. b43legacy_set_status(wldev, B43legacy_STAT_UNINIT);
  3083. wldev->bad_frames_preempt = modparam_bad_frames_preempt;
  3084. tasklet_init(&wldev->isr_tasklet,
  3085. (void (*)(unsigned long))b43legacy_interrupt_tasklet,
  3086. (unsigned long)wldev);
  3087. if (modparam_pio)
  3088. wldev->__using_pio = 1;
  3089. INIT_LIST_HEAD(&wldev->list);
  3090. err = b43legacy_wireless_core_attach(wldev);
  3091. if (err)
  3092. goto err_kfree_wldev;
  3093. list_add(&wldev->list, &wl->devlist);
  3094. wl->nr_devs++;
  3095. ssb_set_drvdata(dev, wldev);
  3096. b43legacy_debugfs_add_device(wldev);
  3097. out:
  3098. return err;
  3099. err_kfree_wldev:
  3100. kfree(wldev);
  3101. return err;
  3102. }
  3103. static void b43legacy_sprom_fixup(struct ssb_bus *bus)
  3104. {
  3105. /* boardflags workarounds */
  3106. if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
  3107. bus->boardinfo.type == 0x4E &&
  3108. bus->boardinfo.rev > 0x40)
  3109. bus->sprom.boardflags_lo |= B43legacy_BFL_PACTRL;
  3110. /* Convert Antennagain values to Q5.2 */
  3111. if (bus->sprom.antenna_gain_bg == 0xFF)
  3112. bus->sprom.antenna_gain_bg = 2; /* if unset, use 2 dBm */
  3113. bus->sprom.antenna_gain_bg <<= 2;
  3114. }
  3115. static void b43legacy_wireless_exit(struct ssb_device *dev,
  3116. struct b43legacy_wl *wl)
  3117. {
  3118. struct ieee80211_hw *hw = wl->hw;
  3119. ssb_set_devtypedata(dev, NULL);
  3120. ieee80211_free_hw(hw);
  3121. }
  3122. static int b43legacy_wireless_init(struct ssb_device *dev)
  3123. {
  3124. struct ssb_sprom *sprom = &dev->bus->sprom;
  3125. struct ieee80211_hw *hw;
  3126. struct b43legacy_wl *wl;
  3127. int err = -ENOMEM;
  3128. b43legacy_sprom_fixup(dev->bus);
  3129. hw = ieee80211_alloc_hw(sizeof(*wl), &b43legacy_hw_ops);
  3130. if (!hw) {
  3131. b43legacyerr(NULL, "Could not allocate ieee80211 device\n");
  3132. goto out;
  3133. }
  3134. /* fill hw info */
  3135. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
  3136. IEEE80211_HW_RX_INCLUDES_FCS;
  3137. hw->max_signal = 100;
  3138. hw->max_rssi = -110;
  3139. hw->max_noise = -110;
  3140. hw->queues = 1; /* FIXME: hardware has more queues */
  3141. SET_IEEE80211_DEV(hw, dev->dev);
  3142. if (is_valid_ether_addr(sprom->et1mac))
  3143. SET_IEEE80211_PERM_ADDR(hw, sprom->et1mac);
  3144. else
  3145. SET_IEEE80211_PERM_ADDR(hw, sprom->il0mac);
  3146. /* Get and initialize struct b43legacy_wl */
  3147. wl = hw_to_b43legacy_wl(hw);
  3148. memset(wl, 0, sizeof(*wl));
  3149. wl->hw = hw;
  3150. spin_lock_init(&wl->irq_lock);
  3151. spin_lock_init(&wl->leds_lock);
  3152. mutex_init(&wl->mutex);
  3153. INIT_LIST_HEAD(&wl->devlist);
  3154. ssb_set_devtypedata(dev, wl);
  3155. b43legacyinfo(wl, "Broadcom %04X WLAN found\n", dev->bus->chip_id);
  3156. err = 0;
  3157. out:
  3158. return err;
  3159. }
  3160. static int b43legacy_probe(struct ssb_device *dev,
  3161. const struct ssb_device_id *id)
  3162. {
  3163. struct b43legacy_wl *wl;
  3164. int err;
  3165. int first = 0;
  3166. wl = ssb_get_devtypedata(dev);
  3167. if (!wl) {
  3168. /* Probing the first core - setup common struct b43legacy_wl */
  3169. first = 1;
  3170. err = b43legacy_wireless_init(dev);
  3171. if (err)
  3172. goto out;
  3173. wl = ssb_get_devtypedata(dev);
  3174. B43legacy_WARN_ON(!wl);
  3175. }
  3176. err = b43legacy_one_core_attach(dev, wl);
  3177. if (err)
  3178. goto err_wireless_exit;
  3179. if (first) {
  3180. err = ieee80211_register_hw(wl->hw);
  3181. if (err)
  3182. goto err_one_core_detach;
  3183. }
  3184. out:
  3185. return err;
  3186. err_one_core_detach:
  3187. b43legacy_one_core_detach(dev);
  3188. err_wireless_exit:
  3189. if (first)
  3190. b43legacy_wireless_exit(dev, wl);
  3191. return err;
  3192. }
  3193. static void b43legacy_remove(struct ssb_device *dev)
  3194. {
  3195. struct b43legacy_wl *wl = ssb_get_devtypedata(dev);
  3196. struct b43legacy_wldev *wldev = ssb_get_drvdata(dev);
  3197. B43legacy_WARN_ON(!wl);
  3198. if (wl->current_dev == wldev)
  3199. ieee80211_unregister_hw(wl->hw);
  3200. b43legacy_one_core_detach(dev);
  3201. if (list_empty(&wl->devlist))
  3202. /* Last core on the chip unregistered.
  3203. * We can destroy common struct b43legacy_wl.
  3204. */
  3205. b43legacy_wireless_exit(dev, wl);
  3206. }
  3207. /* Perform a hardware reset. This can be called from any context. */
  3208. void b43legacy_controller_restart(struct b43legacy_wldev *dev,
  3209. const char *reason)
  3210. {
  3211. /* Must avoid requeueing, if we are in shutdown. */
  3212. if (b43legacy_status(dev) < B43legacy_STAT_INITIALIZED)
  3213. return;
  3214. b43legacyinfo(dev->wl, "Controller RESET (%s) ...\n", reason);
  3215. queue_work(dev->wl->hw->workqueue, &dev->restart_work);
  3216. }
  3217. #ifdef CONFIG_PM
  3218. static int b43legacy_suspend(struct ssb_device *dev, pm_message_t state)
  3219. {
  3220. struct b43legacy_wldev *wldev = ssb_get_drvdata(dev);
  3221. struct b43legacy_wl *wl = wldev->wl;
  3222. b43legacydbg(wl, "Suspending...\n");
  3223. mutex_lock(&wl->mutex);
  3224. wldev->suspend_init_status = b43legacy_status(wldev);
  3225. if (wldev->suspend_init_status >= B43legacy_STAT_STARTED)
  3226. b43legacy_wireless_core_stop(wldev);
  3227. if (wldev->suspend_init_status >= B43legacy_STAT_INITIALIZED)
  3228. b43legacy_wireless_core_exit(wldev);
  3229. mutex_unlock(&wl->mutex);
  3230. b43legacydbg(wl, "Device suspended.\n");
  3231. return 0;
  3232. }
  3233. static int b43legacy_resume(struct ssb_device *dev)
  3234. {
  3235. struct b43legacy_wldev *wldev = ssb_get_drvdata(dev);
  3236. struct b43legacy_wl *wl = wldev->wl;
  3237. int err = 0;
  3238. b43legacydbg(wl, "Resuming...\n");
  3239. mutex_lock(&wl->mutex);
  3240. if (wldev->suspend_init_status >= B43legacy_STAT_INITIALIZED) {
  3241. err = b43legacy_wireless_core_init(wldev);
  3242. if (err) {
  3243. b43legacyerr(wl, "Resume failed at core init\n");
  3244. goto out;
  3245. }
  3246. }
  3247. if (wldev->suspend_init_status >= B43legacy_STAT_STARTED) {
  3248. err = b43legacy_wireless_core_start(wldev);
  3249. if (err) {
  3250. b43legacy_wireless_core_exit(wldev);
  3251. b43legacyerr(wl, "Resume failed at core start\n");
  3252. goto out;
  3253. }
  3254. }
  3255. mutex_unlock(&wl->mutex);
  3256. b43legacydbg(wl, "Device resumed.\n");
  3257. out:
  3258. return err;
  3259. }
  3260. #else /* CONFIG_PM */
  3261. # define b43legacy_suspend NULL
  3262. # define b43legacy_resume NULL
  3263. #endif /* CONFIG_PM */
  3264. static struct ssb_driver b43legacy_ssb_driver = {
  3265. .name = KBUILD_MODNAME,
  3266. .id_table = b43legacy_ssb_tbl,
  3267. .probe = b43legacy_probe,
  3268. .remove = b43legacy_remove,
  3269. .suspend = b43legacy_suspend,
  3270. .resume = b43legacy_resume,
  3271. };
  3272. static int __init b43legacy_init(void)
  3273. {
  3274. int err;
  3275. b43legacy_debugfs_init();
  3276. err = ssb_driver_register(&b43legacy_ssb_driver);
  3277. if (err)
  3278. goto err_dfs_exit;
  3279. return err;
  3280. err_dfs_exit:
  3281. b43legacy_debugfs_exit();
  3282. return err;
  3283. }
  3284. static void __exit b43legacy_exit(void)
  3285. {
  3286. ssb_driver_unregister(&b43legacy_ssb_driver);
  3287. b43legacy_debugfs_exit();
  3288. }
  3289. module_init(b43legacy_init)
  3290. module_exit(b43legacy_exit)