main.c 102 KB

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