bcm43xx_main.c 114 KB

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