bcm43xx_main.c 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210
  1. /*
  2. Broadcom BCM43xx wireless driver
  3. Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
  4. Stefano Brivio <st3@riseup.net>
  5. Michael Buesch <mbuesch@freenet.de>
  6. Danny van Dyk <kugelfang@gentoo.org>
  7. 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/version.h>
  29. #include <linux/firmware.h>
  30. #include <linux/wireless.h>
  31. #include <linux/workqueue.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/dma-mapping.h>
  34. #include <net/iw_handler.h>
  35. #include "bcm43xx.h"
  36. #include "bcm43xx_main.h"
  37. #include "bcm43xx_debugfs.h"
  38. #include "bcm43xx_radio.h"
  39. #include "bcm43xx_phy.h"
  40. #include "bcm43xx_dma.h"
  41. #include "bcm43xx_pio.h"
  42. #include "bcm43xx_power.h"
  43. #include "bcm43xx_wx.h"
  44. #include "bcm43xx_ethtool.h"
  45. #include "bcm43xx_xmit.h"
  46. #include "bcm43xx_sysfs.h"
  47. MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
  48. MODULE_AUTHOR("Martin Langer");
  49. MODULE_AUTHOR("Stefano Brivio");
  50. MODULE_AUTHOR("Michael Buesch");
  51. MODULE_LICENSE("GPL");
  52. #ifdef CONFIG_BCM947XX
  53. extern char *nvram_get(char *name);
  54. #endif
  55. #if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
  56. static int modparam_pio;
  57. module_param_named(pio, modparam_pio, int, 0444);
  58. MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
  59. #elif defined(CONFIG_BCM43XX_DMA)
  60. # define modparam_pio 0
  61. #elif defined(CONFIG_BCM43XX_PIO)
  62. # define modparam_pio 1
  63. #endif
  64. static int modparam_bad_frames_preempt;
  65. module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
  66. MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames Preemption");
  67. static int modparam_short_retry = BCM43xx_DEFAULT_SHORT_RETRY_LIMIT;
  68. module_param_named(short_retry, modparam_short_retry, int, 0444);
  69. MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
  70. static int modparam_long_retry = BCM43xx_DEFAULT_LONG_RETRY_LIMIT;
  71. module_param_named(long_retry, modparam_long_retry, int, 0444);
  72. MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
  73. static int modparam_locale = -1;
  74. module_param_named(locale, modparam_locale, int, 0444);
  75. MODULE_PARM_DESC(country, "Select LocaleCode 0-11 (For travelers)");
  76. static int modparam_noleds;
  77. module_param_named(noleds, modparam_noleds, int, 0444);
  78. MODULE_PARM_DESC(noleds, "Turn off all LED activity");
  79. #ifdef CONFIG_BCM43XX_DEBUG
  80. static char modparam_fwpostfix[64];
  81. module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
  82. MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging.");
  83. #else
  84. # define modparam_fwpostfix ""
  85. #endif /* CONFIG_BCM43XX_DEBUG*/
  86. /* If you want to debug with just a single device, enable this,
  87. * where the string is the pci device ID (as given by the kernel's
  88. * pci_name function) of the device to be used.
  89. */
  90. //#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
  91. /* If you want to enable printing of each MMIO access, enable this. */
  92. //#define DEBUG_ENABLE_MMIO_PRINT
  93. /* If you want to enable printing of MMIO access within
  94. * ucode/pcm upload, initvals write, enable this.
  95. */
  96. //#define DEBUG_ENABLE_UCODE_MMIO_PRINT
  97. /* If you want to enable printing of PCI Config Space access, enable this */
  98. //#define DEBUG_ENABLE_PCILOG
  99. /* Detailed list maintained at:
  100. * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
  101. */
  102. static struct pci_device_id bcm43xx_pci_tbl[] = {
  103. /* Broadcom 4303 802.11b */
  104. { PCI_VENDOR_ID_BROADCOM, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  105. /* Broadcom 4307 802.11b */
  106. { PCI_VENDOR_ID_BROADCOM, 0x4307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  107. /* Broadcom 4318 802.11b/g */
  108. { PCI_VENDOR_ID_BROADCOM, 0x4318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  109. /* Broadcom 4319 802.11a/b/g */
  110. { PCI_VENDOR_ID_BROADCOM, 0x4319, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  111. /* Broadcom 4306 802.11b/g */
  112. { PCI_VENDOR_ID_BROADCOM, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  113. /* Broadcom 4306 802.11a */
  114. // { PCI_VENDOR_ID_BROADCOM, 0x4321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  115. /* Broadcom 4309 802.11a/b/g */
  116. { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  117. /* Broadcom 43XG 802.11b/g */
  118. { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  119. #ifdef CONFIG_BCM947XX
  120. /* SB bus on BCM947xx */
  121. { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  122. #endif
  123. { 0 },
  124. };
  125. MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
  126. static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
  127. {
  128. u32 status;
  129. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  130. if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
  131. val = swab32(val);
  132. bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
  133. mmiowb();
  134. bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
  135. }
  136. static inline
  137. void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
  138. u16 routing, u16 offset)
  139. {
  140. u32 control;
  141. /* "offset" is the WORD offset. */
  142. control = routing;
  143. control <<= 16;
  144. control |= offset;
  145. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
  146. }
  147. u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
  148. u16 routing, u16 offset)
  149. {
  150. u32 ret;
  151. if (routing == BCM43xx_SHM_SHARED) {
  152. if (offset & 0x0003) {
  153. /* Unaligned access */
  154. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  155. ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
  156. ret <<= 16;
  157. bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
  158. ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
  159. return ret;
  160. }
  161. offset >>= 2;
  162. }
  163. bcm43xx_shm_control_word(bcm, routing, offset);
  164. ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
  165. return ret;
  166. }
  167. u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
  168. u16 routing, u16 offset)
  169. {
  170. u16 ret;
  171. if (routing == BCM43xx_SHM_SHARED) {
  172. if (offset & 0x0003) {
  173. /* Unaligned access */
  174. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  175. ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
  176. return ret;
  177. }
  178. offset >>= 2;
  179. }
  180. bcm43xx_shm_control_word(bcm, routing, offset);
  181. ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
  182. return ret;
  183. }
  184. void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
  185. u16 routing, u16 offset,
  186. u32 value)
  187. {
  188. if (routing == BCM43xx_SHM_SHARED) {
  189. if (offset & 0x0003) {
  190. /* Unaligned access */
  191. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  192. mmiowb();
  193. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
  194. (value >> 16) & 0xffff);
  195. mmiowb();
  196. bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
  197. mmiowb();
  198. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
  199. value & 0xffff);
  200. return;
  201. }
  202. offset >>= 2;
  203. }
  204. bcm43xx_shm_control_word(bcm, routing, offset);
  205. mmiowb();
  206. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
  207. }
  208. void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
  209. u16 routing, u16 offset,
  210. u16 value)
  211. {
  212. if (routing == BCM43xx_SHM_SHARED) {
  213. if (offset & 0x0003) {
  214. /* Unaligned access */
  215. bcm43xx_shm_control_word(bcm, routing, offset >> 2);
  216. mmiowb();
  217. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
  218. value);
  219. return;
  220. }
  221. offset >>= 2;
  222. }
  223. bcm43xx_shm_control_word(bcm, routing, offset);
  224. mmiowb();
  225. bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
  226. }
  227. void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
  228. {
  229. /* We need to be careful. As we read the TSF from multiple
  230. * registers, we should take care of register overflows.
  231. * In theory, the whole tsf read process should be atomic.
  232. * We try to be atomic here, by restaring the read process,
  233. * if any of the high registers changed (overflew).
  234. */
  235. if (bcm->current_core->rev >= 3) {
  236. u32 low, high, high2;
  237. do {
  238. high = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
  239. low = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW);
  240. high2 = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
  241. } while (unlikely(high != high2));
  242. *tsf = high;
  243. *tsf <<= 32;
  244. *tsf |= low;
  245. } else {
  246. u64 tmp;
  247. u16 v0, v1, v2, v3;
  248. u16 test1, test2, test3;
  249. do {
  250. v3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
  251. v2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
  252. v1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
  253. v0 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_0);
  254. test3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
  255. test2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
  256. test1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
  257. } while (v3 != test3 || v2 != test2 || v1 != test1);
  258. *tsf = v3;
  259. *tsf <<= 48;
  260. tmp = v2;
  261. tmp <<= 32;
  262. *tsf |= tmp;
  263. tmp = v1;
  264. tmp <<= 16;
  265. *tsf |= tmp;
  266. *tsf |= v0;
  267. }
  268. }
  269. void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
  270. {
  271. u32 status;
  272. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  273. status |= BCM43xx_SBF_TIME_UPDATE;
  274. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
  275. mmiowb();
  276. /* Be careful with the in-progress timer.
  277. * First zero out the low register, so we have a full
  278. * register-overflow duration to complete the operation.
  279. */
  280. if (bcm->current_core->rev >= 3) {
  281. u32 lo = (tsf & 0x00000000FFFFFFFFULL);
  282. u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
  283. bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
  284. mmiowb();
  285. bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
  286. mmiowb();
  287. bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
  288. } else {
  289. u16 v0 = (tsf & 0x000000000000FFFFULL);
  290. u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
  291. u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
  292. u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
  293. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
  294. mmiowb();
  295. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
  296. mmiowb();
  297. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
  298. mmiowb();
  299. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
  300. mmiowb();
  301. bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
  302. }
  303. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  304. status &= ~BCM43xx_SBF_TIME_UPDATE;
  305. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
  306. }
  307. static
  308. void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
  309. u16 offset,
  310. const u8 *mac)
  311. {
  312. u16 data;
  313. offset |= 0x0020;
  314. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
  315. data = mac[0];
  316. data |= mac[1] << 8;
  317. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
  318. data = mac[2];
  319. data |= mac[3] << 8;
  320. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
  321. data = mac[4];
  322. data |= mac[5] << 8;
  323. bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
  324. }
  325. static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
  326. u16 offset)
  327. {
  328. const u8 zero_addr[ETH_ALEN] = { 0 };
  329. bcm43xx_macfilter_set(bcm, offset, zero_addr);
  330. }
  331. static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
  332. {
  333. const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
  334. const u8 *bssid = (const u8 *)(bcm->ieee->bssid);
  335. u8 mac_bssid[ETH_ALEN * 2];
  336. int i;
  337. memcpy(mac_bssid, mac, ETH_ALEN);
  338. memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
  339. /* Write our MAC address and BSSID to template ram */
  340. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
  341. bcm43xx_ram_write(bcm, 0x20 + i, *((u32 *)(mac_bssid + i)));
  342. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
  343. bcm43xx_ram_write(bcm, 0x78 + i, *((u32 *)(mac_bssid + i)));
  344. for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
  345. bcm43xx_ram_write(bcm, 0x478 + i, *((u32 *)(mac_bssid + i)));
  346. }
  347. //FIXME: Well, we should probably call them from somewhere.
  348. #if 0
  349. static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
  350. {
  351. /* slot_time is in usec. */
  352. if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
  353. return;
  354. bcm43xx_write16(bcm, 0x684, 510 + slot_time);
  355. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
  356. }
  357. static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
  358. {
  359. bcm43xx_set_slot_time(bcm, 9);
  360. }
  361. static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
  362. {
  363. bcm43xx_set_slot_time(bcm, 20);
  364. }
  365. #endif
  366. /* FIXME: To get the MAC-filter working, we need to implement the
  367. * following functions (and rename them :)
  368. */
  369. #if 0
  370. static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
  371. {
  372. bcm43xx_mac_suspend(bcm);
  373. bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
  374. bcm43xx_ram_write(bcm, 0x0026, 0x0000);
  375. bcm43xx_ram_write(bcm, 0x0028, 0x0000);
  376. bcm43xx_ram_write(bcm, 0x007E, 0x0000);
  377. bcm43xx_ram_write(bcm, 0x0080, 0x0000);
  378. bcm43xx_ram_write(bcm, 0x047E, 0x0000);
  379. bcm43xx_ram_write(bcm, 0x0480, 0x0000);
  380. if (bcm->current_core->rev < 3) {
  381. bcm43xx_write16(bcm, 0x0610, 0x8000);
  382. bcm43xx_write16(bcm, 0x060E, 0x0000);
  383. } else
  384. bcm43xx_write32(bcm, 0x0188, 0x80000000);
  385. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
  386. if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G &&
  387. ieee80211_is_ofdm_rate(bcm->softmac->txrates.default_rate))
  388. bcm43xx_short_slot_timing_enable(bcm);
  389. bcm43xx_mac_enable(bcm);
  390. }
  391. static void bcm43xx_associate(struct bcm43xx_private *bcm,
  392. const u8 *mac)
  393. {
  394. memcpy(bcm->ieee->bssid, mac, ETH_ALEN);
  395. bcm43xx_mac_suspend(bcm);
  396. bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_ASSOC, mac);
  397. bcm43xx_write_mac_bssid_templates(bcm);
  398. bcm43xx_mac_enable(bcm);
  399. }
  400. #endif
  401. /* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
  402. * Returns the _previously_ enabled IRQ mask.
  403. */
  404. static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
  405. {
  406. u32 old_mask;
  407. old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
  408. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
  409. return old_mask;
  410. }
  411. /* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
  412. * Returns the _previously_ enabled IRQ mask.
  413. */
  414. static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
  415. {
  416. u32 old_mask;
  417. old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
  418. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
  419. return old_mask;
  420. }
  421. /* Synchronize IRQ top- and bottom-half.
  422. * IRQs must be masked before calling this.
  423. * This must not be called with the irq_lock held.
  424. */
  425. static void bcm43xx_synchronize_irq(struct bcm43xx_private *bcm)
  426. {
  427. synchronize_irq(bcm->irq);
  428. tasklet_disable(&bcm->isr_tasklet);
  429. }
  430. /* Make sure we don't receive more data from the device. */
  431. static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm)
  432. {
  433. unsigned long flags;
  434. spin_lock_irqsave(&bcm->irq_lock, flags);
  435. if (unlikely(bcm43xx_status(bcm) != BCM43xx_STAT_INITIALIZED)) {
  436. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  437. return -EBUSY;
  438. }
  439. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  440. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  441. bcm43xx_synchronize_irq(bcm);
  442. return 0;
  443. }
  444. static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
  445. {
  446. struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
  447. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  448. u32 radio_id;
  449. u16 manufact;
  450. u16 version;
  451. u8 revision;
  452. if (bcm->chip_id == 0x4317) {
  453. if (bcm->chip_rev == 0x00)
  454. radio_id = 0x3205017F;
  455. else if (bcm->chip_rev == 0x01)
  456. radio_id = 0x4205017F;
  457. else
  458. radio_id = 0x5205017F;
  459. } else {
  460. bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
  461. radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
  462. radio_id <<= 16;
  463. bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
  464. radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
  465. }
  466. manufact = (radio_id & 0x00000FFF);
  467. version = (radio_id & 0x0FFFF000) >> 12;
  468. revision = (radio_id & 0xF0000000) >> 28;
  469. dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
  470. radio_id, manufact, version, revision);
  471. switch (phy->type) {
  472. case BCM43xx_PHYTYPE_A:
  473. if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
  474. goto err_unsupported_radio;
  475. break;
  476. case BCM43xx_PHYTYPE_B:
  477. if ((version & 0xFFF0) != 0x2050)
  478. goto err_unsupported_radio;
  479. break;
  480. case BCM43xx_PHYTYPE_G:
  481. if (version != 0x2050)
  482. goto err_unsupported_radio;
  483. break;
  484. }
  485. radio->manufact = manufact;
  486. radio->version = version;
  487. radio->revision = revision;
  488. if (phy->type == BCM43xx_PHYTYPE_A)
  489. radio->txpower_desired = bcm->sprom.maxpower_aphy;
  490. else
  491. radio->txpower_desired = bcm->sprom.maxpower_bgphy;
  492. return 0;
  493. err_unsupported_radio:
  494. printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
  495. return -ENODEV;
  496. }
  497. static const char * bcm43xx_locale_iso(u8 locale)
  498. {
  499. /* ISO 3166-1 country codes.
  500. * Note that there aren't ISO 3166-1 codes for
  501. * all or locales. (Not all locales are countries)
  502. */
  503. switch (locale) {
  504. case BCM43xx_LOCALE_WORLD:
  505. case BCM43xx_LOCALE_ALL:
  506. return "XX";
  507. case BCM43xx_LOCALE_THAILAND:
  508. return "TH";
  509. case BCM43xx_LOCALE_ISRAEL:
  510. return "IL";
  511. case BCM43xx_LOCALE_JORDAN:
  512. return "JO";
  513. case BCM43xx_LOCALE_CHINA:
  514. return "CN";
  515. case BCM43xx_LOCALE_JAPAN:
  516. case BCM43xx_LOCALE_JAPAN_HIGH:
  517. return "JP";
  518. case BCM43xx_LOCALE_USA_CANADA_ANZ:
  519. case BCM43xx_LOCALE_USA_LOW:
  520. return "US";
  521. case BCM43xx_LOCALE_EUROPE:
  522. return "EU";
  523. case BCM43xx_LOCALE_NONE:
  524. return " ";
  525. }
  526. assert(0);
  527. return " ";
  528. }
  529. static const char * bcm43xx_locale_string(u8 locale)
  530. {
  531. switch (locale) {
  532. case BCM43xx_LOCALE_WORLD:
  533. return "World";
  534. case BCM43xx_LOCALE_THAILAND:
  535. return "Thailand";
  536. case BCM43xx_LOCALE_ISRAEL:
  537. return "Israel";
  538. case BCM43xx_LOCALE_JORDAN:
  539. return "Jordan";
  540. case BCM43xx_LOCALE_CHINA:
  541. return "China";
  542. case BCM43xx_LOCALE_JAPAN:
  543. return "Japan";
  544. case BCM43xx_LOCALE_USA_CANADA_ANZ:
  545. return "USA/Canada/ANZ";
  546. case BCM43xx_LOCALE_EUROPE:
  547. return "Europe";
  548. case BCM43xx_LOCALE_USA_LOW:
  549. return "USAlow";
  550. case BCM43xx_LOCALE_JAPAN_HIGH:
  551. return "JapanHigh";
  552. case BCM43xx_LOCALE_ALL:
  553. return "All";
  554. case BCM43xx_LOCALE_NONE:
  555. return "None";
  556. }
  557. assert(0);
  558. return "";
  559. }
  560. static inline u8 bcm43xx_crc8(u8 crc, u8 data)
  561. {
  562. static const u8 t[] = {
  563. 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
  564. 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
  565. 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
  566. 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
  567. 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
  568. 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
  569. 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
  570. 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
  571. 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
  572. 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
  573. 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
  574. 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
  575. 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
  576. 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
  577. 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
  578. 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
  579. 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
  580. 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
  581. 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
  582. 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
  583. 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
  584. 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
  585. 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
  586. 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
  587. 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
  588. 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
  589. 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
  590. 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
  591. 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
  592. 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
  593. 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
  594. 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
  595. };
  596. return t[crc ^ data];
  597. }
  598. static u8 bcm43xx_sprom_crc(const u16 *sprom)
  599. {
  600. int word;
  601. u8 crc = 0xFF;
  602. for (word = 0; word < BCM43xx_SPROM_SIZE - 1; word++) {
  603. crc = bcm43xx_crc8(crc, sprom[word] & 0x00FF);
  604. crc = bcm43xx_crc8(crc, (sprom[word] & 0xFF00) >> 8);
  605. }
  606. crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
  607. crc ^= 0xFF;
  608. return crc;
  609. }
  610. int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
  611. {
  612. int i;
  613. u8 crc, expected_crc;
  614. for (i = 0; i < BCM43xx_SPROM_SIZE; i++)
  615. sprom[i] = bcm43xx_read16(bcm, BCM43xx_SPROM_BASE + (i * 2));
  616. /* CRC-8 check. */
  617. crc = bcm43xx_sprom_crc(sprom);
  618. expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
  619. if (crc != expected_crc) {
  620. printk(KERN_WARNING PFX "WARNING: Invalid SPROM checksum "
  621. "(0x%02X, expected: 0x%02X)\n",
  622. crc, expected_crc);
  623. return -EINVAL;
  624. }
  625. return 0;
  626. }
  627. int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
  628. {
  629. int i, err;
  630. u8 crc, expected_crc;
  631. u32 spromctl;
  632. /* CRC-8 validation of the input data. */
  633. crc = bcm43xx_sprom_crc(sprom);
  634. expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
  635. if (crc != expected_crc) {
  636. printk(KERN_ERR PFX "SPROM input data: Invalid CRC\n");
  637. return -EINVAL;
  638. }
  639. printk(KERN_INFO PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n");
  640. err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_SPROMCTL, &spromctl);
  641. if (err)
  642. goto err_ctlreg;
  643. spromctl |= 0x10; /* SPROM WRITE enable. */
  644. bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
  645. if (err)
  646. goto err_ctlreg;
  647. /* We must burn lots of CPU cycles here, but that does not
  648. * really matter as one does not write the SPROM every other minute...
  649. */
  650. printk(KERN_INFO PFX "[ 0%%");
  651. mdelay(500);
  652. for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
  653. if (i == 16)
  654. printk("25%%");
  655. else if (i == 32)
  656. printk("50%%");
  657. else if (i == 48)
  658. printk("75%%");
  659. else if (i % 2)
  660. printk(".");
  661. bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
  662. mmiowb();
  663. mdelay(20);
  664. }
  665. spromctl &= ~0x10; /* SPROM WRITE enable. */
  666. bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
  667. if (err)
  668. goto err_ctlreg;
  669. mdelay(500);
  670. printk("100%% ]\n");
  671. printk(KERN_INFO PFX "SPROM written.\n");
  672. bcm43xx_controller_restart(bcm, "SPROM update");
  673. return 0;
  674. err_ctlreg:
  675. printk(KERN_ERR PFX "Could not access SPROM control register.\n");
  676. return -ENODEV;
  677. }
  678. static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
  679. {
  680. u16 value;
  681. u16 *sprom;
  682. #ifdef CONFIG_BCM947XX
  683. char *c;
  684. #endif
  685. sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
  686. GFP_KERNEL);
  687. if (!sprom) {
  688. printk(KERN_ERR PFX "sprom_extract OOM\n");
  689. return -ENOMEM;
  690. }
  691. #ifdef CONFIG_BCM947XX
  692. sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
  693. sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
  694. if ((c = nvram_get("il0macaddr")) != NULL)
  695. e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
  696. if ((c = nvram_get("et1macaddr")) != NULL)
  697. e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
  698. sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
  699. sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
  700. sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
  701. sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
  702. sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
  703. sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
  704. sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
  705. #else
  706. bcm43xx_sprom_read(bcm, sprom);
  707. #endif
  708. /* boardflags2 */
  709. value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
  710. bcm->sprom.boardflags2 = value;
  711. /* il0macaddr */
  712. value = sprom[BCM43xx_SPROM_IL0MACADDR + 0];
  713. *(((u16 *)bcm->sprom.il0macaddr) + 0) = cpu_to_be16(value);
  714. value = sprom[BCM43xx_SPROM_IL0MACADDR + 1];
  715. *(((u16 *)bcm->sprom.il0macaddr) + 1) = cpu_to_be16(value);
  716. value = sprom[BCM43xx_SPROM_IL0MACADDR + 2];
  717. *(((u16 *)bcm->sprom.il0macaddr) + 2) = cpu_to_be16(value);
  718. /* et0macaddr */
  719. value = sprom[BCM43xx_SPROM_ET0MACADDR + 0];
  720. *(((u16 *)bcm->sprom.et0macaddr) + 0) = cpu_to_be16(value);
  721. value = sprom[BCM43xx_SPROM_ET0MACADDR + 1];
  722. *(((u16 *)bcm->sprom.et0macaddr) + 1) = cpu_to_be16(value);
  723. value = sprom[BCM43xx_SPROM_ET0MACADDR + 2];
  724. *(((u16 *)bcm->sprom.et0macaddr) + 2) = cpu_to_be16(value);
  725. /* et1macaddr */
  726. value = sprom[BCM43xx_SPROM_ET1MACADDR + 0];
  727. *(((u16 *)bcm->sprom.et1macaddr) + 0) = cpu_to_be16(value);
  728. value = sprom[BCM43xx_SPROM_ET1MACADDR + 1];
  729. *(((u16 *)bcm->sprom.et1macaddr) + 1) = cpu_to_be16(value);
  730. value = sprom[BCM43xx_SPROM_ET1MACADDR + 2];
  731. *(((u16 *)bcm->sprom.et1macaddr) + 2) = cpu_to_be16(value);
  732. /* ethernet phy settings */
  733. value = sprom[BCM43xx_SPROM_ETHPHY];
  734. bcm->sprom.et0phyaddr = (value & 0x001F);
  735. bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
  736. bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
  737. bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
  738. /* boardrev, antennas, locale */
  739. value = sprom[BCM43xx_SPROM_BOARDREV];
  740. bcm->sprom.boardrev = (value & 0x00FF);
  741. bcm->sprom.locale = (value & 0x0F00) >> 8;
  742. bcm->sprom.antennas_aphy = (value & 0x3000) >> 12;
  743. bcm->sprom.antennas_bgphy = (value & 0xC000) >> 14;
  744. if (modparam_locale != -1) {
  745. if (modparam_locale >= 0 && modparam_locale <= 11) {
  746. bcm->sprom.locale = modparam_locale;
  747. printk(KERN_WARNING PFX "Operating with modified "
  748. "LocaleCode %u (%s)\n",
  749. bcm->sprom.locale,
  750. bcm43xx_locale_string(bcm->sprom.locale));
  751. } else {
  752. printk(KERN_WARNING PFX "Module parameter \"locale\" "
  753. "invalid value. (0 - 11)\n");
  754. }
  755. }
  756. /* pa0b* */
  757. value = sprom[BCM43xx_SPROM_PA0B0];
  758. bcm->sprom.pa0b0 = value;
  759. value = sprom[BCM43xx_SPROM_PA0B1];
  760. bcm->sprom.pa0b1 = value;
  761. value = sprom[BCM43xx_SPROM_PA0B2];
  762. bcm->sprom.pa0b2 = value;
  763. /* wl0gpio* */
  764. value = sprom[BCM43xx_SPROM_WL0GPIO0];
  765. if (value == 0x0000)
  766. value = 0xFFFF;
  767. bcm->sprom.wl0gpio0 = value & 0x00FF;
  768. bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
  769. value = sprom[BCM43xx_SPROM_WL0GPIO2];
  770. if (value == 0x0000)
  771. value = 0xFFFF;
  772. bcm->sprom.wl0gpio2 = value & 0x00FF;
  773. bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
  774. /* maxpower */
  775. value = sprom[BCM43xx_SPROM_MAXPWR];
  776. bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
  777. bcm->sprom.maxpower_bgphy = value & 0x00FF;
  778. /* pa1b* */
  779. value = sprom[BCM43xx_SPROM_PA1B0];
  780. bcm->sprom.pa1b0 = value;
  781. value = sprom[BCM43xx_SPROM_PA1B1];
  782. bcm->sprom.pa1b1 = value;
  783. value = sprom[BCM43xx_SPROM_PA1B2];
  784. bcm->sprom.pa1b2 = value;
  785. /* idle tssi target */
  786. value = sprom[BCM43xx_SPROM_IDL_TSSI_TGT];
  787. bcm->sprom.idle_tssi_tgt_aphy = value & 0x00FF;
  788. bcm->sprom.idle_tssi_tgt_bgphy = (value & 0xFF00) >> 8;
  789. /* boardflags */
  790. value = sprom[BCM43xx_SPROM_BOARDFLAGS];
  791. if (value == 0xFFFF)
  792. value = 0x0000;
  793. bcm->sprom.boardflags = value;
  794. /* boardflags workarounds */
  795. if (bcm->board_vendor == PCI_VENDOR_ID_DELL &&
  796. bcm->chip_id == 0x4301 &&
  797. bcm->board_revision == 0x74)
  798. bcm->sprom.boardflags |= BCM43xx_BFL_BTCOEXIST;
  799. if (bcm->board_vendor == PCI_VENDOR_ID_APPLE &&
  800. bcm->board_type == 0x4E &&
  801. bcm->board_revision > 0x40)
  802. bcm->sprom.boardflags |= BCM43xx_BFL_PACTRL;
  803. /* antenna gain */
  804. value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
  805. if (value == 0x0000 || value == 0xFFFF)
  806. value = 0x0202;
  807. /* convert values to Q5.2 */
  808. bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
  809. bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
  810. kfree(sprom);
  811. return 0;
  812. }
  813. static int bcm43xx_geo_init(struct bcm43xx_private *bcm)
  814. {
  815. struct ieee80211_geo *geo;
  816. struct ieee80211_channel *chan;
  817. int have_a = 0, have_bg = 0;
  818. int i;
  819. u8 channel;
  820. struct bcm43xx_phyinfo *phy;
  821. const char *iso_country;
  822. geo = kzalloc(sizeof(*geo), GFP_KERNEL);
  823. if (!geo)
  824. return -ENOMEM;
  825. for (i = 0; i < bcm->nr_80211_available; i++) {
  826. phy = &(bcm->core_80211_ext[i].phy);
  827. switch (phy->type) {
  828. case BCM43xx_PHYTYPE_B:
  829. case BCM43xx_PHYTYPE_G:
  830. have_bg = 1;
  831. break;
  832. case BCM43xx_PHYTYPE_A:
  833. have_a = 1;
  834. break;
  835. default:
  836. assert(0);
  837. }
  838. }
  839. iso_country = bcm43xx_locale_iso(bcm->sprom.locale);
  840. if (have_a) {
  841. for (i = 0, channel = IEEE80211_52GHZ_MIN_CHANNEL;
  842. channel <= IEEE80211_52GHZ_MAX_CHANNEL; channel++) {
  843. chan = &geo->a[i++];
  844. chan->freq = bcm43xx_channel_to_freq_a(channel);
  845. chan->channel = channel;
  846. }
  847. geo->a_channels = i;
  848. }
  849. if (have_bg) {
  850. for (i = 0, channel = IEEE80211_24GHZ_MIN_CHANNEL;
  851. channel <= IEEE80211_24GHZ_MAX_CHANNEL; channel++) {
  852. chan = &geo->bg[i++];
  853. chan->freq = bcm43xx_channel_to_freq_bg(channel);
  854. chan->channel = channel;
  855. }
  856. geo->bg_channels = i;
  857. }
  858. memcpy(geo->name, iso_country, 2);
  859. if (0 /*TODO: Outdoor use only */)
  860. geo->name[2] = 'O';
  861. else if (0 /*TODO: Indoor use only */)
  862. geo->name[2] = 'I';
  863. else
  864. geo->name[2] = ' ';
  865. geo->name[3] = '\0';
  866. ieee80211_set_geo(bcm->ieee, geo);
  867. kfree(geo);
  868. return 0;
  869. }
  870. /* DummyTransmission function, as documented on
  871. * http://bcm-specs.sipsolutions.net/DummyTransmission
  872. */
  873. void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
  874. {
  875. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  876. struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
  877. unsigned int i, max_loop;
  878. u16 value = 0;
  879. u32 buffer[5] = {
  880. 0x00000000,
  881. 0x0000D400,
  882. 0x00000000,
  883. 0x00000001,
  884. 0x00000000,
  885. };
  886. switch (phy->type) {
  887. case BCM43xx_PHYTYPE_A:
  888. max_loop = 0x1E;
  889. buffer[0] = 0xCC010200;
  890. break;
  891. case BCM43xx_PHYTYPE_B:
  892. case BCM43xx_PHYTYPE_G:
  893. max_loop = 0xFA;
  894. buffer[0] = 0x6E840B00;
  895. break;
  896. default:
  897. assert(0);
  898. return;
  899. }
  900. for (i = 0; i < 5; i++)
  901. bcm43xx_ram_write(bcm, i * 4, buffer[i]);
  902. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
  903. bcm43xx_write16(bcm, 0x0568, 0x0000);
  904. bcm43xx_write16(bcm, 0x07C0, 0x0000);
  905. bcm43xx_write16(bcm, 0x050C, ((phy->type == BCM43xx_PHYTYPE_A) ? 1 : 0));
  906. bcm43xx_write16(bcm, 0x0508, 0x0000);
  907. bcm43xx_write16(bcm, 0x050A, 0x0000);
  908. bcm43xx_write16(bcm, 0x054C, 0x0000);
  909. bcm43xx_write16(bcm, 0x056A, 0x0014);
  910. bcm43xx_write16(bcm, 0x0568, 0x0826);
  911. bcm43xx_write16(bcm, 0x0500, 0x0000);
  912. bcm43xx_write16(bcm, 0x0502, 0x0030);
  913. if (radio->version == 0x2050 && radio->revision <= 0x5)
  914. bcm43xx_radio_write16(bcm, 0x0051, 0x0017);
  915. for (i = 0x00; i < max_loop; i++) {
  916. value = bcm43xx_read16(bcm, 0x050E);
  917. if (value & 0x0080)
  918. break;
  919. udelay(10);
  920. }
  921. for (i = 0x00; i < 0x0A; i++) {
  922. value = bcm43xx_read16(bcm, 0x050E);
  923. if (value & 0x0400)
  924. break;
  925. udelay(10);
  926. }
  927. for (i = 0x00; i < 0x0A; i++) {
  928. value = bcm43xx_read16(bcm, 0x0690);
  929. if (!(value & 0x0100))
  930. break;
  931. udelay(10);
  932. }
  933. if (radio->version == 0x2050 && radio->revision <= 0x5)
  934. bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
  935. }
  936. static void key_write(struct bcm43xx_private *bcm,
  937. u8 index, u8 algorithm, const u16 *key)
  938. {
  939. unsigned int i, basic_wep = 0;
  940. u32 offset;
  941. u16 value;
  942. /* Write associated key information */
  943. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
  944. ((index << 4) | (algorithm & 0x0F)));
  945. /* The first 4 WEP keys need extra love */
  946. if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
  947. (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
  948. basic_wep = 1;
  949. /* Write key payload, 8 little endian words */
  950. offset = bcm->security_offset + (index * BCM43xx_SEC_KEYSIZE);
  951. for (i = 0; i < (BCM43xx_SEC_KEYSIZE / sizeof(u16)); i++) {
  952. value = cpu_to_le16(key[i]);
  953. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  954. offset + (i * 2), value);
  955. if (!basic_wep)
  956. continue;
  957. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  958. offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
  959. value);
  960. }
  961. }
  962. static void keymac_write(struct bcm43xx_private *bcm,
  963. u8 index, const u32 *addr)
  964. {
  965. /* for keys 0-3 there is no associated mac address */
  966. if (index < 4)
  967. return;
  968. index -= 4;
  969. if (bcm->current_core->rev >= 5) {
  970. bcm43xx_shm_write32(bcm,
  971. BCM43xx_SHM_HWMAC,
  972. index * 2,
  973. cpu_to_be32(*addr));
  974. bcm43xx_shm_write16(bcm,
  975. BCM43xx_SHM_HWMAC,
  976. (index * 2) + 1,
  977. cpu_to_be16(*((u16 *)(addr + 1))));
  978. } else {
  979. if (index < 8) {
  980. TODO(); /* Put them in the macaddress filter */
  981. } else {
  982. TODO();
  983. /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
  984. Keep in mind to update the count of keymacs in 0x003E as well! */
  985. }
  986. }
  987. }
  988. static int bcm43xx_key_write(struct bcm43xx_private *bcm,
  989. u8 index, u8 algorithm,
  990. const u8 *_key, int key_len,
  991. const u8 *mac_addr)
  992. {
  993. u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
  994. if (index >= ARRAY_SIZE(bcm->key))
  995. return -EINVAL;
  996. if (key_len > ARRAY_SIZE(key))
  997. return -EINVAL;
  998. if (algorithm < 1 || algorithm > 5)
  999. return -EINVAL;
  1000. memcpy(key, _key, key_len);
  1001. key_write(bcm, index, algorithm, (const u16 *)key);
  1002. keymac_write(bcm, index, (const u32 *)mac_addr);
  1003. bcm->key[index].algorithm = algorithm;
  1004. return 0;
  1005. }
  1006. static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
  1007. {
  1008. static const u32 zero_mac[2] = { 0 };
  1009. unsigned int i,j, nr_keys = 54;
  1010. u16 offset;
  1011. if (bcm->current_core->rev < 5)
  1012. nr_keys = 16;
  1013. assert(nr_keys <= ARRAY_SIZE(bcm->key));
  1014. for (i = 0; i < nr_keys; i++) {
  1015. bcm->key[i].enabled = 0;
  1016. /* returns for i < 4 immediately */
  1017. keymac_write(bcm, i, zero_mac);
  1018. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  1019. 0x100 + (i * 2), 0x0000);
  1020. for (j = 0; j < 8; j++) {
  1021. offset = bcm->security_offset + (j * 4) + (i * BCM43xx_SEC_KEYSIZE);
  1022. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
  1023. offset, 0x0000);
  1024. }
  1025. }
  1026. dprintk(KERN_INFO PFX "Keys cleared\n");
  1027. }
  1028. /* Lowlevel core-switch function. This is only to be used in
  1029. * bcm43xx_switch_core() and bcm43xx_probe_cores()
  1030. */
  1031. static int _switch_core(struct bcm43xx_private *bcm, int core)
  1032. {
  1033. int err;
  1034. int attempts = 0;
  1035. u32 current_core;
  1036. assert(core >= 0);
  1037. while (1) {
  1038. err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
  1039. (core * 0x1000) + 0x18000000);
  1040. if (unlikely(err))
  1041. goto error;
  1042. err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
  1043. &current_core);
  1044. if (unlikely(err))
  1045. goto error;
  1046. current_core = (current_core - 0x18000000) / 0x1000;
  1047. if (current_core == core)
  1048. break;
  1049. if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
  1050. goto error;
  1051. udelay(10);
  1052. }
  1053. #ifdef CONFIG_BCM947XX
  1054. if (bcm->pci_dev->bus->number == 0)
  1055. bcm->current_core_offset = 0x1000 * core;
  1056. else
  1057. bcm->current_core_offset = 0;
  1058. #endif
  1059. return 0;
  1060. error:
  1061. printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
  1062. return -ENODEV;
  1063. }
  1064. int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
  1065. {
  1066. int err;
  1067. if (unlikely(!new_core))
  1068. return 0;
  1069. if (!new_core->available)
  1070. return -ENODEV;
  1071. if (bcm->current_core == new_core)
  1072. return 0;
  1073. err = _switch_core(bcm, new_core->index);
  1074. if (unlikely(err))
  1075. goto out;
  1076. bcm->current_core = new_core;
  1077. out:
  1078. return err;
  1079. }
  1080. static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
  1081. {
  1082. u32 value;
  1083. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1084. value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
  1085. | BCM43xx_SBTMSTATELOW_REJECT;
  1086. return (value == BCM43xx_SBTMSTATELOW_CLOCK);
  1087. }
  1088. /* disable current core */
  1089. static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
  1090. {
  1091. u32 sbtmstatelow;
  1092. u32 sbtmstatehigh;
  1093. int i;
  1094. /* fetch sbtmstatelow from core information registers */
  1095. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1096. /* core is already in reset */
  1097. if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
  1098. goto out;
  1099. if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
  1100. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
  1101. BCM43xx_SBTMSTATELOW_REJECT;
  1102. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1103. for (i = 0; i < 1000; i++) {
  1104. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1105. if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
  1106. i = -1;
  1107. break;
  1108. }
  1109. udelay(10);
  1110. }
  1111. if (i != -1) {
  1112. printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
  1113. return -EBUSY;
  1114. }
  1115. for (i = 0; i < 1000; i++) {
  1116. sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
  1117. if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
  1118. i = -1;
  1119. break;
  1120. }
  1121. udelay(10);
  1122. }
  1123. if (i != -1) {
  1124. printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
  1125. return -EBUSY;
  1126. }
  1127. sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
  1128. BCM43xx_SBTMSTATELOW_REJECT |
  1129. BCM43xx_SBTMSTATELOW_RESET |
  1130. BCM43xx_SBTMSTATELOW_CLOCK |
  1131. core_flags;
  1132. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1133. udelay(10);
  1134. }
  1135. sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
  1136. BCM43xx_SBTMSTATELOW_REJECT |
  1137. core_flags;
  1138. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1139. out:
  1140. bcm->current_core->enabled = 0;
  1141. return 0;
  1142. }
  1143. /* enable (reset) current core */
  1144. static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
  1145. {
  1146. u32 sbtmstatelow;
  1147. u32 sbtmstatehigh;
  1148. u32 sbimstate;
  1149. int err;
  1150. err = bcm43xx_core_disable(bcm, core_flags);
  1151. if (err)
  1152. goto out;
  1153. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
  1154. BCM43xx_SBTMSTATELOW_RESET |
  1155. BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
  1156. core_flags;
  1157. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1158. udelay(1);
  1159. sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
  1160. if (sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_SERROR) {
  1161. sbtmstatehigh = 0x00000000;
  1162. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATEHIGH, sbtmstatehigh);
  1163. }
  1164. sbimstate = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMSTATE);
  1165. if (sbimstate & (BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT)) {
  1166. sbimstate &= ~(BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT);
  1167. bcm43xx_write32(bcm, BCM43xx_CIR_SBIMSTATE, sbimstate);
  1168. }
  1169. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
  1170. BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
  1171. core_flags;
  1172. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1173. udelay(1);
  1174. sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
  1175. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1176. udelay(1);
  1177. bcm->current_core->enabled = 1;
  1178. assert(err == 0);
  1179. out:
  1180. return err;
  1181. }
  1182. /* http://bcm-specs.sipsolutions.net/80211CoreReset */
  1183. void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
  1184. {
  1185. u32 flags = 0x00040000;
  1186. if ((bcm43xx_core_enabled(bcm)) &&
  1187. !bcm43xx_using_pio(bcm)) {
  1188. //FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
  1189. #ifndef CONFIG_BCM947XX
  1190. /* reset all used DMA controllers. */
  1191. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
  1192. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
  1193. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
  1194. bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
  1195. bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
  1196. if (bcm->current_core->rev < 5)
  1197. bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
  1198. #endif
  1199. }
  1200. if (bcm43xx_status(bcm) == BCM43xx_STAT_SHUTTINGDOWN) {
  1201. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1202. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1203. & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
  1204. } else {
  1205. if (connect_phy)
  1206. flags |= 0x20000000;
  1207. bcm43xx_phy_connect(bcm, connect_phy);
  1208. bcm43xx_core_enable(bcm, flags);
  1209. bcm43xx_write16(bcm, 0x03E6, 0x0000);
  1210. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1211. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1212. | BCM43xx_SBF_400);
  1213. }
  1214. }
  1215. static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
  1216. {
  1217. bcm43xx_radio_turn_off(bcm);
  1218. bcm43xx_write16(bcm, 0x03E6, 0x00F4);
  1219. bcm43xx_core_disable(bcm, 0);
  1220. }
  1221. /* Mark the current 80211 core inactive. */
  1222. static void bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm)
  1223. {
  1224. u32 sbtmstatelow;
  1225. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  1226. bcm43xx_radio_turn_off(bcm);
  1227. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1228. sbtmstatelow &= 0xDFF5FFFF;
  1229. sbtmstatelow |= 0x000A0000;
  1230. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1231. udelay(1);
  1232. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  1233. sbtmstatelow &= 0xFFF5FFFF;
  1234. sbtmstatelow |= 0x00080000;
  1235. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  1236. udelay(1);
  1237. }
  1238. static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
  1239. {
  1240. u32 v0, v1;
  1241. u16 tmp;
  1242. struct bcm43xx_xmitstatus stat;
  1243. while (1) {
  1244. v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
  1245. if (!v0)
  1246. break;
  1247. v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
  1248. stat.cookie = (v0 >> 16) & 0x0000FFFF;
  1249. tmp = (u16)((v0 & 0xFFF0) | ((v0 & 0xF) >> 1));
  1250. stat.flags = tmp & 0xFF;
  1251. stat.cnt1 = (tmp & 0x0F00) >> 8;
  1252. stat.cnt2 = (tmp & 0xF000) >> 12;
  1253. stat.seq = (u16)(v1 & 0xFFFF);
  1254. stat.unknown = (u16)((v1 >> 16) & 0xFF);
  1255. bcm43xx_debugfs_log_txstat(bcm, &stat);
  1256. if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
  1257. continue;
  1258. if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK)) {
  1259. //TODO: packet was not acked (was lost)
  1260. }
  1261. //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
  1262. if (bcm43xx_using_pio(bcm))
  1263. bcm43xx_pio_handle_xmitstatus(bcm, &stat);
  1264. else
  1265. bcm43xx_dma_handle_xmitstatus(bcm, &stat);
  1266. }
  1267. }
  1268. static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
  1269. {
  1270. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x408, 0x7F7F);
  1271. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x40A, 0x7F7F);
  1272. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
  1273. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD) | (1 << 4));
  1274. assert(bcm->noisecalc.core_at_start == bcm->current_core);
  1275. assert(bcm->noisecalc.channel_at_start == bcm43xx_current_radio(bcm)->channel);
  1276. }
  1277. static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
  1278. {
  1279. /* Top half of Link Quality calculation. */
  1280. if (bcm->noisecalc.calculation_running)
  1281. return;
  1282. bcm->noisecalc.core_at_start = bcm->current_core;
  1283. bcm->noisecalc.channel_at_start = bcm43xx_current_radio(bcm)->channel;
  1284. bcm->noisecalc.calculation_running = 1;
  1285. bcm->noisecalc.nr_samples = 0;
  1286. bcm43xx_generate_noise_sample(bcm);
  1287. }
  1288. static void handle_irq_noise(struct bcm43xx_private *bcm)
  1289. {
  1290. struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
  1291. u16 tmp;
  1292. u8 noise[4];
  1293. u8 i, j;
  1294. s32 average;
  1295. /* Bottom half of Link Quality calculation. */
  1296. assert(bcm->noisecalc.calculation_running);
  1297. if (bcm->noisecalc.core_at_start != bcm->current_core ||
  1298. bcm->noisecalc.channel_at_start != radio->channel)
  1299. goto drop_calculation;
  1300. tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x408);
  1301. noise[0] = (tmp & 0x00FF);
  1302. noise[1] = (tmp & 0xFF00) >> 8;
  1303. tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40A);
  1304. noise[2] = (tmp & 0x00FF);
  1305. noise[3] = (tmp & 0xFF00) >> 8;
  1306. if (noise[0] == 0x7F || noise[1] == 0x7F ||
  1307. noise[2] == 0x7F || noise[3] == 0x7F)
  1308. goto generate_new;
  1309. /* Get the noise samples. */
  1310. assert(bcm->noisecalc.nr_samples < 8);
  1311. i = bcm->noisecalc.nr_samples;
  1312. noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1313. noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1314. noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1315. noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
  1316. bcm->noisecalc.samples[i][0] = radio->nrssi_lt[noise[0]];
  1317. bcm->noisecalc.samples[i][1] = radio->nrssi_lt[noise[1]];
  1318. bcm->noisecalc.samples[i][2] = radio->nrssi_lt[noise[2]];
  1319. bcm->noisecalc.samples[i][3] = radio->nrssi_lt[noise[3]];
  1320. bcm->noisecalc.nr_samples++;
  1321. if (bcm->noisecalc.nr_samples == 8) {
  1322. /* Calculate the Link Quality by the noise samples. */
  1323. average = 0;
  1324. for (i = 0; i < 8; i++) {
  1325. for (j = 0; j < 4; j++)
  1326. average += bcm->noisecalc.samples[i][j];
  1327. }
  1328. average /= (8 * 4);
  1329. average *= 125;
  1330. average += 64;
  1331. average /= 128;
  1332. tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
  1333. tmp = (tmp / 128) & 0x1F;
  1334. if (tmp >= 8)
  1335. average += 2;
  1336. else
  1337. average -= 25;
  1338. if (tmp == 8)
  1339. average -= 72;
  1340. else
  1341. average -= 48;
  1342. /* FIXME: This is wrong, but people want fancy stats. well... */
  1343. bcm->stats.noise = average;
  1344. if (average > -65)
  1345. bcm->stats.link_quality = 0;
  1346. else if (average > -75)
  1347. bcm->stats.link_quality = 1;
  1348. else if (average > -85)
  1349. bcm->stats.link_quality = 2;
  1350. else
  1351. bcm->stats.link_quality = 3;
  1352. // dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
  1353. drop_calculation:
  1354. bcm->noisecalc.calculation_running = 0;
  1355. return;
  1356. }
  1357. generate_new:
  1358. bcm43xx_generate_noise_sample(bcm);
  1359. }
  1360. static void handle_irq_ps(struct bcm43xx_private *bcm)
  1361. {
  1362. if (bcm->ieee->iw_mode == IW_MODE_MASTER) {
  1363. ///TODO: PS TBTT
  1364. } else {
  1365. if (1/*FIXME: the last PSpoll frame was sent successfully */)
  1366. bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
  1367. }
  1368. if (bcm->ieee->iw_mode == IW_MODE_ADHOC)
  1369. bcm->reg124_set_0x4 = 1;
  1370. //FIXME else set to false?
  1371. }
  1372. static void handle_irq_reg124(struct bcm43xx_private *bcm)
  1373. {
  1374. if (!bcm->reg124_set_0x4)
  1375. return;
  1376. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
  1377. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
  1378. | 0x4);
  1379. //FIXME: reset reg124_set_0x4 to false?
  1380. }
  1381. static void handle_irq_pmq(struct bcm43xx_private *bcm)
  1382. {
  1383. u32 tmp;
  1384. //TODO: AP mode.
  1385. while (1) {
  1386. tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
  1387. if (!(tmp & 0x00000008))
  1388. break;
  1389. }
  1390. /* 16bit write is odd, but correct. */
  1391. bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
  1392. }
  1393. static void bcm43xx_generate_beacon_template(struct bcm43xx_private *bcm,
  1394. u16 ram_offset, u16 shm_size_offset)
  1395. {
  1396. u32 value;
  1397. u16 size = 0;
  1398. /* Timestamp. */
  1399. //FIXME: assumption: The chip sets the timestamp
  1400. value = 0;
  1401. bcm43xx_ram_write(bcm, ram_offset++, value);
  1402. bcm43xx_ram_write(bcm, ram_offset++, value);
  1403. size += 8;
  1404. /* Beacon Interval / Capability Information */
  1405. value = 0x0000;//FIXME: Which interval?
  1406. value |= (1 << 0) << 16; /* ESS */
  1407. value |= (1 << 2) << 16; /* CF Pollable */ //FIXME?
  1408. value |= (1 << 3) << 16; /* CF Poll Request */ //FIXME?
  1409. if (!bcm->ieee->open_wep)
  1410. value |= (1 << 4) << 16; /* Privacy */
  1411. bcm43xx_ram_write(bcm, ram_offset++, value);
  1412. size += 4;
  1413. /* SSID */
  1414. //TODO
  1415. /* FH Parameter Set */
  1416. //TODO
  1417. /* DS Parameter Set */
  1418. //TODO
  1419. /* CF Parameter Set */
  1420. //TODO
  1421. /* TIM */
  1422. //TODO
  1423. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
  1424. }
  1425. static void handle_irq_beacon(struct bcm43xx_private *bcm)
  1426. {
  1427. u32 status;
  1428. bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
  1429. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
  1430. if ((status & 0x1) && (status & 0x2)) {
  1431. /* ACK beacon IRQ. */
  1432. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
  1433. BCM43xx_IRQ_BEACON);
  1434. bcm->irq_savedstate |= BCM43xx_IRQ_BEACON;
  1435. return;
  1436. }
  1437. if (!(status & 0x1)) {
  1438. bcm43xx_generate_beacon_template(bcm, 0x68, 0x18);
  1439. status |= 0x1;
  1440. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
  1441. }
  1442. if (!(status & 0x2)) {
  1443. bcm43xx_generate_beacon_template(bcm, 0x468, 0x1A);
  1444. status |= 0x2;
  1445. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
  1446. }
  1447. }
  1448. /* Interrupt handler bottom-half */
  1449. static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
  1450. {
  1451. u32 reason;
  1452. u32 dma_reason[4];
  1453. int activity = 0;
  1454. unsigned long flags;
  1455. #ifdef CONFIG_BCM43XX_DEBUG
  1456. u32 _handled = 0x00000000;
  1457. # define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
  1458. #else
  1459. # define bcmirq_handled(irq) do { /* nothing */ } while (0)
  1460. #endif /* CONFIG_BCM43XX_DEBUG*/
  1461. spin_lock_irqsave(&bcm->irq_lock, flags);
  1462. reason = bcm->irq_reason;
  1463. dma_reason[0] = bcm->dma_reason[0];
  1464. dma_reason[1] = bcm->dma_reason[1];
  1465. dma_reason[2] = bcm->dma_reason[2];
  1466. dma_reason[3] = bcm->dma_reason[3];
  1467. if (unlikely(reason & BCM43xx_IRQ_XMIT_ERROR)) {
  1468. /* TX error. We get this when Template Ram is written in wrong endianess
  1469. * in dummy_tx(). We also get this if something is wrong with the TX header
  1470. * on DMA or PIO queues.
  1471. * Maybe we get this in other error conditions, too.
  1472. */
  1473. printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
  1474. bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
  1475. }
  1476. if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_FATALMASK) |
  1477. (dma_reason[1] & BCM43xx_DMAIRQ_FATALMASK) |
  1478. (dma_reason[2] & BCM43xx_DMAIRQ_FATALMASK) |
  1479. (dma_reason[3] & BCM43xx_DMAIRQ_FATALMASK))) {
  1480. printkl(KERN_ERR PFX "FATAL ERROR: Fatal DMA error: "
  1481. "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
  1482. dma_reason[0], dma_reason[1],
  1483. dma_reason[2], dma_reason[3]);
  1484. bcm43xx_controller_restart(bcm, "DMA error");
  1485. mmiowb();
  1486. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  1487. return;
  1488. }
  1489. if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) |
  1490. (dma_reason[1] & BCM43xx_DMAIRQ_NONFATALMASK) |
  1491. (dma_reason[2] & BCM43xx_DMAIRQ_NONFATALMASK) |
  1492. (dma_reason[3] & BCM43xx_DMAIRQ_NONFATALMASK))) {
  1493. printkl(KERN_ERR PFX "DMA error: "
  1494. "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
  1495. dma_reason[0], dma_reason[1],
  1496. dma_reason[2], dma_reason[3]);
  1497. }
  1498. if (reason & BCM43xx_IRQ_PS) {
  1499. handle_irq_ps(bcm);
  1500. bcmirq_handled(BCM43xx_IRQ_PS);
  1501. }
  1502. if (reason & BCM43xx_IRQ_REG124) {
  1503. handle_irq_reg124(bcm);
  1504. bcmirq_handled(BCM43xx_IRQ_REG124);
  1505. }
  1506. if (reason & BCM43xx_IRQ_BEACON) {
  1507. if (bcm->ieee->iw_mode == IW_MODE_MASTER)
  1508. handle_irq_beacon(bcm);
  1509. bcmirq_handled(BCM43xx_IRQ_BEACON);
  1510. }
  1511. if (reason & BCM43xx_IRQ_PMQ) {
  1512. handle_irq_pmq(bcm);
  1513. bcmirq_handled(BCM43xx_IRQ_PMQ);
  1514. }
  1515. if (reason & BCM43xx_IRQ_SCAN) {
  1516. /*TODO*/
  1517. //bcmirq_handled(BCM43xx_IRQ_SCAN);
  1518. }
  1519. if (reason & BCM43xx_IRQ_NOISE) {
  1520. handle_irq_noise(bcm);
  1521. bcmirq_handled(BCM43xx_IRQ_NOISE);
  1522. }
  1523. /* Check the DMA reason registers for received data. */
  1524. assert(!(dma_reason[1] & BCM43xx_DMAIRQ_RX_DONE));
  1525. assert(!(dma_reason[2] & BCM43xx_DMAIRQ_RX_DONE));
  1526. if (dma_reason[0] & BCM43xx_DMAIRQ_RX_DONE) {
  1527. if (bcm43xx_using_pio(bcm))
  1528. bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue0);
  1529. else
  1530. bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
  1531. /* We intentionally don't set "activity" to 1, here. */
  1532. }
  1533. if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
  1534. if (bcm43xx_using_pio(bcm))
  1535. bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
  1536. else
  1537. bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring1);
  1538. activity = 1;
  1539. }
  1540. bcmirq_handled(BCM43xx_IRQ_RX);
  1541. if (reason & BCM43xx_IRQ_XMIT_STATUS) {
  1542. handle_irq_transmit_status(bcm);
  1543. activity = 1;
  1544. //TODO: In AP mode, this also causes sending of powersave responses.
  1545. bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
  1546. }
  1547. /* IRQ_PIO_WORKAROUND is handled in the top-half. */
  1548. bcmirq_handled(BCM43xx_IRQ_PIO_WORKAROUND);
  1549. #ifdef CONFIG_BCM43XX_DEBUG
  1550. if (unlikely(reason & ~_handled)) {
  1551. printkl(KERN_WARNING PFX
  1552. "Unhandled IRQ! Reason: 0x%08x, Unhandled: 0x%08x, "
  1553. "DMA: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
  1554. reason, (reason & ~_handled),
  1555. dma_reason[0], dma_reason[1],
  1556. dma_reason[2], dma_reason[3]);
  1557. }
  1558. #endif
  1559. #undef bcmirq_handled
  1560. if (!modparam_noleds)
  1561. bcm43xx_leds_update(bcm, activity);
  1562. bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
  1563. mmiowb();
  1564. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  1565. }
  1566. static void pio_irq_workaround(struct bcm43xx_private *bcm,
  1567. u16 base, int queueidx)
  1568. {
  1569. u16 rxctl;
  1570. rxctl = bcm43xx_read16(bcm, base + BCM43xx_PIO_RXCTL);
  1571. if (rxctl & BCM43xx_PIO_RXCTL_DATAAVAILABLE)
  1572. bcm->dma_reason[queueidx] |= BCM43xx_DMAIRQ_RX_DONE;
  1573. else
  1574. bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
  1575. }
  1576. static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
  1577. {
  1578. if (bcm43xx_using_pio(bcm) &&
  1579. (bcm->current_core->rev < 3) &&
  1580. (!(reason & BCM43xx_IRQ_PIO_WORKAROUND))) {
  1581. /* Apply a PIO specific workaround to the dma_reasons */
  1582. pio_irq_workaround(bcm, BCM43xx_MMIO_PIO1_BASE, 0);
  1583. pio_irq_workaround(bcm, BCM43xx_MMIO_PIO2_BASE, 1);
  1584. pio_irq_workaround(bcm, BCM43xx_MMIO_PIO3_BASE, 2);
  1585. pio_irq_workaround(bcm, BCM43xx_MMIO_PIO4_BASE, 3);
  1586. }
  1587. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
  1588. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_REASON,
  1589. bcm->dma_reason[0]);
  1590. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_REASON,
  1591. bcm->dma_reason[1]);
  1592. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_REASON,
  1593. bcm->dma_reason[2]);
  1594. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_REASON,
  1595. bcm->dma_reason[3]);
  1596. }
  1597. /* Interrupt handler top-half */
  1598. static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
  1599. {
  1600. irqreturn_t ret = IRQ_HANDLED;
  1601. struct bcm43xx_private *bcm = dev_id;
  1602. u32 reason;
  1603. if (!bcm)
  1604. return IRQ_NONE;
  1605. spin_lock(&bcm->irq_lock);
  1606. assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
  1607. assert(bcm->current_core->id == BCM43xx_COREID_80211);
  1608. reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  1609. if (reason == 0xffffffff) {
  1610. /* irq not for us (shared irq) */
  1611. ret = IRQ_NONE;
  1612. goto out;
  1613. }
  1614. reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
  1615. if (!reason)
  1616. goto out;
  1617. bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
  1618. & 0x0001dc00;
  1619. bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
  1620. & 0x0000dc00;
  1621. bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
  1622. & 0x0000dc00;
  1623. bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
  1624. & 0x0001dc00;
  1625. bcm43xx_interrupt_ack(bcm, reason);
  1626. /* disable all IRQs. They are enabled again in the bottom half. */
  1627. bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  1628. /* save the reason code and call our bottom half. */
  1629. bcm->irq_reason = reason;
  1630. tasklet_schedule(&bcm->isr_tasklet);
  1631. out:
  1632. mmiowb();
  1633. spin_unlock(&bcm->irq_lock);
  1634. return ret;
  1635. }
  1636. static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
  1637. {
  1638. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  1639. if (bcm->firmware_norelease && !force)
  1640. return; /* Suspending or controller reset. */
  1641. release_firmware(phy->ucode);
  1642. phy->ucode = NULL;
  1643. release_firmware(phy->pcm);
  1644. phy->pcm = NULL;
  1645. release_firmware(phy->initvals0);
  1646. phy->initvals0 = NULL;
  1647. release_firmware(phy->initvals1);
  1648. phy->initvals1 = NULL;
  1649. }
  1650. static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
  1651. {
  1652. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  1653. u8 rev = bcm->current_core->rev;
  1654. int err = 0;
  1655. int nr;
  1656. char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
  1657. if (!phy->ucode) {
  1658. snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_microcode%d%s.fw",
  1659. (rev >= 5 ? 5 : rev),
  1660. modparam_fwpostfix);
  1661. err = request_firmware(&phy->ucode, buf, &bcm->pci_dev->dev);
  1662. if (err) {
  1663. printk(KERN_ERR PFX
  1664. "Error: Microcode \"%s\" not available or load failed.\n",
  1665. buf);
  1666. goto error;
  1667. }
  1668. }
  1669. if (!phy->pcm) {
  1670. snprintf(buf, ARRAY_SIZE(buf),
  1671. "bcm43xx_pcm%d%s.fw",
  1672. (rev < 5 ? 4 : 5),
  1673. modparam_fwpostfix);
  1674. err = request_firmware(&phy->pcm, buf, &bcm->pci_dev->dev);
  1675. if (err) {
  1676. printk(KERN_ERR PFX
  1677. "Error: PCM \"%s\" not available or load failed.\n",
  1678. buf);
  1679. goto error;
  1680. }
  1681. }
  1682. if (!phy->initvals0) {
  1683. if (rev == 2 || rev == 4) {
  1684. switch (phy->type) {
  1685. case BCM43xx_PHYTYPE_A:
  1686. nr = 3;
  1687. break;
  1688. case BCM43xx_PHYTYPE_B:
  1689. case BCM43xx_PHYTYPE_G:
  1690. nr = 1;
  1691. break;
  1692. default:
  1693. goto err_noinitval;
  1694. }
  1695. } else if (rev >= 5) {
  1696. switch (phy->type) {
  1697. case BCM43xx_PHYTYPE_A:
  1698. nr = 7;
  1699. break;
  1700. case BCM43xx_PHYTYPE_B:
  1701. case BCM43xx_PHYTYPE_G:
  1702. nr = 5;
  1703. break;
  1704. default:
  1705. goto err_noinitval;
  1706. }
  1707. } else
  1708. goto err_noinitval;
  1709. snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
  1710. nr, modparam_fwpostfix);
  1711. err = request_firmware(&phy->initvals0, buf, &bcm->pci_dev->dev);
  1712. if (err) {
  1713. printk(KERN_ERR PFX
  1714. "Error: InitVals \"%s\" not available or load failed.\n",
  1715. buf);
  1716. goto error;
  1717. }
  1718. if (phy->initvals0->size % sizeof(struct bcm43xx_initval)) {
  1719. printk(KERN_ERR PFX "InitVals fileformat error.\n");
  1720. goto error;
  1721. }
  1722. }
  1723. if (!phy->initvals1) {
  1724. if (rev >= 5) {
  1725. u32 sbtmstatehigh;
  1726. switch (phy->type) {
  1727. case BCM43xx_PHYTYPE_A:
  1728. sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
  1729. if (sbtmstatehigh & 0x00010000)
  1730. nr = 9;
  1731. else
  1732. nr = 10;
  1733. break;
  1734. case BCM43xx_PHYTYPE_B:
  1735. case BCM43xx_PHYTYPE_G:
  1736. nr = 6;
  1737. break;
  1738. default:
  1739. goto err_noinitval;
  1740. }
  1741. snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
  1742. nr, modparam_fwpostfix);
  1743. err = request_firmware(&phy->initvals1, buf, &bcm->pci_dev->dev);
  1744. if (err) {
  1745. printk(KERN_ERR PFX
  1746. "Error: InitVals \"%s\" not available or load failed.\n",
  1747. buf);
  1748. goto error;
  1749. }
  1750. if (phy->initvals1->size % sizeof(struct bcm43xx_initval)) {
  1751. printk(KERN_ERR PFX "InitVals fileformat error.\n");
  1752. goto error;
  1753. }
  1754. }
  1755. }
  1756. out:
  1757. return err;
  1758. error:
  1759. bcm43xx_release_firmware(bcm, 1);
  1760. goto out;
  1761. err_noinitval:
  1762. printk(KERN_ERR PFX "Error: No InitVals available!\n");
  1763. err = -ENOENT;
  1764. goto error;
  1765. }
  1766. static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
  1767. {
  1768. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  1769. const u32 *data;
  1770. unsigned int i, len;
  1771. /* Upload Microcode. */
  1772. data = (u32 *)(phy->ucode->data);
  1773. len = phy->ucode->size / sizeof(u32);
  1774. bcm43xx_shm_control_word(bcm, BCM43xx_SHM_UCODE, 0x0000);
  1775. for (i = 0; i < len; i++) {
  1776. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
  1777. be32_to_cpu(data[i]));
  1778. udelay(10);
  1779. }
  1780. /* Upload PCM data. */
  1781. data = (u32 *)(phy->pcm->data);
  1782. len = phy->pcm->size / sizeof(u32);
  1783. bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01ea);
  1784. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, 0x00004000);
  1785. bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01eb);
  1786. for (i = 0; i < len; i++) {
  1787. bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
  1788. be32_to_cpu(data[i]));
  1789. udelay(10);
  1790. }
  1791. }
  1792. static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
  1793. const struct bcm43xx_initval *data,
  1794. const unsigned int len)
  1795. {
  1796. u16 offset, size;
  1797. u32 value;
  1798. unsigned int i;
  1799. for (i = 0; i < len; i++) {
  1800. offset = be16_to_cpu(data[i].offset);
  1801. size = be16_to_cpu(data[i].size);
  1802. value = be32_to_cpu(data[i].value);
  1803. if (unlikely(offset >= 0x1000))
  1804. goto err_format;
  1805. if (size == 2) {
  1806. if (unlikely(value & 0xFFFF0000))
  1807. goto err_format;
  1808. bcm43xx_write16(bcm, offset, (u16)value);
  1809. } else if (size == 4) {
  1810. bcm43xx_write32(bcm, offset, value);
  1811. } else
  1812. goto err_format;
  1813. }
  1814. return 0;
  1815. err_format:
  1816. printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
  1817. "Please fix your bcm43xx firmware files.\n");
  1818. return -EPROTO;
  1819. }
  1820. static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
  1821. {
  1822. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  1823. int err;
  1824. err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)phy->initvals0->data,
  1825. phy->initvals0->size / sizeof(struct bcm43xx_initval));
  1826. if (err)
  1827. goto out;
  1828. if (phy->initvals1) {
  1829. err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)phy->initvals1->data,
  1830. phy->initvals1->size / sizeof(struct bcm43xx_initval));
  1831. if (err)
  1832. goto out;
  1833. }
  1834. out:
  1835. return err;
  1836. }
  1837. #ifdef CONFIG_BCM947XX
  1838. static struct pci_device_id bcm43xx_47xx_ids[] = {
  1839. { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4324) },
  1840. { 0 }
  1841. };
  1842. #endif
  1843. static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
  1844. {
  1845. int err;
  1846. bcm->irq = bcm->pci_dev->irq;
  1847. #ifdef CONFIG_BCM947XX
  1848. if (bcm->pci_dev->bus->number == 0) {
  1849. struct pci_dev *d;
  1850. struct pci_device_id *id;
  1851. for (id = bcm43xx_47xx_ids; id->vendor; id++) {
  1852. d = pci_get_device(id->vendor, id->device, NULL);
  1853. if (d != NULL) {
  1854. bcm->irq = d->irq;
  1855. pci_dev_put(d);
  1856. break;
  1857. }
  1858. }
  1859. }
  1860. #endif
  1861. err = request_irq(bcm->irq, bcm43xx_interrupt_handler,
  1862. IRQF_SHARED, KBUILD_MODNAME, bcm);
  1863. if (err)
  1864. printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
  1865. return err;
  1866. }
  1867. /* Switch to the core used to write the GPIO register.
  1868. * This is either the ChipCommon, or the PCI core.
  1869. */
  1870. static int switch_to_gpio_core(struct bcm43xx_private *bcm)
  1871. {
  1872. int err;
  1873. /* Where to find the GPIO register depends on the chipset.
  1874. * If it has a ChipCommon, its register at offset 0x6c is the GPIO
  1875. * control register. Otherwise the register at offset 0x6c in the
  1876. * PCI core is the GPIO control register.
  1877. */
  1878. err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
  1879. if (err == -ENODEV) {
  1880. err = bcm43xx_switch_core(bcm, &bcm->core_pci);
  1881. if (unlikely(err == -ENODEV)) {
  1882. printk(KERN_ERR PFX "gpio error: "
  1883. "Neither ChipCommon nor PCI core available!\n");
  1884. }
  1885. }
  1886. return err;
  1887. }
  1888. /* Initialize the GPIOs
  1889. * http://bcm-specs.sipsolutions.net/GPIO
  1890. */
  1891. static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
  1892. {
  1893. struct bcm43xx_coreinfo *old_core;
  1894. int err;
  1895. u32 mask, set;
  1896. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1897. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1898. & 0xFFFF3FFF);
  1899. bcm43xx_leds_switch_all(bcm, 0);
  1900. bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
  1901. bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
  1902. mask = 0x0000001F;
  1903. set = 0x0000000F;
  1904. if (bcm->chip_id == 0x4301) {
  1905. mask |= 0x0060;
  1906. set |= 0x0060;
  1907. }
  1908. if (0 /* FIXME: conditional unknown */) {
  1909. bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
  1910. bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
  1911. | 0x0100);
  1912. mask |= 0x0180;
  1913. set |= 0x0180;
  1914. }
  1915. if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
  1916. bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
  1917. bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
  1918. | 0x0200);
  1919. mask |= 0x0200;
  1920. set |= 0x0200;
  1921. }
  1922. if (bcm->current_core->rev >= 2)
  1923. mask |= 0x0010; /* FIXME: This is redundant. */
  1924. old_core = bcm->current_core;
  1925. err = switch_to_gpio_core(bcm);
  1926. if (err)
  1927. goto out;
  1928. bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
  1929. (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
  1930. err = bcm43xx_switch_core(bcm, old_core);
  1931. out:
  1932. return err;
  1933. }
  1934. /* Turn off all GPIO stuff. Call this on module unload, for example. */
  1935. static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
  1936. {
  1937. struct bcm43xx_coreinfo *old_core;
  1938. int err;
  1939. old_core = bcm->current_core;
  1940. err = switch_to_gpio_core(bcm);
  1941. if (err)
  1942. return err;
  1943. bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
  1944. err = bcm43xx_switch_core(bcm, old_core);
  1945. assert(err == 0);
  1946. return 0;
  1947. }
  1948. /* http://bcm-specs.sipsolutions.net/EnableMac */
  1949. void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
  1950. {
  1951. bcm->mac_suspended--;
  1952. assert(bcm->mac_suspended >= 0);
  1953. if (bcm->mac_suspended == 0) {
  1954. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1955. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1956. | BCM43xx_SBF_MAC_ENABLED);
  1957. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, BCM43xx_IRQ_READY);
  1958. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
  1959. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
  1960. bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
  1961. }
  1962. }
  1963. /* http://bcm-specs.sipsolutions.net/SuspendMAC */
  1964. void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
  1965. {
  1966. int i;
  1967. u32 tmp;
  1968. assert(bcm->mac_suspended >= 0);
  1969. if (bcm->mac_suspended == 0) {
  1970. bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
  1971. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  1972. bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
  1973. & ~BCM43xx_SBF_MAC_ENABLED);
  1974. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
  1975. for (i = 10000; i; i--) {
  1976. tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  1977. if (tmp & BCM43xx_IRQ_READY)
  1978. goto out;
  1979. udelay(1);
  1980. }
  1981. printkl(KERN_ERR PFX "MAC suspend failed\n");
  1982. }
  1983. out:
  1984. bcm->mac_suspended++;
  1985. }
  1986. void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
  1987. int iw_mode)
  1988. {
  1989. unsigned long flags;
  1990. struct net_device *net_dev = bcm->net_dev;
  1991. u32 status;
  1992. u16 value;
  1993. spin_lock_irqsave(&bcm->ieee->lock, flags);
  1994. bcm->ieee->iw_mode = iw_mode;
  1995. spin_unlock_irqrestore(&bcm->ieee->lock, flags);
  1996. if (iw_mode == IW_MODE_MONITOR)
  1997. net_dev->type = ARPHRD_IEEE80211;
  1998. else
  1999. net_dev->type = ARPHRD_ETHER;
  2000. status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2001. /* Reset status to infrastructured mode */
  2002. status &= ~(BCM43xx_SBF_MODE_AP | BCM43xx_SBF_MODE_MONITOR);
  2003. status &= ~BCM43xx_SBF_MODE_PROMISC;
  2004. status |= BCM43xx_SBF_MODE_NOTADHOC;
  2005. /* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
  2006. status |= BCM43xx_SBF_MODE_PROMISC;
  2007. switch (iw_mode) {
  2008. case IW_MODE_MONITOR:
  2009. status |= BCM43xx_SBF_MODE_MONITOR;
  2010. status |= BCM43xx_SBF_MODE_PROMISC;
  2011. break;
  2012. case IW_MODE_ADHOC:
  2013. status &= ~BCM43xx_SBF_MODE_NOTADHOC;
  2014. break;
  2015. case IW_MODE_MASTER:
  2016. status |= BCM43xx_SBF_MODE_AP;
  2017. break;
  2018. case IW_MODE_SECOND:
  2019. case IW_MODE_REPEAT:
  2020. TODO(); /* TODO */
  2021. break;
  2022. case IW_MODE_INFRA:
  2023. /* nothing to be done here... */
  2024. break;
  2025. default:
  2026. dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
  2027. }
  2028. if (net_dev->flags & IFF_PROMISC)
  2029. status |= BCM43xx_SBF_MODE_PROMISC;
  2030. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
  2031. value = 0x0002;
  2032. if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
  2033. if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
  2034. value = 0x0064;
  2035. else
  2036. value = 0x0032;
  2037. }
  2038. bcm43xx_write16(bcm, 0x0612, value);
  2039. }
  2040. /* This is the opposite of bcm43xx_chip_init() */
  2041. static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
  2042. {
  2043. bcm43xx_radio_turn_off(bcm);
  2044. if (!modparam_noleds)
  2045. bcm43xx_leds_exit(bcm);
  2046. bcm43xx_gpio_cleanup(bcm);
  2047. bcm43xx_release_firmware(bcm, 0);
  2048. }
  2049. /* Initialize the chip
  2050. * http://bcm-specs.sipsolutions.net/ChipInit
  2051. */
  2052. static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
  2053. {
  2054. struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
  2055. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  2056. int err;
  2057. int i, tmp;
  2058. u32 value32;
  2059. u16 value16;
  2060. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
  2061. BCM43xx_SBF_CORE_READY
  2062. | BCM43xx_SBF_400);
  2063. err = bcm43xx_request_firmware(bcm);
  2064. if (err)
  2065. goto out;
  2066. bcm43xx_upload_microcode(bcm);
  2067. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xFFFFFFFF);
  2068. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
  2069. i = 0;
  2070. while (1) {
  2071. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  2072. if (value32 == BCM43xx_IRQ_READY)
  2073. break;
  2074. i++;
  2075. if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
  2076. printk(KERN_ERR PFX "IRQ_READY timeout\n");
  2077. err = -ENODEV;
  2078. goto err_release_fw;
  2079. }
  2080. udelay(10);
  2081. }
  2082. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
  2083. err = bcm43xx_gpio_init(bcm);
  2084. if (err)
  2085. goto err_release_fw;
  2086. err = bcm43xx_upload_initvals(bcm);
  2087. if (err)
  2088. goto err_gpio_cleanup;
  2089. bcm43xx_radio_turn_on(bcm);
  2090. bcm43xx_write16(bcm, 0x03E6, 0x0000);
  2091. err = bcm43xx_phy_init(bcm);
  2092. if (err)
  2093. goto err_radio_off;
  2094. /* Select initial Interference Mitigation. */
  2095. tmp = radio->interfmode;
  2096. radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
  2097. bcm43xx_radio_set_interference_mitigation(bcm, tmp);
  2098. bcm43xx_phy_set_antenna_diversity(bcm);
  2099. bcm43xx_radio_set_txantenna(bcm, BCM43xx_RADIO_TXANTENNA_DEFAULT);
  2100. if (phy->type == BCM43xx_PHYTYPE_B) {
  2101. value16 = bcm43xx_read16(bcm, 0x005E);
  2102. value16 |= 0x0004;
  2103. bcm43xx_write16(bcm, 0x005E, value16);
  2104. }
  2105. bcm43xx_write32(bcm, 0x0100, 0x01000000);
  2106. if (bcm->current_core->rev < 5)
  2107. bcm43xx_write32(bcm, 0x010C, 0x01000000);
  2108. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2109. value32 &= ~ BCM43xx_SBF_MODE_NOTADHOC;
  2110. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2111. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2112. value32 |= BCM43xx_SBF_MODE_NOTADHOC;
  2113. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2114. value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2115. value32 |= 0x100000;
  2116. bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
  2117. if (bcm43xx_using_pio(bcm)) {
  2118. bcm43xx_write32(bcm, 0x0210, 0x00000100);
  2119. bcm43xx_write32(bcm, 0x0230, 0x00000100);
  2120. bcm43xx_write32(bcm, 0x0250, 0x00000100);
  2121. bcm43xx_write32(bcm, 0x0270, 0x00000100);
  2122. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0034, 0x0000);
  2123. }
  2124. /* Probe Response Timeout value */
  2125. /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
  2126. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0074, 0x0000);
  2127. /* Initially set the wireless operation mode. */
  2128. bcm43xx_set_iwmode(bcm, bcm->ieee->iw_mode);
  2129. if (bcm->current_core->rev < 3) {
  2130. bcm43xx_write16(bcm, 0x060E, 0x0000);
  2131. bcm43xx_write16(bcm, 0x0610, 0x8000);
  2132. bcm43xx_write16(bcm, 0x0604, 0x0000);
  2133. bcm43xx_write16(bcm, 0x0606, 0x0200);
  2134. } else {
  2135. bcm43xx_write32(bcm, 0x0188, 0x80000000);
  2136. bcm43xx_write32(bcm, 0x018C, 0x02000000);
  2137. }
  2138. bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0x00004000);
  2139. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_IRQ_MASK, 0x0001DC00);
  2140. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
  2141. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_IRQ_MASK, 0x0000DC00);
  2142. bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_IRQ_MASK, 0x0001DC00);
  2143. value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  2144. value32 |= 0x00100000;
  2145. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
  2146. bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
  2147. assert(err == 0);
  2148. dprintk(KERN_INFO PFX "Chip initialized\n");
  2149. out:
  2150. return err;
  2151. err_radio_off:
  2152. bcm43xx_radio_turn_off(bcm);
  2153. err_gpio_cleanup:
  2154. bcm43xx_gpio_cleanup(bcm);
  2155. err_release_fw:
  2156. bcm43xx_release_firmware(bcm, 1);
  2157. goto out;
  2158. }
  2159. /* Validate chip access
  2160. * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
  2161. static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
  2162. {
  2163. u32 value;
  2164. u32 shm_backup;
  2165. shm_backup = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000);
  2166. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0xAA5555AA);
  2167. if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0xAA5555AA)
  2168. goto error;
  2169. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
  2170. if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
  2171. goto error;
  2172. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
  2173. value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
  2174. if ((value | 0x80000000) != 0x80000400)
  2175. goto error;
  2176. value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
  2177. if (value != 0x00000000)
  2178. goto error;
  2179. return 0;
  2180. error:
  2181. printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
  2182. return -ENODEV;
  2183. }
  2184. static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
  2185. {
  2186. /* Initialize a "phyinfo" structure. The structure is already
  2187. * zeroed out.
  2188. * This is called on insmod time to initialize members.
  2189. */
  2190. phy->savedpctlreg = 0xFFFF;
  2191. spin_lock_init(&phy->lock);
  2192. }
  2193. static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
  2194. {
  2195. /* Initialize a "radioinfo" structure. The structure is already
  2196. * zeroed out.
  2197. * This is called on insmod time to initialize members.
  2198. */
  2199. radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
  2200. radio->channel = 0xFF;
  2201. radio->initial_channel = 0xFF;
  2202. }
  2203. static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
  2204. {
  2205. int err, i;
  2206. int current_core;
  2207. u32 core_vendor, core_id, core_rev;
  2208. u32 sb_id_hi, chip_id_32 = 0;
  2209. u16 pci_device, chip_id_16;
  2210. u8 core_count;
  2211. memset(&bcm->core_chipcommon, 0, sizeof(struct bcm43xx_coreinfo));
  2212. memset(&bcm->core_pci, 0, sizeof(struct bcm43xx_coreinfo));
  2213. memset(&bcm->core_80211, 0, sizeof(struct bcm43xx_coreinfo)
  2214. * BCM43xx_MAX_80211_CORES);
  2215. memset(&bcm->core_80211_ext, 0, sizeof(struct bcm43xx_coreinfo_80211)
  2216. * BCM43xx_MAX_80211_CORES);
  2217. bcm->nr_80211_available = 0;
  2218. bcm->current_core = NULL;
  2219. bcm->active_80211_core = NULL;
  2220. /* map core 0 */
  2221. err = _switch_core(bcm, 0);
  2222. if (err)
  2223. goto out;
  2224. /* fetch sb_id_hi from core information registers */
  2225. sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
  2226. core_id = (sb_id_hi & 0xFFF0) >> 4;
  2227. core_rev = (sb_id_hi & 0xF);
  2228. core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
  2229. /* if present, chipcommon is always core 0; read the chipid from it */
  2230. if (core_id == BCM43xx_COREID_CHIPCOMMON) {
  2231. chip_id_32 = bcm43xx_read32(bcm, 0);
  2232. chip_id_16 = chip_id_32 & 0xFFFF;
  2233. bcm->core_chipcommon.available = 1;
  2234. bcm->core_chipcommon.id = core_id;
  2235. bcm->core_chipcommon.rev = core_rev;
  2236. bcm->core_chipcommon.index = 0;
  2237. /* While we are at it, also read the capabilities. */
  2238. bcm->chipcommon_capabilities = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_CAPABILITIES);
  2239. } else {
  2240. /* without a chipCommon, use a hard coded table. */
  2241. pci_device = bcm->pci_dev->device;
  2242. if (pci_device == 0x4301)
  2243. chip_id_16 = 0x4301;
  2244. else if ((pci_device >= 0x4305) && (pci_device <= 0x4307))
  2245. chip_id_16 = 0x4307;
  2246. else if ((pci_device >= 0x4402) && (pci_device <= 0x4403))
  2247. chip_id_16 = 0x4402;
  2248. else if ((pci_device >= 0x4610) && (pci_device <= 0x4615))
  2249. chip_id_16 = 0x4610;
  2250. else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
  2251. chip_id_16 = 0x4710;
  2252. #ifdef CONFIG_BCM947XX
  2253. else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
  2254. chip_id_16 = 0x4309;
  2255. #endif
  2256. else {
  2257. printk(KERN_ERR PFX "Could not determine Chip ID\n");
  2258. return -ENODEV;
  2259. }
  2260. }
  2261. /* ChipCommon with Core Rev >=4 encodes number of cores,
  2262. * otherwise consult hardcoded table */
  2263. if ((core_id == BCM43xx_COREID_CHIPCOMMON) && (core_rev >= 4)) {
  2264. core_count = (chip_id_32 & 0x0F000000) >> 24;
  2265. } else {
  2266. switch (chip_id_16) {
  2267. case 0x4610:
  2268. case 0x4704:
  2269. case 0x4710:
  2270. core_count = 9;
  2271. break;
  2272. case 0x4310:
  2273. core_count = 8;
  2274. break;
  2275. case 0x5365:
  2276. core_count = 7;
  2277. break;
  2278. case 0x4306:
  2279. core_count = 6;
  2280. break;
  2281. case 0x4301:
  2282. case 0x4307:
  2283. core_count = 5;
  2284. break;
  2285. case 0x4402:
  2286. core_count = 3;
  2287. break;
  2288. default:
  2289. /* SOL if we get here */
  2290. assert(0);
  2291. core_count = 1;
  2292. }
  2293. }
  2294. bcm->chip_id = chip_id_16;
  2295. bcm->chip_rev = (chip_id_32 & 0x000F0000) >> 16;
  2296. bcm->chip_package = (chip_id_32 & 0x00F00000) >> 20;
  2297. dprintk(KERN_INFO PFX "Chip ID 0x%x, rev 0x%x\n",
  2298. bcm->chip_id, bcm->chip_rev);
  2299. dprintk(KERN_INFO PFX "Number of cores: %d\n", core_count);
  2300. if (bcm->core_chipcommon.available) {
  2301. dprintk(KERN_INFO PFX "Core 0: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
  2302. core_id, core_rev, core_vendor,
  2303. bcm43xx_core_enabled(bcm) ? "enabled" : "disabled");
  2304. }
  2305. if (bcm->core_chipcommon.available)
  2306. current_core = 1;
  2307. else
  2308. current_core = 0;
  2309. for ( ; current_core < core_count; current_core++) {
  2310. struct bcm43xx_coreinfo *core;
  2311. struct bcm43xx_coreinfo_80211 *ext_80211;
  2312. err = _switch_core(bcm, current_core);
  2313. if (err)
  2314. goto out;
  2315. /* Gather information */
  2316. /* fetch sb_id_hi from core information registers */
  2317. sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
  2318. /* extract core_id, core_rev, core_vendor */
  2319. core_id = (sb_id_hi & 0xFFF0) >> 4;
  2320. core_rev = (sb_id_hi & 0xF);
  2321. core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
  2322. dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
  2323. current_core, core_id, core_rev, core_vendor,
  2324. bcm43xx_core_enabled(bcm) ? "enabled" : "disabled" );
  2325. core = NULL;
  2326. switch (core_id) {
  2327. case BCM43xx_COREID_PCI:
  2328. core = &bcm->core_pci;
  2329. if (core->available) {
  2330. printk(KERN_WARNING PFX "Multiple PCI cores found.\n");
  2331. continue;
  2332. }
  2333. break;
  2334. case BCM43xx_COREID_80211:
  2335. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  2336. core = &(bcm->core_80211[i]);
  2337. ext_80211 = &(bcm->core_80211_ext[i]);
  2338. if (!core->available)
  2339. break;
  2340. core = NULL;
  2341. }
  2342. if (!core) {
  2343. printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
  2344. BCM43xx_MAX_80211_CORES);
  2345. continue;
  2346. }
  2347. if (i != 0) {
  2348. /* More than one 80211 core is only supported
  2349. * by special chips.
  2350. * There are chips with two 80211 cores, but with
  2351. * dangling pins on the second core. Be careful
  2352. * and ignore these cores here.
  2353. */
  2354. if (bcm->pci_dev->device != 0x4324) {
  2355. dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
  2356. continue;
  2357. }
  2358. }
  2359. switch (core_rev) {
  2360. case 2:
  2361. case 4:
  2362. case 5:
  2363. case 6:
  2364. case 7:
  2365. case 9:
  2366. break;
  2367. default:
  2368. printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
  2369. core_rev);
  2370. err = -ENODEV;
  2371. goto out;
  2372. }
  2373. bcm->nr_80211_available++;
  2374. core->priv = ext_80211;
  2375. bcm43xx_init_struct_phyinfo(&ext_80211->phy);
  2376. bcm43xx_init_struct_radioinfo(&ext_80211->radio);
  2377. break;
  2378. case BCM43xx_COREID_CHIPCOMMON:
  2379. printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
  2380. break;
  2381. }
  2382. if (core) {
  2383. core->available = 1;
  2384. core->id = core_id;
  2385. core->rev = core_rev;
  2386. core->index = current_core;
  2387. }
  2388. }
  2389. if (!bcm->core_80211[0].available) {
  2390. printk(KERN_ERR PFX "Error: No 80211 core found!\n");
  2391. err = -ENODEV;
  2392. goto out;
  2393. }
  2394. err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
  2395. assert(err == 0);
  2396. out:
  2397. return err;
  2398. }
  2399. static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
  2400. {
  2401. const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
  2402. u8 *bssid = bcm->ieee->bssid;
  2403. switch (bcm->ieee->iw_mode) {
  2404. case IW_MODE_ADHOC:
  2405. random_ether_addr(bssid);
  2406. break;
  2407. case IW_MODE_MASTER:
  2408. case IW_MODE_INFRA:
  2409. case IW_MODE_REPEAT:
  2410. case IW_MODE_SECOND:
  2411. case IW_MODE_MONITOR:
  2412. memcpy(bssid, mac, ETH_ALEN);
  2413. break;
  2414. default:
  2415. assert(0);
  2416. }
  2417. }
  2418. static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
  2419. u16 rate,
  2420. int is_ofdm)
  2421. {
  2422. u16 offset;
  2423. if (is_ofdm) {
  2424. offset = 0x480;
  2425. offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
  2426. }
  2427. else {
  2428. offset = 0x4C0;
  2429. offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
  2430. }
  2431. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
  2432. bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
  2433. }
  2434. static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
  2435. {
  2436. switch (bcm43xx_current_phy(bcm)->type) {
  2437. case BCM43xx_PHYTYPE_A:
  2438. case BCM43xx_PHYTYPE_G:
  2439. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_6MB, 1);
  2440. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_12MB, 1);
  2441. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_18MB, 1);
  2442. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_24MB, 1);
  2443. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_36MB, 1);
  2444. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_48MB, 1);
  2445. bcm43xx_rate_memory_write(bcm, IEEE80211_OFDM_RATE_54MB, 1);
  2446. case BCM43xx_PHYTYPE_B:
  2447. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_1MB, 0);
  2448. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_2MB, 0);
  2449. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_5MB, 0);
  2450. bcm43xx_rate_memory_write(bcm, IEEE80211_CCK_RATE_11MB, 0);
  2451. break;
  2452. default:
  2453. assert(0);
  2454. }
  2455. }
  2456. static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
  2457. {
  2458. bcm43xx_chip_cleanup(bcm);
  2459. bcm43xx_pio_free(bcm);
  2460. bcm43xx_dma_free(bcm);
  2461. bcm->current_core->initialized = 0;
  2462. }
  2463. /* http://bcm-specs.sipsolutions.net/80211Init */
  2464. static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm,
  2465. int active_wlcore)
  2466. {
  2467. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  2468. struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
  2469. u32 ucodeflags;
  2470. int err;
  2471. u32 sbimconfiglow;
  2472. u8 limit;
  2473. if (bcm->chip_rev < 5) {
  2474. sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
  2475. sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
  2476. sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
  2477. if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
  2478. sbimconfiglow |= 0x32;
  2479. else if (bcm->bustype == BCM43xx_BUSTYPE_SB)
  2480. sbimconfiglow |= 0x53;
  2481. else
  2482. assert(0);
  2483. bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
  2484. }
  2485. bcm43xx_phy_calibrate(bcm);
  2486. err = bcm43xx_chip_init(bcm);
  2487. if (err)
  2488. goto out;
  2489. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0016, bcm->current_core->rev);
  2490. ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, BCM43xx_UCODEFLAGS_OFFSET);
  2491. if (0 /*FIXME: which condition has to be used here? */)
  2492. ucodeflags |= 0x00000010;
  2493. /* HW decryption needs to be set now */
  2494. ucodeflags |= 0x40000000;
  2495. if (phy->type == BCM43xx_PHYTYPE_G) {
  2496. ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
  2497. if (phy->rev == 1)
  2498. ucodeflags |= BCM43xx_UCODEFLAG_UNKGPHY;
  2499. if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
  2500. ucodeflags |= BCM43xx_UCODEFLAG_UNKPACTRL;
  2501. } else if (phy->type == BCM43xx_PHYTYPE_B) {
  2502. ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
  2503. if (phy->rev >= 2 && radio->version == 0x2050)
  2504. ucodeflags &= ~BCM43xx_UCODEFLAG_UNKGPHY;
  2505. }
  2506. if (ucodeflags != bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
  2507. BCM43xx_UCODEFLAGS_OFFSET)) {
  2508. bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
  2509. BCM43xx_UCODEFLAGS_OFFSET, ucodeflags);
  2510. }
  2511. /* Short/Long Retry Limit.
  2512. * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
  2513. * the chip-internal counter.
  2514. */
  2515. limit = limit_value(modparam_short_retry, 0, 0xF);
  2516. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0006, limit);
  2517. limit = limit_value(modparam_long_retry, 0, 0xF);
  2518. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0007, limit);
  2519. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
  2520. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
  2521. bcm43xx_rate_memory_init(bcm);
  2522. /* Minimum Contention Window */
  2523. if (phy->type == BCM43xx_PHYTYPE_B)
  2524. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
  2525. else
  2526. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
  2527. /* Maximum Contention Window */
  2528. bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
  2529. bcm43xx_gen_bssid(bcm);
  2530. bcm43xx_write_mac_bssid_templates(bcm);
  2531. if (bcm->current_core->rev >= 5)
  2532. bcm43xx_write16(bcm, 0x043C, 0x000C);
  2533. if (active_wlcore) {
  2534. if (bcm43xx_using_pio(bcm))
  2535. err = bcm43xx_pio_init(bcm);
  2536. else
  2537. err = bcm43xx_dma_init(bcm);
  2538. if (err)
  2539. goto err_chip_cleanup;
  2540. }
  2541. bcm43xx_write16(bcm, 0x0612, 0x0050);
  2542. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0416, 0x0050);
  2543. bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0414, 0x01F4);
  2544. if (active_wlcore) {
  2545. if (radio->initial_channel != 0xFF)
  2546. bcm43xx_radio_selectchannel(bcm, radio->initial_channel, 0);
  2547. }
  2548. /* Don't enable MAC/IRQ here, as it will race with the IRQ handler.
  2549. * We enable it later.
  2550. */
  2551. bcm->current_core->initialized = 1;
  2552. out:
  2553. return err;
  2554. err_chip_cleanup:
  2555. bcm43xx_chip_cleanup(bcm);
  2556. goto out;
  2557. }
  2558. static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
  2559. {
  2560. int err;
  2561. u16 pci_status;
  2562. err = bcm43xx_pctl_set_crystal(bcm, 1);
  2563. if (err)
  2564. goto out;
  2565. bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
  2566. bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
  2567. out:
  2568. return err;
  2569. }
  2570. static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
  2571. {
  2572. bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
  2573. bcm43xx_pctl_set_crystal(bcm, 0);
  2574. }
  2575. static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
  2576. u32 address,
  2577. u32 data)
  2578. {
  2579. bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
  2580. bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
  2581. }
  2582. static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
  2583. {
  2584. int err;
  2585. struct bcm43xx_coreinfo *old_core;
  2586. old_core = bcm->current_core;
  2587. err = bcm43xx_switch_core(bcm, &bcm->core_pci);
  2588. if (err)
  2589. goto out;
  2590. bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
  2591. bcm43xx_switch_core(bcm, old_core);
  2592. assert(err == 0);
  2593. out:
  2594. return err;
  2595. }
  2596. /* Make an I/O Core usable. "core_mask" is the bitmask of the cores to enable.
  2597. * To enable core 0, pass a core_mask of 1<<0
  2598. */
  2599. static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
  2600. u32 core_mask)
  2601. {
  2602. u32 backplane_flag_nr;
  2603. u32 value;
  2604. struct bcm43xx_coreinfo *old_core;
  2605. int err = 0;
  2606. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
  2607. backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
  2608. old_core = bcm->current_core;
  2609. err = bcm43xx_switch_core(bcm, &bcm->core_pci);
  2610. if (err)
  2611. goto out;
  2612. if (bcm->core_pci.rev < 6) {
  2613. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
  2614. value |= (1 << backplane_flag_nr);
  2615. bcm43xx_write32(bcm, BCM43xx_CIR_SBINTVEC, value);
  2616. } else {
  2617. err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
  2618. if (err) {
  2619. printk(KERN_ERR PFX "Error: ICR setup failure!\n");
  2620. goto out_switch_back;
  2621. }
  2622. value |= core_mask << 8;
  2623. err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
  2624. if (err) {
  2625. printk(KERN_ERR PFX "Error: ICR setup failure!\n");
  2626. goto out_switch_back;
  2627. }
  2628. }
  2629. value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
  2630. value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
  2631. bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
  2632. if (bcm->core_pci.rev < 5) {
  2633. value = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
  2634. value |= (2 << BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT)
  2635. & BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
  2636. value |= (3 << BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT)
  2637. & BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
  2638. bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, value);
  2639. err = bcm43xx_pcicore_commit_settings(bcm);
  2640. assert(err == 0);
  2641. }
  2642. out_switch_back:
  2643. err = bcm43xx_switch_core(bcm, old_core);
  2644. out:
  2645. return err;
  2646. }
  2647. static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
  2648. {
  2649. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  2650. if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
  2651. return;
  2652. bcm43xx_mac_suspend(bcm);
  2653. bcm43xx_phy_lo_g_measure(bcm);
  2654. bcm43xx_mac_enable(bcm);
  2655. }
  2656. static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
  2657. {
  2658. bcm43xx_phy_lo_mark_all_unused(bcm);
  2659. if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
  2660. bcm43xx_mac_suspend(bcm);
  2661. bcm43xx_calc_nrssi_slope(bcm);
  2662. bcm43xx_mac_enable(bcm);
  2663. }
  2664. }
  2665. static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
  2666. {
  2667. /* Update device statistics. */
  2668. bcm43xx_calculate_link_quality(bcm);
  2669. }
  2670. static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
  2671. {
  2672. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  2673. struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
  2674. if (phy->type == BCM43xx_PHYTYPE_G) {
  2675. //TODO: update_aci_moving_average
  2676. if (radio->aci_enable && radio->aci_wlan_automatic) {
  2677. bcm43xx_mac_suspend(bcm);
  2678. if (!radio->aci_enable && 1 /*TODO: not scanning? */) {
  2679. if (0 /*TODO: bunch of conditions*/) {
  2680. bcm43xx_radio_set_interference_mitigation(bcm,
  2681. BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
  2682. }
  2683. } else if (1/*TODO*/) {
  2684. /*
  2685. if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
  2686. bcm43xx_radio_set_interference_mitigation(bcm,
  2687. BCM43xx_RADIO_INTERFMODE_NONE);
  2688. }
  2689. */
  2690. }
  2691. bcm43xx_mac_enable(bcm);
  2692. } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
  2693. phy->rev == 1) {
  2694. //TODO: implement rev1 workaround
  2695. }
  2696. }
  2697. bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
  2698. //TODO for APHY (temperature?)
  2699. }
  2700. static void do_periodic_work(struct bcm43xx_private *bcm)
  2701. {
  2702. unsigned int state;
  2703. state = bcm->periodic_state;
  2704. if (state % 8 == 0)
  2705. bcm43xx_periodic_every120sec(bcm);
  2706. if (state % 4 == 0)
  2707. bcm43xx_periodic_every60sec(bcm);
  2708. if (state % 2 == 0)
  2709. bcm43xx_periodic_every30sec(bcm);
  2710. if (state % 1 == 0)
  2711. bcm43xx_periodic_every15sec(bcm);
  2712. bcm->periodic_state = state + 1;
  2713. schedule_delayed_work(&bcm->periodic_work, HZ * 15);
  2714. }
  2715. /* Estimate a "Badness" value based on the periodic work
  2716. * state-machine state. "Badness" is worse (bigger), if the
  2717. * periodic work will take longer.
  2718. */
  2719. static int estimate_periodic_work_badness(unsigned int state)
  2720. {
  2721. int badness = 0;
  2722. if (state % 8 == 0) /* every 120 sec */
  2723. badness += 10;
  2724. if (state % 4 == 0) /* every 60 sec */
  2725. badness += 5;
  2726. if (state % 2 == 0) /* every 30 sec */
  2727. badness += 1;
  2728. if (state % 1 == 0) /* every 15 sec */
  2729. badness += 1;
  2730. #define BADNESS_LIMIT 4
  2731. return badness;
  2732. }
  2733. static void bcm43xx_periodic_work_handler(void *d)
  2734. {
  2735. struct bcm43xx_private *bcm = d;
  2736. unsigned long flags;
  2737. u32 savedirqs = 0;
  2738. int badness;
  2739. badness = estimate_periodic_work_badness(bcm->periodic_state);
  2740. if (badness > BADNESS_LIMIT) {
  2741. /* Periodic work will take a long time, so we want it to
  2742. * be preemtible.
  2743. */
  2744. netif_stop_queue(bcm->net_dev);
  2745. synchronize_net();
  2746. spin_lock_irqsave(&bcm->irq_lock, flags);
  2747. bcm43xx_mac_suspend(bcm);
  2748. if (bcm43xx_using_pio(bcm))
  2749. bcm43xx_pio_freeze_txqueues(bcm);
  2750. savedirqs = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  2751. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  2752. mutex_lock(&bcm->mutex);
  2753. bcm43xx_synchronize_irq(bcm);
  2754. } else {
  2755. /* Periodic work should take short time, so we want low
  2756. * locking overhead.
  2757. */
  2758. mutex_lock(&bcm->mutex);
  2759. spin_lock_irqsave(&bcm->irq_lock, flags);
  2760. }
  2761. do_periodic_work(bcm);
  2762. if (badness > BADNESS_LIMIT) {
  2763. spin_lock_irqsave(&bcm->irq_lock, flags);
  2764. if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)) {
  2765. tasklet_enable(&bcm->isr_tasklet);
  2766. bcm43xx_interrupt_enable(bcm, savedirqs);
  2767. if (bcm43xx_using_pio(bcm))
  2768. bcm43xx_pio_thaw_txqueues(bcm);
  2769. bcm43xx_mac_enable(bcm);
  2770. }
  2771. netif_wake_queue(bcm->net_dev);
  2772. }
  2773. mmiowb();
  2774. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  2775. mutex_unlock(&bcm->mutex);
  2776. }
  2777. static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
  2778. {
  2779. cancel_rearming_delayed_work(&bcm->periodic_work);
  2780. }
  2781. static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
  2782. {
  2783. struct work_struct *work = &(bcm->periodic_work);
  2784. assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
  2785. INIT_WORK(work, bcm43xx_periodic_work_handler, bcm);
  2786. schedule_work(work);
  2787. }
  2788. static void bcm43xx_security_init(struct bcm43xx_private *bcm)
  2789. {
  2790. bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
  2791. 0x0056) * 2;
  2792. bcm43xx_clear_keys(bcm);
  2793. }
  2794. static int bcm43xx_rng_read(struct hwrng *rng, u32 *data)
  2795. {
  2796. struct bcm43xx_private *bcm = (struct bcm43xx_private *)rng->priv;
  2797. unsigned long flags;
  2798. spin_lock_irqsave(&(bcm)->irq_lock, flags);
  2799. *data = bcm43xx_read16(bcm, BCM43xx_MMIO_RNG);
  2800. spin_unlock_irqrestore(&(bcm)->irq_lock, flags);
  2801. return (sizeof(u16));
  2802. }
  2803. static void bcm43xx_rng_exit(struct bcm43xx_private *bcm)
  2804. {
  2805. hwrng_unregister(&bcm->rng);
  2806. }
  2807. static int bcm43xx_rng_init(struct bcm43xx_private *bcm)
  2808. {
  2809. int err;
  2810. snprintf(bcm->rng_name, ARRAY_SIZE(bcm->rng_name),
  2811. "%s_%s", KBUILD_MODNAME, bcm->net_dev->name);
  2812. bcm->rng.name = bcm->rng_name;
  2813. bcm->rng.data_read = bcm43xx_rng_read;
  2814. bcm->rng.priv = (unsigned long)bcm;
  2815. err = hwrng_register(&bcm->rng);
  2816. if (err)
  2817. printk(KERN_ERR PFX "RNG init failed (%d)\n", err);
  2818. return err;
  2819. }
  2820. static int bcm43xx_shutdown_all_wireless_cores(struct bcm43xx_private *bcm)
  2821. {
  2822. int ret = 0;
  2823. int i, err;
  2824. struct bcm43xx_coreinfo *core;
  2825. bcm43xx_set_status(bcm, BCM43xx_STAT_SHUTTINGDOWN);
  2826. for (i = 0; i < bcm->nr_80211_available; i++) {
  2827. core = &(bcm->core_80211[i]);
  2828. assert(core->available);
  2829. if (!core->initialized)
  2830. continue;
  2831. err = bcm43xx_switch_core(bcm, core);
  2832. if (err) {
  2833. dprintk(KERN_ERR PFX "shutdown_all_wireless_cores "
  2834. "switch_core failed (%d)\n", err);
  2835. ret = err;
  2836. continue;
  2837. }
  2838. bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
  2839. bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
  2840. bcm43xx_wireless_core_cleanup(bcm);
  2841. if (core == bcm->active_80211_core)
  2842. bcm->active_80211_core = NULL;
  2843. }
  2844. free_irq(bcm->irq, bcm);
  2845. bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
  2846. return ret;
  2847. }
  2848. /* This is the opposite of bcm43xx_init_board() */
  2849. static void bcm43xx_free_board(struct bcm43xx_private *bcm)
  2850. {
  2851. bcm43xx_sysfs_unregister(bcm);
  2852. bcm43xx_periodic_tasks_delete(bcm);
  2853. mutex_lock(&(bcm)->mutex);
  2854. bcm43xx_shutdown_all_wireless_cores(bcm);
  2855. bcm43xx_pctl_set_crystal(bcm, 0);
  2856. mutex_unlock(&(bcm)->mutex);
  2857. }
  2858. static void prepare_phydata_for_init(struct bcm43xx_phyinfo *phy)
  2859. {
  2860. phy->antenna_diversity = 0xFFFF;
  2861. memset(phy->minlowsig, 0xFF, sizeof(phy->minlowsig));
  2862. memset(phy->minlowsigpos, 0, sizeof(phy->minlowsigpos));
  2863. /* Flags */
  2864. phy->calibrated = 0;
  2865. phy->is_locked = 0;
  2866. if (phy->_lo_pairs) {
  2867. memset(phy->_lo_pairs, 0,
  2868. sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT);
  2869. }
  2870. memset(phy->loopback_gain, 0, sizeof(phy->loopback_gain));
  2871. }
  2872. static void prepare_radiodata_for_init(struct bcm43xx_private *bcm,
  2873. struct bcm43xx_radioinfo *radio)
  2874. {
  2875. int i;
  2876. /* Set default attenuation values. */
  2877. radio->baseband_atten = bcm43xx_default_baseband_attenuation(bcm);
  2878. radio->radio_atten = bcm43xx_default_radio_attenuation(bcm);
  2879. radio->txctl1 = bcm43xx_default_txctl1(bcm);
  2880. radio->txctl2 = 0xFFFF;
  2881. radio->txpwr_offset = 0;
  2882. /* NRSSI */
  2883. radio->nrssislope = 0;
  2884. for (i = 0; i < ARRAY_SIZE(radio->nrssi); i++)
  2885. radio->nrssi[i] = -1000;
  2886. for (i = 0; i < ARRAY_SIZE(radio->nrssi_lt); i++)
  2887. radio->nrssi_lt[i] = i;
  2888. radio->lofcal = 0xFFFF;
  2889. radio->initval = 0xFFFF;
  2890. radio->aci_enable = 0;
  2891. radio->aci_wlan_automatic = 0;
  2892. radio->aci_hw_rssi = 0;
  2893. }
  2894. static void prepare_priv_for_init(struct bcm43xx_private *bcm)
  2895. {
  2896. int i;
  2897. struct bcm43xx_coreinfo *core;
  2898. struct bcm43xx_coreinfo_80211 *wlext;
  2899. assert(!bcm->active_80211_core);
  2900. bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING);
  2901. /* Flags */
  2902. bcm->was_initialized = 0;
  2903. bcm->reg124_set_0x4 = 0;
  2904. /* Stats */
  2905. memset(&bcm->stats, 0, sizeof(bcm->stats));
  2906. /* Wireless core data */
  2907. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  2908. core = &(bcm->core_80211[i]);
  2909. wlext = core->priv;
  2910. if (!core->available)
  2911. continue;
  2912. assert(wlext == &(bcm->core_80211_ext[i]));
  2913. prepare_phydata_for_init(&wlext->phy);
  2914. prepare_radiodata_for_init(bcm, &wlext->radio);
  2915. }
  2916. /* IRQ related flags */
  2917. bcm->irq_reason = 0;
  2918. memset(bcm->dma_reason, 0, sizeof(bcm->dma_reason));
  2919. bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
  2920. /* Noise calculation context */
  2921. memset(&bcm->noisecalc, 0, sizeof(bcm->noisecalc));
  2922. /* Periodic work context */
  2923. bcm->periodic_state = 0;
  2924. }
  2925. static int wireless_core_up(struct bcm43xx_private *bcm,
  2926. int active_wlcore)
  2927. {
  2928. int err;
  2929. if (!bcm43xx_core_enabled(bcm))
  2930. bcm43xx_wireless_core_reset(bcm, 1);
  2931. if (!active_wlcore)
  2932. bcm43xx_wireless_core_mark_inactive(bcm);
  2933. err = bcm43xx_wireless_core_init(bcm, active_wlcore);
  2934. if (err)
  2935. goto out;
  2936. if (!active_wlcore)
  2937. bcm43xx_radio_turn_off(bcm);
  2938. out:
  2939. return err;
  2940. }
  2941. /* Select and enable the "to be used" wireless core.
  2942. * Locking: bcm->mutex must be aquired before calling this.
  2943. * bcm->irq_lock must not be aquired.
  2944. */
  2945. int bcm43xx_select_wireless_core(struct bcm43xx_private *bcm,
  2946. int phytype)
  2947. {
  2948. int i, err;
  2949. struct bcm43xx_coreinfo *active_core = NULL;
  2950. struct bcm43xx_coreinfo_80211 *active_wlext = NULL;
  2951. struct bcm43xx_coreinfo *core;
  2952. struct bcm43xx_coreinfo_80211 *wlext;
  2953. int adjust_active_sbtmstatelow = 0;
  2954. might_sleep();
  2955. if (phytype < 0) {
  2956. /* If no phytype is requested, select the first core. */
  2957. assert(bcm->core_80211[0].available);
  2958. wlext = bcm->core_80211[0].priv;
  2959. phytype = wlext->phy.type;
  2960. }
  2961. /* Find the requested core. */
  2962. for (i = 0; i < bcm->nr_80211_available; i++) {
  2963. core = &(bcm->core_80211[i]);
  2964. wlext = core->priv;
  2965. if (wlext->phy.type == phytype) {
  2966. active_core = core;
  2967. active_wlext = wlext;
  2968. break;
  2969. }
  2970. }
  2971. if (!active_core)
  2972. return -ESRCH; /* No such PHYTYPE on this board. */
  2973. if (bcm->active_80211_core) {
  2974. /* We already selected a wl core in the past.
  2975. * So first clean up everything.
  2976. */
  2977. dprintk(KERN_INFO PFX "select_wireless_core: cleanup\n");
  2978. ieee80211softmac_stop(bcm->net_dev);
  2979. bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZED);
  2980. err = bcm43xx_disable_interrupts_sync(bcm);
  2981. assert(!err);
  2982. tasklet_enable(&bcm->isr_tasklet);
  2983. err = bcm43xx_shutdown_all_wireless_cores(bcm);
  2984. if (err)
  2985. goto error;
  2986. /* Ok, everything down, continue to re-initialize. */
  2987. bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZING);
  2988. }
  2989. /* Reset all data structures. */
  2990. prepare_priv_for_init(bcm);
  2991. err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
  2992. if (err)
  2993. goto error;
  2994. /* Mark all unused cores "inactive". */
  2995. for (i = 0; i < bcm->nr_80211_available; i++) {
  2996. core = &(bcm->core_80211[i]);
  2997. wlext = core->priv;
  2998. if (core == active_core)
  2999. continue;
  3000. err = bcm43xx_switch_core(bcm, core);
  3001. if (err) {
  3002. dprintk(KERN_ERR PFX "Could not switch to inactive "
  3003. "802.11 core (%d)\n", err);
  3004. goto error;
  3005. }
  3006. err = wireless_core_up(bcm, 0);
  3007. if (err) {
  3008. dprintk(KERN_ERR PFX "core_up for inactive 802.11 core "
  3009. "failed (%d)\n", err);
  3010. goto error;
  3011. }
  3012. adjust_active_sbtmstatelow = 1;
  3013. }
  3014. /* Now initialize the active 802.11 core. */
  3015. err = bcm43xx_switch_core(bcm, active_core);
  3016. if (err) {
  3017. dprintk(KERN_ERR PFX "Could not switch to active "
  3018. "802.11 core (%d)\n", err);
  3019. goto error;
  3020. }
  3021. if (adjust_active_sbtmstatelow &&
  3022. active_wlext->phy.type == BCM43xx_PHYTYPE_G) {
  3023. u32 sbtmstatelow;
  3024. sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
  3025. sbtmstatelow |= 0x20000000;
  3026. bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
  3027. }
  3028. err = wireless_core_up(bcm, 1);
  3029. if (err) {
  3030. dprintk(KERN_ERR PFX "core_up for active 802.11 core "
  3031. "failed (%d)\n", err);
  3032. goto error;
  3033. }
  3034. err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
  3035. if (err)
  3036. goto error;
  3037. bcm->active_80211_core = active_core;
  3038. bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
  3039. bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr));
  3040. bcm43xx_security_init(bcm);
  3041. ieee80211softmac_start(bcm->net_dev);
  3042. /* Let's go! Be careful after enabling the IRQs.
  3043. * Don't switch cores, for example.
  3044. */
  3045. bcm43xx_mac_enable(bcm);
  3046. bcm43xx_set_status(bcm, BCM43xx_STAT_INITIALIZED);
  3047. err = bcm43xx_initialize_irq(bcm);
  3048. if (err)
  3049. goto error;
  3050. bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
  3051. dprintk(KERN_INFO PFX "Selected 802.11 core (phytype %d)\n",
  3052. active_wlext->phy.type);
  3053. return 0;
  3054. error:
  3055. bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
  3056. bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
  3057. return err;
  3058. }
  3059. static int bcm43xx_init_board(struct bcm43xx_private *bcm)
  3060. {
  3061. int err;
  3062. mutex_lock(&(bcm)->mutex);
  3063. tasklet_enable(&bcm->isr_tasklet);
  3064. err = bcm43xx_pctl_set_crystal(bcm, 1);
  3065. if (err)
  3066. goto err_tasklet;
  3067. err = bcm43xx_pctl_init(bcm);
  3068. if (err)
  3069. goto err_crystal_off;
  3070. err = bcm43xx_select_wireless_core(bcm, -1);
  3071. if (err)
  3072. goto err_crystal_off;
  3073. bcm43xx_periodic_tasks_setup(bcm);
  3074. err = bcm43xx_sysfs_register(bcm);
  3075. if (err)
  3076. goto err_wlshutdown;
  3077. /*FIXME: This should be handled by softmac instead. */
  3078. schedule_work(&bcm->softmac->associnfo.work);
  3079. out:
  3080. mutex_unlock(&(bcm)->mutex);
  3081. return err;
  3082. err_wlshutdown:
  3083. bcm43xx_shutdown_all_wireless_cores(bcm);
  3084. err_crystal_off:
  3085. bcm43xx_pctl_set_crystal(bcm, 0);
  3086. err_tasklet:
  3087. tasklet_disable(&bcm->isr_tasklet);
  3088. goto out;
  3089. }
  3090. static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
  3091. {
  3092. struct pci_dev *pci_dev = bcm->pci_dev;
  3093. int i;
  3094. bcm43xx_chipset_detach(bcm);
  3095. /* Do _not_ access the chip, after it is detached. */
  3096. pci_iounmap(pci_dev, bcm->mmio_addr);
  3097. pci_release_regions(pci_dev);
  3098. pci_disable_device(pci_dev);
  3099. /* Free allocated structures/fields */
  3100. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  3101. kfree(bcm->core_80211_ext[i].phy._lo_pairs);
  3102. if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
  3103. kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
  3104. }
  3105. }
  3106. static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
  3107. {
  3108. struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
  3109. u16 value;
  3110. u8 phy_version;
  3111. u8 phy_type;
  3112. u8 phy_rev;
  3113. int phy_rev_ok = 1;
  3114. void *p;
  3115. value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
  3116. phy_version = (value & 0xF000) >> 12;
  3117. phy_type = (value & 0x0F00) >> 8;
  3118. phy_rev = (value & 0x000F);
  3119. dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
  3120. phy_version, phy_type, phy_rev);
  3121. switch (phy_type) {
  3122. case BCM43xx_PHYTYPE_A:
  3123. if (phy_rev >= 4)
  3124. phy_rev_ok = 0;
  3125. /*FIXME: We need to switch the ieee->modulation, etc.. flags,
  3126. * if we switch 80211 cores after init is done.
  3127. * As we do not implement on the fly switching between
  3128. * wireless cores, I will leave this as a future task.
  3129. */
  3130. bcm->ieee->modulation = IEEE80211_OFDM_MODULATION;
  3131. bcm->ieee->mode = IEEE_A;
  3132. bcm->ieee->freq_band = IEEE80211_52GHZ_BAND |
  3133. IEEE80211_24GHZ_BAND;
  3134. break;
  3135. case BCM43xx_PHYTYPE_B:
  3136. if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
  3137. phy_rev_ok = 0;
  3138. bcm->ieee->modulation = IEEE80211_CCK_MODULATION;
  3139. bcm->ieee->mode = IEEE_B;
  3140. bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
  3141. break;
  3142. case BCM43xx_PHYTYPE_G:
  3143. if (phy_rev > 7)
  3144. phy_rev_ok = 0;
  3145. bcm->ieee->modulation = IEEE80211_OFDM_MODULATION |
  3146. IEEE80211_CCK_MODULATION;
  3147. bcm->ieee->mode = IEEE_G;
  3148. bcm->ieee->freq_band = IEEE80211_24GHZ_BAND;
  3149. break;
  3150. default:
  3151. printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
  3152. phy_type);
  3153. return -ENODEV;
  3154. };
  3155. if (!phy_rev_ok) {
  3156. printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
  3157. phy_rev);
  3158. }
  3159. phy->version = phy_version;
  3160. phy->type = phy_type;
  3161. phy->rev = phy_rev;
  3162. if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
  3163. p = kzalloc(sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT,
  3164. GFP_KERNEL);
  3165. if (!p)
  3166. return -ENOMEM;
  3167. phy->_lo_pairs = p;
  3168. }
  3169. return 0;
  3170. }
  3171. static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
  3172. {
  3173. struct pci_dev *pci_dev = bcm->pci_dev;
  3174. struct net_device *net_dev = bcm->net_dev;
  3175. int err;
  3176. int i;
  3177. u32 coremask;
  3178. err = pci_enable_device(pci_dev);
  3179. if (err) {
  3180. printk(KERN_ERR PFX "pci_enable_device() failed\n");
  3181. goto out;
  3182. }
  3183. err = pci_request_regions(pci_dev, KBUILD_MODNAME);
  3184. if (err) {
  3185. printk(KERN_ERR PFX "pci_request_regions() failed\n");
  3186. goto err_pci_disable;
  3187. }
  3188. /* enable PCI bus-mastering */
  3189. pci_set_master(pci_dev);
  3190. bcm->mmio_addr = pci_iomap(pci_dev, 0, ~0UL);
  3191. if (!bcm->mmio_addr) {
  3192. printk(KERN_ERR PFX "pci_iomap() failed\n");
  3193. err = -EIO;
  3194. goto err_pci_release;
  3195. }
  3196. net_dev->base_addr = (unsigned long)bcm->mmio_addr;
  3197. bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
  3198. &bcm->board_vendor);
  3199. bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
  3200. &bcm->board_type);
  3201. bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
  3202. &bcm->board_revision);
  3203. err = bcm43xx_chipset_attach(bcm);
  3204. if (err)
  3205. goto err_iounmap;
  3206. err = bcm43xx_pctl_init(bcm);
  3207. if (err)
  3208. goto err_chipset_detach;
  3209. err = bcm43xx_probe_cores(bcm);
  3210. if (err)
  3211. goto err_chipset_detach;
  3212. /* Attach all IO cores to the backplane. */
  3213. coremask = 0;
  3214. for (i = 0; i < bcm->nr_80211_available; i++)
  3215. coremask |= (1 << bcm->core_80211[i].index);
  3216. //FIXME: Also attach some non80211 cores?
  3217. err = bcm43xx_setup_backplane_pci_connection(bcm, coremask);
  3218. if (err) {
  3219. printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
  3220. goto err_chipset_detach;
  3221. }
  3222. err = bcm43xx_sprom_extract(bcm);
  3223. if (err)
  3224. goto err_chipset_detach;
  3225. err = bcm43xx_leds_init(bcm);
  3226. if (err)
  3227. goto err_chipset_detach;
  3228. for (i = 0; i < bcm->nr_80211_available; i++) {
  3229. err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
  3230. assert(err != -ENODEV);
  3231. if (err)
  3232. goto err_80211_unwind;
  3233. /* Enable the selected wireless core.
  3234. * Connect PHY only on the first core.
  3235. */
  3236. bcm43xx_wireless_core_reset(bcm, (i == 0));
  3237. err = bcm43xx_read_phyinfo(bcm);
  3238. if (err && (i == 0))
  3239. goto err_80211_unwind;
  3240. err = bcm43xx_read_radioinfo(bcm);
  3241. if (err && (i == 0))
  3242. goto err_80211_unwind;
  3243. err = bcm43xx_validate_chip(bcm);
  3244. if (err && (i == 0))
  3245. goto err_80211_unwind;
  3246. bcm43xx_radio_turn_off(bcm);
  3247. err = bcm43xx_phy_init_tssi2dbm_table(bcm);
  3248. if (err)
  3249. goto err_80211_unwind;
  3250. bcm43xx_wireless_core_disable(bcm);
  3251. }
  3252. err = bcm43xx_geo_init(bcm);
  3253. if (err)
  3254. goto err_80211_unwind;
  3255. bcm43xx_pctl_set_crystal(bcm, 0);
  3256. /* Set the MAC address in the networking subsystem */
  3257. if (is_valid_ether_addr(bcm->sprom.et1macaddr))
  3258. memcpy(bcm->net_dev->dev_addr, bcm->sprom.et1macaddr, 6);
  3259. else
  3260. memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
  3261. snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
  3262. "Broadcom %04X", bcm->chip_id);
  3263. assert(err == 0);
  3264. out:
  3265. return err;
  3266. err_80211_unwind:
  3267. for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
  3268. kfree(bcm->core_80211_ext[i].phy._lo_pairs);
  3269. if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
  3270. kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
  3271. }
  3272. err_chipset_detach:
  3273. bcm43xx_chipset_detach(bcm);
  3274. err_iounmap:
  3275. pci_iounmap(pci_dev, bcm->mmio_addr);
  3276. err_pci_release:
  3277. pci_release_regions(pci_dev);
  3278. err_pci_disable:
  3279. pci_disable_device(pci_dev);
  3280. goto out;
  3281. }
  3282. /* Do the Hardware IO operations to send the txb */
  3283. static inline int bcm43xx_tx(struct bcm43xx_private *bcm,
  3284. struct ieee80211_txb *txb)
  3285. {
  3286. int err = -ENODEV;
  3287. if (bcm43xx_using_pio(bcm))
  3288. err = bcm43xx_pio_tx(bcm, txb);
  3289. else
  3290. err = bcm43xx_dma_tx(bcm, txb);
  3291. bcm->net_dev->trans_start = jiffies;
  3292. return err;
  3293. }
  3294. static void bcm43xx_ieee80211_set_chan(struct net_device *net_dev,
  3295. u8 channel)
  3296. {
  3297. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3298. struct bcm43xx_radioinfo *radio;
  3299. unsigned long flags;
  3300. mutex_lock(&bcm->mutex);
  3301. spin_lock_irqsave(&bcm->irq_lock, flags);
  3302. if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
  3303. bcm43xx_mac_suspend(bcm);
  3304. bcm43xx_radio_selectchannel(bcm, channel, 0);
  3305. bcm43xx_mac_enable(bcm);
  3306. } else {
  3307. radio = bcm43xx_current_radio(bcm);
  3308. radio->initial_channel = channel;
  3309. }
  3310. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  3311. mutex_unlock(&bcm->mutex);
  3312. }
  3313. /* set_security() callback in struct ieee80211_device */
  3314. static void bcm43xx_ieee80211_set_security(struct net_device *net_dev,
  3315. struct ieee80211_security *sec)
  3316. {
  3317. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3318. struct ieee80211_security *secinfo = &bcm->ieee->sec;
  3319. unsigned long flags;
  3320. int keyidx;
  3321. dprintk(KERN_INFO PFX "set security called");
  3322. mutex_lock(&bcm->mutex);
  3323. spin_lock_irqsave(&bcm->irq_lock, flags);
  3324. for (keyidx = 0; keyidx<WEP_KEYS; keyidx++)
  3325. if (sec->flags & (1<<keyidx)) {
  3326. secinfo->encode_alg[keyidx] = sec->encode_alg[keyidx];
  3327. secinfo->key_sizes[keyidx] = sec->key_sizes[keyidx];
  3328. memcpy(secinfo->keys[keyidx], sec->keys[keyidx], SCM_KEY_LEN);
  3329. }
  3330. if (sec->flags & SEC_ACTIVE_KEY) {
  3331. secinfo->active_key = sec->active_key;
  3332. dprintk(", .active_key = %d", sec->active_key);
  3333. }
  3334. if (sec->flags & SEC_UNICAST_GROUP) {
  3335. secinfo->unicast_uses_group = sec->unicast_uses_group;
  3336. dprintk(", .unicast_uses_group = %d", sec->unicast_uses_group);
  3337. }
  3338. if (sec->flags & SEC_LEVEL) {
  3339. secinfo->level = sec->level;
  3340. dprintk(", .level = %d", sec->level);
  3341. }
  3342. if (sec->flags & SEC_ENABLED) {
  3343. secinfo->enabled = sec->enabled;
  3344. dprintk(", .enabled = %d", sec->enabled);
  3345. }
  3346. if (sec->flags & SEC_ENCRYPT) {
  3347. secinfo->encrypt = sec->encrypt;
  3348. dprintk(", .encrypt = %d", sec->encrypt);
  3349. }
  3350. if (sec->flags & SEC_AUTH_MODE) {
  3351. secinfo->auth_mode = sec->auth_mode;
  3352. dprintk(", .auth_mode = %d", sec->auth_mode);
  3353. }
  3354. dprintk("\n");
  3355. if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED &&
  3356. !bcm->ieee->host_encrypt) {
  3357. if (secinfo->enabled) {
  3358. /* upload WEP keys to hardware */
  3359. char null_address[6] = { 0 };
  3360. u8 algorithm = 0;
  3361. for (keyidx = 0; keyidx<WEP_KEYS; keyidx++) {
  3362. if (!(sec->flags & (1<<keyidx)))
  3363. continue;
  3364. switch (sec->encode_alg[keyidx]) {
  3365. case SEC_ALG_NONE: algorithm = BCM43xx_SEC_ALGO_NONE; break;
  3366. case SEC_ALG_WEP:
  3367. algorithm = BCM43xx_SEC_ALGO_WEP;
  3368. if (secinfo->key_sizes[keyidx] == 13)
  3369. algorithm = BCM43xx_SEC_ALGO_WEP104;
  3370. break;
  3371. case SEC_ALG_TKIP:
  3372. FIXME();
  3373. algorithm = BCM43xx_SEC_ALGO_TKIP;
  3374. break;
  3375. case SEC_ALG_CCMP:
  3376. FIXME();
  3377. algorithm = BCM43xx_SEC_ALGO_AES;
  3378. break;
  3379. default:
  3380. assert(0);
  3381. break;
  3382. }
  3383. bcm43xx_key_write(bcm, keyidx, algorithm, sec->keys[keyidx], secinfo->key_sizes[keyidx], &null_address[0]);
  3384. bcm->key[keyidx].enabled = 1;
  3385. bcm->key[keyidx].algorithm = algorithm;
  3386. }
  3387. } else
  3388. bcm43xx_clear_keys(bcm);
  3389. }
  3390. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  3391. mutex_unlock(&bcm->mutex);
  3392. }
  3393. /* hard_start_xmit() callback in struct ieee80211_device */
  3394. static int bcm43xx_ieee80211_hard_start_xmit(struct ieee80211_txb *txb,
  3395. struct net_device *net_dev,
  3396. int pri)
  3397. {
  3398. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3399. int err = -ENODEV;
  3400. unsigned long flags;
  3401. spin_lock_irqsave(&bcm->irq_lock, flags);
  3402. if (likely(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED))
  3403. err = bcm43xx_tx(bcm, txb);
  3404. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  3405. return err;
  3406. }
  3407. static struct net_device_stats * bcm43xx_net_get_stats(struct net_device *net_dev)
  3408. {
  3409. return &(bcm43xx_priv(net_dev)->ieee->stats);
  3410. }
  3411. static void bcm43xx_net_tx_timeout(struct net_device *net_dev)
  3412. {
  3413. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3414. unsigned long flags;
  3415. spin_lock_irqsave(&bcm->irq_lock, flags);
  3416. bcm43xx_controller_restart(bcm, "TX timeout");
  3417. spin_unlock_irqrestore(&bcm->irq_lock, flags);
  3418. }
  3419. #ifdef CONFIG_NET_POLL_CONTROLLER
  3420. static void bcm43xx_net_poll_controller(struct net_device *net_dev)
  3421. {
  3422. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3423. unsigned long flags;
  3424. local_irq_save(flags);
  3425. if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED)
  3426. bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
  3427. local_irq_restore(flags);
  3428. }
  3429. #endif /* CONFIG_NET_POLL_CONTROLLER */
  3430. static int bcm43xx_net_open(struct net_device *net_dev)
  3431. {
  3432. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3433. return bcm43xx_init_board(bcm);
  3434. }
  3435. static int bcm43xx_net_stop(struct net_device *net_dev)
  3436. {
  3437. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3438. int err;
  3439. ieee80211softmac_stop(net_dev);
  3440. err = bcm43xx_disable_interrupts_sync(bcm);
  3441. assert(!err);
  3442. bcm43xx_free_board(bcm);
  3443. return 0;
  3444. }
  3445. static int bcm43xx_init_private(struct bcm43xx_private *bcm,
  3446. struct net_device *net_dev,
  3447. struct pci_dev *pci_dev)
  3448. {
  3449. int err;
  3450. bcm43xx_set_status(bcm, BCM43xx_STAT_UNINIT);
  3451. bcm->ieee = netdev_priv(net_dev);
  3452. bcm->softmac = ieee80211_priv(net_dev);
  3453. bcm->softmac->set_channel = bcm43xx_ieee80211_set_chan;
  3454. bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
  3455. bcm->mac_suspended = 1;
  3456. bcm->pci_dev = pci_dev;
  3457. bcm->net_dev = net_dev;
  3458. bcm->bad_frames_preempt = modparam_bad_frames_preempt;
  3459. spin_lock_init(&bcm->irq_lock);
  3460. spin_lock_init(&bcm->leds_lock);
  3461. mutex_init(&bcm->mutex);
  3462. tasklet_init(&bcm->isr_tasklet,
  3463. (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
  3464. (unsigned long)bcm);
  3465. tasklet_disable_nosync(&bcm->isr_tasklet);
  3466. if (modparam_pio) {
  3467. bcm->__using_pio = 1;
  3468. } else {
  3469. err = pci_set_dma_mask(pci_dev, DMA_30BIT_MASK);
  3470. err |= pci_set_consistent_dma_mask(pci_dev, DMA_30BIT_MASK);
  3471. if (err) {
  3472. #ifdef CONFIG_BCM43XX_PIO
  3473. printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
  3474. bcm->__using_pio = 1;
  3475. #else
  3476. printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
  3477. "Recompile the driver with PIO support, please.\n");
  3478. return -ENODEV;
  3479. #endif /* CONFIG_BCM43XX_PIO */
  3480. }
  3481. }
  3482. bcm->rts_threshold = BCM43xx_DEFAULT_RTS_THRESHOLD;
  3483. /* default to sw encryption for now */
  3484. bcm->ieee->host_build_iv = 0;
  3485. bcm->ieee->host_encrypt = 1;
  3486. bcm->ieee->host_decrypt = 1;
  3487. bcm->ieee->iw_mode = BCM43xx_INITIAL_IWMODE;
  3488. bcm->ieee->tx_headroom = sizeof(struct bcm43xx_txhdr);
  3489. bcm->ieee->set_security = bcm43xx_ieee80211_set_security;
  3490. bcm->ieee->hard_start_xmit = bcm43xx_ieee80211_hard_start_xmit;
  3491. return 0;
  3492. }
  3493. static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
  3494. const struct pci_device_id *ent)
  3495. {
  3496. struct net_device *net_dev;
  3497. struct bcm43xx_private *bcm;
  3498. int err;
  3499. #ifdef CONFIG_BCM947XX
  3500. if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
  3501. return -ENODEV;
  3502. #endif
  3503. #ifdef DEBUG_SINGLE_DEVICE_ONLY
  3504. if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
  3505. return -ENODEV;
  3506. #endif
  3507. net_dev = alloc_ieee80211softmac(sizeof(*bcm));
  3508. if (!net_dev) {
  3509. printk(KERN_ERR PFX
  3510. "could not allocate ieee80211 device %s\n",
  3511. pci_name(pdev));
  3512. err = -ENOMEM;
  3513. goto out;
  3514. }
  3515. /* initialize the net_device struct */
  3516. SET_MODULE_OWNER(net_dev);
  3517. SET_NETDEV_DEV(net_dev, &pdev->dev);
  3518. net_dev->open = bcm43xx_net_open;
  3519. net_dev->stop = bcm43xx_net_stop;
  3520. net_dev->get_stats = bcm43xx_net_get_stats;
  3521. net_dev->tx_timeout = bcm43xx_net_tx_timeout;
  3522. #ifdef CONFIG_NET_POLL_CONTROLLER
  3523. net_dev->poll_controller = bcm43xx_net_poll_controller;
  3524. #endif
  3525. net_dev->wireless_handlers = &bcm43xx_wx_handlers_def;
  3526. net_dev->irq = pdev->irq;
  3527. SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
  3528. /* initialize the bcm43xx_private struct */
  3529. bcm = bcm43xx_priv(net_dev);
  3530. memset(bcm, 0, sizeof(*bcm));
  3531. err = bcm43xx_init_private(bcm, net_dev, pdev);
  3532. if (err)
  3533. goto err_free_netdev;
  3534. pci_set_drvdata(pdev, net_dev);
  3535. err = bcm43xx_attach_board(bcm);
  3536. if (err)
  3537. goto err_free_netdev;
  3538. err = register_netdev(net_dev);
  3539. if (err) {
  3540. printk(KERN_ERR PFX "Cannot register net device, "
  3541. "aborting.\n");
  3542. err = -ENOMEM;
  3543. goto err_detach_board;
  3544. }
  3545. bcm43xx_debugfs_add_device(bcm);
  3546. assert(err == 0);
  3547. out:
  3548. return err;
  3549. err_detach_board:
  3550. bcm43xx_detach_board(bcm);
  3551. err_free_netdev:
  3552. free_ieee80211softmac(net_dev);
  3553. goto out;
  3554. }
  3555. static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
  3556. {
  3557. struct net_device *net_dev = pci_get_drvdata(pdev);
  3558. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3559. bcm43xx_debugfs_remove_device(bcm);
  3560. unregister_netdev(net_dev);
  3561. bcm43xx_detach_board(bcm);
  3562. free_ieee80211softmac(net_dev);
  3563. }
  3564. /* Hard-reset the chip. Do not call this directly.
  3565. * Use bcm43xx_controller_restart()
  3566. */
  3567. static void bcm43xx_chip_reset(void *_bcm)
  3568. {
  3569. struct bcm43xx_private *bcm = _bcm;
  3570. struct bcm43xx_phyinfo *phy;
  3571. int err;
  3572. mutex_lock(&(bcm)->mutex);
  3573. phy = bcm43xx_current_phy(bcm);
  3574. err = bcm43xx_select_wireless_core(bcm, phy->type);
  3575. mutex_unlock(&(bcm)->mutex);
  3576. printk(KERN_ERR PFX "Controller restart%s\n",
  3577. (err == 0) ? "ed" : " failed");
  3578. }
  3579. /* Hard-reset the chip.
  3580. * This can be called from interrupt or process context.
  3581. */
  3582. void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
  3583. {
  3584. assert(bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED);
  3585. bcm43xx_set_status(bcm, BCM43xx_STAT_RESTARTING);
  3586. printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
  3587. INIT_WORK(&bcm->restart_work, bcm43xx_chip_reset, bcm);
  3588. schedule_work(&bcm->restart_work);
  3589. }
  3590. #ifdef CONFIG_PM
  3591. static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
  3592. {
  3593. struct net_device *net_dev = pci_get_drvdata(pdev);
  3594. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3595. int err;
  3596. dprintk(KERN_INFO PFX "Suspending...\n");
  3597. netif_device_detach(net_dev);
  3598. bcm->was_initialized = 0;
  3599. if (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZED) {
  3600. bcm->was_initialized = 1;
  3601. ieee80211softmac_stop(net_dev);
  3602. err = bcm43xx_disable_interrupts_sync(bcm);
  3603. if (unlikely(err)) {
  3604. dprintk(KERN_ERR PFX "Suspend failed.\n");
  3605. return -EAGAIN;
  3606. }
  3607. bcm->firmware_norelease = 1;
  3608. bcm43xx_free_board(bcm);
  3609. bcm->firmware_norelease = 0;
  3610. }
  3611. bcm43xx_chipset_detach(bcm);
  3612. pci_save_state(pdev);
  3613. pci_disable_device(pdev);
  3614. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  3615. dprintk(KERN_INFO PFX "Device suspended.\n");
  3616. return 0;
  3617. }
  3618. static int bcm43xx_resume(struct pci_dev *pdev)
  3619. {
  3620. struct net_device *net_dev = pci_get_drvdata(pdev);
  3621. struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
  3622. int err = 0;
  3623. dprintk(KERN_INFO PFX "Resuming...\n");
  3624. pci_set_power_state(pdev, 0);
  3625. pci_enable_device(pdev);
  3626. pci_restore_state(pdev);
  3627. bcm43xx_chipset_attach(bcm);
  3628. if (bcm->was_initialized)
  3629. err = bcm43xx_init_board(bcm);
  3630. if (err) {
  3631. printk(KERN_ERR PFX "Resume failed!\n");
  3632. return err;
  3633. }
  3634. netif_device_attach(net_dev);
  3635. dprintk(KERN_INFO PFX "Device resumed.\n");
  3636. return 0;
  3637. }
  3638. #endif /* CONFIG_PM */
  3639. static struct pci_driver bcm43xx_pci_driver = {
  3640. .name = KBUILD_MODNAME,
  3641. .id_table = bcm43xx_pci_tbl,
  3642. .probe = bcm43xx_init_one,
  3643. .remove = __devexit_p(bcm43xx_remove_one),
  3644. #ifdef CONFIG_PM
  3645. .suspend = bcm43xx_suspend,
  3646. .resume = bcm43xx_resume,
  3647. #endif /* CONFIG_PM */
  3648. };
  3649. static int __init bcm43xx_init(void)
  3650. {
  3651. printk(KERN_INFO KBUILD_MODNAME " driver\n");
  3652. bcm43xx_debugfs_init();
  3653. return pci_register_driver(&bcm43xx_pci_driver);
  3654. }
  3655. static void __exit bcm43xx_exit(void)
  3656. {
  3657. pci_unregister_driver(&bcm43xx_pci_driver);
  3658. bcm43xx_debugfs_exit();
  3659. }
  3660. module_init(bcm43xx_init)
  3661. module_exit(bcm43xx_exit)