main.c 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903
  1. /*
  2. Broadcom B43 wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
  4. Copyright (c) 2005 Stefano Brivio <stefano.brivio@polimi.it>
  5. Copyright (c) 2005-2009 Michael Buesch <mb@bu3sch.de>
  6. Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
  7. Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  8. Some parts of the code in this file are derived from the ipw2200
  9. driver Copyright(c) 2003 - 2004 Intel Corporation.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; see the file COPYING. If not, write to
  20. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  21. Boston, MA 02110-1301, USA.
  22. */
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/if_arp.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/firmware.h>
  29. #include <linux/wireless.h>
  30. #include <linux/workqueue.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/io.h>
  33. #include <linux/dma-mapping.h>
  34. #include <asm/unaligned.h>
  35. #include "b43.h"
  36. #include "main.h"
  37. #include "debugfs.h"
  38. #include "phy_common.h"
  39. #include "phy_g.h"
  40. #include "phy_n.h"
  41. #include "dma.h"
  42. #include "pio.h"
  43. #include "sysfs.h"
  44. #include "xmit.h"
  45. #include "lo.h"
  46. #include "pcmcia.h"
  47. MODULE_DESCRIPTION("Broadcom B43 wireless driver");
  48. MODULE_AUTHOR("Martin Langer");
  49. MODULE_AUTHOR("Stefano Brivio");
  50. MODULE_AUTHOR("Michael Buesch");
  51. MODULE_LICENSE("GPL");
  52. MODULE_FIRMWARE(B43_SUPPORTED_FIRMWARE_ID);
  53. static int modparam_bad_frames_preempt;
  54. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  55. MODULE_PARM_DESC(bad_frames_preempt,
  56. "enable(1) / disable(0) Bad Frames Preemption");
  57. static char modparam_fwpostfix[16];
  58. module_param_string(fwpostfix, modparam_fwpostfix, 16, 0444);
  59. MODULE_PARM_DESC(fwpostfix, "Postfix for the .fw files to load.");
  60. static int modparam_hwpctl;
  61. module_param_named(hwpctl, modparam_hwpctl, int, 0444);
  62. MODULE_PARM_DESC(hwpctl, "Enable hardware-side power control (default off)");
  63. static int modparam_nohwcrypt;
  64. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  65. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  66. static int modparam_qos = 1;
  67. module_param_named(qos, modparam_qos, int, 0444);
  68. MODULE_PARM_DESC(qos, "Enable QOS support (default on)");
  69. static int modparam_btcoex = 1;
  70. module_param_named(btcoex, modparam_btcoex, int, 0444);
  71. MODULE_PARM_DESC(btcoex, "Enable Bluetooth coexistance (default on)");
  72. int b43_modparam_verbose = B43_VERBOSITY_DEFAULT;
  73. module_param_named(verbose, b43_modparam_verbose, int, 0644);
  74. MODULE_PARM_DESC(verbose, "Log message verbosity: 0=error, 1=warn, 2=info(default), 3=debug");
  75. static const struct ssb_device_id b43_ssb_tbl[] = {
  76. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5),
  77. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 6),
  78. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 7),
  79. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 9),
  80. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 10),
  81. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 11),
  82. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 13),
  83. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 15),
  84. SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 16),
  85. SSB_DEVTABLE_END
  86. };
  87. MODULE_DEVICE_TABLE(ssb, b43_ssb_tbl);
  88. /* Channel and ratetables are shared for all devices.
  89. * They can't be const, because ieee80211 puts some precalculated
  90. * data in there. This data is the same for all devices, so we don't
  91. * get concurrency issues */
  92. #define RATETAB_ENT(_rateid, _flags) \
  93. { \
  94. .bitrate = B43_RATE_TO_BASE100KBPS(_rateid), \
  95. .hw_value = (_rateid), \
  96. .flags = (_flags), \
  97. }
  98. /*
  99. * NOTE: When changing this, sync with xmit.c's
  100. * b43_plcp_get_bitrate_idx_* functions!
  101. */
  102. static struct ieee80211_rate __b43_ratetable[] = {
  103. RATETAB_ENT(B43_CCK_RATE_1MB, 0),
  104. RATETAB_ENT(B43_CCK_RATE_2MB, IEEE80211_RATE_SHORT_PREAMBLE),
  105. RATETAB_ENT(B43_CCK_RATE_5MB, IEEE80211_RATE_SHORT_PREAMBLE),
  106. RATETAB_ENT(B43_CCK_RATE_11MB, IEEE80211_RATE_SHORT_PREAMBLE),
  107. RATETAB_ENT(B43_OFDM_RATE_6MB, 0),
  108. RATETAB_ENT(B43_OFDM_RATE_9MB, 0),
  109. RATETAB_ENT(B43_OFDM_RATE_12MB, 0),
  110. RATETAB_ENT(B43_OFDM_RATE_18MB, 0),
  111. RATETAB_ENT(B43_OFDM_RATE_24MB, 0),
  112. RATETAB_ENT(B43_OFDM_RATE_36MB, 0),
  113. RATETAB_ENT(B43_OFDM_RATE_48MB, 0),
  114. RATETAB_ENT(B43_OFDM_RATE_54MB, 0),
  115. };
  116. #define b43_a_ratetable (__b43_ratetable + 4)
  117. #define b43_a_ratetable_size 8
  118. #define b43_b_ratetable (__b43_ratetable + 0)
  119. #define b43_b_ratetable_size 4
  120. #define b43_g_ratetable (__b43_ratetable + 0)
  121. #define b43_g_ratetable_size 12
  122. #define CHAN4G(_channel, _freq, _flags) { \
  123. .band = IEEE80211_BAND_2GHZ, \
  124. .center_freq = (_freq), \
  125. .hw_value = (_channel), \
  126. .flags = (_flags), \
  127. .max_antenna_gain = 0, \
  128. .max_power = 30, \
  129. }
  130. static struct ieee80211_channel b43_2ghz_chantable[] = {
  131. CHAN4G(1, 2412, 0),
  132. CHAN4G(2, 2417, 0),
  133. CHAN4G(3, 2422, 0),
  134. CHAN4G(4, 2427, 0),
  135. CHAN4G(5, 2432, 0),
  136. CHAN4G(6, 2437, 0),
  137. CHAN4G(7, 2442, 0),
  138. CHAN4G(8, 2447, 0),
  139. CHAN4G(9, 2452, 0),
  140. CHAN4G(10, 2457, 0),
  141. CHAN4G(11, 2462, 0),
  142. CHAN4G(12, 2467, 0),
  143. CHAN4G(13, 2472, 0),
  144. CHAN4G(14, 2484, 0),
  145. };
  146. #undef CHAN4G
  147. #define CHAN5G(_channel, _flags) { \
  148. .band = IEEE80211_BAND_5GHZ, \
  149. .center_freq = 5000 + (5 * (_channel)), \
  150. .hw_value = (_channel), \
  151. .flags = (_flags), \
  152. .max_antenna_gain = 0, \
  153. .max_power = 30, \
  154. }
  155. static struct ieee80211_channel b43_5ghz_nphy_chantable[] = {
  156. CHAN5G(32, 0), CHAN5G(34, 0),
  157. CHAN5G(36, 0), CHAN5G(38, 0),
  158. CHAN5G(40, 0), CHAN5G(42, 0),
  159. CHAN5G(44, 0), CHAN5G(46, 0),
  160. CHAN5G(48, 0), CHAN5G(50, 0),
  161. CHAN5G(52, 0), CHAN5G(54, 0),
  162. CHAN5G(56, 0), CHAN5G(58, 0),
  163. CHAN5G(60, 0), CHAN5G(62, 0),
  164. CHAN5G(64, 0), CHAN5G(66, 0),
  165. CHAN5G(68, 0), CHAN5G(70, 0),
  166. CHAN5G(72, 0), CHAN5G(74, 0),
  167. CHAN5G(76, 0), CHAN5G(78, 0),
  168. CHAN5G(80, 0), CHAN5G(82, 0),
  169. CHAN5G(84, 0), CHAN5G(86, 0),
  170. CHAN5G(88, 0), CHAN5G(90, 0),
  171. CHAN5G(92, 0), CHAN5G(94, 0),
  172. CHAN5G(96, 0), CHAN5G(98, 0),
  173. CHAN5G(100, 0), CHAN5G(102, 0),
  174. CHAN5G(104, 0), CHAN5G(106, 0),
  175. CHAN5G(108, 0), CHAN5G(110, 0),
  176. CHAN5G(112, 0), CHAN5G(114, 0),
  177. CHAN5G(116, 0), CHAN5G(118, 0),
  178. CHAN5G(120, 0), CHAN5G(122, 0),
  179. CHAN5G(124, 0), CHAN5G(126, 0),
  180. CHAN5G(128, 0), CHAN5G(130, 0),
  181. CHAN5G(132, 0), CHAN5G(134, 0),
  182. CHAN5G(136, 0), CHAN5G(138, 0),
  183. CHAN5G(140, 0), CHAN5G(142, 0),
  184. CHAN5G(144, 0), CHAN5G(145, 0),
  185. CHAN5G(146, 0), CHAN5G(147, 0),
  186. CHAN5G(148, 0), CHAN5G(149, 0),
  187. CHAN5G(150, 0), CHAN5G(151, 0),
  188. CHAN5G(152, 0), CHAN5G(153, 0),
  189. CHAN5G(154, 0), CHAN5G(155, 0),
  190. CHAN5G(156, 0), CHAN5G(157, 0),
  191. CHAN5G(158, 0), CHAN5G(159, 0),
  192. CHAN5G(160, 0), CHAN5G(161, 0),
  193. CHAN5G(162, 0), CHAN5G(163, 0),
  194. CHAN5G(164, 0), CHAN5G(165, 0),
  195. CHAN5G(166, 0), CHAN5G(168, 0),
  196. CHAN5G(170, 0), CHAN5G(172, 0),
  197. CHAN5G(174, 0), CHAN5G(176, 0),
  198. CHAN5G(178, 0), CHAN5G(180, 0),
  199. CHAN5G(182, 0), CHAN5G(184, 0),
  200. CHAN5G(186, 0), CHAN5G(188, 0),
  201. CHAN5G(190, 0), CHAN5G(192, 0),
  202. CHAN5G(194, 0), CHAN5G(196, 0),
  203. CHAN5G(198, 0), CHAN5G(200, 0),
  204. CHAN5G(202, 0), CHAN5G(204, 0),
  205. CHAN5G(206, 0), CHAN5G(208, 0),
  206. CHAN5G(210, 0), CHAN5G(212, 0),
  207. CHAN5G(214, 0), CHAN5G(216, 0),
  208. CHAN5G(218, 0), CHAN5G(220, 0),
  209. CHAN5G(222, 0), CHAN5G(224, 0),
  210. CHAN5G(226, 0), CHAN5G(228, 0),
  211. };
  212. static struct ieee80211_channel b43_5ghz_aphy_chantable[] = {
  213. CHAN5G(34, 0), CHAN5G(36, 0),
  214. CHAN5G(38, 0), CHAN5G(40, 0),
  215. CHAN5G(42, 0), CHAN5G(44, 0),
  216. CHAN5G(46, 0), CHAN5G(48, 0),
  217. CHAN5G(52, 0), CHAN5G(56, 0),
  218. CHAN5G(60, 0), CHAN5G(64, 0),
  219. CHAN5G(100, 0), CHAN5G(104, 0),
  220. CHAN5G(108, 0), CHAN5G(112, 0),
  221. CHAN5G(116, 0), CHAN5G(120, 0),
  222. CHAN5G(124, 0), CHAN5G(128, 0),
  223. CHAN5G(132, 0), CHAN5G(136, 0),
  224. CHAN5G(140, 0), CHAN5G(149, 0),
  225. CHAN5G(153, 0), CHAN5G(157, 0),
  226. CHAN5G(161, 0), CHAN5G(165, 0),
  227. CHAN5G(184, 0), CHAN5G(188, 0),
  228. CHAN5G(192, 0), CHAN5G(196, 0),
  229. CHAN5G(200, 0), CHAN5G(204, 0),
  230. CHAN5G(208, 0), CHAN5G(212, 0),
  231. CHAN5G(216, 0),
  232. };
  233. #undef CHAN5G
  234. static struct ieee80211_supported_band b43_band_5GHz_nphy = {
  235. .band = IEEE80211_BAND_5GHZ,
  236. .channels = b43_5ghz_nphy_chantable,
  237. .n_channels = ARRAY_SIZE(b43_5ghz_nphy_chantable),
  238. .bitrates = b43_a_ratetable,
  239. .n_bitrates = b43_a_ratetable_size,
  240. };
  241. static struct ieee80211_supported_band b43_band_5GHz_aphy = {
  242. .band = IEEE80211_BAND_5GHZ,
  243. .channels = b43_5ghz_aphy_chantable,
  244. .n_channels = ARRAY_SIZE(b43_5ghz_aphy_chantable),
  245. .bitrates = b43_a_ratetable,
  246. .n_bitrates = b43_a_ratetable_size,
  247. };
  248. static struct ieee80211_supported_band b43_band_2GHz = {
  249. .band = IEEE80211_BAND_2GHZ,
  250. .channels = b43_2ghz_chantable,
  251. .n_channels = ARRAY_SIZE(b43_2ghz_chantable),
  252. .bitrates = b43_g_ratetable,
  253. .n_bitrates = b43_g_ratetable_size,
  254. };
  255. static void b43_wireless_core_exit(struct b43_wldev *dev);
  256. static int b43_wireless_core_init(struct b43_wldev *dev);
  257. static void b43_wireless_core_stop(struct b43_wldev *dev);
  258. static int b43_wireless_core_start(struct b43_wldev *dev);
  259. static int b43_ratelimit(struct b43_wl *wl)
  260. {
  261. if (!wl || !wl->current_dev)
  262. return 1;
  263. if (b43_status(wl->current_dev) < B43_STAT_STARTED)
  264. return 1;
  265. /* We are up and running.
  266. * Ratelimit the messages to avoid DoS over the net. */
  267. return net_ratelimit();
  268. }
  269. void b43info(struct b43_wl *wl, const char *fmt, ...)
  270. {
  271. va_list args;
  272. if (b43_modparam_verbose < B43_VERBOSITY_INFO)
  273. return;
  274. if (!b43_ratelimit(wl))
  275. return;
  276. va_start(args, fmt);
  277. printk(KERN_INFO "b43-%s: ",
  278. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  279. vprintk(fmt, args);
  280. va_end(args);
  281. }
  282. void b43err(struct b43_wl *wl, const char *fmt, ...)
  283. {
  284. va_list args;
  285. if (b43_modparam_verbose < B43_VERBOSITY_ERROR)
  286. return;
  287. if (!b43_ratelimit(wl))
  288. return;
  289. va_start(args, fmt);
  290. printk(KERN_ERR "b43-%s ERROR: ",
  291. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  292. vprintk(fmt, args);
  293. va_end(args);
  294. }
  295. void b43warn(struct b43_wl *wl, const char *fmt, ...)
  296. {
  297. va_list args;
  298. if (b43_modparam_verbose < B43_VERBOSITY_WARN)
  299. return;
  300. if (!b43_ratelimit(wl))
  301. return;
  302. va_start(args, fmt);
  303. printk(KERN_WARNING "b43-%s warning: ",
  304. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  305. vprintk(fmt, args);
  306. va_end(args);
  307. }
  308. void b43dbg(struct b43_wl *wl, const char *fmt, ...)
  309. {
  310. va_list args;
  311. if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
  312. return;
  313. va_start(args, fmt);
  314. printk(KERN_DEBUG "b43-%s debug: ",
  315. (wl && wl->hw) ? wiphy_name(wl->hw->wiphy) : "wlan");
  316. vprintk(fmt, args);
  317. va_end(args);
  318. }
  319. static void b43_ram_write(struct b43_wldev *dev, u16 offset, u32 val)
  320. {
  321. u32 macctl;
  322. B43_WARN_ON(offset % 4 != 0);
  323. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  324. if (macctl & B43_MACCTL_BE)
  325. val = swab32(val);
  326. b43_write32(dev, B43_MMIO_RAM_CONTROL, offset);
  327. mmiowb();
  328. b43_write32(dev, B43_MMIO_RAM_DATA, val);
  329. }
  330. static inline void b43_shm_control_word(struct b43_wldev *dev,
  331. u16 routing, u16 offset)
  332. {
  333. u32 control;
  334. /* "offset" is the WORD offset. */
  335. control = routing;
  336. control <<= 16;
  337. control |= offset;
  338. b43_write32(dev, B43_MMIO_SHM_CONTROL, control);
  339. }
  340. u32 __b43_shm_read32(struct b43_wldev *dev, u16 routing, u16 offset)
  341. {
  342. u32 ret;
  343. if (routing == B43_SHM_SHARED) {
  344. B43_WARN_ON(offset & 0x0001);
  345. if (offset & 0x0003) {
  346. /* Unaligned access */
  347. b43_shm_control_word(dev, routing, offset >> 2);
  348. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  349. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  350. ret |= ((u32)b43_read16(dev, B43_MMIO_SHM_DATA)) << 16;
  351. goto out;
  352. }
  353. offset >>= 2;
  354. }
  355. b43_shm_control_word(dev, routing, offset);
  356. ret = b43_read32(dev, B43_MMIO_SHM_DATA);
  357. out:
  358. return ret;
  359. }
  360. u32 b43_shm_read32(struct b43_wldev *dev, u16 routing, u16 offset)
  361. {
  362. struct b43_wl *wl = dev->wl;
  363. unsigned long flags;
  364. u32 ret;
  365. spin_lock_irqsave(&wl->shm_lock, flags);
  366. ret = __b43_shm_read32(dev, routing, offset);
  367. spin_unlock_irqrestore(&wl->shm_lock, flags);
  368. return ret;
  369. }
  370. u16 __b43_shm_read16(struct b43_wldev *dev, u16 routing, u16 offset)
  371. {
  372. u16 ret;
  373. if (routing == B43_SHM_SHARED) {
  374. B43_WARN_ON(offset & 0x0001);
  375. if (offset & 0x0003) {
  376. /* Unaligned access */
  377. b43_shm_control_word(dev, routing, offset >> 2);
  378. ret = b43_read16(dev, B43_MMIO_SHM_DATA_UNALIGNED);
  379. goto out;
  380. }
  381. offset >>= 2;
  382. }
  383. b43_shm_control_word(dev, routing, offset);
  384. ret = b43_read16(dev, B43_MMIO_SHM_DATA);
  385. out:
  386. return ret;
  387. }
  388. u16 b43_shm_read16(struct b43_wldev *dev, u16 routing, u16 offset)
  389. {
  390. struct b43_wl *wl = dev->wl;
  391. unsigned long flags;
  392. u16 ret;
  393. spin_lock_irqsave(&wl->shm_lock, flags);
  394. ret = __b43_shm_read16(dev, routing, offset);
  395. spin_unlock_irqrestore(&wl->shm_lock, flags);
  396. return ret;
  397. }
  398. void __b43_shm_write32(struct b43_wldev *dev, u16 routing, u16 offset, u32 value)
  399. {
  400. if (routing == B43_SHM_SHARED) {
  401. B43_WARN_ON(offset & 0x0001);
  402. if (offset & 0x0003) {
  403. /* Unaligned access */
  404. b43_shm_control_word(dev, routing, offset >> 2);
  405. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED,
  406. value & 0xFFFF);
  407. b43_shm_control_word(dev, routing, (offset >> 2) + 1);
  408. b43_write16(dev, B43_MMIO_SHM_DATA,
  409. (value >> 16) & 0xFFFF);
  410. return;
  411. }
  412. offset >>= 2;
  413. }
  414. b43_shm_control_word(dev, routing, offset);
  415. b43_write32(dev, B43_MMIO_SHM_DATA, value);
  416. }
  417. void b43_shm_write32(struct b43_wldev *dev, u16 routing, u16 offset, u32 value)
  418. {
  419. struct b43_wl *wl = dev->wl;
  420. unsigned long flags;
  421. spin_lock_irqsave(&wl->shm_lock, flags);
  422. __b43_shm_write32(dev, routing, offset, value);
  423. spin_unlock_irqrestore(&wl->shm_lock, flags);
  424. }
  425. void __b43_shm_write16(struct b43_wldev *dev, u16 routing, u16 offset, u16 value)
  426. {
  427. if (routing == B43_SHM_SHARED) {
  428. B43_WARN_ON(offset & 0x0001);
  429. if (offset & 0x0003) {
  430. /* Unaligned access */
  431. b43_shm_control_word(dev, routing, offset >> 2);
  432. b43_write16(dev, B43_MMIO_SHM_DATA_UNALIGNED, value);
  433. return;
  434. }
  435. offset >>= 2;
  436. }
  437. b43_shm_control_word(dev, routing, offset);
  438. b43_write16(dev, B43_MMIO_SHM_DATA, value);
  439. }
  440. void b43_shm_write16(struct b43_wldev *dev, u16 routing, u16 offset, u16 value)
  441. {
  442. struct b43_wl *wl = dev->wl;
  443. unsigned long flags;
  444. spin_lock_irqsave(&wl->shm_lock, flags);
  445. __b43_shm_write16(dev, routing, offset, value);
  446. spin_unlock_irqrestore(&wl->shm_lock, flags);
  447. }
  448. /* Read HostFlags */
  449. u64 b43_hf_read(struct b43_wldev *dev)
  450. {
  451. u64 ret;
  452. ret = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFHI);
  453. ret <<= 16;
  454. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFMI);
  455. ret <<= 16;
  456. ret |= b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFLO);
  457. return ret;
  458. }
  459. /* Write HostFlags */
  460. void b43_hf_write(struct b43_wldev *dev, u64 value)
  461. {
  462. u16 lo, mi, hi;
  463. lo = (value & 0x00000000FFFFULL);
  464. mi = (value & 0x0000FFFF0000ULL) >> 16;
  465. hi = (value & 0xFFFF00000000ULL) >> 32;
  466. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFLO, lo);
  467. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFMI, mi);
  468. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTFHI, hi);
  469. }
  470. /* Read the firmware capabilities bitmask (Opensource firmware only) */
  471. static u16 b43_fwcapa_read(struct b43_wldev *dev)
  472. {
  473. B43_WARN_ON(!dev->fw.opensource);
  474. return b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_FWCAPA);
  475. }
  476. void b43_tsf_read(struct b43_wldev *dev, u64 *tsf)
  477. {
  478. u32 low, high;
  479. B43_WARN_ON(dev->dev->id.revision < 3);
  480. /* The hardware guarantees us an atomic read, if we
  481. * read the low register first. */
  482. low = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_LOW);
  483. high = b43_read32(dev, B43_MMIO_REV3PLUS_TSF_HIGH);
  484. *tsf = high;
  485. *tsf <<= 32;
  486. *tsf |= low;
  487. }
  488. static void b43_time_lock(struct b43_wldev *dev)
  489. {
  490. u32 macctl;
  491. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  492. macctl |= B43_MACCTL_TBTTHOLD;
  493. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  494. /* Commit the write */
  495. b43_read32(dev, B43_MMIO_MACCTL);
  496. }
  497. static void b43_time_unlock(struct b43_wldev *dev)
  498. {
  499. u32 macctl;
  500. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  501. macctl &= ~B43_MACCTL_TBTTHOLD;
  502. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  503. /* Commit the write */
  504. b43_read32(dev, B43_MMIO_MACCTL);
  505. }
  506. static void b43_tsf_write_locked(struct b43_wldev *dev, u64 tsf)
  507. {
  508. u32 low, high;
  509. B43_WARN_ON(dev->dev->id.revision < 3);
  510. low = tsf;
  511. high = (tsf >> 32);
  512. /* The hardware guarantees us an atomic write, if we
  513. * write the low register first. */
  514. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_LOW, low);
  515. mmiowb();
  516. b43_write32(dev, B43_MMIO_REV3PLUS_TSF_HIGH, high);
  517. mmiowb();
  518. }
  519. void b43_tsf_write(struct b43_wldev *dev, u64 tsf)
  520. {
  521. b43_time_lock(dev);
  522. b43_tsf_write_locked(dev, tsf);
  523. b43_time_unlock(dev);
  524. }
  525. static
  526. void b43_macfilter_set(struct b43_wldev *dev, u16 offset, const u8 *mac)
  527. {
  528. static const u8 zero_addr[ETH_ALEN] = { 0 };
  529. u16 data;
  530. if (!mac)
  531. mac = zero_addr;
  532. offset |= 0x0020;
  533. b43_write16(dev, B43_MMIO_MACFILTER_CONTROL, offset);
  534. data = mac[0];
  535. data |= mac[1] << 8;
  536. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  537. data = mac[2];
  538. data |= mac[3] << 8;
  539. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  540. data = mac[4];
  541. data |= mac[5] << 8;
  542. b43_write16(dev, B43_MMIO_MACFILTER_DATA, data);
  543. }
  544. static void b43_write_mac_bssid_templates(struct b43_wldev *dev)
  545. {
  546. const u8 *mac;
  547. const u8 *bssid;
  548. u8 mac_bssid[ETH_ALEN * 2];
  549. int i;
  550. u32 tmp;
  551. bssid = dev->wl->bssid;
  552. mac = dev->wl->mac_addr;
  553. b43_macfilter_set(dev, B43_MACFILTER_BSSID, bssid);
  554. memcpy(mac_bssid, mac, ETH_ALEN);
  555. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  556. /* Write our MAC address and BSSID to template ram */
  557. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32)) {
  558. tmp = (u32) (mac_bssid[i + 0]);
  559. tmp |= (u32) (mac_bssid[i + 1]) << 8;
  560. tmp |= (u32) (mac_bssid[i + 2]) << 16;
  561. tmp |= (u32) (mac_bssid[i + 3]) << 24;
  562. b43_ram_write(dev, 0x20 + i, tmp);
  563. }
  564. }
  565. static void b43_upload_card_macaddress(struct b43_wldev *dev)
  566. {
  567. b43_write_mac_bssid_templates(dev);
  568. b43_macfilter_set(dev, B43_MACFILTER_SELF, dev->wl->mac_addr);
  569. }
  570. static void b43_set_slot_time(struct b43_wldev *dev, u16 slot_time)
  571. {
  572. /* slot_time is in usec. */
  573. if (dev->phy.type != B43_PHYTYPE_G)
  574. return;
  575. b43_write16(dev, 0x684, 510 + slot_time);
  576. b43_shm_write16(dev, B43_SHM_SHARED, 0x0010, slot_time);
  577. }
  578. static void b43_short_slot_timing_enable(struct b43_wldev *dev)
  579. {
  580. b43_set_slot_time(dev, 9);
  581. }
  582. static void b43_short_slot_timing_disable(struct b43_wldev *dev)
  583. {
  584. b43_set_slot_time(dev, 20);
  585. }
  586. /* Synchronize IRQ top- and bottom-half.
  587. * IRQs must be masked before calling this.
  588. * This must not be called with the irq_lock held.
  589. */
  590. static void b43_synchronize_irq(struct b43_wldev *dev)
  591. {
  592. synchronize_irq(dev->dev->irq);
  593. tasklet_kill(&dev->isr_tasklet);
  594. }
  595. /* DummyTransmission function, as documented on
  596. * http://bcm-specs.sipsolutions.net/DummyTransmission
  597. */
  598. void b43_dummy_transmission(struct b43_wldev *dev)
  599. {
  600. struct b43_wl *wl = dev->wl;
  601. struct b43_phy *phy = &dev->phy;
  602. unsigned int i, max_loop;
  603. u16 value;
  604. u32 buffer[5] = {
  605. 0x00000000,
  606. 0x00D40000,
  607. 0x00000000,
  608. 0x01000000,
  609. 0x00000000,
  610. };
  611. switch (phy->type) {
  612. case B43_PHYTYPE_A:
  613. max_loop = 0x1E;
  614. buffer[0] = 0x000201CC;
  615. break;
  616. case B43_PHYTYPE_B:
  617. case B43_PHYTYPE_G:
  618. max_loop = 0xFA;
  619. buffer[0] = 0x000B846E;
  620. break;
  621. default:
  622. B43_WARN_ON(1);
  623. return;
  624. }
  625. spin_lock_irq(&wl->irq_lock);
  626. write_lock(&wl->tx_lock);
  627. for (i = 0; i < 5; i++)
  628. b43_ram_write(dev, i * 4, buffer[i]);
  629. /* Commit writes */
  630. b43_read32(dev, B43_MMIO_MACCTL);
  631. b43_write16(dev, 0x0568, 0x0000);
  632. b43_write16(dev, 0x07C0, 0x0000);
  633. value = ((phy->type == B43_PHYTYPE_A) ? 1 : 0);
  634. b43_write16(dev, 0x050C, value);
  635. b43_write16(dev, 0x0508, 0x0000);
  636. b43_write16(dev, 0x050A, 0x0000);
  637. b43_write16(dev, 0x054C, 0x0000);
  638. b43_write16(dev, 0x056A, 0x0014);
  639. b43_write16(dev, 0x0568, 0x0826);
  640. b43_write16(dev, 0x0500, 0x0000);
  641. b43_write16(dev, 0x0502, 0x0030);
  642. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  643. b43_radio_write16(dev, 0x0051, 0x0017);
  644. for (i = 0x00; i < max_loop; i++) {
  645. value = b43_read16(dev, 0x050E);
  646. if (value & 0x0080)
  647. break;
  648. udelay(10);
  649. }
  650. for (i = 0x00; i < 0x0A; i++) {
  651. value = b43_read16(dev, 0x050E);
  652. if (value & 0x0400)
  653. break;
  654. udelay(10);
  655. }
  656. for (i = 0x00; i < 0x19; i++) {
  657. value = b43_read16(dev, 0x0690);
  658. if (!(value & 0x0100))
  659. break;
  660. udelay(10);
  661. }
  662. if (phy->radio_ver == 0x2050 && phy->radio_rev <= 0x5)
  663. b43_radio_write16(dev, 0x0051, 0x0037);
  664. write_unlock(&wl->tx_lock);
  665. spin_unlock_irq(&wl->irq_lock);
  666. }
  667. static void key_write(struct b43_wldev *dev,
  668. u8 index, u8 algorithm, const u8 *key)
  669. {
  670. unsigned int i;
  671. u32 offset;
  672. u16 value;
  673. u16 kidx;
  674. /* Key index/algo block */
  675. kidx = b43_kidx_to_fw(dev, index);
  676. value = ((kidx << 4) | algorithm);
  677. b43_shm_write16(dev, B43_SHM_SHARED,
  678. B43_SHM_SH_KEYIDXBLOCK + (kidx * 2), value);
  679. /* Write the key to the Key Table Pointer offset */
  680. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  681. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  682. value = key[i];
  683. value |= (u16) (key[i + 1]) << 8;
  684. b43_shm_write16(dev, B43_SHM_SHARED, offset + i, value);
  685. }
  686. }
  687. static void keymac_write(struct b43_wldev *dev, u8 index, const u8 *addr)
  688. {
  689. u32 addrtmp[2] = { 0, 0, };
  690. u8 pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  691. if (b43_new_kidx_api(dev))
  692. pairwise_keys_start = B43_NR_GROUP_KEYS;
  693. B43_WARN_ON(index < pairwise_keys_start);
  694. /* We have four default TX keys and possibly four default RX keys.
  695. * Physical mac 0 is mapped to physical key 4 or 8, depending
  696. * on the firmware version.
  697. * So we must adjust the index here.
  698. */
  699. index -= pairwise_keys_start;
  700. B43_WARN_ON(index >= B43_NR_PAIRWISE_KEYS);
  701. if (addr) {
  702. addrtmp[0] = addr[0];
  703. addrtmp[0] |= ((u32) (addr[1]) << 8);
  704. addrtmp[0] |= ((u32) (addr[2]) << 16);
  705. addrtmp[0] |= ((u32) (addr[3]) << 24);
  706. addrtmp[1] = addr[4];
  707. addrtmp[1] |= ((u32) (addr[5]) << 8);
  708. }
  709. /* Receive match transmitter address (RCMTA) mechanism */
  710. b43_shm_write32(dev, B43_SHM_RCMTA,
  711. (index * 2) + 0, addrtmp[0]);
  712. b43_shm_write16(dev, B43_SHM_RCMTA,
  713. (index * 2) + 1, addrtmp[1]);
  714. }
  715. static void do_key_write(struct b43_wldev *dev,
  716. u8 index, u8 algorithm,
  717. const u8 *key, size_t key_len, const u8 *mac_addr)
  718. {
  719. u8 buf[B43_SEC_KEYSIZE] = { 0, };
  720. u8 pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  721. if (b43_new_kidx_api(dev))
  722. pairwise_keys_start = B43_NR_GROUP_KEYS;
  723. B43_WARN_ON(index >= ARRAY_SIZE(dev->key));
  724. B43_WARN_ON(key_len > B43_SEC_KEYSIZE);
  725. if (index >= pairwise_keys_start)
  726. keymac_write(dev, index, NULL); /* First zero out mac. */
  727. if (key)
  728. memcpy(buf, key, key_len);
  729. key_write(dev, index, algorithm, buf);
  730. if (index >= pairwise_keys_start)
  731. keymac_write(dev, index, mac_addr);
  732. dev->key[index].algorithm = algorithm;
  733. }
  734. static int b43_key_write(struct b43_wldev *dev,
  735. int index, u8 algorithm,
  736. const u8 *key, size_t key_len,
  737. const u8 *mac_addr,
  738. struct ieee80211_key_conf *keyconf)
  739. {
  740. int i;
  741. int pairwise_keys_start;
  742. if (key_len > B43_SEC_KEYSIZE)
  743. return -EINVAL;
  744. for (i = 0; i < ARRAY_SIZE(dev->key); i++) {
  745. /* Check that we don't already have this key. */
  746. B43_WARN_ON(dev->key[i].keyconf == keyconf);
  747. }
  748. if (index < 0) {
  749. /* Pairwise key. Get an empty slot for the key. */
  750. if (b43_new_kidx_api(dev))
  751. pairwise_keys_start = B43_NR_GROUP_KEYS;
  752. else
  753. pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  754. for (i = pairwise_keys_start;
  755. i < pairwise_keys_start + B43_NR_PAIRWISE_KEYS;
  756. i++) {
  757. B43_WARN_ON(i >= ARRAY_SIZE(dev->key));
  758. if (!dev->key[i].keyconf) {
  759. /* found empty */
  760. index = i;
  761. break;
  762. }
  763. }
  764. if (index < 0) {
  765. b43warn(dev->wl, "Out of hardware key memory\n");
  766. return -ENOSPC;
  767. }
  768. } else
  769. B43_WARN_ON(index > 3);
  770. do_key_write(dev, index, algorithm, key, key_len, mac_addr);
  771. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  772. /* Default RX key */
  773. B43_WARN_ON(mac_addr);
  774. do_key_write(dev, index + 4, algorithm, key, key_len, NULL);
  775. }
  776. keyconf->hw_key_idx = index;
  777. dev->key[index].keyconf = keyconf;
  778. return 0;
  779. }
  780. static int b43_key_clear(struct b43_wldev *dev, int index)
  781. {
  782. if (B43_WARN_ON((index < 0) || (index >= ARRAY_SIZE(dev->key))))
  783. return -EINVAL;
  784. do_key_write(dev, index, B43_SEC_ALGO_NONE,
  785. NULL, B43_SEC_KEYSIZE, NULL);
  786. if ((index <= 3) && !b43_new_kidx_api(dev)) {
  787. do_key_write(dev, index + 4, B43_SEC_ALGO_NONE,
  788. NULL, B43_SEC_KEYSIZE, NULL);
  789. }
  790. dev->key[index].keyconf = NULL;
  791. return 0;
  792. }
  793. static void b43_clear_keys(struct b43_wldev *dev)
  794. {
  795. int i, count;
  796. if (b43_new_kidx_api(dev))
  797. count = B43_NR_GROUP_KEYS + B43_NR_PAIRWISE_KEYS;
  798. else
  799. count = B43_NR_GROUP_KEYS * 2 + B43_NR_PAIRWISE_KEYS;
  800. for (i = 0; i < count; i++)
  801. b43_key_clear(dev, i);
  802. }
  803. static void b43_dump_keymemory(struct b43_wldev *dev)
  804. {
  805. unsigned int i, index, count, offset, pairwise_keys_start;
  806. u8 mac[ETH_ALEN];
  807. u16 algo;
  808. u32 rcmta0;
  809. u16 rcmta1;
  810. u64 hf;
  811. struct b43_key *key;
  812. if (!b43_debug(dev, B43_DBG_KEYS))
  813. return;
  814. hf = b43_hf_read(dev);
  815. b43dbg(dev->wl, "Hardware key memory dump: USEDEFKEYS=%u\n",
  816. !!(hf & B43_HF_USEDEFKEYS));
  817. if (b43_new_kidx_api(dev)) {
  818. pairwise_keys_start = B43_NR_GROUP_KEYS;
  819. count = B43_NR_GROUP_KEYS + B43_NR_PAIRWISE_KEYS;
  820. } else {
  821. pairwise_keys_start = B43_NR_GROUP_KEYS * 2;
  822. count = B43_NR_GROUP_KEYS * 2 + B43_NR_PAIRWISE_KEYS;
  823. }
  824. for (index = 0; index < count; index++) {
  825. key = &(dev->key[index]);
  826. printk(KERN_DEBUG "Key slot %02u: %s",
  827. index, (key->keyconf == NULL) ? " " : "*");
  828. offset = dev->ktp + (index * B43_SEC_KEYSIZE);
  829. for (i = 0; i < B43_SEC_KEYSIZE; i += 2) {
  830. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, offset + i);
  831. printk("%02X%02X", (tmp & 0xFF), ((tmp >> 8) & 0xFF));
  832. }
  833. algo = b43_shm_read16(dev, B43_SHM_SHARED,
  834. B43_SHM_SH_KEYIDXBLOCK + (index * 2));
  835. printk(" Algo: %04X/%02X", algo, key->algorithm);
  836. if (index >= pairwise_keys_start) {
  837. rcmta0 = b43_shm_read32(dev, B43_SHM_RCMTA,
  838. ((index - pairwise_keys_start) * 2) + 0);
  839. rcmta1 = b43_shm_read16(dev, B43_SHM_RCMTA,
  840. ((index - pairwise_keys_start) * 2) + 1);
  841. *((__le32 *)(&mac[0])) = cpu_to_le32(rcmta0);
  842. *((__le16 *)(&mac[4])) = cpu_to_le16(rcmta1);
  843. printk(" MAC: %pM", mac);
  844. } else
  845. printk(" DEFAULT KEY");
  846. printk("\n");
  847. }
  848. }
  849. void b43_power_saving_ctl_bits(struct b43_wldev *dev, unsigned int ps_flags)
  850. {
  851. u32 macctl;
  852. u16 ucstat;
  853. bool hwps;
  854. bool awake;
  855. int i;
  856. B43_WARN_ON((ps_flags & B43_PS_ENABLED) &&
  857. (ps_flags & B43_PS_DISABLED));
  858. B43_WARN_ON((ps_flags & B43_PS_AWAKE) && (ps_flags & B43_PS_ASLEEP));
  859. if (ps_flags & B43_PS_ENABLED) {
  860. hwps = 1;
  861. } else if (ps_flags & B43_PS_DISABLED) {
  862. hwps = 0;
  863. } else {
  864. //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
  865. // and thus is not an AP and we are associated, set bit 25
  866. }
  867. if (ps_flags & B43_PS_AWAKE) {
  868. awake = 1;
  869. } else if (ps_flags & B43_PS_ASLEEP) {
  870. awake = 0;
  871. } else {
  872. //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
  873. // or we are associated, or FIXME, or the latest PS-Poll packet sent was
  874. // successful, set bit26
  875. }
  876. /* FIXME: For now we force awake-on and hwps-off */
  877. hwps = 0;
  878. awake = 1;
  879. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  880. if (hwps)
  881. macctl |= B43_MACCTL_HWPS;
  882. else
  883. macctl &= ~B43_MACCTL_HWPS;
  884. if (awake)
  885. macctl |= B43_MACCTL_AWAKE;
  886. else
  887. macctl &= ~B43_MACCTL_AWAKE;
  888. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  889. /* Commit write */
  890. b43_read32(dev, B43_MMIO_MACCTL);
  891. if (awake && dev->dev->id.revision >= 5) {
  892. /* Wait for the microcode to wake up. */
  893. for (i = 0; i < 100; i++) {
  894. ucstat = b43_shm_read16(dev, B43_SHM_SHARED,
  895. B43_SHM_SH_UCODESTAT);
  896. if (ucstat != B43_SHM_SH_UCODESTAT_SLEEP)
  897. break;
  898. udelay(10);
  899. }
  900. }
  901. }
  902. void b43_wireless_core_reset(struct b43_wldev *dev, u32 flags)
  903. {
  904. u32 tmslow;
  905. u32 macctl;
  906. flags |= B43_TMSLOW_PHYCLKEN;
  907. flags |= B43_TMSLOW_PHYRESET;
  908. ssb_device_enable(dev->dev, flags);
  909. msleep(2); /* Wait for the PLL to turn on. */
  910. /* Now take the PHY out of Reset again */
  911. tmslow = ssb_read32(dev->dev, SSB_TMSLOW);
  912. tmslow |= SSB_TMSLOW_FGC;
  913. tmslow &= ~B43_TMSLOW_PHYRESET;
  914. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  915. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  916. msleep(1);
  917. tmslow &= ~SSB_TMSLOW_FGC;
  918. ssb_write32(dev->dev, SSB_TMSLOW, tmslow);
  919. ssb_read32(dev->dev, SSB_TMSLOW); /* flush */
  920. msleep(1);
  921. /* Turn Analog ON, but only if we already know the PHY-type.
  922. * This protects against very early setup where we don't know the
  923. * PHY-type, yet. wireless_core_reset will be called once again later,
  924. * when we know the PHY-type. */
  925. if (dev->phy.ops)
  926. dev->phy.ops->switch_analog(dev, 1);
  927. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  928. macctl &= ~B43_MACCTL_GMODE;
  929. if (flags & B43_TMSLOW_GMODE)
  930. macctl |= B43_MACCTL_GMODE;
  931. macctl |= B43_MACCTL_IHR_ENABLED;
  932. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  933. }
  934. static void handle_irq_transmit_status(struct b43_wldev *dev)
  935. {
  936. u32 v0, v1;
  937. u16 tmp;
  938. struct b43_txstatus stat;
  939. while (1) {
  940. v0 = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  941. if (!(v0 & 0x00000001))
  942. break;
  943. v1 = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  944. stat.cookie = (v0 >> 16);
  945. stat.seq = (v1 & 0x0000FFFF);
  946. stat.phy_stat = ((v1 & 0x00FF0000) >> 16);
  947. tmp = (v0 & 0x0000FFFF);
  948. stat.frame_count = ((tmp & 0xF000) >> 12);
  949. stat.rts_count = ((tmp & 0x0F00) >> 8);
  950. stat.supp_reason = ((tmp & 0x001C) >> 2);
  951. stat.pm_indicated = !!(tmp & 0x0080);
  952. stat.intermediate = !!(tmp & 0x0040);
  953. stat.for_ampdu = !!(tmp & 0x0020);
  954. stat.acked = !!(tmp & 0x0002);
  955. b43_handle_txstatus(dev, &stat);
  956. }
  957. }
  958. static void drain_txstatus_queue(struct b43_wldev *dev)
  959. {
  960. u32 dummy;
  961. if (dev->dev->id.revision < 5)
  962. return;
  963. /* Read all entries from the microcode TXstatus FIFO
  964. * and throw them away.
  965. */
  966. while (1) {
  967. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_0);
  968. if (!(dummy & 0x00000001))
  969. break;
  970. dummy = b43_read32(dev, B43_MMIO_XMITSTAT_1);
  971. }
  972. }
  973. static u32 b43_jssi_read(struct b43_wldev *dev)
  974. {
  975. u32 val = 0;
  976. val = b43_shm_read16(dev, B43_SHM_SHARED, 0x08A);
  977. val <<= 16;
  978. val |= b43_shm_read16(dev, B43_SHM_SHARED, 0x088);
  979. return val;
  980. }
  981. static void b43_jssi_write(struct b43_wldev *dev, u32 jssi)
  982. {
  983. b43_shm_write16(dev, B43_SHM_SHARED, 0x088, (jssi & 0x0000FFFF));
  984. b43_shm_write16(dev, B43_SHM_SHARED, 0x08A, (jssi & 0xFFFF0000) >> 16);
  985. }
  986. static void b43_generate_noise_sample(struct b43_wldev *dev)
  987. {
  988. b43_jssi_write(dev, 0x7F7F7F7F);
  989. b43_write32(dev, B43_MMIO_MACCMD,
  990. b43_read32(dev, B43_MMIO_MACCMD) | B43_MACCMD_BGNOISE);
  991. }
  992. static void b43_calculate_link_quality(struct b43_wldev *dev)
  993. {
  994. /* Top half of Link Quality calculation. */
  995. if (dev->phy.type != B43_PHYTYPE_G)
  996. return;
  997. if (dev->noisecalc.calculation_running)
  998. return;
  999. dev->noisecalc.calculation_running = 1;
  1000. dev->noisecalc.nr_samples = 0;
  1001. b43_generate_noise_sample(dev);
  1002. }
  1003. static void handle_irq_noise(struct b43_wldev *dev)
  1004. {
  1005. struct b43_phy_g *phy = dev->phy.g;
  1006. u16 tmp;
  1007. u8 noise[4];
  1008. u8 i, j;
  1009. s32 average;
  1010. /* Bottom half of Link Quality calculation. */
  1011. if (dev->phy.type != B43_PHYTYPE_G)
  1012. return;
  1013. /* Possible race condition: It might be possible that the user
  1014. * changed to a different channel in the meantime since we
  1015. * started the calculation. We ignore that fact, since it's
  1016. * not really that much of a problem. The background noise is
  1017. * an estimation only anyway. Slightly wrong results will get damped
  1018. * by the averaging of the 8 sample rounds. Additionally the
  1019. * value is shortlived. So it will be replaced by the next noise
  1020. * calculation round soon. */
  1021. B43_WARN_ON(!dev->noisecalc.calculation_running);
  1022. *((__le32 *)noise) = cpu_to_le32(b43_jssi_read(dev));
  1023. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  1024. noise[2] == 0x7F || noise[3] == 0x7F)
  1025. goto generate_new;
  1026. /* Get the noise samples. */
  1027. B43_WARN_ON(dev->noisecalc.nr_samples >= 8);
  1028. i = dev->noisecalc.nr_samples;
  1029. noise[0] = clamp_val(noise[0], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1030. noise[1] = clamp_val(noise[1], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1031. noise[2] = clamp_val(noise[2], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1032. noise[3] = clamp_val(noise[3], 0, ARRAY_SIZE(phy->nrssi_lt) - 1);
  1033. dev->noisecalc.samples[i][0] = phy->nrssi_lt[noise[0]];
  1034. dev->noisecalc.samples[i][1] = phy->nrssi_lt[noise[1]];
  1035. dev->noisecalc.samples[i][2] = phy->nrssi_lt[noise[2]];
  1036. dev->noisecalc.samples[i][3] = phy->nrssi_lt[noise[3]];
  1037. dev->noisecalc.nr_samples++;
  1038. if (dev->noisecalc.nr_samples == 8) {
  1039. /* Calculate the Link Quality by the noise samples. */
  1040. average = 0;
  1041. for (i = 0; i < 8; i++) {
  1042. for (j = 0; j < 4; j++)
  1043. average += dev->noisecalc.samples[i][j];
  1044. }
  1045. average /= (8 * 4);
  1046. average *= 125;
  1047. average += 64;
  1048. average /= 128;
  1049. tmp = b43_shm_read16(dev, B43_SHM_SHARED, 0x40C);
  1050. tmp = (tmp / 128) & 0x1F;
  1051. if (tmp >= 8)
  1052. average += 2;
  1053. else
  1054. average -= 25;
  1055. if (tmp == 8)
  1056. average -= 72;
  1057. else
  1058. average -= 48;
  1059. dev->stats.link_noise = average;
  1060. dev->noisecalc.calculation_running = 0;
  1061. return;
  1062. }
  1063. generate_new:
  1064. b43_generate_noise_sample(dev);
  1065. }
  1066. static void handle_irq_tbtt_indication(struct b43_wldev *dev)
  1067. {
  1068. if (b43_is_mode(dev->wl, NL80211_IFTYPE_AP)) {
  1069. ///TODO: PS TBTT
  1070. } else {
  1071. if (1 /*FIXME: the last PSpoll frame was sent successfully */ )
  1072. b43_power_saving_ctl_bits(dev, 0);
  1073. }
  1074. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC))
  1075. dev->dfq_valid = 1;
  1076. }
  1077. static void handle_irq_atim_end(struct b43_wldev *dev)
  1078. {
  1079. if (dev->dfq_valid) {
  1080. b43_write32(dev, B43_MMIO_MACCMD,
  1081. b43_read32(dev, B43_MMIO_MACCMD)
  1082. | B43_MACCMD_DFQ_VALID);
  1083. dev->dfq_valid = 0;
  1084. }
  1085. }
  1086. static void handle_irq_pmq(struct b43_wldev *dev)
  1087. {
  1088. u32 tmp;
  1089. //TODO: AP mode.
  1090. while (1) {
  1091. tmp = b43_read32(dev, B43_MMIO_PS_STATUS);
  1092. if (!(tmp & 0x00000008))
  1093. break;
  1094. }
  1095. /* 16bit write is odd, but correct. */
  1096. b43_write16(dev, B43_MMIO_PS_STATUS, 0x0002);
  1097. }
  1098. static void b43_write_template_common(struct b43_wldev *dev,
  1099. const u8 *data, u16 size,
  1100. u16 ram_offset,
  1101. u16 shm_size_offset, u8 rate)
  1102. {
  1103. u32 i, tmp;
  1104. struct b43_plcp_hdr4 plcp;
  1105. plcp.data = 0;
  1106. b43_generate_plcp_hdr(&plcp, size + FCS_LEN, rate);
  1107. b43_ram_write(dev, ram_offset, le32_to_cpu(plcp.data));
  1108. ram_offset += sizeof(u32);
  1109. /* The PLCP is 6 bytes long, but we only wrote 4 bytes, yet.
  1110. * So leave the first two bytes of the next write blank.
  1111. */
  1112. tmp = (u32) (data[0]) << 16;
  1113. tmp |= (u32) (data[1]) << 24;
  1114. b43_ram_write(dev, ram_offset, tmp);
  1115. ram_offset += sizeof(u32);
  1116. for (i = 2; i < size; i += sizeof(u32)) {
  1117. tmp = (u32) (data[i + 0]);
  1118. if (i + 1 < size)
  1119. tmp |= (u32) (data[i + 1]) << 8;
  1120. if (i + 2 < size)
  1121. tmp |= (u32) (data[i + 2]) << 16;
  1122. if (i + 3 < size)
  1123. tmp |= (u32) (data[i + 3]) << 24;
  1124. b43_ram_write(dev, ram_offset + i - 2, tmp);
  1125. }
  1126. b43_shm_write16(dev, B43_SHM_SHARED, shm_size_offset,
  1127. size + sizeof(struct b43_plcp_hdr6));
  1128. }
  1129. /* Check if the use of the antenna that ieee80211 told us to
  1130. * use is possible. This will fall back to DEFAULT.
  1131. * "antenna_nr" is the antenna identifier we got from ieee80211. */
  1132. u8 b43_ieee80211_antenna_sanitize(struct b43_wldev *dev,
  1133. u8 antenna_nr)
  1134. {
  1135. u8 antenna_mask;
  1136. if (antenna_nr == 0) {
  1137. /* Zero means "use default antenna". That's always OK. */
  1138. return 0;
  1139. }
  1140. /* Get the mask of available antennas. */
  1141. if (dev->phy.gmode)
  1142. antenna_mask = dev->dev->bus->sprom.ant_available_bg;
  1143. else
  1144. antenna_mask = dev->dev->bus->sprom.ant_available_a;
  1145. if (!(antenna_mask & (1 << (antenna_nr - 1)))) {
  1146. /* This antenna is not available. Fall back to default. */
  1147. return 0;
  1148. }
  1149. return antenna_nr;
  1150. }
  1151. /* Convert a b43 antenna number value to the PHY TX control value. */
  1152. static u16 b43_antenna_to_phyctl(int antenna)
  1153. {
  1154. switch (antenna) {
  1155. case B43_ANTENNA0:
  1156. return B43_TXH_PHY_ANT0;
  1157. case B43_ANTENNA1:
  1158. return B43_TXH_PHY_ANT1;
  1159. case B43_ANTENNA2:
  1160. return B43_TXH_PHY_ANT2;
  1161. case B43_ANTENNA3:
  1162. return B43_TXH_PHY_ANT3;
  1163. case B43_ANTENNA_AUTO:
  1164. return B43_TXH_PHY_ANT01AUTO;
  1165. }
  1166. B43_WARN_ON(1);
  1167. return 0;
  1168. }
  1169. static void b43_write_beacon_template(struct b43_wldev *dev,
  1170. u16 ram_offset,
  1171. u16 shm_size_offset)
  1172. {
  1173. unsigned int i, len, variable_len;
  1174. const struct ieee80211_mgmt *bcn;
  1175. const u8 *ie;
  1176. bool tim_found = 0;
  1177. unsigned int rate;
  1178. u16 ctl;
  1179. int antenna;
  1180. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(dev->wl->current_beacon);
  1181. bcn = (const struct ieee80211_mgmt *)(dev->wl->current_beacon->data);
  1182. len = min((size_t) dev->wl->current_beacon->len,
  1183. 0x200 - sizeof(struct b43_plcp_hdr6));
  1184. rate = ieee80211_get_tx_rate(dev->wl->hw, info)->hw_value;
  1185. b43_write_template_common(dev, (const u8 *)bcn,
  1186. len, ram_offset, shm_size_offset, rate);
  1187. /* Write the PHY TX control parameters. */
  1188. antenna = B43_ANTENNA_DEFAULT;
  1189. antenna = b43_antenna_to_phyctl(antenna);
  1190. ctl = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL);
  1191. /* We can't send beacons with short preamble. Would get PHY errors. */
  1192. ctl &= ~B43_TXH_PHY_SHORTPRMBL;
  1193. ctl &= ~B43_TXH_PHY_ANT;
  1194. ctl &= ~B43_TXH_PHY_ENC;
  1195. ctl |= antenna;
  1196. if (b43_is_cck_rate(rate))
  1197. ctl |= B43_TXH_PHY_ENC_CCK;
  1198. else
  1199. ctl |= B43_TXH_PHY_ENC_OFDM;
  1200. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, ctl);
  1201. /* Find the position of the TIM and the DTIM_period value
  1202. * and write them to SHM. */
  1203. ie = bcn->u.beacon.variable;
  1204. variable_len = len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  1205. for (i = 0; i < variable_len - 2; ) {
  1206. uint8_t ie_id, ie_len;
  1207. ie_id = ie[i];
  1208. ie_len = ie[i + 1];
  1209. if (ie_id == 5) {
  1210. u16 tim_position;
  1211. u16 dtim_period;
  1212. /* This is the TIM Information Element */
  1213. /* Check whether the ie_len is in the beacon data range. */
  1214. if (variable_len < ie_len + 2 + i)
  1215. break;
  1216. /* A valid TIM is at least 4 bytes long. */
  1217. if (ie_len < 4)
  1218. break;
  1219. tim_found = 1;
  1220. tim_position = sizeof(struct b43_plcp_hdr6);
  1221. tim_position += offsetof(struct ieee80211_mgmt, u.beacon.variable);
  1222. tim_position += i;
  1223. dtim_period = ie[i + 3];
  1224. b43_shm_write16(dev, B43_SHM_SHARED,
  1225. B43_SHM_SH_TIMBPOS, tim_position);
  1226. b43_shm_write16(dev, B43_SHM_SHARED,
  1227. B43_SHM_SH_DTIMPER, dtim_period);
  1228. break;
  1229. }
  1230. i += ie_len + 2;
  1231. }
  1232. if (!tim_found) {
  1233. /*
  1234. * If ucode wants to modify TIM do it behind the beacon, this
  1235. * will happen, for example, when doing mesh networking.
  1236. */
  1237. b43_shm_write16(dev, B43_SHM_SHARED,
  1238. B43_SHM_SH_TIMBPOS,
  1239. len + sizeof(struct b43_plcp_hdr6));
  1240. b43_shm_write16(dev, B43_SHM_SHARED,
  1241. B43_SHM_SH_DTIMPER, 0);
  1242. }
  1243. b43dbg(dev->wl, "Updated beacon template at 0x%x\n", ram_offset);
  1244. }
  1245. static void b43_upload_beacon0(struct b43_wldev *dev)
  1246. {
  1247. struct b43_wl *wl = dev->wl;
  1248. if (wl->beacon0_uploaded)
  1249. return;
  1250. b43_write_beacon_template(dev, 0x68, 0x18);
  1251. wl->beacon0_uploaded = 1;
  1252. }
  1253. static void b43_upload_beacon1(struct b43_wldev *dev)
  1254. {
  1255. struct b43_wl *wl = dev->wl;
  1256. if (wl->beacon1_uploaded)
  1257. return;
  1258. b43_write_beacon_template(dev, 0x468, 0x1A);
  1259. wl->beacon1_uploaded = 1;
  1260. }
  1261. static void handle_irq_beacon(struct b43_wldev *dev)
  1262. {
  1263. struct b43_wl *wl = dev->wl;
  1264. u32 cmd, beacon0_valid, beacon1_valid;
  1265. if (!b43_is_mode(wl, NL80211_IFTYPE_AP) &&
  1266. !b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
  1267. return;
  1268. /* This is the bottom half of the asynchronous beacon update. */
  1269. /* Ignore interrupt in the future. */
  1270. dev->irq_mask &= ~B43_IRQ_BEACON;
  1271. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1272. beacon0_valid = (cmd & B43_MACCMD_BEACON0_VALID);
  1273. beacon1_valid = (cmd & B43_MACCMD_BEACON1_VALID);
  1274. /* Schedule interrupt manually, if busy. */
  1275. if (beacon0_valid && beacon1_valid) {
  1276. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_BEACON);
  1277. dev->irq_mask |= B43_IRQ_BEACON;
  1278. return;
  1279. }
  1280. if (unlikely(wl->beacon_templates_virgin)) {
  1281. /* We never uploaded a beacon before.
  1282. * Upload both templates now, but only mark one valid. */
  1283. wl->beacon_templates_virgin = 0;
  1284. b43_upload_beacon0(dev);
  1285. b43_upload_beacon1(dev);
  1286. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1287. cmd |= B43_MACCMD_BEACON0_VALID;
  1288. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1289. } else {
  1290. if (!beacon0_valid) {
  1291. b43_upload_beacon0(dev);
  1292. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1293. cmd |= B43_MACCMD_BEACON0_VALID;
  1294. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1295. } else if (!beacon1_valid) {
  1296. b43_upload_beacon1(dev);
  1297. cmd = b43_read32(dev, B43_MMIO_MACCMD);
  1298. cmd |= B43_MACCMD_BEACON1_VALID;
  1299. b43_write32(dev, B43_MMIO_MACCMD, cmd);
  1300. }
  1301. }
  1302. }
  1303. static void b43_beacon_update_trigger_work(struct work_struct *work)
  1304. {
  1305. struct b43_wl *wl = container_of(work, struct b43_wl,
  1306. beacon_update_trigger);
  1307. struct b43_wldev *dev;
  1308. mutex_lock(&wl->mutex);
  1309. dev = wl->current_dev;
  1310. if (likely(dev && (b43_status(dev) >= B43_STAT_INITIALIZED))) {
  1311. spin_lock_irq(&wl->irq_lock);
  1312. /* update beacon right away or defer to irq */
  1313. handle_irq_beacon(dev);
  1314. /* The handler might have updated the IRQ mask. */
  1315. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  1316. mmiowb();
  1317. spin_unlock_irq(&wl->irq_lock);
  1318. }
  1319. mutex_unlock(&wl->mutex);
  1320. }
  1321. /* Asynchronously update the packet templates in template RAM.
  1322. * Locking: Requires wl->irq_lock to be locked. */
  1323. static void b43_update_templates(struct b43_wl *wl)
  1324. {
  1325. struct sk_buff *beacon;
  1326. /* This is the top half of the ansynchronous beacon update.
  1327. * The bottom half is the beacon IRQ.
  1328. * Beacon update must be asynchronous to avoid sending an
  1329. * invalid beacon. This can happen for example, if the firmware
  1330. * transmits a beacon while we are updating it. */
  1331. /* We could modify the existing beacon and set the aid bit in
  1332. * the TIM field, but that would probably require resizing and
  1333. * moving of data within the beacon template.
  1334. * Simply request a new beacon and let mac80211 do the hard work. */
  1335. beacon = ieee80211_beacon_get(wl->hw, wl->vif);
  1336. if (unlikely(!beacon))
  1337. return;
  1338. if (wl->current_beacon)
  1339. dev_kfree_skb_any(wl->current_beacon);
  1340. wl->current_beacon = beacon;
  1341. wl->beacon0_uploaded = 0;
  1342. wl->beacon1_uploaded = 0;
  1343. ieee80211_queue_work(wl->hw, &wl->beacon_update_trigger);
  1344. }
  1345. static void b43_set_beacon_int(struct b43_wldev *dev, u16 beacon_int)
  1346. {
  1347. b43_time_lock(dev);
  1348. if (dev->dev->id.revision >= 3) {
  1349. b43_write32(dev, B43_MMIO_TSF_CFP_REP, (beacon_int << 16));
  1350. b43_write32(dev, B43_MMIO_TSF_CFP_START, (beacon_int << 10));
  1351. } else {
  1352. b43_write16(dev, 0x606, (beacon_int >> 6));
  1353. b43_write16(dev, 0x610, beacon_int);
  1354. }
  1355. b43_time_unlock(dev);
  1356. b43dbg(dev->wl, "Set beacon interval to %u\n", beacon_int);
  1357. }
  1358. static void b43_handle_firmware_panic(struct b43_wldev *dev)
  1359. {
  1360. u16 reason;
  1361. /* Read the register that contains the reason code for the panic. */
  1362. reason = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_FWPANIC_REASON_REG);
  1363. b43err(dev->wl, "Whoopsy, firmware panic! Reason: %u\n", reason);
  1364. switch (reason) {
  1365. default:
  1366. b43dbg(dev->wl, "The panic reason is unknown.\n");
  1367. /* fallthrough */
  1368. case B43_FWPANIC_DIE:
  1369. /* Do not restart the controller or firmware.
  1370. * The device is nonfunctional from now on.
  1371. * Restarting would result in this panic to trigger again,
  1372. * so we avoid that recursion. */
  1373. break;
  1374. case B43_FWPANIC_RESTART:
  1375. b43_controller_restart(dev, "Microcode panic");
  1376. break;
  1377. }
  1378. }
  1379. static void handle_irq_ucode_debug(struct b43_wldev *dev)
  1380. {
  1381. unsigned int i, cnt;
  1382. u16 reason, marker_id, marker_line;
  1383. __le16 *buf;
  1384. /* The proprietary firmware doesn't have this IRQ. */
  1385. if (!dev->fw.opensource)
  1386. return;
  1387. /* Read the register that contains the reason code for this IRQ. */
  1388. reason = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_DEBUGIRQ_REASON_REG);
  1389. switch (reason) {
  1390. case B43_DEBUGIRQ_PANIC:
  1391. b43_handle_firmware_panic(dev);
  1392. break;
  1393. case B43_DEBUGIRQ_DUMP_SHM:
  1394. if (!B43_DEBUG)
  1395. break; /* Only with driver debugging enabled. */
  1396. buf = kmalloc(4096, GFP_ATOMIC);
  1397. if (!buf) {
  1398. b43dbg(dev->wl, "SHM-dump: Failed to allocate memory\n");
  1399. goto out;
  1400. }
  1401. for (i = 0; i < 4096; i += 2) {
  1402. u16 tmp = b43_shm_read16(dev, B43_SHM_SHARED, i);
  1403. buf[i / 2] = cpu_to_le16(tmp);
  1404. }
  1405. b43info(dev->wl, "Shared memory dump:\n");
  1406. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_OFFSET,
  1407. 16, 2, buf, 4096, 1);
  1408. kfree(buf);
  1409. break;
  1410. case B43_DEBUGIRQ_DUMP_REGS:
  1411. if (!B43_DEBUG)
  1412. break; /* Only with driver debugging enabled. */
  1413. b43info(dev->wl, "Microcode register dump:\n");
  1414. for (i = 0, cnt = 0; i < 64; i++) {
  1415. u16 tmp = b43_shm_read16(dev, B43_SHM_SCRATCH, i);
  1416. if (cnt == 0)
  1417. printk(KERN_INFO);
  1418. printk("r%02u: 0x%04X ", i, tmp);
  1419. cnt++;
  1420. if (cnt == 6) {
  1421. printk("\n");
  1422. cnt = 0;
  1423. }
  1424. }
  1425. printk("\n");
  1426. break;
  1427. case B43_DEBUGIRQ_MARKER:
  1428. if (!B43_DEBUG)
  1429. break; /* Only with driver debugging enabled. */
  1430. marker_id = b43_shm_read16(dev, B43_SHM_SCRATCH,
  1431. B43_MARKER_ID_REG);
  1432. marker_line = b43_shm_read16(dev, B43_SHM_SCRATCH,
  1433. B43_MARKER_LINE_REG);
  1434. b43info(dev->wl, "The firmware just executed the MARKER(%u) "
  1435. "at line number %u\n",
  1436. marker_id, marker_line);
  1437. break;
  1438. default:
  1439. b43dbg(dev->wl, "Debug-IRQ triggered for unknown reason: %u\n",
  1440. reason);
  1441. }
  1442. out:
  1443. /* Acknowledge the debug-IRQ, so the firmware can continue. */
  1444. b43_shm_write16(dev, B43_SHM_SCRATCH,
  1445. B43_DEBUGIRQ_REASON_REG, B43_DEBUGIRQ_ACK);
  1446. }
  1447. /* Interrupt handler bottom-half */
  1448. static void b43_interrupt_tasklet(struct b43_wldev *dev)
  1449. {
  1450. u32 reason;
  1451. u32 dma_reason[ARRAY_SIZE(dev->dma_reason)];
  1452. u32 merged_dma_reason = 0;
  1453. int i;
  1454. unsigned long flags;
  1455. spin_lock_irqsave(&dev->wl->irq_lock, flags);
  1456. B43_WARN_ON(b43_status(dev) != B43_STAT_STARTED);
  1457. reason = dev->irq_reason;
  1458. for (i = 0; i < ARRAY_SIZE(dma_reason); i++) {
  1459. dma_reason[i] = dev->dma_reason[i];
  1460. merged_dma_reason |= dma_reason[i];
  1461. }
  1462. if (unlikely(reason & B43_IRQ_MAC_TXERR))
  1463. b43err(dev->wl, "MAC transmission error\n");
  1464. if (unlikely(reason & B43_IRQ_PHY_TXERR)) {
  1465. b43err(dev->wl, "PHY transmission error\n");
  1466. rmb();
  1467. if (unlikely(atomic_dec_and_test(&dev->phy.txerr_cnt))) {
  1468. atomic_set(&dev->phy.txerr_cnt,
  1469. B43_PHY_TX_BADNESS_LIMIT);
  1470. b43err(dev->wl, "Too many PHY TX errors, "
  1471. "restarting the controller\n");
  1472. b43_controller_restart(dev, "PHY TX errors");
  1473. }
  1474. }
  1475. if (unlikely(merged_dma_reason & (B43_DMAIRQ_FATALMASK |
  1476. B43_DMAIRQ_NONFATALMASK))) {
  1477. if (merged_dma_reason & B43_DMAIRQ_FATALMASK) {
  1478. b43err(dev->wl, "Fatal DMA error: "
  1479. "0x%08X, 0x%08X, 0x%08X, "
  1480. "0x%08X, 0x%08X, 0x%08X\n",
  1481. dma_reason[0], dma_reason[1],
  1482. dma_reason[2], dma_reason[3],
  1483. dma_reason[4], dma_reason[5]);
  1484. b43_controller_restart(dev, "DMA error");
  1485. mmiowb();
  1486. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1487. return;
  1488. }
  1489. if (merged_dma_reason & B43_DMAIRQ_NONFATALMASK) {
  1490. b43err(dev->wl, "DMA error: "
  1491. "0x%08X, 0x%08X, 0x%08X, "
  1492. "0x%08X, 0x%08X, 0x%08X\n",
  1493. dma_reason[0], dma_reason[1],
  1494. dma_reason[2], dma_reason[3],
  1495. dma_reason[4], dma_reason[5]);
  1496. }
  1497. }
  1498. if (unlikely(reason & B43_IRQ_UCODE_DEBUG))
  1499. handle_irq_ucode_debug(dev);
  1500. if (reason & B43_IRQ_TBTT_INDI)
  1501. handle_irq_tbtt_indication(dev);
  1502. if (reason & B43_IRQ_ATIM_END)
  1503. handle_irq_atim_end(dev);
  1504. if (reason & B43_IRQ_BEACON)
  1505. handle_irq_beacon(dev);
  1506. if (reason & B43_IRQ_PMQ)
  1507. handle_irq_pmq(dev);
  1508. if (reason & B43_IRQ_TXFIFO_FLUSH_OK)
  1509. ;/* TODO */
  1510. if (reason & B43_IRQ_NOISESAMPLE_OK)
  1511. handle_irq_noise(dev);
  1512. /* Check the DMA reason registers for received data. */
  1513. if (dma_reason[0] & B43_DMAIRQ_RX_DONE) {
  1514. if (b43_using_pio_transfers(dev))
  1515. b43_pio_rx(dev->pio.rx_queue);
  1516. else
  1517. b43_dma_rx(dev->dma.rx_ring);
  1518. }
  1519. B43_WARN_ON(dma_reason[1] & B43_DMAIRQ_RX_DONE);
  1520. B43_WARN_ON(dma_reason[2] & B43_DMAIRQ_RX_DONE);
  1521. B43_WARN_ON(dma_reason[3] & B43_DMAIRQ_RX_DONE);
  1522. B43_WARN_ON(dma_reason[4] & B43_DMAIRQ_RX_DONE);
  1523. B43_WARN_ON(dma_reason[5] & B43_DMAIRQ_RX_DONE);
  1524. if (reason & B43_IRQ_TX_OK)
  1525. handle_irq_transmit_status(dev);
  1526. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  1527. mmiowb();
  1528. spin_unlock_irqrestore(&dev->wl->irq_lock, flags);
  1529. }
  1530. static void b43_interrupt_ack(struct b43_wldev *dev, u32 reason)
  1531. {
  1532. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, reason);
  1533. b43_write32(dev, B43_MMIO_DMA0_REASON, dev->dma_reason[0]);
  1534. b43_write32(dev, B43_MMIO_DMA1_REASON, dev->dma_reason[1]);
  1535. b43_write32(dev, B43_MMIO_DMA2_REASON, dev->dma_reason[2]);
  1536. b43_write32(dev, B43_MMIO_DMA3_REASON, dev->dma_reason[3]);
  1537. b43_write32(dev, B43_MMIO_DMA4_REASON, dev->dma_reason[4]);
  1538. /* Unused ring
  1539. b43_write32(dev, B43_MMIO_DMA5_REASON, dev->dma_reason[5]);
  1540. */
  1541. }
  1542. /* Interrupt handler top-half */
  1543. static irqreturn_t b43_interrupt_handler(int irq, void *dev_id)
  1544. {
  1545. irqreturn_t ret = IRQ_NONE;
  1546. struct b43_wldev *dev = dev_id;
  1547. u32 reason;
  1548. B43_WARN_ON(!dev);
  1549. spin_lock(&dev->wl->irq_lock);
  1550. if (unlikely(b43_status(dev) < B43_STAT_STARTED)) {
  1551. /* This can only happen on shared IRQ lines. */
  1552. goto out;
  1553. }
  1554. reason = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1555. if (reason == 0xffffffff) /* shared IRQ */
  1556. goto out;
  1557. ret = IRQ_HANDLED;
  1558. reason &= dev->irq_mask;
  1559. if (!reason)
  1560. goto out;
  1561. dev->dma_reason[0] = b43_read32(dev, B43_MMIO_DMA0_REASON)
  1562. & 0x0001DC00;
  1563. dev->dma_reason[1] = b43_read32(dev, B43_MMIO_DMA1_REASON)
  1564. & 0x0000DC00;
  1565. dev->dma_reason[2] = b43_read32(dev, B43_MMIO_DMA2_REASON)
  1566. & 0x0000DC00;
  1567. dev->dma_reason[3] = b43_read32(dev, B43_MMIO_DMA3_REASON)
  1568. & 0x0001DC00;
  1569. dev->dma_reason[4] = b43_read32(dev, B43_MMIO_DMA4_REASON)
  1570. & 0x0000DC00;
  1571. /* Unused ring
  1572. dev->dma_reason[5] = b43_read32(dev, B43_MMIO_DMA5_REASON)
  1573. & 0x0000DC00;
  1574. */
  1575. b43_interrupt_ack(dev, reason);
  1576. /* disable all IRQs. They are enabled again in the bottom half. */
  1577. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  1578. /* save the reason code and call our bottom half. */
  1579. dev->irq_reason = reason;
  1580. tasklet_schedule(&dev->isr_tasklet);
  1581. out:
  1582. mmiowb();
  1583. spin_unlock(&dev->wl->irq_lock);
  1584. return ret;
  1585. }
  1586. void b43_do_release_fw(struct b43_firmware_file *fw)
  1587. {
  1588. release_firmware(fw->data);
  1589. fw->data = NULL;
  1590. fw->filename = NULL;
  1591. }
  1592. static void b43_release_firmware(struct b43_wldev *dev)
  1593. {
  1594. b43_do_release_fw(&dev->fw.ucode);
  1595. b43_do_release_fw(&dev->fw.pcm);
  1596. b43_do_release_fw(&dev->fw.initvals);
  1597. b43_do_release_fw(&dev->fw.initvals_band);
  1598. }
  1599. static void b43_print_fw_helptext(struct b43_wl *wl, bool error)
  1600. {
  1601. const char text[] =
  1602. "You must go to " \
  1603. "http://wireless.kernel.org/en/users/Drivers/b43#devicefirmware " \
  1604. "and download the correct firmware for this driver version. " \
  1605. "Please carefully read all instructions on this website.\n";
  1606. if (error)
  1607. b43err(wl, text);
  1608. else
  1609. b43warn(wl, text);
  1610. }
  1611. int b43_do_request_fw(struct b43_request_fw_context *ctx,
  1612. const char *name,
  1613. struct b43_firmware_file *fw)
  1614. {
  1615. const struct firmware *blob;
  1616. struct b43_fw_header *hdr;
  1617. u32 size;
  1618. int err;
  1619. if (!name) {
  1620. /* Don't fetch anything. Free possibly cached firmware. */
  1621. /* FIXME: We should probably keep it anyway, to save some headache
  1622. * on suspend/resume with multiband devices. */
  1623. b43_do_release_fw(fw);
  1624. return 0;
  1625. }
  1626. if (fw->filename) {
  1627. if ((fw->type == ctx->req_type) &&
  1628. (strcmp(fw->filename, name) == 0))
  1629. return 0; /* Already have this fw. */
  1630. /* Free the cached firmware first. */
  1631. /* FIXME: We should probably do this later after we successfully
  1632. * got the new fw. This could reduce headache with multiband devices.
  1633. * We could also redesign this to cache the firmware for all possible
  1634. * bands all the time. */
  1635. b43_do_release_fw(fw);
  1636. }
  1637. switch (ctx->req_type) {
  1638. case B43_FWTYPE_PROPRIETARY:
  1639. snprintf(ctx->fwname, sizeof(ctx->fwname),
  1640. "b43%s/%s.fw",
  1641. modparam_fwpostfix, name);
  1642. break;
  1643. case B43_FWTYPE_OPENSOURCE:
  1644. snprintf(ctx->fwname, sizeof(ctx->fwname),
  1645. "b43-open%s/%s.fw",
  1646. modparam_fwpostfix, name);
  1647. break;
  1648. default:
  1649. B43_WARN_ON(1);
  1650. return -ENOSYS;
  1651. }
  1652. err = request_firmware(&blob, ctx->fwname, ctx->dev->dev->dev);
  1653. if (err == -ENOENT) {
  1654. snprintf(ctx->errors[ctx->req_type],
  1655. sizeof(ctx->errors[ctx->req_type]),
  1656. "Firmware file \"%s\" not found\n", ctx->fwname);
  1657. return err;
  1658. } else if (err) {
  1659. snprintf(ctx->errors[ctx->req_type],
  1660. sizeof(ctx->errors[ctx->req_type]),
  1661. "Firmware file \"%s\" request failed (err=%d)\n",
  1662. ctx->fwname, err);
  1663. return err;
  1664. }
  1665. if (blob->size < sizeof(struct b43_fw_header))
  1666. goto err_format;
  1667. hdr = (struct b43_fw_header *)(blob->data);
  1668. switch (hdr->type) {
  1669. case B43_FW_TYPE_UCODE:
  1670. case B43_FW_TYPE_PCM:
  1671. size = be32_to_cpu(hdr->size);
  1672. if (size != blob->size - sizeof(struct b43_fw_header))
  1673. goto err_format;
  1674. /* fallthrough */
  1675. case B43_FW_TYPE_IV:
  1676. if (hdr->ver != 1)
  1677. goto err_format;
  1678. break;
  1679. default:
  1680. goto err_format;
  1681. }
  1682. fw->data = blob;
  1683. fw->filename = name;
  1684. fw->type = ctx->req_type;
  1685. return 0;
  1686. err_format:
  1687. snprintf(ctx->errors[ctx->req_type],
  1688. sizeof(ctx->errors[ctx->req_type]),
  1689. "Firmware file \"%s\" format error.\n", ctx->fwname);
  1690. release_firmware(blob);
  1691. return -EPROTO;
  1692. }
  1693. static int b43_try_request_fw(struct b43_request_fw_context *ctx)
  1694. {
  1695. struct b43_wldev *dev = ctx->dev;
  1696. struct b43_firmware *fw = &ctx->dev->fw;
  1697. const u8 rev = ctx->dev->dev->id.revision;
  1698. const char *filename;
  1699. u32 tmshigh;
  1700. int err;
  1701. /* Get microcode */
  1702. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  1703. if ((rev >= 5) && (rev <= 10))
  1704. filename = "ucode5";
  1705. else if ((rev >= 11) && (rev <= 12))
  1706. filename = "ucode11";
  1707. else if (rev >= 13)
  1708. filename = "ucode13";
  1709. else
  1710. goto err_no_ucode;
  1711. err = b43_do_request_fw(ctx, filename, &fw->ucode);
  1712. if (err)
  1713. goto err_load;
  1714. /* Get PCM code */
  1715. if ((rev >= 5) && (rev <= 10))
  1716. filename = "pcm5";
  1717. else if (rev >= 11)
  1718. filename = NULL;
  1719. else
  1720. goto err_no_pcm;
  1721. fw->pcm_request_failed = 0;
  1722. err = b43_do_request_fw(ctx, filename, &fw->pcm);
  1723. if (err == -ENOENT) {
  1724. /* We did not find a PCM file? Not fatal, but
  1725. * core rev <= 10 must do without hwcrypto then. */
  1726. fw->pcm_request_failed = 1;
  1727. } else if (err)
  1728. goto err_load;
  1729. /* Get initvals */
  1730. switch (dev->phy.type) {
  1731. case B43_PHYTYPE_A:
  1732. if ((rev >= 5) && (rev <= 10)) {
  1733. if (tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY)
  1734. filename = "a0g1initvals5";
  1735. else
  1736. filename = "a0g0initvals5";
  1737. } else
  1738. goto err_no_initvals;
  1739. break;
  1740. case B43_PHYTYPE_G:
  1741. if ((rev >= 5) && (rev <= 10))
  1742. filename = "b0g0initvals5";
  1743. else if (rev >= 13)
  1744. filename = "b0g0initvals13";
  1745. else
  1746. goto err_no_initvals;
  1747. break;
  1748. case B43_PHYTYPE_N:
  1749. if ((rev >= 11) && (rev <= 12))
  1750. filename = "n0initvals11";
  1751. else
  1752. goto err_no_initvals;
  1753. break;
  1754. default:
  1755. goto err_no_initvals;
  1756. }
  1757. err = b43_do_request_fw(ctx, filename, &fw->initvals);
  1758. if (err)
  1759. goto err_load;
  1760. /* Get bandswitch initvals */
  1761. switch (dev->phy.type) {
  1762. case B43_PHYTYPE_A:
  1763. if ((rev >= 5) && (rev <= 10)) {
  1764. if (tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY)
  1765. filename = "a0g1bsinitvals5";
  1766. else
  1767. filename = "a0g0bsinitvals5";
  1768. } else if (rev >= 11)
  1769. filename = NULL;
  1770. else
  1771. goto err_no_initvals;
  1772. break;
  1773. case B43_PHYTYPE_G:
  1774. if ((rev >= 5) && (rev <= 10))
  1775. filename = "b0g0bsinitvals5";
  1776. else if (rev >= 11)
  1777. filename = NULL;
  1778. else
  1779. goto err_no_initvals;
  1780. break;
  1781. case B43_PHYTYPE_N:
  1782. if ((rev >= 11) && (rev <= 12))
  1783. filename = "n0bsinitvals11";
  1784. else
  1785. goto err_no_initvals;
  1786. break;
  1787. default:
  1788. goto err_no_initvals;
  1789. }
  1790. err = b43_do_request_fw(ctx, filename, &fw->initvals_band);
  1791. if (err)
  1792. goto err_load;
  1793. return 0;
  1794. err_no_ucode:
  1795. err = ctx->fatal_failure = -EOPNOTSUPP;
  1796. b43err(dev->wl, "The driver does not know which firmware (ucode) "
  1797. "is required for your device (wl-core rev %u)\n", rev);
  1798. goto error;
  1799. err_no_pcm:
  1800. err = ctx->fatal_failure = -EOPNOTSUPP;
  1801. b43err(dev->wl, "The driver does not know which firmware (PCM) "
  1802. "is required for your device (wl-core rev %u)\n", rev);
  1803. goto error;
  1804. err_no_initvals:
  1805. err = ctx->fatal_failure = -EOPNOTSUPP;
  1806. b43err(dev->wl, "The driver does not know which firmware (initvals) "
  1807. "is required for your device (wl-core rev %u)\n", rev);
  1808. goto error;
  1809. err_load:
  1810. /* We failed to load this firmware image. The error message
  1811. * already is in ctx->errors. Return and let our caller decide
  1812. * what to do. */
  1813. goto error;
  1814. error:
  1815. b43_release_firmware(dev);
  1816. return err;
  1817. }
  1818. static int b43_request_firmware(struct b43_wldev *dev)
  1819. {
  1820. struct b43_request_fw_context *ctx;
  1821. unsigned int i;
  1822. int err;
  1823. const char *errmsg;
  1824. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  1825. if (!ctx)
  1826. return -ENOMEM;
  1827. ctx->dev = dev;
  1828. ctx->req_type = B43_FWTYPE_PROPRIETARY;
  1829. err = b43_try_request_fw(ctx);
  1830. if (!err)
  1831. goto out; /* Successfully loaded it. */
  1832. err = ctx->fatal_failure;
  1833. if (err)
  1834. goto out;
  1835. ctx->req_type = B43_FWTYPE_OPENSOURCE;
  1836. err = b43_try_request_fw(ctx);
  1837. if (!err)
  1838. goto out; /* Successfully loaded it. */
  1839. err = ctx->fatal_failure;
  1840. if (err)
  1841. goto out;
  1842. /* Could not find a usable firmware. Print the errors. */
  1843. for (i = 0; i < B43_NR_FWTYPES; i++) {
  1844. errmsg = ctx->errors[i];
  1845. if (strlen(errmsg))
  1846. b43err(dev->wl, errmsg);
  1847. }
  1848. b43_print_fw_helptext(dev->wl, 1);
  1849. err = -ENOENT;
  1850. out:
  1851. kfree(ctx);
  1852. return err;
  1853. }
  1854. static int b43_upload_microcode(struct b43_wldev *dev)
  1855. {
  1856. const size_t hdr_len = sizeof(struct b43_fw_header);
  1857. const __be32 *data;
  1858. unsigned int i, len;
  1859. u16 fwrev, fwpatch, fwdate, fwtime;
  1860. u32 tmp, macctl;
  1861. int err = 0;
  1862. /* Jump the microcode PSM to offset 0 */
  1863. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1864. B43_WARN_ON(macctl & B43_MACCTL_PSM_RUN);
  1865. macctl |= B43_MACCTL_PSM_JMP0;
  1866. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1867. /* Zero out all microcode PSM registers and shared memory. */
  1868. for (i = 0; i < 64; i++)
  1869. b43_shm_write16(dev, B43_SHM_SCRATCH, i, 0);
  1870. for (i = 0; i < 4096; i += 2)
  1871. b43_shm_write16(dev, B43_SHM_SHARED, i, 0);
  1872. /* Upload Microcode. */
  1873. data = (__be32 *) (dev->fw.ucode.data->data + hdr_len);
  1874. len = (dev->fw.ucode.data->size - hdr_len) / sizeof(__be32);
  1875. b43_shm_control_word(dev, B43_SHM_UCODE | B43_SHM_AUTOINC_W, 0x0000);
  1876. for (i = 0; i < len; i++) {
  1877. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  1878. udelay(10);
  1879. }
  1880. if (dev->fw.pcm.data) {
  1881. /* Upload PCM data. */
  1882. data = (__be32 *) (dev->fw.pcm.data->data + hdr_len);
  1883. len = (dev->fw.pcm.data->size - hdr_len) / sizeof(__be32);
  1884. b43_shm_control_word(dev, B43_SHM_HW, 0x01EA);
  1885. b43_write32(dev, B43_MMIO_SHM_DATA, 0x00004000);
  1886. /* No need for autoinc bit in SHM_HW */
  1887. b43_shm_control_word(dev, B43_SHM_HW, 0x01EB);
  1888. for (i = 0; i < len; i++) {
  1889. b43_write32(dev, B43_MMIO_SHM_DATA, be32_to_cpu(data[i]));
  1890. udelay(10);
  1891. }
  1892. }
  1893. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, B43_IRQ_ALL);
  1894. /* Start the microcode PSM */
  1895. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1896. macctl &= ~B43_MACCTL_PSM_JMP0;
  1897. macctl |= B43_MACCTL_PSM_RUN;
  1898. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1899. /* Wait for the microcode to load and respond */
  1900. i = 0;
  1901. while (1) {
  1902. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  1903. if (tmp == B43_IRQ_MAC_SUSPENDED)
  1904. break;
  1905. i++;
  1906. if (i >= 20) {
  1907. b43err(dev->wl, "Microcode not responding\n");
  1908. b43_print_fw_helptext(dev->wl, 1);
  1909. err = -ENODEV;
  1910. goto error;
  1911. }
  1912. msleep_interruptible(50);
  1913. if (signal_pending(current)) {
  1914. err = -EINTR;
  1915. goto error;
  1916. }
  1917. }
  1918. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON); /* dummy read */
  1919. /* Get and check the revisions. */
  1920. fwrev = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEREV);
  1921. fwpatch = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEPATCH);
  1922. fwdate = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODEDATE);
  1923. fwtime = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_UCODETIME);
  1924. if (fwrev <= 0x128) {
  1925. b43err(dev->wl, "YOUR FIRMWARE IS TOO OLD. Firmware from "
  1926. "binary drivers older than version 4.x is unsupported. "
  1927. "You must upgrade your firmware files.\n");
  1928. b43_print_fw_helptext(dev->wl, 1);
  1929. err = -EOPNOTSUPP;
  1930. goto error;
  1931. }
  1932. dev->fw.rev = fwrev;
  1933. dev->fw.patch = fwpatch;
  1934. dev->fw.opensource = (fwdate == 0xFFFF);
  1935. /* Default to use-all-queues. */
  1936. dev->wl->hw->queues = dev->wl->mac80211_initially_registered_queues;
  1937. dev->qos_enabled = !!modparam_qos;
  1938. /* Default to firmware/hardware crypto acceleration. */
  1939. dev->hwcrypto_enabled = 1;
  1940. if (dev->fw.opensource) {
  1941. u16 fwcapa;
  1942. /* Patchlevel info is encoded in the "time" field. */
  1943. dev->fw.patch = fwtime;
  1944. b43info(dev->wl, "Loading OpenSource firmware version %u.%u\n",
  1945. dev->fw.rev, dev->fw.patch);
  1946. fwcapa = b43_fwcapa_read(dev);
  1947. if (!(fwcapa & B43_FWCAPA_HWCRYPTO) || dev->fw.pcm_request_failed) {
  1948. b43info(dev->wl, "Hardware crypto acceleration not supported by firmware\n");
  1949. /* Disable hardware crypto and fall back to software crypto. */
  1950. dev->hwcrypto_enabled = 0;
  1951. }
  1952. if (!(fwcapa & B43_FWCAPA_QOS)) {
  1953. b43info(dev->wl, "QoS not supported by firmware\n");
  1954. /* Disable QoS. Tweak hw->queues to 1. It will be restored before
  1955. * ieee80211_unregister to make sure the networking core can
  1956. * properly free possible resources. */
  1957. dev->wl->hw->queues = 1;
  1958. dev->qos_enabled = 0;
  1959. }
  1960. } else {
  1961. b43info(dev->wl, "Loading firmware version %u.%u "
  1962. "(20%.2i-%.2i-%.2i %.2i:%.2i:%.2i)\n",
  1963. fwrev, fwpatch,
  1964. (fwdate >> 12) & 0xF, (fwdate >> 8) & 0xF, fwdate & 0xFF,
  1965. (fwtime >> 11) & 0x1F, (fwtime >> 5) & 0x3F, fwtime & 0x1F);
  1966. if (dev->fw.pcm_request_failed) {
  1967. b43warn(dev->wl, "No \"pcm5.fw\" firmware file found. "
  1968. "Hardware accelerated cryptography is disabled.\n");
  1969. b43_print_fw_helptext(dev->wl, 0);
  1970. }
  1971. }
  1972. if (b43_is_old_txhdr_format(dev)) {
  1973. /* We're over the deadline, but we keep support for old fw
  1974. * until it turns out to be in major conflict with something new. */
  1975. b43warn(dev->wl, "You are using an old firmware image. "
  1976. "Support for old firmware will be removed soon "
  1977. "(official deadline was July 2008).\n");
  1978. b43_print_fw_helptext(dev->wl, 0);
  1979. }
  1980. return 0;
  1981. error:
  1982. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  1983. macctl &= ~B43_MACCTL_PSM_RUN;
  1984. macctl |= B43_MACCTL_PSM_JMP0;
  1985. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  1986. return err;
  1987. }
  1988. static int b43_write_initvals(struct b43_wldev *dev,
  1989. const struct b43_iv *ivals,
  1990. size_t count,
  1991. size_t array_size)
  1992. {
  1993. const struct b43_iv *iv;
  1994. u16 offset;
  1995. size_t i;
  1996. bool bit32;
  1997. BUILD_BUG_ON(sizeof(struct b43_iv) != 6);
  1998. iv = ivals;
  1999. for (i = 0; i < count; i++) {
  2000. if (array_size < sizeof(iv->offset_size))
  2001. goto err_format;
  2002. array_size -= sizeof(iv->offset_size);
  2003. offset = be16_to_cpu(iv->offset_size);
  2004. bit32 = !!(offset & B43_IV_32BIT);
  2005. offset &= B43_IV_OFFSET_MASK;
  2006. if (offset >= 0x1000)
  2007. goto err_format;
  2008. if (bit32) {
  2009. u32 value;
  2010. if (array_size < sizeof(iv->data.d32))
  2011. goto err_format;
  2012. array_size -= sizeof(iv->data.d32);
  2013. value = get_unaligned_be32(&iv->data.d32);
  2014. b43_write32(dev, offset, value);
  2015. iv = (const struct b43_iv *)((const uint8_t *)iv +
  2016. sizeof(__be16) +
  2017. sizeof(__be32));
  2018. } else {
  2019. u16 value;
  2020. if (array_size < sizeof(iv->data.d16))
  2021. goto err_format;
  2022. array_size -= sizeof(iv->data.d16);
  2023. value = be16_to_cpu(iv->data.d16);
  2024. b43_write16(dev, offset, value);
  2025. iv = (const struct b43_iv *)((const uint8_t *)iv +
  2026. sizeof(__be16) +
  2027. sizeof(__be16));
  2028. }
  2029. }
  2030. if (array_size)
  2031. goto err_format;
  2032. return 0;
  2033. err_format:
  2034. b43err(dev->wl, "Initial Values Firmware file-format error.\n");
  2035. b43_print_fw_helptext(dev->wl, 1);
  2036. return -EPROTO;
  2037. }
  2038. static int b43_upload_initvals(struct b43_wldev *dev)
  2039. {
  2040. const size_t hdr_len = sizeof(struct b43_fw_header);
  2041. const struct b43_fw_header *hdr;
  2042. struct b43_firmware *fw = &dev->fw;
  2043. const struct b43_iv *ivals;
  2044. size_t count;
  2045. int err;
  2046. hdr = (const struct b43_fw_header *)(fw->initvals.data->data);
  2047. ivals = (const struct b43_iv *)(fw->initvals.data->data + hdr_len);
  2048. count = be32_to_cpu(hdr->size);
  2049. err = b43_write_initvals(dev, ivals, count,
  2050. fw->initvals.data->size - hdr_len);
  2051. if (err)
  2052. goto out;
  2053. if (fw->initvals_band.data) {
  2054. hdr = (const struct b43_fw_header *)(fw->initvals_band.data->data);
  2055. ivals = (const struct b43_iv *)(fw->initvals_band.data->data + hdr_len);
  2056. count = be32_to_cpu(hdr->size);
  2057. err = b43_write_initvals(dev, ivals, count,
  2058. fw->initvals_band.data->size - hdr_len);
  2059. if (err)
  2060. goto out;
  2061. }
  2062. out:
  2063. return err;
  2064. }
  2065. /* Initialize the GPIOs
  2066. * http://bcm-specs.sipsolutions.net/GPIO
  2067. */
  2068. static int b43_gpio_init(struct b43_wldev *dev)
  2069. {
  2070. struct ssb_bus *bus = dev->dev->bus;
  2071. struct ssb_device *gpiodev, *pcidev = NULL;
  2072. u32 mask, set;
  2073. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  2074. & ~B43_MACCTL_GPOUTSMSK);
  2075. b43_write16(dev, B43_MMIO_GPIO_MASK, b43_read16(dev, B43_MMIO_GPIO_MASK)
  2076. | 0x000F);
  2077. mask = 0x0000001F;
  2078. set = 0x0000000F;
  2079. if (dev->dev->bus->chip_id == 0x4301) {
  2080. mask |= 0x0060;
  2081. set |= 0x0060;
  2082. }
  2083. if (0 /* FIXME: conditional unknown */ ) {
  2084. b43_write16(dev, B43_MMIO_GPIO_MASK,
  2085. b43_read16(dev, B43_MMIO_GPIO_MASK)
  2086. | 0x0100);
  2087. mask |= 0x0180;
  2088. set |= 0x0180;
  2089. }
  2090. if (dev->dev->bus->sprom.boardflags_lo & B43_BFL_PACTRL) {
  2091. b43_write16(dev, B43_MMIO_GPIO_MASK,
  2092. b43_read16(dev, B43_MMIO_GPIO_MASK)
  2093. | 0x0200);
  2094. mask |= 0x0200;
  2095. set |= 0x0200;
  2096. }
  2097. if (dev->dev->id.revision >= 2)
  2098. mask |= 0x0010; /* FIXME: This is redundant. */
  2099. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2100. pcidev = bus->pcicore.dev;
  2101. #endif
  2102. gpiodev = bus->chipco.dev ? : pcidev;
  2103. if (!gpiodev)
  2104. return 0;
  2105. ssb_write32(gpiodev, B43_GPIO_CONTROL,
  2106. (ssb_read32(gpiodev, B43_GPIO_CONTROL)
  2107. & mask) | set);
  2108. return 0;
  2109. }
  2110. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  2111. static void b43_gpio_cleanup(struct b43_wldev *dev)
  2112. {
  2113. struct ssb_bus *bus = dev->dev->bus;
  2114. struct ssb_device *gpiodev, *pcidev = NULL;
  2115. #ifdef CONFIG_SSB_DRIVER_PCICORE
  2116. pcidev = bus->pcicore.dev;
  2117. #endif
  2118. gpiodev = bus->chipco.dev ? : pcidev;
  2119. if (!gpiodev)
  2120. return;
  2121. ssb_write32(gpiodev, B43_GPIO_CONTROL, 0);
  2122. }
  2123. /* http://bcm-specs.sipsolutions.net/EnableMac */
  2124. void b43_mac_enable(struct b43_wldev *dev)
  2125. {
  2126. if (b43_debug(dev, B43_DBG_FIRMWARE)) {
  2127. u16 fwstate;
  2128. fwstate = b43_shm_read16(dev, B43_SHM_SHARED,
  2129. B43_SHM_SH_UCODESTAT);
  2130. if ((fwstate != B43_SHM_SH_UCODESTAT_SUSP) &&
  2131. (fwstate != B43_SHM_SH_UCODESTAT_SLEEP)) {
  2132. b43err(dev->wl, "b43_mac_enable(): The firmware "
  2133. "should be suspended, but current state is %u\n",
  2134. fwstate);
  2135. }
  2136. }
  2137. dev->mac_suspended--;
  2138. B43_WARN_ON(dev->mac_suspended < 0);
  2139. if (dev->mac_suspended == 0) {
  2140. b43_write32(dev, B43_MMIO_MACCTL,
  2141. b43_read32(dev, B43_MMIO_MACCTL)
  2142. | B43_MACCTL_ENABLED);
  2143. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON,
  2144. B43_IRQ_MAC_SUSPENDED);
  2145. /* Commit writes */
  2146. b43_read32(dev, B43_MMIO_MACCTL);
  2147. b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2148. b43_power_saving_ctl_bits(dev, 0);
  2149. }
  2150. }
  2151. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  2152. void b43_mac_suspend(struct b43_wldev *dev)
  2153. {
  2154. int i;
  2155. u32 tmp;
  2156. might_sleep();
  2157. B43_WARN_ON(dev->mac_suspended < 0);
  2158. if (dev->mac_suspended == 0) {
  2159. b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
  2160. b43_write32(dev, B43_MMIO_MACCTL,
  2161. b43_read32(dev, B43_MMIO_MACCTL)
  2162. & ~B43_MACCTL_ENABLED);
  2163. /* force pci to flush the write */
  2164. b43_read32(dev, B43_MMIO_MACCTL);
  2165. for (i = 35; i; i--) {
  2166. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2167. if (tmp & B43_IRQ_MAC_SUSPENDED)
  2168. goto out;
  2169. udelay(10);
  2170. }
  2171. /* Hm, it seems this will take some time. Use msleep(). */
  2172. for (i = 40; i; i--) {
  2173. tmp = b43_read32(dev, B43_MMIO_GEN_IRQ_REASON);
  2174. if (tmp & B43_IRQ_MAC_SUSPENDED)
  2175. goto out;
  2176. msleep(1);
  2177. }
  2178. b43err(dev->wl, "MAC suspend failed\n");
  2179. }
  2180. out:
  2181. dev->mac_suspended++;
  2182. }
  2183. static void b43_adjust_opmode(struct b43_wldev *dev)
  2184. {
  2185. struct b43_wl *wl = dev->wl;
  2186. u32 ctl;
  2187. u16 cfp_pretbtt;
  2188. ctl = b43_read32(dev, B43_MMIO_MACCTL);
  2189. /* Reset status to STA infrastructure mode. */
  2190. ctl &= ~B43_MACCTL_AP;
  2191. ctl &= ~B43_MACCTL_KEEP_CTL;
  2192. ctl &= ~B43_MACCTL_KEEP_BADPLCP;
  2193. ctl &= ~B43_MACCTL_KEEP_BAD;
  2194. ctl &= ~B43_MACCTL_PROMISC;
  2195. ctl &= ~B43_MACCTL_BEACPROMISC;
  2196. ctl |= B43_MACCTL_INFRA;
  2197. if (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  2198. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT))
  2199. ctl |= B43_MACCTL_AP;
  2200. else if (b43_is_mode(wl, NL80211_IFTYPE_ADHOC))
  2201. ctl &= ~B43_MACCTL_INFRA;
  2202. if (wl->filter_flags & FIF_CONTROL)
  2203. ctl |= B43_MACCTL_KEEP_CTL;
  2204. if (wl->filter_flags & FIF_FCSFAIL)
  2205. ctl |= B43_MACCTL_KEEP_BAD;
  2206. if (wl->filter_flags & FIF_PLCPFAIL)
  2207. ctl |= B43_MACCTL_KEEP_BADPLCP;
  2208. if (wl->filter_flags & FIF_PROMISC_IN_BSS)
  2209. ctl |= B43_MACCTL_PROMISC;
  2210. if (wl->filter_flags & FIF_BCN_PRBRESP_PROMISC)
  2211. ctl |= B43_MACCTL_BEACPROMISC;
  2212. /* Workaround: On old hardware the HW-MAC-address-filter
  2213. * doesn't work properly, so always run promisc in filter
  2214. * it in software. */
  2215. if (dev->dev->id.revision <= 4)
  2216. ctl |= B43_MACCTL_PROMISC;
  2217. b43_write32(dev, B43_MMIO_MACCTL, ctl);
  2218. cfp_pretbtt = 2;
  2219. if ((ctl & B43_MACCTL_INFRA) && !(ctl & B43_MACCTL_AP)) {
  2220. if (dev->dev->bus->chip_id == 0x4306 &&
  2221. dev->dev->bus->chip_rev == 3)
  2222. cfp_pretbtt = 100;
  2223. else
  2224. cfp_pretbtt = 50;
  2225. }
  2226. b43_write16(dev, 0x612, cfp_pretbtt);
  2227. }
  2228. static void b43_rate_memory_write(struct b43_wldev *dev, u16 rate, int is_ofdm)
  2229. {
  2230. u16 offset;
  2231. if (is_ofdm) {
  2232. offset = 0x480;
  2233. offset += (b43_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  2234. } else {
  2235. offset = 0x4C0;
  2236. offset += (b43_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  2237. }
  2238. b43_shm_write16(dev, B43_SHM_SHARED, offset + 0x20,
  2239. b43_shm_read16(dev, B43_SHM_SHARED, offset));
  2240. }
  2241. static void b43_rate_memory_init(struct b43_wldev *dev)
  2242. {
  2243. switch (dev->phy.type) {
  2244. case B43_PHYTYPE_A:
  2245. case B43_PHYTYPE_G:
  2246. case B43_PHYTYPE_N:
  2247. b43_rate_memory_write(dev, B43_OFDM_RATE_6MB, 1);
  2248. b43_rate_memory_write(dev, B43_OFDM_RATE_12MB, 1);
  2249. b43_rate_memory_write(dev, B43_OFDM_RATE_18MB, 1);
  2250. b43_rate_memory_write(dev, B43_OFDM_RATE_24MB, 1);
  2251. b43_rate_memory_write(dev, B43_OFDM_RATE_36MB, 1);
  2252. b43_rate_memory_write(dev, B43_OFDM_RATE_48MB, 1);
  2253. b43_rate_memory_write(dev, B43_OFDM_RATE_54MB, 1);
  2254. if (dev->phy.type == B43_PHYTYPE_A)
  2255. break;
  2256. /* fallthrough */
  2257. case B43_PHYTYPE_B:
  2258. b43_rate_memory_write(dev, B43_CCK_RATE_1MB, 0);
  2259. b43_rate_memory_write(dev, B43_CCK_RATE_2MB, 0);
  2260. b43_rate_memory_write(dev, B43_CCK_RATE_5MB, 0);
  2261. b43_rate_memory_write(dev, B43_CCK_RATE_11MB, 0);
  2262. break;
  2263. default:
  2264. B43_WARN_ON(1);
  2265. }
  2266. }
  2267. /* Set the default values for the PHY TX Control Words. */
  2268. static void b43_set_phytxctl_defaults(struct b43_wldev *dev)
  2269. {
  2270. u16 ctl = 0;
  2271. ctl |= B43_TXH_PHY_ENC_CCK;
  2272. ctl |= B43_TXH_PHY_ANT01AUTO;
  2273. ctl |= B43_TXH_PHY_TXPWR;
  2274. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_BEACPHYCTL, ctl);
  2275. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, ctl);
  2276. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, ctl);
  2277. }
  2278. /* Set the TX-Antenna for management frames sent by firmware. */
  2279. static void b43_mgmtframe_txantenna(struct b43_wldev *dev, int antenna)
  2280. {
  2281. u16 ant;
  2282. u16 tmp;
  2283. ant = b43_antenna_to_phyctl(antenna);
  2284. /* For ACK/CTS */
  2285. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL);
  2286. tmp = (tmp & ~B43_TXH_PHY_ANT) | ant;
  2287. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_ACKCTSPHYCTL, tmp);
  2288. /* For Probe Resposes */
  2289. tmp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL);
  2290. tmp = (tmp & ~B43_TXH_PHY_ANT) | ant;
  2291. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRPHYCTL, tmp);
  2292. }
  2293. /* This is the opposite of b43_chip_init() */
  2294. static void b43_chip_exit(struct b43_wldev *dev)
  2295. {
  2296. b43_phy_exit(dev);
  2297. b43_gpio_cleanup(dev);
  2298. /* firmware is released later */
  2299. }
  2300. /* Initialize the chip
  2301. * http://bcm-specs.sipsolutions.net/ChipInit
  2302. */
  2303. static int b43_chip_init(struct b43_wldev *dev)
  2304. {
  2305. struct b43_phy *phy = &dev->phy;
  2306. int err;
  2307. u32 value32, macctl;
  2308. u16 value16;
  2309. /* Initialize the MAC control */
  2310. macctl = B43_MACCTL_IHR_ENABLED | B43_MACCTL_SHM_ENABLED;
  2311. if (dev->phy.gmode)
  2312. macctl |= B43_MACCTL_GMODE;
  2313. macctl |= B43_MACCTL_INFRA;
  2314. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  2315. err = b43_request_firmware(dev);
  2316. if (err)
  2317. goto out;
  2318. err = b43_upload_microcode(dev);
  2319. if (err)
  2320. goto out; /* firmware is released later */
  2321. err = b43_gpio_init(dev);
  2322. if (err)
  2323. goto out; /* firmware is released later */
  2324. err = b43_upload_initvals(dev);
  2325. if (err)
  2326. goto err_gpio_clean;
  2327. /* Turn the Analog on and initialize the PHY. */
  2328. phy->ops->switch_analog(dev, 1);
  2329. err = b43_phy_init(dev);
  2330. if (err)
  2331. goto err_gpio_clean;
  2332. /* Disable Interference Mitigation. */
  2333. if (phy->ops->interf_mitigation)
  2334. phy->ops->interf_mitigation(dev, B43_INTERFMODE_NONE);
  2335. /* Select the antennae */
  2336. if (phy->ops->set_rx_antenna)
  2337. phy->ops->set_rx_antenna(dev, B43_ANTENNA_DEFAULT);
  2338. b43_mgmtframe_txantenna(dev, B43_ANTENNA_DEFAULT);
  2339. if (phy->type == B43_PHYTYPE_B) {
  2340. value16 = b43_read16(dev, 0x005E);
  2341. value16 |= 0x0004;
  2342. b43_write16(dev, 0x005E, value16);
  2343. }
  2344. b43_write32(dev, 0x0100, 0x01000000);
  2345. if (dev->dev->id.revision < 5)
  2346. b43_write32(dev, 0x010C, 0x01000000);
  2347. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  2348. & ~B43_MACCTL_INFRA);
  2349. b43_write32(dev, B43_MMIO_MACCTL, b43_read32(dev, B43_MMIO_MACCTL)
  2350. | B43_MACCTL_INFRA);
  2351. /* Probe Response Timeout value */
  2352. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  2353. b43_shm_write16(dev, B43_SHM_SHARED, 0x0074, 0x0000);
  2354. /* Initially set the wireless operation mode. */
  2355. b43_adjust_opmode(dev);
  2356. if (dev->dev->id.revision < 3) {
  2357. b43_write16(dev, 0x060E, 0x0000);
  2358. b43_write16(dev, 0x0610, 0x8000);
  2359. b43_write16(dev, 0x0604, 0x0000);
  2360. b43_write16(dev, 0x0606, 0x0200);
  2361. } else {
  2362. b43_write32(dev, 0x0188, 0x80000000);
  2363. b43_write32(dev, 0x018C, 0x02000000);
  2364. }
  2365. b43_write32(dev, B43_MMIO_GEN_IRQ_REASON, 0x00004000);
  2366. b43_write32(dev, B43_MMIO_DMA0_IRQ_MASK, 0x0001DC00);
  2367. b43_write32(dev, B43_MMIO_DMA1_IRQ_MASK, 0x0000DC00);
  2368. b43_write32(dev, B43_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  2369. b43_write32(dev, B43_MMIO_DMA3_IRQ_MASK, 0x0001DC00);
  2370. b43_write32(dev, B43_MMIO_DMA4_IRQ_MASK, 0x0000DC00);
  2371. b43_write32(dev, B43_MMIO_DMA5_IRQ_MASK, 0x0000DC00);
  2372. value32 = ssb_read32(dev->dev, SSB_TMSLOW);
  2373. value32 |= 0x00100000;
  2374. ssb_write32(dev->dev, SSB_TMSLOW, value32);
  2375. b43_write16(dev, B43_MMIO_POWERUP_DELAY,
  2376. dev->dev->bus->chipco.fast_pwrup_delay);
  2377. err = 0;
  2378. b43dbg(dev->wl, "Chip initialized\n");
  2379. out:
  2380. return err;
  2381. err_gpio_clean:
  2382. b43_gpio_cleanup(dev);
  2383. return err;
  2384. }
  2385. static void b43_periodic_every60sec(struct b43_wldev *dev)
  2386. {
  2387. const struct b43_phy_operations *ops = dev->phy.ops;
  2388. if (ops->pwork_60sec)
  2389. ops->pwork_60sec(dev);
  2390. /* Force check the TX power emission now. */
  2391. b43_phy_txpower_check(dev, B43_TXPWR_IGNORE_TIME);
  2392. }
  2393. static void b43_periodic_every30sec(struct b43_wldev *dev)
  2394. {
  2395. /* Update device statistics. */
  2396. b43_calculate_link_quality(dev);
  2397. }
  2398. static void b43_periodic_every15sec(struct b43_wldev *dev)
  2399. {
  2400. struct b43_phy *phy = &dev->phy;
  2401. u16 wdr;
  2402. if (dev->fw.opensource) {
  2403. /* Check if the firmware is still alive.
  2404. * It will reset the watchdog counter to 0 in its idle loop. */
  2405. wdr = b43_shm_read16(dev, B43_SHM_SCRATCH, B43_WATCHDOG_REG);
  2406. if (unlikely(wdr)) {
  2407. b43err(dev->wl, "Firmware watchdog: The firmware died!\n");
  2408. b43_controller_restart(dev, "Firmware watchdog");
  2409. return;
  2410. } else {
  2411. b43_shm_write16(dev, B43_SHM_SCRATCH,
  2412. B43_WATCHDOG_REG, 1);
  2413. }
  2414. }
  2415. if (phy->ops->pwork_15sec)
  2416. phy->ops->pwork_15sec(dev);
  2417. atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
  2418. wmb();
  2419. }
  2420. static void do_periodic_work(struct b43_wldev *dev)
  2421. {
  2422. unsigned int state;
  2423. state = dev->periodic_state;
  2424. if (state % 4 == 0)
  2425. b43_periodic_every60sec(dev);
  2426. if (state % 2 == 0)
  2427. b43_periodic_every30sec(dev);
  2428. b43_periodic_every15sec(dev);
  2429. }
  2430. /* Periodic work locking policy:
  2431. * The whole periodic work handler is protected by
  2432. * wl->mutex. If another lock is needed somewhere in the
  2433. * pwork callchain, it's aquired in-place, where it's needed.
  2434. */
  2435. static void b43_periodic_work_handler(struct work_struct *work)
  2436. {
  2437. struct b43_wldev *dev = container_of(work, struct b43_wldev,
  2438. periodic_work.work);
  2439. struct b43_wl *wl = dev->wl;
  2440. unsigned long delay;
  2441. mutex_lock(&wl->mutex);
  2442. if (unlikely(b43_status(dev) != B43_STAT_STARTED))
  2443. goto out;
  2444. if (b43_debug(dev, B43_DBG_PWORK_STOP))
  2445. goto out_requeue;
  2446. do_periodic_work(dev);
  2447. dev->periodic_state++;
  2448. out_requeue:
  2449. if (b43_debug(dev, B43_DBG_PWORK_FAST))
  2450. delay = msecs_to_jiffies(50);
  2451. else
  2452. delay = round_jiffies_relative(HZ * 15);
  2453. ieee80211_queue_delayed_work(wl->hw, &dev->periodic_work, delay);
  2454. out:
  2455. mutex_unlock(&wl->mutex);
  2456. }
  2457. static void b43_periodic_tasks_setup(struct b43_wldev *dev)
  2458. {
  2459. struct delayed_work *work = &dev->periodic_work;
  2460. dev->periodic_state = 0;
  2461. INIT_DELAYED_WORK(work, b43_periodic_work_handler);
  2462. ieee80211_queue_delayed_work(dev->wl->hw, work, 0);
  2463. }
  2464. /* Check if communication with the device works correctly. */
  2465. static int b43_validate_chipaccess(struct b43_wldev *dev)
  2466. {
  2467. u32 v, backup0, backup4;
  2468. backup0 = b43_shm_read32(dev, B43_SHM_SHARED, 0);
  2469. backup4 = b43_shm_read32(dev, B43_SHM_SHARED, 4);
  2470. /* Check for read/write and endianness problems. */
  2471. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0x55AAAA55);
  2472. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0x55AAAA55)
  2473. goto error;
  2474. b43_shm_write32(dev, B43_SHM_SHARED, 0, 0xAA5555AA);
  2475. if (b43_shm_read32(dev, B43_SHM_SHARED, 0) != 0xAA5555AA)
  2476. goto error;
  2477. /* Check if unaligned 32bit SHM_SHARED access works properly.
  2478. * However, don't bail out on failure, because it's noncritical. */
  2479. b43_shm_write16(dev, B43_SHM_SHARED, 0, 0x1122);
  2480. b43_shm_write16(dev, B43_SHM_SHARED, 2, 0x3344);
  2481. b43_shm_write16(dev, B43_SHM_SHARED, 4, 0x5566);
  2482. b43_shm_write16(dev, B43_SHM_SHARED, 6, 0x7788);
  2483. if (b43_shm_read32(dev, B43_SHM_SHARED, 2) != 0x55663344)
  2484. b43warn(dev->wl, "Unaligned 32bit SHM read access is broken\n");
  2485. b43_shm_write32(dev, B43_SHM_SHARED, 2, 0xAABBCCDD);
  2486. if (b43_shm_read16(dev, B43_SHM_SHARED, 0) != 0x1122 ||
  2487. b43_shm_read16(dev, B43_SHM_SHARED, 2) != 0xCCDD ||
  2488. b43_shm_read16(dev, B43_SHM_SHARED, 4) != 0xAABB ||
  2489. b43_shm_read16(dev, B43_SHM_SHARED, 6) != 0x7788)
  2490. b43warn(dev->wl, "Unaligned 32bit SHM write access is broken\n");
  2491. b43_shm_write32(dev, B43_SHM_SHARED, 0, backup0);
  2492. b43_shm_write32(dev, B43_SHM_SHARED, 4, backup4);
  2493. if ((dev->dev->id.revision >= 3) && (dev->dev->id.revision <= 10)) {
  2494. /* The 32bit register shadows the two 16bit registers
  2495. * with update sideeffects. Validate this. */
  2496. b43_write16(dev, B43_MMIO_TSF_CFP_START, 0xAAAA);
  2497. b43_write32(dev, B43_MMIO_TSF_CFP_START, 0xCCCCBBBB);
  2498. if (b43_read16(dev, B43_MMIO_TSF_CFP_START_LOW) != 0xBBBB)
  2499. goto error;
  2500. if (b43_read16(dev, B43_MMIO_TSF_CFP_START_HIGH) != 0xCCCC)
  2501. goto error;
  2502. }
  2503. b43_write32(dev, B43_MMIO_TSF_CFP_START, 0);
  2504. v = b43_read32(dev, B43_MMIO_MACCTL);
  2505. v |= B43_MACCTL_GMODE;
  2506. if (v != (B43_MACCTL_GMODE | B43_MACCTL_IHR_ENABLED))
  2507. goto error;
  2508. return 0;
  2509. error:
  2510. b43err(dev->wl, "Failed to validate the chipaccess\n");
  2511. return -ENODEV;
  2512. }
  2513. static void b43_security_init(struct b43_wldev *dev)
  2514. {
  2515. dev->ktp = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_KTP);
  2516. /* KTP is a word address, but we address SHM bytewise.
  2517. * So multiply by two.
  2518. */
  2519. dev->ktp *= 2;
  2520. /* Number of RCMTA address slots */
  2521. b43_write16(dev, B43_MMIO_RCMTA_COUNT, B43_NR_PAIRWISE_KEYS);
  2522. /* Clear the key memory. */
  2523. b43_clear_keys(dev);
  2524. }
  2525. #ifdef CONFIG_B43_HWRNG
  2526. static int b43_rng_read(struct hwrng *rng, u32 *data)
  2527. {
  2528. struct b43_wl *wl = (struct b43_wl *)rng->priv;
  2529. unsigned long flags;
  2530. /* Don't take wl->mutex here, as it could deadlock with
  2531. * hwrng internal locking. It's not needed to take
  2532. * wl->mutex here, anyway. */
  2533. spin_lock_irqsave(&wl->irq_lock, flags);
  2534. *data = b43_read16(wl->current_dev, B43_MMIO_RNG);
  2535. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2536. return (sizeof(u16));
  2537. }
  2538. #endif /* CONFIG_B43_HWRNG */
  2539. static void b43_rng_exit(struct b43_wl *wl)
  2540. {
  2541. #ifdef CONFIG_B43_HWRNG
  2542. if (wl->rng_initialized)
  2543. hwrng_unregister(&wl->rng);
  2544. #endif /* CONFIG_B43_HWRNG */
  2545. }
  2546. static int b43_rng_init(struct b43_wl *wl)
  2547. {
  2548. int err = 0;
  2549. #ifdef CONFIG_B43_HWRNG
  2550. snprintf(wl->rng_name, ARRAY_SIZE(wl->rng_name),
  2551. "%s_%s", KBUILD_MODNAME, wiphy_name(wl->hw->wiphy));
  2552. wl->rng.name = wl->rng_name;
  2553. wl->rng.data_read = b43_rng_read;
  2554. wl->rng.priv = (unsigned long)wl;
  2555. wl->rng_initialized = 1;
  2556. err = hwrng_register(&wl->rng);
  2557. if (err) {
  2558. wl->rng_initialized = 0;
  2559. b43err(wl, "Failed to register the random "
  2560. "number generator (%d)\n", err);
  2561. }
  2562. #endif /* CONFIG_B43_HWRNG */
  2563. return err;
  2564. }
  2565. static int b43_op_tx(struct ieee80211_hw *hw,
  2566. struct sk_buff *skb)
  2567. {
  2568. struct b43_wl *wl = hw_to_b43_wl(hw);
  2569. struct b43_wldev *dev = wl->current_dev;
  2570. unsigned long flags;
  2571. int err;
  2572. if (unlikely(skb->len < 2 + 2 + 6)) {
  2573. /* Too short, this can't be a valid frame. */
  2574. goto drop_packet;
  2575. }
  2576. B43_WARN_ON(skb_shinfo(skb)->nr_frags);
  2577. if (unlikely(!dev))
  2578. goto drop_packet;
  2579. /* Transmissions on seperate queues can run concurrently. */
  2580. read_lock_irqsave(&wl->tx_lock, flags);
  2581. err = -ENODEV;
  2582. if (likely(b43_status(dev) >= B43_STAT_STARTED)) {
  2583. if (b43_using_pio_transfers(dev))
  2584. err = b43_pio_tx(dev, skb);
  2585. else
  2586. err = b43_dma_tx(dev, skb);
  2587. }
  2588. read_unlock_irqrestore(&wl->tx_lock, flags);
  2589. if (unlikely(err))
  2590. goto drop_packet;
  2591. return NETDEV_TX_OK;
  2592. drop_packet:
  2593. /* We can not transmit this packet. Drop it. */
  2594. dev_kfree_skb_any(skb);
  2595. return NETDEV_TX_OK;
  2596. }
  2597. /* Locking: wl->irq_lock */
  2598. static void b43_qos_params_upload(struct b43_wldev *dev,
  2599. const struct ieee80211_tx_queue_params *p,
  2600. u16 shm_offset)
  2601. {
  2602. u16 params[B43_NR_QOSPARAMS];
  2603. int bslots, tmp;
  2604. unsigned int i;
  2605. bslots = b43_read16(dev, B43_MMIO_RNG) & p->cw_min;
  2606. memset(&params, 0, sizeof(params));
  2607. params[B43_QOSPARAM_TXOP] = p->txop * 32;
  2608. params[B43_QOSPARAM_CWMIN] = p->cw_min;
  2609. params[B43_QOSPARAM_CWMAX] = p->cw_max;
  2610. params[B43_QOSPARAM_CWCUR] = p->cw_min;
  2611. params[B43_QOSPARAM_AIFS] = p->aifs;
  2612. params[B43_QOSPARAM_BSLOTS] = bslots;
  2613. params[B43_QOSPARAM_REGGAP] = bslots + p->aifs;
  2614. for (i = 0; i < ARRAY_SIZE(params); i++) {
  2615. if (i == B43_QOSPARAM_STATUS) {
  2616. tmp = b43_shm_read16(dev, B43_SHM_SHARED,
  2617. shm_offset + (i * 2));
  2618. /* Mark the parameters as updated. */
  2619. tmp |= 0x100;
  2620. b43_shm_write16(dev, B43_SHM_SHARED,
  2621. shm_offset + (i * 2),
  2622. tmp);
  2623. } else {
  2624. b43_shm_write16(dev, B43_SHM_SHARED,
  2625. shm_offset + (i * 2),
  2626. params[i]);
  2627. }
  2628. }
  2629. }
  2630. /* Mapping of mac80211 queue numbers to b43 QoS SHM offsets. */
  2631. static const u16 b43_qos_shm_offsets[] = {
  2632. /* [mac80211-queue-nr] = SHM_OFFSET, */
  2633. [0] = B43_QOS_VOICE,
  2634. [1] = B43_QOS_VIDEO,
  2635. [2] = B43_QOS_BESTEFFORT,
  2636. [3] = B43_QOS_BACKGROUND,
  2637. };
  2638. /* Update all QOS parameters in hardware. */
  2639. static void b43_qos_upload_all(struct b43_wldev *dev)
  2640. {
  2641. struct b43_wl *wl = dev->wl;
  2642. struct b43_qos_params *params;
  2643. unsigned int i;
  2644. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  2645. ARRAY_SIZE(wl->qos_params));
  2646. b43_mac_suspend(dev);
  2647. for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
  2648. params = &(wl->qos_params[i]);
  2649. b43_qos_params_upload(dev, &(params->p),
  2650. b43_qos_shm_offsets[i]);
  2651. }
  2652. b43_mac_enable(dev);
  2653. }
  2654. static void b43_qos_clear(struct b43_wl *wl)
  2655. {
  2656. struct b43_qos_params *params;
  2657. unsigned int i;
  2658. /* Initialize QoS parameters to sane defaults. */
  2659. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  2660. ARRAY_SIZE(wl->qos_params));
  2661. for (i = 0; i < ARRAY_SIZE(wl->qos_params); i++) {
  2662. params = &(wl->qos_params[i]);
  2663. switch (b43_qos_shm_offsets[i]) {
  2664. case B43_QOS_VOICE:
  2665. params->p.txop = 0;
  2666. params->p.aifs = 2;
  2667. params->p.cw_min = 0x0001;
  2668. params->p.cw_max = 0x0001;
  2669. break;
  2670. case B43_QOS_VIDEO:
  2671. params->p.txop = 0;
  2672. params->p.aifs = 2;
  2673. params->p.cw_min = 0x0001;
  2674. params->p.cw_max = 0x0001;
  2675. break;
  2676. case B43_QOS_BESTEFFORT:
  2677. params->p.txop = 0;
  2678. params->p.aifs = 3;
  2679. params->p.cw_min = 0x0001;
  2680. params->p.cw_max = 0x03FF;
  2681. break;
  2682. case B43_QOS_BACKGROUND:
  2683. params->p.txop = 0;
  2684. params->p.aifs = 7;
  2685. params->p.cw_min = 0x0001;
  2686. params->p.cw_max = 0x03FF;
  2687. break;
  2688. default:
  2689. B43_WARN_ON(1);
  2690. }
  2691. }
  2692. }
  2693. /* Initialize the core's QOS capabilities */
  2694. static void b43_qos_init(struct b43_wldev *dev)
  2695. {
  2696. /* Upload the current QOS parameters. */
  2697. b43_qos_upload_all(dev);
  2698. /* Enable QOS support. */
  2699. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_EDCF);
  2700. b43_write16(dev, B43_MMIO_IFSCTL,
  2701. b43_read16(dev, B43_MMIO_IFSCTL)
  2702. | B43_MMIO_IFSCTL_USE_EDCF);
  2703. }
  2704. static int b43_op_conf_tx(struct ieee80211_hw *hw, u16 _queue,
  2705. const struct ieee80211_tx_queue_params *params)
  2706. {
  2707. struct b43_wl *wl = hw_to_b43_wl(hw);
  2708. struct b43_wldev *dev;
  2709. unsigned int queue = (unsigned int)_queue;
  2710. int err = -ENODEV;
  2711. if (queue >= ARRAY_SIZE(wl->qos_params)) {
  2712. /* Queue not available or don't support setting
  2713. * params on this queue. Return success to not
  2714. * confuse mac80211. */
  2715. return 0;
  2716. }
  2717. BUILD_BUG_ON(ARRAY_SIZE(b43_qos_shm_offsets) !=
  2718. ARRAY_SIZE(wl->qos_params));
  2719. mutex_lock(&wl->mutex);
  2720. dev = wl->current_dev;
  2721. if (unlikely(!dev || (b43_status(dev) < B43_STAT_INITIALIZED)))
  2722. goto out_unlock;
  2723. memcpy(&(wl->qos_params[queue].p), params, sizeof(*params));
  2724. b43_mac_suspend(dev);
  2725. b43_qos_params_upload(dev, &(wl->qos_params[queue].p),
  2726. b43_qos_shm_offsets[queue]);
  2727. b43_mac_enable(dev);
  2728. err = 0;
  2729. out_unlock:
  2730. mutex_unlock(&wl->mutex);
  2731. return err;
  2732. }
  2733. static int b43_op_get_tx_stats(struct ieee80211_hw *hw,
  2734. struct ieee80211_tx_queue_stats *stats)
  2735. {
  2736. struct b43_wl *wl = hw_to_b43_wl(hw);
  2737. struct b43_wldev *dev = wl->current_dev;
  2738. unsigned long flags;
  2739. int err = -ENODEV;
  2740. if (!dev)
  2741. goto out;
  2742. spin_lock_irqsave(&wl->irq_lock, flags);
  2743. if (likely(b43_status(dev) >= B43_STAT_STARTED)) {
  2744. if (b43_using_pio_transfers(dev))
  2745. b43_pio_get_tx_stats(dev, stats);
  2746. else
  2747. b43_dma_get_tx_stats(dev, stats);
  2748. err = 0;
  2749. }
  2750. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2751. out:
  2752. return err;
  2753. }
  2754. static int b43_op_get_stats(struct ieee80211_hw *hw,
  2755. struct ieee80211_low_level_stats *stats)
  2756. {
  2757. struct b43_wl *wl = hw_to_b43_wl(hw);
  2758. unsigned long flags;
  2759. spin_lock_irqsave(&wl->irq_lock, flags);
  2760. memcpy(stats, &wl->ieee_stats, sizeof(*stats));
  2761. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2762. return 0;
  2763. }
  2764. static u64 b43_op_get_tsf(struct ieee80211_hw *hw)
  2765. {
  2766. struct b43_wl *wl = hw_to_b43_wl(hw);
  2767. struct b43_wldev *dev;
  2768. u64 tsf;
  2769. mutex_lock(&wl->mutex);
  2770. spin_lock_irq(&wl->irq_lock);
  2771. dev = wl->current_dev;
  2772. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED))
  2773. b43_tsf_read(dev, &tsf);
  2774. else
  2775. tsf = 0;
  2776. spin_unlock_irq(&wl->irq_lock);
  2777. mutex_unlock(&wl->mutex);
  2778. return tsf;
  2779. }
  2780. static void b43_op_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  2781. {
  2782. struct b43_wl *wl = hw_to_b43_wl(hw);
  2783. struct b43_wldev *dev;
  2784. mutex_lock(&wl->mutex);
  2785. spin_lock_irq(&wl->irq_lock);
  2786. dev = wl->current_dev;
  2787. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED))
  2788. b43_tsf_write(dev, tsf);
  2789. spin_unlock_irq(&wl->irq_lock);
  2790. mutex_unlock(&wl->mutex);
  2791. }
  2792. static void b43_put_phy_into_reset(struct b43_wldev *dev)
  2793. {
  2794. struct ssb_device *sdev = dev->dev;
  2795. u32 tmslow;
  2796. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2797. tmslow &= ~B43_TMSLOW_GMODE;
  2798. tmslow |= B43_TMSLOW_PHYRESET;
  2799. tmslow |= SSB_TMSLOW_FGC;
  2800. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2801. msleep(1);
  2802. tmslow = ssb_read32(sdev, SSB_TMSLOW);
  2803. tmslow &= ~SSB_TMSLOW_FGC;
  2804. tmslow |= B43_TMSLOW_PHYRESET;
  2805. ssb_write32(sdev, SSB_TMSLOW, tmslow);
  2806. msleep(1);
  2807. }
  2808. static const char *band_to_string(enum ieee80211_band band)
  2809. {
  2810. switch (band) {
  2811. case IEEE80211_BAND_5GHZ:
  2812. return "5";
  2813. case IEEE80211_BAND_2GHZ:
  2814. return "2.4";
  2815. default:
  2816. break;
  2817. }
  2818. B43_WARN_ON(1);
  2819. return "";
  2820. }
  2821. /* Expects wl->mutex locked */
  2822. static int b43_switch_band(struct b43_wl *wl, struct ieee80211_channel *chan)
  2823. {
  2824. struct b43_wldev *up_dev = NULL;
  2825. struct b43_wldev *down_dev;
  2826. struct b43_wldev *d;
  2827. int err;
  2828. bool uninitialized_var(gmode);
  2829. int prev_status;
  2830. /* Find a device and PHY which supports the band. */
  2831. list_for_each_entry(d, &wl->devlist, list) {
  2832. switch (chan->band) {
  2833. case IEEE80211_BAND_5GHZ:
  2834. if (d->phy.supports_5ghz) {
  2835. up_dev = d;
  2836. gmode = 0;
  2837. }
  2838. break;
  2839. case IEEE80211_BAND_2GHZ:
  2840. if (d->phy.supports_2ghz) {
  2841. up_dev = d;
  2842. gmode = 1;
  2843. }
  2844. break;
  2845. default:
  2846. B43_WARN_ON(1);
  2847. return -EINVAL;
  2848. }
  2849. if (up_dev)
  2850. break;
  2851. }
  2852. if (!up_dev) {
  2853. b43err(wl, "Could not find a device for %s-GHz band operation\n",
  2854. band_to_string(chan->band));
  2855. return -ENODEV;
  2856. }
  2857. if ((up_dev == wl->current_dev) &&
  2858. (!!wl->current_dev->phy.gmode == !!gmode)) {
  2859. /* This device is already running. */
  2860. return 0;
  2861. }
  2862. b43dbg(wl, "Switching to %s-GHz band\n",
  2863. band_to_string(chan->band));
  2864. down_dev = wl->current_dev;
  2865. prev_status = b43_status(down_dev);
  2866. /* Shutdown the currently running core. */
  2867. if (prev_status >= B43_STAT_STARTED)
  2868. b43_wireless_core_stop(down_dev);
  2869. if (prev_status >= B43_STAT_INITIALIZED)
  2870. b43_wireless_core_exit(down_dev);
  2871. if (down_dev != up_dev) {
  2872. /* We switch to a different core, so we put PHY into
  2873. * RESET on the old core. */
  2874. b43_put_phy_into_reset(down_dev);
  2875. }
  2876. /* Now start the new core. */
  2877. up_dev->phy.gmode = gmode;
  2878. if (prev_status >= B43_STAT_INITIALIZED) {
  2879. err = b43_wireless_core_init(up_dev);
  2880. if (err) {
  2881. b43err(wl, "Fatal: Could not initialize device for "
  2882. "selected %s-GHz band\n",
  2883. band_to_string(chan->band));
  2884. goto init_failure;
  2885. }
  2886. }
  2887. if (prev_status >= B43_STAT_STARTED) {
  2888. err = b43_wireless_core_start(up_dev);
  2889. if (err) {
  2890. b43err(wl, "Fatal: Coult not start device for "
  2891. "selected %s-GHz band\n",
  2892. band_to_string(chan->band));
  2893. b43_wireless_core_exit(up_dev);
  2894. goto init_failure;
  2895. }
  2896. }
  2897. B43_WARN_ON(b43_status(up_dev) != prev_status);
  2898. wl->current_dev = up_dev;
  2899. return 0;
  2900. init_failure:
  2901. /* Whoops, failed to init the new core. No core is operating now. */
  2902. wl->current_dev = NULL;
  2903. return err;
  2904. }
  2905. /* Write the short and long frame retry limit values. */
  2906. static void b43_set_retry_limits(struct b43_wldev *dev,
  2907. unsigned int short_retry,
  2908. unsigned int long_retry)
  2909. {
  2910. /* The retry limit is a 4-bit counter. Enforce this to avoid overflowing
  2911. * the chip-internal counter. */
  2912. short_retry = min(short_retry, (unsigned int)0xF);
  2913. long_retry = min(long_retry, (unsigned int)0xF);
  2914. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_SRLIMIT,
  2915. short_retry);
  2916. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_LRLIMIT,
  2917. long_retry);
  2918. }
  2919. static int b43_op_config(struct ieee80211_hw *hw, u32 changed)
  2920. {
  2921. struct b43_wl *wl = hw_to_b43_wl(hw);
  2922. struct b43_wldev *dev;
  2923. struct b43_phy *phy;
  2924. struct ieee80211_conf *conf = &hw->conf;
  2925. unsigned long flags;
  2926. int antenna;
  2927. int err = 0;
  2928. mutex_lock(&wl->mutex);
  2929. /* Switch the band (if necessary). This might change the active core. */
  2930. err = b43_switch_band(wl, conf->channel);
  2931. if (err)
  2932. goto out_unlock_mutex;
  2933. dev = wl->current_dev;
  2934. phy = &dev->phy;
  2935. b43_mac_suspend(dev);
  2936. if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
  2937. b43_set_retry_limits(dev, conf->short_frame_max_tx_count,
  2938. conf->long_frame_max_tx_count);
  2939. changed &= ~IEEE80211_CONF_CHANGE_RETRY_LIMITS;
  2940. if (!changed)
  2941. goto out_mac_enable;
  2942. /* Switch to the requested channel.
  2943. * The firmware takes care of races with the TX handler. */
  2944. if (conf->channel->hw_value != phy->channel)
  2945. b43_switch_channel(dev, conf->channel->hw_value);
  2946. dev->wl->radiotap_enabled = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  2947. /* Adjust the desired TX power level. */
  2948. if (conf->power_level != 0) {
  2949. spin_lock_irqsave(&wl->irq_lock, flags);
  2950. if (conf->power_level != phy->desired_txpower) {
  2951. phy->desired_txpower = conf->power_level;
  2952. b43_phy_txpower_check(dev, B43_TXPWR_IGNORE_TIME |
  2953. B43_TXPWR_IGNORE_TSSI);
  2954. }
  2955. spin_unlock_irqrestore(&wl->irq_lock, flags);
  2956. }
  2957. /* Antennas for RX and management frame TX. */
  2958. antenna = B43_ANTENNA_DEFAULT;
  2959. b43_mgmtframe_txantenna(dev, antenna);
  2960. antenna = B43_ANTENNA_DEFAULT;
  2961. if (phy->ops->set_rx_antenna)
  2962. phy->ops->set_rx_antenna(dev, antenna);
  2963. if (wl->radio_enabled != phy->radio_on) {
  2964. if (wl->radio_enabled) {
  2965. b43_software_rfkill(dev, false);
  2966. b43info(dev->wl, "Radio turned on by software\n");
  2967. if (!dev->radio_hw_enable) {
  2968. b43info(dev->wl, "The hardware RF-kill button "
  2969. "still turns the radio physically off. "
  2970. "Press the button to turn it on.\n");
  2971. }
  2972. } else {
  2973. b43_software_rfkill(dev, true);
  2974. b43info(dev->wl, "Radio turned off by software\n");
  2975. }
  2976. }
  2977. out_mac_enable:
  2978. b43_mac_enable(dev);
  2979. out_unlock_mutex:
  2980. mutex_unlock(&wl->mutex);
  2981. return err;
  2982. }
  2983. static void b43_update_basic_rates(struct b43_wldev *dev, u32 brates)
  2984. {
  2985. struct ieee80211_supported_band *sband =
  2986. dev->wl->hw->wiphy->bands[b43_current_band(dev->wl)];
  2987. struct ieee80211_rate *rate;
  2988. int i;
  2989. u16 basic, direct, offset, basic_offset, rateptr;
  2990. for (i = 0; i < sband->n_bitrates; i++) {
  2991. rate = &sband->bitrates[i];
  2992. if (b43_is_cck_rate(rate->hw_value)) {
  2993. direct = B43_SHM_SH_CCKDIRECT;
  2994. basic = B43_SHM_SH_CCKBASIC;
  2995. offset = b43_plcp_get_ratecode_cck(rate->hw_value);
  2996. offset &= 0xF;
  2997. } else {
  2998. direct = B43_SHM_SH_OFDMDIRECT;
  2999. basic = B43_SHM_SH_OFDMBASIC;
  3000. offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
  3001. offset &= 0xF;
  3002. }
  3003. rate = ieee80211_get_response_rate(sband, brates, rate->bitrate);
  3004. if (b43_is_cck_rate(rate->hw_value)) {
  3005. basic_offset = b43_plcp_get_ratecode_cck(rate->hw_value);
  3006. basic_offset &= 0xF;
  3007. } else {
  3008. basic_offset = b43_plcp_get_ratecode_ofdm(rate->hw_value);
  3009. basic_offset &= 0xF;
  3010. }
  3011. /*
  3012. * Get the pointer that we need to point to
  3013. * from the direct map
  3014. */
  3015. rateptr = b43_shm_read16(dev, B43_SHM_SHARED,
  3016. direct + 2 * basic_offset);
  3017. /* and write it to the basic map */
  3018. b43_shm_write16(dev, B43_SHM_SHARED, basic + 2 * offset,
  3019. rateptr);
  3020. }
  3021. }
  3022. static void b43_op_bss_info_changed(struct ieee80211_hw *hw,
  3023. struct ieee80211_vif *vif,
  3024. struct ieee80211_bss_conf *conf,
  3025. u32 changed)
  3026. {
  3027. struct b43_wl *wl = hw_to_b43_wl(hw);
  3028. struct b43_wldev *dev;
  3029. unsigned long flags;
  3030. mutex_lock(&wl->mutex);
  3031. dev = wl->current_dev;
  3032. if (!dev || b43_status(dev) < B43_STAT_STARTED)
  3033. goto out_unlock_mutex;
  3034. B43_WARN_ON(wl->vif != vif);
  3035. spin_lock_irqsave(&wl->irq_lock, flags);
  3036. if (changed & BSS_CHANGED_BSSID) {
  3037. if (conf->bssid)
  3038. memcpy(wl->bssid, conf->bssid, ETH_ALEN);
  3039. else
  3040. memset(wl->bssid, 0, ETH_ALEN);
  3041. }
  3042. if (b43_status(dev) >= B43_STAT_INITIALIZED) {
  3043. if (changed & BSS_CHANGED_BEACON &&
  3044. (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  3045. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) ||
  3046. b43_is_mode(wl, NL80211_IFTYPE_ADHOC)))
  3047. b43_update_templates(wl);
  3048. if (changed & BSS_CHANGED_BSSID)
  3049. b43_write_mac_bssid_templates(dev);
  3050. }
  3051. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3052. b43_mac_suspend(dev);
  3053. /* Update templates for AP/mesh mode. */
  3054. if (changed & BSS_CHANGED_BEACON_INT &&
  3055. (b43_is_mode(wl, NL80211_IFTYPE_AP) ||
  3056. b43_is_mode(wl, NL80211_IFTYPE_MESH_POINT) ||
  3057. b43_is_mode(wl, NL80211_IFTYPE_ADHOC)))
  3058. b43_set_beacon_int(dev, conf->beacon_int);
  3059. if (changed & BSS_CHANGED_BASIC_RATES)
  3060. b43_update_basic_rates(dev, conf->basic_rates);
  3061. if (changed & BSS_CHANGED_ERP_SLOT) {
  3062. if (conf->use_short_slot)
  3063. b43_short_slot_timing_enable(dev);
  3064. else
  3065. b43_short_slot_timing_disable(dev);
  3066. }
  3067. b43_mac_enable(dev);
  3068. out_unlock_mutex:
  3069. mutex_unlock(&wl->mutex);
  3070. }
  3071. static int b43_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3072. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  3073. struct ieee80211_key_conf *key)
  3074. {
  3075. struct b43_wl *wl = hw_to_b43_wl(hw);
  3076. struct b43_wldev *dev;
  3077. u8 algorithm;
  3078. u8 index;
  3079. int err;
  3080. static const u8 bcast_addr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  3081. if (modparam_nohwcrypt)
  3082. return -ENOSPC; /* User disabled HW-crypto */
  3083. mutex_lock(&wl->mutex);
  3084. spin_lock_irq(&wl->irq_lock);
  3085. write_lock(&wl->tx_lock);
  3086. /* Why do we need all this locking here?
  3087. * mutex -> Every config operation must take it.
  3088. * irq_lock -> We modify the dev->key array, which is accessed
  3089. * in the IRQ handlers.
  3090. * tx_lock -> We modify the dev->key array, which is accessed
  3091. * in the TX handler.
  3092. */
  3093. dev = wl->current_dev;
  3094. err = -ENODEV;
  3095. if (!dev || b43_status(dev) < B43_STAT_INITIALIZED)
  3096. goto out_unlock;
  3097. if (dev->fw.pcm_request_failed || !dev->hwcrypto_enabled) {
  3098. /* We don't have firmware for the crypto engine.
  3099. * Must use software-crypto. */
  3100. err = -EOPNOTSUPP;
  3101. goto out_unlock;
  3102. }
  3103. err = -EINVAL;
  3104. switch (key->alg) {
  3105. case ALG_WEP:
  3106. if (key->keylen == WLAN_KEY_LEN_WEP40)
  3107. algorithm = B43_SEC_ALGO_WEP40;
  3108. else
  3109. algorithm = B43_SEC_ALGO_WEP104;
  3110. break;
  3111. case ALG_TKIP:
  3112. algorithm = B43_SEC_ALGO_TKIP;
  3113. break;
  3114. case ALG_CCMP:
  3115. algorithm = B43_SEC_ALGO_AES;
  3116. break;
  3117. default:
  3118. B43_WARN_ON(1);
  3119. goto out_unlock;
  3120. }
  3121. index = (u8) (key->keyidx);
  3122. if (index > 3)
  3123. goto out_unlock;
  3124. switch (cmd) {
  3125. case SET_KEY:
  3126. if (algorithm == B43_SEC_ALGO_TKIP) {
  3127. /* FIXME: No TKIP hardware encryption for now. */
  3128. err = -EOPNOTSUPP;
  3129. goto out_unlock;
  3130. }
  3131. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
  3132. if (WARN_ON(!sta)) {
  3133. err = -EOPNOTSUPP;
  3134. goto out_unlock;
  3135. }
  3136. /* Pairwise key with an assigned MAC address. */
  3137. err = b43_key_write(dev, -1, algorithm,
  3138. key->key, key->keylen,
  3139. sta->addr, key);
  3140. } else {
  3141. /* Group key */
  3142. err = b43_key_write(dev, index, algorithm,
  3143. key->key, key->keylen, NULL, key);
  3144. }
  3145. if (err)
  3146. goto out_unlock;
  3147. if (algorithm == B43_SEC_ALGO_WEP40 ||
  3148. algorithm == B43_SEC_ALGO_WEP104) {
  3149. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_USEDEFKEYS);
  3150. } else {
  3151. b43_hf_write(dev,
  3152. b43_hf_read(dev) & ~B43_HF_USEDEFKEYS);
  3153. }
  3154. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  3155. break;
  3156. case DISABLE_KEY: {
  3157. err = b43_key_clear(dev, key->hw_key_idx);
  3158. if (err)
  3159. goto out_unlock;
  3160. break;
  3161. }
  3162. default:
  3163. B43_WARN_ON(1);
  3164. }
  3165. out_unlock:
  3166. if (!err) {
  3167. b43dbg(wl, "%s hardware based encryption for keyidx: %d, "
  3168. "mac: %pM\n",
  3169. cmd == SET_KEY ? "Using" : "Disabling", key->keyidx,
  3170. sta ? sta->addr : bcast_addr);
  3171. b43_dump_keymemory(dev);
  3172. }
  3173. write_unlock(&wl->tx_lock);
  3174. spin_unlock_irq(&wl->irq_lock);
  3175. mutex_unlock(&wl->mutex);
  3176. return err;
  3177. }
  3178. static void b43_op_configure_filter(struct ieee80211_hw *hw,
  3179. unsigned int changed, unsigned int *fflags,
  3180. int mc_count, struct dev_addr_list *mc_list)
  3181. {
  3182. struct b43_wl *wl = hw_to_b43_wl(hw);
  3183. struct b43_wldev *dev = wl->current_dev;
  3184. unsigned long flags;
  3185. if (!dev) {
  3186. *fflags = 0;
  3187. return;
  3188. }
  3189. spin_lock_irqsave(&wl->irq_lock, flags);
  3190. *fflags &= FIF_PROMISC_IN_BSS |
  3191. FIF_ALLMULTI |
  3192. FIF_FCSFAIL |
  3193. FIF_PLCPFAIL |
  3194. FIF_CONTROL |
  3195. FIF_OTHER_BSS |
  3196. FIF_BCN_PRBRESP_PROMISC;
  3197. changed &= FIF_PROMISC_IN_BSS |
  3198. FIF_ALLMULTI |
  3199. FIF_FCSFAIL |
  3200. FIF_PLCPFAIL |
  3201. FIF_CONTROL |
  3202. FIF_OTHER_BSS |
  3203. FIF_BCN_PRBRESP_PROMISC;
  3204. wl->filter_flags = *fflags;
  3205. if (changed && b43_status(dev) >= B43_STAT_INITIALIZED)
  3206. b43_adjust_opmode(dev);
  3207. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3208. }
  3209. /* Locking: wl->mutex */
  3210. static void b43_wireless_core_stop(struct b43_wldev *dev)
  3211. {
  3212. struct b43_wl *wl = dev->wl;
  3213. unsigned long flags;
  3214. if (b43_status(dev) < B43_STAT_STARTED)
  3215. return;
  3216. /* Disable and sync interrupts. We must do this before than
  3217. * setting the status to INITIALIZED, as the interrupt handler
  3218. * won't care about IRQs then. */
  3219. spin_lock_irqsave(&wl->irq_lock, flags);
  3220. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, 0);
  3221. b43_read32(dev, B43_MMIO_GEN_IRQ_MASK); /* flush */
  3222. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3223. b43_synchronize_irq(dev);
  3224. write_lock_irqsave(&wl->tx_lock, flags);
  3225. b43_set_status(dev, B43_STAT_INITIALIZED);
  3226. write_unlock_irqrestore(&wl->tx_lock, flags);
  3227. b43_pio_stop(dev);
  3228. mutex_unlock(&wl->mutex);
  3229. /* Must unlock as it would otherwise deadlock. No races here.
  3230. * Cancel the possibly running self-rearming periodic work. */
  3231. cancel_delayed_work_sync(&dev->periodic_work);
  3232. mutex_lock(&wl->mutex);
  3233. b43_mac_suspend(dev);
  3234. free_irq(dev->dev->irq, dev);
  3235. b43dbg(wl, "Wireless interface stopped\n");
  3236. }
  3237. /* Locking: wl->mutex */
  3238. static int b43_wireless_core_start(struct b43_wldev *dev)
  3239. {
  3240. int err;
  3241. B43_WARN_ON(b43_status(dev) != B43_STAT_INITIALIZED);
  3242. drain_txstatus_queue(dev);
  3243. err = request_irq(dev->dev->irq, b43_interrupt_handler,
  3244. IRQF_SHARED, KBUILD_MODNAME, dev);
  3245. if (err) {
  3246. b43err(dev->wl, "Cannot request IRQ-%d\n", dev->dev->irq);
  3247. goto out;
  3248. }
  3249. /* We are ready to run. */
  3250. b43_set_status(dev, B43_STAT_STARTED);
  3251. /* Start data flow (TX/RX). */
  3252. b43_mac_enable(dev);
  3253. b43_write32(dev, B43_MMIO_GEN_IRQ_MASK, dev->irq_mask);
  3254. /* Start maintainance work */
  3255. b43_periodic_tasks_setup(dev);
  3256. b43dbg(dev->wl, "Wireless interface started\n");
  3257. out:
  3258. return err;
  3259. }
  3260. /* Get PHY and RADIO versioning numbers */
  3261. static int b43_phy_versioning(struct b43_wldev *dev)
  3262. {
  3263. struct b43_phy *phy = &dev->phy;
  3264. u32 tmp;
  3265. u8 analog_type;
  3266. u8 phy_type;
  3267. u8 phy_rev;
  3268. u16 radio_manuf;
  3269. u16 radio_ver;
  3270. u16 radio_rev;
  3271. int unsupported = 0;
  3272. /* Get PHY versioning */
  3273. tmp = b43_read16(dev, B43_MMIO_PHY_VER);
  3274. analog_type = (tmp & B43_PHYVER_ANALOG) >> B43_PHYVER_ANALOG_SHIFT;
  3275. phy_type = (tmp & B43_PHYVER_TYPE) >> B43_PHYVER_TYPE_SHIFT;
  3276. phy_rev = (tmp & B43_PHYVER_VERSION);
  3277. switch (phy_type) {
  3278. case B43_PHYTYPE_A:
  3279. if (phy_rev >= 4)
  3280. unsupported = 1;
  3281. break;
  3282. case B43_PHYTYPE_B:
  3283. if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6
  3284. && phy_rev != 7)
  3285. unsupported = 1;
  3286. break;
  3287. case B43_PHYTYPE_G:
  3288. if (phy_rev > 9)
  3289. unsupported = 1;
  3290. break;
  3291. #ifdef CONFIG_B43_NPHY
  3292. case B43_PHYTYPE_N:
  3293. if (phy_rev > 4)
  3294. unsupported = 1;
  3295. break;
  3296. #endif
  3297. #ifdef CONFIG_B43_PHY_LP
  3298. case B43_PHYTYPE_LP:
  3299. if (phy_rev > 1)
  3300. unsupported = 1;
  3301. break;
  3302. #endif
  3303. default:
  3304. unsupported = 1;
  3305. };
  3306. if (unsupported) {
  3307. b43err(dev->wl, "FOUND UNSUPPORTED PHY "
  3308. "(Analog %u, Type %u, Revision %u)\n",
  3309. analog_type, phy_type, phy_rev);
  3310. return -EOPNOTSUPP;
  3311. }
  3312. b43dbg(dev->wl, "Found PHY: Analog %u, Type %u, Revision %u\n",
  3313. analog_type, phy_type, phy_rev);
  3314. /* Get RADIO versioning */
  3315. if (dev->dev->bus->chip_id == 0x4317) {
  3316. if (dev->dev->bus->chip_rev == 0)
  3317. tmp = 0x3205017F;
  3318. else if (dev->dev->bus->chip_rev == 1)
  3319. tmp = 0x4205017F;
  3320. else
  3321. tmp = 0x5205017F;
  3322. } else {
  3323. b43_write16(dev, B43_MMIO_RADIO_CONTROL, B43_RADIOCTL_ID);
  3324. tmp = b43_read16(dev, B43_MMIO_RADIO_DATA_LOW);
  3325. b43_write16(dev, B43_MMIO_RADIO_CONTROL, B43_RADIOCTL_ID);
  3326. tmp |= (u32)b43_read16(dev, B43_MMIO_RADIO_DATA_HIGH) << 16;
  3327. }
  3328. radio_manuf = (tmp & 0x00000FFF);
  3329. radio_ver = (tmp & 0x0FFFF000) >> 12;
  3330. radio_rev = (tmp & 0xF0000000) >> 28;
  3331. if (radio_manuf != 0x17F /* Broadcom */)
  3332. unsupported = 1;
  3333. switch (phy_type) {
  3334. case B43_PHYTYPE_A:
  3335. if (radio_ver != 0x2060)
  3336. unsupported = 1;
  3337. if (radio_rev != 1)
  3338. unsupported = 1;
  3339. if (radio_manuf != 0x17F)
  3340. unsupported = 1;
  3341. break;
  3342. case B43_PHYTYPE_B:
  3343. if ((radio_ver & 0xFFF0) != 0x2050)
  3344. unsupported = 1;
  3345. break;
  3346. case B43_PHYTYPE_G:
  3347. if (radio_ver != 0x2050)
  3348. unsupported = 1;
  3349. break;
  3350. case B43_PHYTYPE_N:
  3351. if (radio_ver != 0x2055 && radio_ver != 0x2056)
  3352. unsupported = 1;
  3353. break;
  3354. case B43_PHYTYPE_LP:
  3355. if (radio_ver != 0x2062)
  3356. unsupported = 1;
  3357. break;
  3358. default:
  3359. B43_WARN_ON(1);
  3360. }
  3361. if (unsupported) {
  3362. b43err(dev->wl, "FOUND UNSUPPORTED RADIO "
  3363. "(Manuf 0x%X, Version 0x%X, Revision %u)\n",
  3364. radio_manuf, radio_ver, radio_rev);
  3365. return -EOPNOTSUPP;
  3366. }
  3367. b43dbg(dev->wl, "Found Radio: Manuf 0x%X, Version 0x%X, Revision %u\n",
  3368. radio_manuf, radio_ver, radio_rev);
  3369. phy->radio_manuf = radio_manuf;
  3370. phy->radio_ver = radio_ver;
  3371. phy->radio_rev = radio_rev;
  3372. phy->analog = analog_type;
  3373. phy->type = phy_type;
  3374. phy->rev = phy_rev;
  3375. return 0;
  3376. }
  3377. static void setup_struct_phy_for_init(struct b43_wldev *dev,
  3378. struct b43_phy *phy)
  3379. {
  3380. phy->hardware_power_control = !!modparam_hwpctl;
  3381. phy->next_txpwr_check_time = jiffies;
  3382. /* PHY TX errors counter. */
  3383. atomic_set(&phy->txerr_cnt, B43_PHY_TX_BADNESS_LIMIT);
  3384. #if B43_DEBUG
  3385. phy->phy_locked = 0;
  3386. phy->radio_locked = 0;
  3387. #endif
  3388. }
  3389. static void setup_struct_wldev_for_init(struct b43_wldev *dev)
  3390. {
  3391. dev->dfq_valid = 0;
  3392. /* Assume the radio is enabled. If it's not enabled, the state will
  3393. * immediately get fixed on the first periodic work run. */
  3394. dev->radio_hw_enable = 1;
  3395. /* Stats */
  3396. memset(&dev->stats, 0, sizeof(dev->stats));
  3397. setup_struct_phy_for_init(dev, &dev->phy);
  3398. /* IRQ related flags */
  3399. dev->irq_reason = 0;
  3400. memset(dev->dma_reason, 0, sizeof(dev->dma_reason));
  3401. dev->irq_mask = B43_IRQ_MASKTEMPLATE;
  3402. if (b43_modparam_verbose < B43_VERBOSITY_DEBUG)
  3403. dev->irq_mask &= ~B43_IRQ_PHY_TXERR;
  3404. dev->mac_suspended = 1;
  3405. /* Noise calculation context */
  3406. memset(&dev->noisecalc, 0, sizeof(dev->noisecalc));
  3407. }
  3408. static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
  3409. {
  3410. struct ssb_sprom *sprom = &dev->dev->bus->sprom;
  3411. u64 hf;
  3412. if (!modparam_btcoex)
  3413. return;
  3414. if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST))
  3415. return;
  3416. if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode)
  3417. return;
  3418. hf = b43_hf_read(dev);
  3419. if (sprom->boardflags_lo & B43_BFL_BTCMOD)
  3420. hf |= B43_HF_BTCOEXALT;
  3421. else
  3422. hf |= B43_HF_BTCOEX;
  3423. b43_hf_write(dev, hf);
  3424. }
  3425. static void b43_bluetooth_coext_disable(struct b43_wldev *dev)
  3426. {
  3427. if (!modparam_btcoex)
  3428. return;
  3429. //TODO
  3430. }
  3431. static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev)
  3432. {
  3433. #ifdef CONFIG_SSB_DRIVER_PCICORE
  3434. struct ssb_bus *bus = dev->dev->bus;
  3435. u32 tmp;
  3436. if (bus->pcicore.dev &&
  3437. bus->pcicore.dev->id.coreid == SSB_DEV_PCI &&
  3438. bus->pcicore.dev->id.revision <= 5) {
  3439. /* IMCFGLO timeouts workaround. */
  3440. tmp = ssb_read32(dev->dev, SSB_IMCFGLO);
  3441. tmp &= ~SSB_IMCFGLO_REQTO;
  3442. tmp &= ~SSB_IMCFGLO_SERTO;
  3443. switch (bus->bustype) {
  3444. case SSB_BUSTYPE_PCI:
  3445. case SSB_BUSTYPE_PCMCIA:
  3446. tmp |= 0x32;
  3447. break;
  3448. case SSB_BUSTYPE_SSB:
  3449. tmp |= 0x53;
  3450. break;
  3451. }
  3452. ssb_write32(dev->dev, SSB_IMCFGLO, tmp);
  3453. }
  3454. #endif /* CONFIG_SSB_DRIVER_PCICORE */
  3455. }
  3456. static void b43_set_synth_pu_delay(struct b43_wldev *dev, bool idle)
  3457. {
  3458. u16 pu_delay;
  3459. /* The time value is in microseconds. */
  3460. if (dev->phy.type == B43_PHYTYPE_A)
  3461. pu_delay = 3700;
  3462. else
  3463. pu_delay = 1050;
  3464. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC) || idle)
  3465. pu_delay = 500;
  3466. if ((dev->phy.radio_ver == 0x2050) && (dev->phy.radio_rev == 8))
  3467. pu_delay = max(pu_delay, (u16)2400);
  3468. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SPUWKUP, pu_delay);
  3469. }
  3470. /* Set the TSF CFP pre-TargetBeaconTransmissionTime. */
  3471. static void b43_set_pretbtt(struct b43_wldev *dev)
  3472. {
  3473. u16 pretbtt;
  3474. /* The time value is in microseconds. */
  3475. if (b43_is_mode(dev->wl, NL80211_IFTYPE_ADHOC)) {
  3476. pretbtt = 2;
  3477. } else {
  3478. if (dev->phy.type == B43_PHYTYPE_A)
  3479. pretbtt = 120;
  3480. else
  3481. pretbtt = 250;
  3482. }
  3483. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRETBTT, pretbtt);
  3484. b43_write16(dev, B43_MMIO_TSF_CFP_PRETBTT, pretbtt);
  3485. }
  3486. /* Shutdown a wireless core */
  3487. /* Locking: wl->mutex */
  3488. static void b43_wireless_core_exit(struct b43_wldev *dev)
  3489. {
  3490. u32 macctl;
  3491. B43_WARN_ON(b43_status(dev) > B43_STAT_INITIALIZED);
  3492. if (b43_status(dev) != B43_STAT_INITIALIZED)
  3493. return;
  3494. b43_set_status(dev, B43_STAT_UNINIT);
  3495. /* Stop the microcode PSM. */
  3496. macctl = b43_read32(dev, B43_MMIO_MACCTL);
  3497. macctl &= ~B43_MACCTL_PSM_RUN;
  3498. macctl |= B43_MACCTL_PSM_JMP0;
  3499. b43_write32(dev, B43_MMIO_MACCTL, macctl);
  3500. if (!dev->suspend_in_progress) {
  3501. b43_leds_exit(dev);
  3502. b43_rng_exit(dev->wl);
  3503. }
  3504. b43_dma_free(dev);
  3505. b43_pio_free(dev);
  3506. b43_chip_exit(dev);
  3507. dev->phy.ops->switch_analog(dev, 0);
  3508. if (dev->wl->current_beacon) {
  3509. dev_kfree_skb_any(dev->wl->current_beacon);
  3510. dev->wl->current_beacon = NULL;
  3511. }
  3512. ssb_device_disable(dev->dev, 0);
  3513. ssb_bus_may_powerdown(dev->dev->bus);
  3514. }
  3515. /* Initialize a wireless core */
  3516. static int b43_wireless_core_init(struct b43_wldev *dev)
  3517. {
  3518. struct b43_wl *wl = dev->wl;
  3519. struct ssb_bus *bus = dev->dev->bus;
  3520. struct ssb_sprom *sprom = &bus->sprom;
  3521. struct b43_phy *phy = &dev->phy;
  3522. int err;
  3523. u64 hf;
  3524. u32 tmp;
  3525. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  3526. err = ssb_bus_powerup(bus, 0);
  3527. if (err)
  3528. goto out;
  3529. if (!ssb_device_is_enabled(dev->dev)) {
  3530. tmp = phy->gmode ? B43_TMSLOW_GMODE : 0;
  3531. b43_wireless_core_reset(dev, tmp);
  3532. }
  3533. /* Reset all data structures. */
  3534. setup_struct_wldev_for_init(dev);
  3535. phy->ops->prepare_structs(dev);
  3536. /* Enable IRQ routing to this device. */
  3537. ssb_pcicore_dev_irqvecs_enable(&bus->pcicore, dev->dev);
  3538. b43_imcfglo_timeouts_workaround(dev);
  3539. b43_bluetooth_coext_disable(dev);
  3540. if (phy->ops->prepare_hardware) {
  3541. err = phy->ops->prepare_hardware(dev);
  3542. if (err)
  3543. goto err_busdown;
  3544. }
  3545. err = b43_chip_init(dev);
  3546. if (err)
  3547. goto err_busdown;
  3548. b43_shm_write16(dev, B43_SHM_SHARED,
  3549. B43_SHM_SH_WLCOREREV, dev->dev->id.revision);
  3550. hf = b43_hf_read(dev);
  3551. if (phy->type == B43_PHYTYPE_G) {
  3552. hf |= B43_HF_SYMW;
  3553. if (phy->rev == 1)
  3554. hf |= B43_HF_GDCW;
  3555. if (sprom->boardflags_lo & B43_BFL_PACTRL)
  3556. hf |= B43_HF_OFDMPABOOST;
  3557. }
  3558. if (phy->radio_ver == 0x2050) {
  3559. if (phy->radio_rev == 6)
  3560. hf |= B43_HF_4318TSSI;
  3561. if (phy->radio_rev < 6)
  3562. hf |= B43_HF_VCORECALC;
  3563. }
  3564. if (sprom->boardflags_lo & B43_BFL_XTAL_NOSLOW)
  3565. hf |= B43_HF_DSCRQ; /* Disable slowclock requests from ucode. */
  3566. #ifdef CONFIG_SSB_DRIVER_PCICORE
  3567. if ((bus->bustype == SSB_BUSTYPE_PCI) &&
  3568. (bus->pcicore.dev->id.revision <= 10))
  3569. hf |= B43_HF_PCISCW; /* PCI slow clock workaround. */
  3570. #endif
  3571. hf &= ~B43_HF_SKCFPUP;
  3572. b43_hf_write(dev, hf);
  3573. b43_set_retry_limits(dev, B43_DEFAULT_SHORT_RETRY_LIMIT,
  3574. B43_DEFAULT_LONG_RETRY_LIMIT);
  3575. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_SFFBLIM, 3);
  3576. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_LFFBLIM, 2);
  3577. /* Disable sending probe responses from firmware.
  3578. * Setting the MaxTime to one usec will always trigger
  3579. * a timeout, so we never send any probe resp.
  3580. * A timeout of zero is infinite. */
  3581. b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_PRMAXTIME, 1);
  3582. b43_rate_memory_init(dev);
  3583. b43_set_phytxctl_defaults(dev);
  3584. /* Minimum Contention Window */
  3585. if (phy->type == B43_PHYTYPE_B) {
  3586. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0x1F);
  3587. } else {
  3588. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MINCONT, 0xF);
  3589. }
  3590. /* Maximum Contention Window */
  3591. b43_shm_write16(dev, B43_SHM_SCRATCH, B43_SHM_SC_MAXCONT, 0x3FF);
  3592. if ((dev->dev->bus->bustype == SSB_BUSTYPE_PCMCIA) || B43_FORCE_PIO) {
  3593. dev->__using_pio_transfers = 1;
  3594. err = b43_pio_init(dev);
  3595. } else {
  3596. dev->__using_pio_transfers = 0;
  3597. err = b43_dma_init(dev);
  3598. }
  3599. if (err)
  3600. goto err_chip_exit;
  3601. b43_qos_init(dev);
  3602. b43_set_synth_pu_delay(dev, 1);
  3603. b43_bluetooth_coext_enable(dev);
  3604. ssb_bus_powerup(bus, !(sprom->boardflags_lo & B43_BFL_XTAL_NOSLOW));
  3605. b43_upload_card_macaddress(dev);
  3606. b43_security_init(dev);
  3607. if (!dev->suspend_in_progress)
  3608. b43_rng_init(wl);
  3609. b43_set_status(dev, B43_STAT_INITIALIZED);
  3610. if (!dev->suspend_in_progress)
  3611. b43_leds_init(dev);
  3612. out:
  3613. return err;
  3614. err_chip_exit:
  3615. b43_chip_exit(dev);
  3616. err_busdown:
  3617. ssb_bus_may_powerdown(bus);
  3618. B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
  3619. return err;
  3620. }
  3621. static int b43_op_add_interface(struct ieee80211_hw *hw,
  3622. struct ieee80211_if_init_conf *conf)
  3623. {
  3624. struct b43_wl *wl = hw_to_b43_wl(hw);
  3625. struct b43_wldev *dev;
  3626. unsigned long flags;
  3627. int err = -EOPNOTSUPP;
  3628. /* TODO: allow WDS/AP devices to coexist */
  3629. if (conf->type != NL80211_IFTYPE_AP &&
  3630. conf->type != NL80211_IFTYPE_MESH_POINT &&
  3631. conf->type != NL80211_IFTYPE_STATION &&
  3632. conf->type != NL80211_IFTYPE_WDS &&
  3633. conf->type != NL80211_IFTYPE_ADHOC)
  3634. return -EOPNOTSUPP;
  3635. mutex_lock(&wl->mutex);
  3636. if (wl->operating)
  3637. goto out_mutex_unlock;
  3638. b43dbg(wl, "Adding Interface type %d\n", conf->type);
  3639. dev = wl->current_dev;
  3640. wl->operating = 1;
  3641. wl->vif = conf->vif;
  3642. wl->if_type = conf->type;
  3643. memcpy(wl->mac_addr, conf->mac_addr, ETH_ALEN);
  3644. spin_lock_irqsave(&wl->irq_lock, flags);
  3645. b43_adjust_opmode(dev);
  3646. b43_set_pretbtt(dev);
  3647. b43_set_synth_pu_delay(dev, 0);
  3648. b43_upload_card_macaddress(dev);
  3649. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3650. err = 0;
  3651. out_mutex_unlock:
  3652. mutex_unlock(&wl->mutex);
  3653. return err;
  3654. }
  3655. static void b43_op_remove_interface(struct ieee80211_hw *hw,
  3656. struct ieee80211_if_init_conf *conf)
  3657. {
  3658. struct b43_wl *wl = hw_to_b43_wl(hw);
  3659. struct b43_wldev *dev = wl->current_dev;
  3660. unsigned long flags;
  3661. b43dbg(wl, "Removing Interface type %d\n", conf->type);
  3662. mutex_lock(&wl->mutex);
  3663. B43_WARN_ON(!wl->operating);
  3664. B43_WARN_ON(wl->vif != conf->vif);
  3665. wl->vif = NULL;
  3666. wl->operating = 0;
  3667. spin_lock_irqsave(&wl->irq_lock, flags);
  3668. b43_adjust_opmode(dev);
  3669. memset(wl->mac_addr, 0, ETH_ALEN);
  3670. b43_upload_card_macaddress(dev);
  3671. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3672. mutex_unlock(&wl->mutex);
  3673. }
  3674. static int b43_op_start(struct ieee80211_hw *hw)
  3675. {
  3676. struct b43_wl *wl = hw_to_b43_wl(hw);
  3677. struct b43_wldev *dev = wl->current_dev;
  3678. int did_init = 0;
  3679. int err = 0;
  3680. /* Kill all old instance specific information to make sure
  3681. * the card won't use it in the short timeframe between start
  3682. * and mac80211 reconfiguring it. */
  3683. memset(wl->bssid, 0, ETH_ALEN);
  3684. memset(wl->mac_addr, 0, ETH_ALEN);
  3685. wl->filter_flags = 0;
  3686. wl->radiotap_enabled = 0;
  3687. b43_qos_clear(wl);
  3688. wl->beacon0_uploaded = 0;
  3689. wl->beacon1_uploaded = 0;
  3690. wl->beacon_templates_virgin = 1;
  3691. wl->radio_enabled = 1;
  3692. mutex_lock(&wl->mutex);
  3693. if (b43_status(dev) < B43_STAT_INITIALIZED) {
  3694. err = b43_wireless_core_init(dev);
  3695. if (err)
  3696. goto out_mutex_unlock;
  3697. did_init = 1;
  3698. }
  3699. if (b43_status(dev) < B43_STAT_STARTED) {
  3700. err = b43_wireless_core_start(dev);
  3701. if (err) {
  3702. if (did_init)
  3703. b43_wireless_core_exit(dev);
  3704. goto out_mutex_unlock;
  3705. }
  3706. }
  3707. /* XXX: only do if device doesn't support rfkill irq */
  3708. wiphy_rfkill_start_polling(hw->wiphy);
  3709. out_mutex_unlock:
  3710. mutex_unlock(&wl->mutex);
  3711. return err;
  3712. }
  3713. static void b43_op_stop(struct ieee80211_hw *hw)
  3714. {
  3715. struct b43_wl *wl = hw_to_b43_wl(hw);
  3716. struct b43_wldev *dev = wl->current_dev;
  3717. cancel_work_sync(&(wl->beacon_update_trigger));
  3718. mutex_lock(&wl->mutex);
  3719. if (b43_status(dev) >= B43_STAT_STARTED)
  3720. b43_wireless_core_stop(dev);
  3721. b43_wireless_core_exit(dev);
  3722. wl->radio_enabled = 0;
  3723. mutex_unlock(&wl->mutex);
  3724. cancel_work_sync(&(wl->txpower_adjust_work));
  3725. }
  3726. static int b43_op_beacon_set_tim(struct ieee80211_hw *hw,
  3727. struct ieee80211_sta *sta, bool set)
  3728. {
  3729. struct b43_wl *wl = hw_to_b43_wl(hw);
  3730. unsigned long flags;
  3731. spin_lock_irqsave(&wl->irq_lock, flags);
  3732. b43_update_templates(wl);
  3733. spin_unlock_irqrestore(&wl->irq_lock, flags);
  3734. return 0;
  3735. }
  3736. static void b43_op_sta_notify(struct ieee80211_hw *hw,
  3737. struct ieee80211_vif *vif,
  3738. enum sta_notify_cmd notify_cmd,
  3739. struct ieee80211_sta *sta)
  3740. {
  3741. struct b43_wl *wl = hw_to_b43_wl(hw);
  3742. B43_WARN_ON(!vif || wl->vif != vif);
  3743. }
  3744. static void b43_op_sw_scan_start_notifier(struct ieee80211_hw *hw)
  3745. {
  3746. struct b43_wl *wl = hw_to_b43_wl(hw);
  3747. struct b43_wldev *dev;
  3748. mutex_lock(&wl->mutex);
  3749. dev = wl->current_dev;
  3750. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED)) {
  3751. /* Disable CFP update during scan on other channels. */
  3752. b43_hf_write(dev, b43_hf_read(dev) | B43_HF_SKCFPUP);
  3753. }
  3754. mutex_unlock(&wl->mutex);
  3755. }
  3756. static void b43_op_sw_scan_complete_notifier(struct ieee80211_hw *hw)
  3757. {
  3758. struct b43_wl *wl = hw_to_b43_wl(hw);
  3759. struct b43_wldev *dev;
  3760. mutex_lock(&wl->mutex);
  3761. dev = wl->current_dev;
  3762. if (dev && (b43_status(dev) >= B43_STAT_INITIALIZED)) {
  3763. /* Re-enable CFP update. */
  3764. b43_hf_write(dev, b43_hf_read(dev) & ~B43_HF_SKCFPUP);
  3765. }
  3766. mutex_unlock(&wl->mutex);
  3767. }
  3768. static const struct ieee80211_ops b43_hw_ops = {
  3769. .tx = b43_op_tx,
  3770. .conf_tx = b43_op_conf_tx,
  3771. .add_interface = b43_op_add_interface,
  3772. .remove_interface = b43_op_remove_interface,
  3773. .config = b43_op_config,
  3774. .bss_info_changed = b43_op_bss_info_changed,
  3775. .configure_filter = b43_op_configure_filter,
  3776. .set_key = b43_op_set_key,
  3777. .get_stats = b43_op_get_stats,
  3778. .get_tx_stats = b43_op_get_tx_stats,
  3779. .get_tsf = b43_op_get_tsf,
  3780. .set_tsf = b43_op_set_tsf,
  3781. .start = b43_op_start,
  3782. .stop = b43_op_stop,
  3783. .set_tim = b43_op_beacon_set_tim,
  3784. .sta_notify = b43_op_sta_notify,
  3785. .sw_scan_start = b43_op_sw_scan_start_notifier,
  3786. .sw_scan_complete = b43_op_sw_scan_complete_notifier,
  3787. .rfkill_poll = b43_rfkill_poll,
  3788. };
  3789. /* Hard-reset the chip. Do not call this directly.
  3790. * Use b43_controller_restart()
  3791. */
  3792. static void b43_chip_reset(struct work_struct *work)
  3793. {
  3794. struct b43_wldev *dev =
  3795. container_of(work, struct b43_wldev, restart_work);
  3796. struct b43_wl *wl = dev->wl;
  3797. int err = 0;
  3798. int prev_status;
  3799. mutex_lock(&wl->mutex);
  3800. prev_status = b43_status(dev);
  3801. /* Bring the device down... */
  3802. if (prev_status >= B43_STAT_STARTED)
  3803. b43_wireless_core_stop(dev);
  3804. if (prev_status >= B43_STAT_INITIALIZED)
  3805. b43_wireless_core_exit(dev);
  3806. /* ...and up again. */
  3807. if (prev_status >= B43_STAT_INITIALIZED) {
  3808. err = b43_wireless_core_init(dev);
  3809. if (err)
  3810. goto out;
  3811. }
  3812. if (prev_status >= B43_STAT_STARTED) {
  3813. err = b43_wireless_core_start(dev);
  3814. if (err) {
  3815. b43_wireless_core_exit(dev);
  3816. goto out;
  3817. }
  3818. }
  3819. out:
  3820. if (err)
  3821. wl->current_dev = NULL; /* Failed to init the dev. */
  3822. mutex_unlock(&wl->mutex);
  3823. if (err)
  3824. b43err(wl, "Controller restart FAILED\n");
  3825. else
  3826. b43info(wl, "Controller restarted\n");
  3827. }
  3828. static int b43_setup_bands(struct b43_wldev *dev,
  3829. bool have_2ghz_phy, bool have_5ghz_phy)
  3830. {
  3831. struct ieee80211_hw *hw = dev->wl->hw;
  3832. if (have_2ghz_phy)
  3833. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &b43_band_2GHz;
  3834. if (dev->phy.type == B43_PHYTYPE_N) {
  3835. if (have_5ghz_phy)
  3836. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &b43_band_5GHz_nphy;
  3837. } else {
  3838. if (have_5ghz_phy)
  3839. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &b43_band_5GHz_aphy;
  3840. }
  3841. dev->phy.supports_2ghz = have_2ghz_phy;
  3842. dev->phy.supports_5ghz = have_5ghz_phy;
  3843. return 0;
  3844. }
  3845. static void b43_wireless_core_detach(struct b43_wldev *dev)
  3846. {
  3847. /* We release firmware that late to not be required to re-request
  3848. * is all the time when we reinit the core. */
  3849. b43_release_firmware(dev);
  3850. b43_phy_free(dev);
  3851. }
  3852. static int b43_wireless_core_attach(struct b43_wldev *dev)
  3853. {
  3854. struct b43_wl *wl = dev->wl;
  3855. struct ssb_bus *bus = dev->dev->bus;
  3856. struct pci_dev *pdev = bus->host_pci;
  3857. int err;
  3858. bool have_2ghz_phy = 0, have_5ghz_phy = 0;
  3859. u32 tmp;
  3860. /* Do NOT do any device initialization here.
  3861. * Do it in wireless_core_init() instead.
  3862. * This function is for gathering basic information about the HW, only.
  3863. * Also some structs may be set up here. But most likely you want to have
  3864. * that in core_init(), too.
  3865. */
  3866. err = ssb_bus_powerup(bus, 0);
  3867. if (err) {
  3868. b43err(wl, "Bus powerup failed\n");
  3869. goto out;
  3870. }
  3871. /* Get the PHY type. */
  3872. if (dev->dev->id.revision >= 5) {
  3873. u32 tmshigh;
  3874. tmshigh = ssb_read32(dev->dev, SSB_TMSHIGH);
  3875. have_2ghz_phy = !!(tmshigh & B43_TMSHIGH_HAVE_2GHZ_PHY);
  3876. have_5ghz_phy = !!(tmshigh & B43_TMSHIGH_HAVE_5GHZ_PHY);
  3877. } else
  3878. B43_WARN_ON(1);
  3879. dev->phy.gmode = have_2ghz_phy;
  3880. dev->phy.radio_on = 1;
  3881. tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
  3882. b43_wireless_core_reset(dev, tmp);
  3883. err = b43_phy_versioning(dev);
  3884. if (err)
  3885. goto err_powerdown;
  3886. /* Check if this device supports multiband. */
  3887. if (!pdev ||
  3888. (pdev->device != 0x4312 &&
  3889. pdev->device != 0x4319 && pdev->device != 0x4324)) {
  3890. /* No multiband support. */
  3891. have_2ghz_phy = 0;
  3892. have_5ghz_phy = 0;
  3893. switch (dev->phy.type) {
  3894. case B43_PHYTYPE_A:
  3895. have_5ghz_phy = 1;
  3896. break;
  3897. case B43_PHYTYPE_G:
  3898. case B43_PHYTYPE_N:
  3899. case B43_PHYTYPE_LP:
  3900. have_2ghz_phy = 1;
  3901. break;
  3902. default:
  3903. B43_WARN_ON(1);
  3904. }
  3905. }
  3906. if (dev->phy.type == B43_PHYTYPE_A) {
  3907. /* FIXME */
  3908. b43err(wl, "IEEE 802.11a devices are unsupported\n");
  3909. err = -EOPNOTSUPP;
  3910. goto err_powerdown;
  3911. }
  3912. if (1 /* disable A-PHY */) {
  3913. /* FIXME: For now we disable the A-PHY on multi-PHY devices. */
  3914. if (dev->phy.type != B43_PHYTYPE_N) {
  3915. have_2ghz_phy = 1;
  3916. have_5ghz_phy = 0;
  3917. }
  3918. }
  3919. err = b43_phy_allocate(dev);
  3920. if (err)
  3921. goto err_powerdown;
  3922. dev->phy.gmode = have_2ghz_phy;
  3923. tmp = dev->phy.gmode ? B43_TMSLOW_GMODE : 0;
  3924. b43_wireless_core_reset(dev, tmp);
  3925. err = b43_validate_chipaccess(dev);
  3926. if (err)
  3927. goto err_phy_free;
  3928. err = b43_setup_bands(dev, have_2ghz_phy, have_5ghz_phy);
  3929. if (err)
  3930. goto err_phy_free;
  3931. /* Now set some default "current_dev" */
  3932. if (!wl->current_dev)
  3933. wl->current_dev = dev;
  3934. INIT_WORK(&dev->restart_work, b43_chip_reset);
  3935. dev->phy.ops->switch_analog(dev, 0);
  3936. ssb_device_disable(dev->dev, 0);
  3937. ssb_bus_may_powerdown(bus);
  3938. out:
  3939. return err;
  3940. err_phy_free:
  3941. b43_phy_free(dev);
  3942. err_powerdown:
  3943. ssb_bus_may_powerdown(bus);
  3944. return err;
  3945. }
  3946. static void b43_one_core_detach(struct ssb_device *dev)
  3947. {
  3948. struct b43_wldev *wldev;
  3949. struct b43_wl *wl;
  3950. /* Do not cancel ieee80211-workqueue based work here.
  3951. * See comment in b43_remove(). */
  3952. wldev = ssb_get_drvdata(dev);
  3953. wl = wldev->wl;
  3954. b43_debugfs_remove_device(wldev);
  3955. b43_wireless_core_detach(wldev);
  3956. list_del(&wldev->list);
  3957. wl->nr_devs--;
  3958. ssb_set_drvdata(dev, NULL);
  3959. kfree(wldev);
  3960. }
  3961. static int b43_one_core_attach(struct ssb_device *dev, struct b43_wl *wl)
  3962. {
  3963. struct b43_wldev *wldev;
  3964. struct pci_dev *pdev;
  3965. int err = -ENOMEM;
  3966. if (!list_empty(&wl->devlist)) {
  3967. /* We are not the first core on this chip. */
  3968. pdev = dev->bus->host_pci;
  3969. /* Only special chips support more than one wireless
  3970. * core, although some of the other chips have more than
  3971. * one wireless core as well. Check for this and
  3972. * bail out early.
  3973. */
  3974. if (!pdev ||
  3975. ((pdev->device != 0x4321) &&
  3976. (pdev->device != 0x4313) && (pdev->device != 0x431A))) {
  3977. b43dbg(wl, "Ignoring unconnected 802.11 core\n");
  3978. return -ENODEV;
  3979. }
  3980. }
  3981. wldev = kzalloc(sizeof(*wldev), GFP_KERNEL);
  3982. if (!wldev)
  3983. goto out;
  3984. wldev->dev = dev;
  3985. wldev->wl = wl;
  3986. b43_set_status(wldev, B43_STAT_UNINIT);
  3987. wldev->bad_frames_preempt = modparam_bad_frames_preempt;
  3988. tasklet_init(&wldev->isr_tasklet,
  3989. (void (*)(unsigned long))b43_interrupt_tasklet,
  3990. (unsigned long)wldev);
  3991. INIT_LIST_HEAD(&wldev->list);
  3992. err = b43_wireless_core_attach(wldev);
  3993. if (err)
  3994. goto err_kfree_wldev;
  3995. list_add(&wldev->list, &wl->devlist);
  3996. wl->nr_devs++;
  3997. ssb_set_drvdata(dev, wldev);
  3998. b43_debugfs_add_device(wldev);
  3999. out:
  4000. return err;
  4001. err_kfree_wldev:
  4002. kfree(wldev);
  4003. return err;
  4004. }
  4005. #define IS_PDEV(pdev, _vendor, _device, _subvendor, _subdevice) ( \
  4006. (pdev->vendor == PCI_VENDOR_ID_##_vendor) && \
  4007. (pdev->device == _device) && \
  4008. (pdev->subsystem_vendor == PCI_VENDOR_ID_##_subvendor) && \
  4009. (pdev->subsystem_device == _subdevice) )
  4010. static void b43_sprom_fixup(struct ssb_bus *bus)
  4011. {
  4012. struct pci_dev *pdev;
  4013. /* boardflags workarounds */
  4014. if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL &&
  4015. bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74)
  4016. bus->sprom.boardflags_lo |= B43_BFL_BTCOEXIST;
  4017. if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
  4018. bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40)
  4019. bus->sprom.boardflags_lo |= B43_BFL_PACTRL;
  4020. if (bus->bustype == SSB_BUSTYPE_PCI) {
  4021. pdev = bus->host_pci;
  4022. if (IS_PDEV(pdev, BROADCOM, 0x4318, ASUSTEK, 0x100F) ||
  4023. IS_PDEV(pdev, BROADCOM, 0x4320, DELL, 0x0003) ||
  4024. IS_PDEV(pdev, BROADCOM, 0x4320, HP, 0x12f8) ||
  4025. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0015) ||
  4026. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0014) ||
  4027. IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013) ||
  4028. IS_PDEV(pdev, BROADCOM, 0x4320, MOTOROLA, 0x7010))
  4029. bus->sprom.boardflags_lo &= ~B43_BFL_BTCOEXIST;
  4030. }
  4031. }
  4032. static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl)
  4033. {
  4034. struct ieee80211_hw *hw = wl->hw;
  4035. ssb_set_devtypedata(dev, NULL);
  4036. ieee80211_free_hw(hw);
  4037. }
  4038. static int b43_wireless_init(struct ssb_device *dev)
  4039. {
  4040. struct ssb_sprom *sprom = &dev->bus->sprom;
  4041. struct ieee80211_hw *hw;
  4042. struct b43_wl *wl;
  4043. int err = -ENOMEM;
  4044. b43_sprom_fixup(dev->bus);
  4045. hw = ieee80211_alloc_hw(sizeof(*wl), &b43_hw_ops);
  4046. if (!hw) {
  4047. b43err(NULL, "Could not allocate ieee80211 device\n");
  4048. goto out;
  4049. }
  4050. wl = hw_to_b43_wl(hw);
  4051. /* fill hw info */
  4052. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  4053. IEEE80211_HW_SIGNAL_DBM |
  4054. IEEE80211_HW_NOISE_DBM;
  4055. hw->wiphy->interface_modes =
  4056. BIT(NL80211_IFTYPE_AP) |
  4057. BIT(NL80211_IFTYPE_MESH_POINT) |
  4058. BIT(NL80211_IFTYPE_STATION) |
  4059. BIT(NL80211_IFTYPE_WDS) |
  4060. BIT(NL80211_IFTYPE_ADHOC);
  4061. hw->queues = modparam_qos ? 4 : 1;
  4062. wl->mac80211_initially_registered_queues = hw->queues;
  4063. hw->max_rates = 2;
  4064. SET_IEEE80211_DEV(hw, dev->dev);
  4065. if (is_valid_ether_addr(sprom->et1mac))
  4066. SET_IEEE80211_PERM_ADDR(hw, sprom->et1mac);
  4067. else
  4068. SET_IEEE80211_PERM_ADDR(hw, sprom->il0mac);
  4069. /* Initialize struct b43_wl */
  4070. wl->hw = hw;
  4071. spin_lock_init(&wl->irq_lock);
  4072. rwlock_init(&wl->tx_lock);
  4073. spin_lock_init(&wl->leds_lock);
  4074. spin_lock_init(&wl->shm_lock);
  4075. mutex_init(&wl->mutex);
  4076. INIT_LIST_HEAD(&wl->devlist);
  4077. INIT_WORK(&wl->beacon_update_trigger, b43_beacon_update_trigger_work);
  4078. INIT_WORK(&wl->txpower_adjust_work, b43_phy_txpower_adjust_work);
  4079. ssb_set_devtypedata(dev, wl);
  4080. b43info(wl, "Broadcom %04X WLAN found (core revision %u)\n",
  4081. dev->bus->chip_id, dev->id.revision);
  4082. err = 0;
  4083. out:
  4084. return err;
  4085. }
  4086. static int b43_probe(struct ssb_device *dev, const struct ssb_device_id *id)
  4087. {
  4088. struct b43_wl *wl;
  4089. int err;
  4090. int first = 0;
  4091. wl = ssb_get_devtypedata(dev);
  4092. if (!wl) {
  4093. /* Probing the first core. Must setup common struct b43_wl */
  4094. first = 1;
  4095. err = b43_wireless_init(dev);
  4096. if (err)
  4097. goto out;
  4098. wl = ssb_get_devtypedata(dev);
  4099. B43_WARN_ON(!wl);
  4100. }
  4101. err = b43_one_core_attach(dev, wl);
  4102. if (err)
  4103. goto err_wireless_exit;
  4104. if (first) {
  4105. err = ieee80211_register_hw(wl->hw);
  4106. if (err)
  4107. goto err_one_core_detach;
  4108. }
  4109. out:
  4110. return err;
  4111. err_one_core_detach:
  4112. b43_one_core_detach(dev);
  4113. err_wireless_exit:
  4114. if (first)
  4115. b43_wireless_exit(dev, wl);
  4116. return err;
  4117. }
  4118. static void b43_remove(struct ssb_device *dev)
  4119. {
  4120. struct b43_wl *wl = ssb_get_devtypedata(dev);
  4121. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  4122. /* We must cancel any work here before unregistering from ieee80211,
  4123. * as the ieee80211 unreg will destroy the workqueue. */
  4124. cancel_work_sync(&wldev->restart_work);
  4125. B43_WARN_ON(!wl);
  4126. if (wl->current_dev == wldev) {
  4127. /* Restore the queues count before unregistering, because firmware detect
  4128. * might have modified it. Restoring is important, so the networking
  4129. * stack can properly free resources. */
  4130. wl->hw->queues = wl->mac80211_initially_registered_queues;
  4131. ieee80211_unregister_hw(wl->hw);
  4132. }
  4133. b43_one_core_detach(dev);
  4134. if (list_empty(&wl->devlist)) {
  4135. /* Last core on the chip unregistered.
  4136. * We can destroy common struct b43_wl.
  4137. */
  4138. b43_wireless_exit(dev, wl);
  4139. }
  4140. }
  4141. /* Perform a hardware reset. This can be called from any context. */
  4142. void b43_controller_restart(struct b43_wldev *dev, const char *reason)
  4143. {
  4144. /* Must avoid requeueing, if we are in shutdown. */
  4145. if (b43_status(dev) < B43_STAT_INITIALIZED)
  4146. return;
  4147. b43info(dev->wl, "Controller RESET (%s) ...\n", reason);
  4148. ieee80211_queue_work(dev->wl->hw, &dev->restart_work);
  4149. }
  4150. #ifdef CONFIG_PM
  4151. static int b43_suspend(struct ssb_device *dev, pm_message_t state)
  4152. {
  4153. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  4154. struct b43_wl *wl = wldev->wl;
  4155. b43dbg(wl, "Suspending...\n");
  4156. mutex_lock(&wl->mutex);
  4157. wldev->suspend_in_progress = true;
  4158. wldev->suspend_init_status = b43_status(wldev);
  4159. if (wldev->suspend_init_status >= B43_STAT_STARTED)
  4160. b43_wireless_core_stop(wldev);
  4161. if (wldev->suspend_init_status >= B43_STAT_INITIALIZED)
  4162. b43_wireless_core_exit(wldev);
  4163. mutex_unlock(&wl->mutex);
  4164. b43dbg(wl, "Device suspended.\n");
  4165. return 0;
  4166. }
  4167. static int b43_resume(struct ssb_device *dev)
  4168. {
  4169. struct b43_wldev *wldev = ssb_get_drvdata(dev);
  4170. struct b43_wl *wl = wldev->wl;
  4171. int err = 0;
  4172. b43dbg(wl, "Resuming...\n");
  4173. mutex_lock(&wl->mutex);
  4174. if (wldev->suspend_init_status >= B43_STAT_INITIALIZED) {
  4175. err = b43_wireless_core_init(wldev);
  4176. if (err) {
  4177. b43err(wl, "Resume failed at core init\n");
  4178. goto out;
  4179. }
  4180. }
  4181. if (wldev->suspend_init_status >= B43_STAT_STARTED) {
  4182. err = b43_wireless_core_start(wldev);
  4183. if (err) {
  4184. b43_leds_exit(wldev);
  4185. b43_rng_exit(wldev->wl);
  4186. b43_wireless_core_exit(wldev);
  4187. b43err(wl, "Resume failed at core start\n");
  4188. goto out;
  4189. }
  4190. }
  4191. b43dbg(wl, "Device resumed.\n");
  4192. out:
  4193. wldev->suspend_in_progress = false;
  4194. mutex_unlock(&wl->mutex);
  4195. return err;
  4196. }
  4197. #else /* CONFIG_PM */
  4198. # define b43_suspend NULL
  4199. # define b43_resume NULL
  4200. #endif /* CONFIG_PM */
  4201. static struct ssb_driver b43_ssb_driver = {
  4202. .name = KBUILD_MODNAME,
  4203. .id_table = b43_ssb_tbl,
  4204. .probe = b43_probe,
  4205. .remove = b43_remove,
  4206. .suspend = b43_suspend,
  4207. .resume = b43_resume,
  4208. };
  4209. static void b43_print_driverinfo(void)
  4210. {
  4211. const char *feat_pci = "", *feat_pcmcia = "", *feat_nphy = "",
  4212. *feat_leds = "";
  4213. #ifdef CONFIG_B43_PCI_AUTOSELECT
  4214. feat_pci = "P";
  4215. #endif
  4216. #ifdef CONFIG_B43_PCMCIA
  4217. feat_pcmcia = "M";
  4218. #endif
  4219. #ifdef CONFIG_B43_NPHY
  4220. feat_nphy = "N";
  4221. #endif
  4222. #ifdef CONFIG_B43_LEDS
  4223. feat_leds = "L";
  4224. #endif
  4225. printk(KERN_INFO "Broadcom 43xx driver loaded "
  4226. "[ Features: %s%s%s%s, Firmware-ID: "
  4227. B43_SUPPORTED_FIRMWARE_ID " ]\n",
  4228. feat_pci, feat_pcmcia, feat_nphy,
  4229. feat_leds);
  4230. }
  4231. static int __init b43_init(void)
  4232. {
  4233. int err;
  4234. b43_debugfs_init();
  4235. err = b43_pcmcia_init();
  4236. if (err)
  4237. goto err_dfs_exit;
  4238. err = ssb_driver_register(&b43_ssb_driver);
  4239. if (err)
  4240. goto err_pcmcia_exit;
  4241. b43_print_driverinfo();
  4242. return err;
  4243. err_pcmcia_exit:
  4244. b43_pcmcia_exit();
  4245. err_dfs_exit:
  4246. b43_debugfs_exit();
  4247. return err;
  4248. }
  4249. static void __exit b43_exit(void)
  4250. {
  4251. ssb_driver_unregister(&b43_ssb_driver);
  4252. b43_pcmcia_exit();
  4253. b43_debugfs_exit();
  4254. }
  4255. module_init(b43_init)
  4256. module_exit(b43_exit)