hostap_hw.c 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634
  1. /*
  2. * Host AP (software wireless LAN access point) driver for
  3. * Intersil Prism2/2.5/3.
  4. *
  5. * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  6. * <jkmaline@cc.hut.fi>
  7. * Copyright (c) 2002-2004, Jouni Malinen <jkmaline@cc.hut.fi>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation. See README and COPYING for
  12. * more details.
  13. *
  14. * FIX:
  15. * - there is currently no way of associating TX packets to correct wds device
  16. * when TX Exc/OK event occurs, so all tx_packets and some
  17. * tx_errors/tx_dropped are added to the main netdevice; using sw_support
  18. * field in txdesc might be used to fix this (using Alloc event to increment
  19. * tx_packets would need some further info in txfid table)
  20. *
  21. * Buffer Access Path (BAP) usage:
  22. * Prism2 cards have two separate BAPs for accessing the card memory. These
  23. * should allow concurrent access to two different frames and the driver
  24. * previously used BAP0 for sending data and BAP1 for receiving data.
  25. * However, there seems to be number of issues with concurrent access and at
  26. * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI
  27. * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between
  28. * host and card memories. BAP0 accesses are protected with local->baplock
  29. * (spin_lock_bh) to prevent concurrent use.
  30. */
  31. #include <linux/config.h>
  32. #include <linux/version.h>
  33. #include <asm/delay.h>
  34. #include <asm/uaccess.h>
  35. #include <linux/slab.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/proc_fs.h>
  39. #include <linux/if_arp.h>
  40. #include <linux/delay.h>
  41. #include <linux/random.h>
  42. #include <linux/wait.h>
  43. #include <linux/sched.h>
  44. #include <linux/rtnetlink.h>
  45. #include <linux/wireless.h>
  46. #include <net/iw_handler.h>
  47. #include <asm/irq.h>
  48. #include "hostap_80211.h"
  49. #include "hostap.h"
  50. #include "hostap_ap.h"
  51. /* #define final_version */
  52. static int mtu = 1500;
  53. module_param(mtu, int, 0444);
  54. MODULE_PARM_DESC(mtu, "Maximum transfer unit");
  55. static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS };
  56. module_param_array(channel, int, NULL, 0444);
  57. MODULE_PARM_DESC(channel, "Initial channel");
  58. static char essid[33] = "test";
  59. module_param_string(essid, essid, sizeof(essid), 0444);
  60. MODULE_PARM_DESC(essid, "Host AP's ESSID");
  61. static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS };
  62. module_param_array(iw_mode, int, NULL, 0444);
  63. MODULE_PARM_DESC(iw_mode, "Initial operation mode");
  64. static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS };
  65. module_param_array(beacon_int, int, NULL, 0444);
  66. MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)");
  67. static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS };
  68. module_param_array(dtim_period, int, NULL, 0444);
  69. MODULE_PARM_DESC(dtim_period, "DTIM period");
  70. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  71. static int bus_master_threshold_rx[MAX_PARM_DEVICES] = { 100, DEF_INTS };
  72. module_param_array(bus_master_threshold_rx, int, NULL, 0444);
  73. MODULE_PARM_DESC(bus_master_threshold_rx, "Packet length threshold for using "
  74. "PCI bus master on RX");
  75. static int bus_master_threshold_tx[MAX_PARM_DEVICES] = { 100, DEF_INTS };
  76. module_param_array(bus_master_threshold_tx, int, NULL, 0444);
  77. MODULE_PARM_DESC(bus_master_threshold_tx, "Packet length threshold for using "
  78. "PCI bus master on TX");
  79. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  80. static char dev_template[16] = "wlan%d";
  81. module_param_string(dev_template, dev_template, sizeof(dev_template), 0444);
  82. MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: "
  83. "wlan%d)");
  84. #ifdef final_version
  85. #define EXTRA_EVENTS_WTERR 0
  86. #else
  87. /* check WTERR events (Wait Time-out) in development versions */
  88. #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
  89. #endif
  90. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  91. #define EXTRA_EVENTS_BUS_MASTER (HFA384X_EV_PCI_M0 | HFA384X_EV_PCI_M1)
  92. #else
  93. #define EXTRA_EVENTS_BUS_MASTER 0
  94. #endif
  95. /* Events that will be using BAP0 */
  96. #define HFA384X_BAP0_EVENTS \
  97. (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
  98. /* event mask, i.e., events that will result in an interrupt */
  99. #define HFA384X_EVENT_MASK \
  100. (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
  101. HFA384X_EV_CMD | HFA384X_EV_TICK | \
  102. EXTRA_EVENTS_WTERR | EXTRA_EVENTS_BUS_MASTER)
  103. /* Default TX control flags: use 802.11 headers and request interrupt for
  104. * failed transmits. Frames that request ACK callback, will add
  105. * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
  106. */
  107. #define HFA384X_TX_CTRL_FLAGS \
  108. (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
  109. /* ca. 1 usec */
  110. #define HFA384X_CMD_BUSY_TIMEOUT 5000
  111. #define HFA384X_BAP_BUSY_TIMEOUT 50000
  112. /* ca. 10 usec */
  113. #define HFA384X_CMD_COMPL_TIMEOUT 20000
  114. #define HFA384X_DL_COMPL_TIMEOUT 1000000
  115. /* Wait times for initialization; yield to other processes to avoid busy
  116. * waiting for long time. */
  117. #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
  118. #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
  119. static void prism2_hw_reset(struct net_device *dev);
  120. static void prism2_check_sta_fw_version(local_info_t *local);
  121. #ifdef PRISM2_DOWNLOAD_SUPPORT
  122. /* hostap_download.c */
  123. static int prism2_download_aux_dump(struct net_device *dev,
  124. unsigned int addr, int len, u8 *buf);
  125. static u8 * prism2_read_pda(struct net_device *dev);
  126. static int prism2_download(local_info_t *local,
  127. struct prism2_download_param *param);
  128. static void prism2_download_free_data(struct prism2_download_data *dl);
  129. static int prism2_download_volatile(local_info_t *local,
  130. struct prism2_download_data *param);
  131. static int prism2_download_genesis(local_info_t *local,
  132. struct prism2_download_data *param);
  133. static int prism2_get_ram_size(local_info_t *local);
  134. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  135. #ifndef final_version
  136. /* magic value written to SWSUPPORT0 reg. for detecting whether card is still
  137. * present */
  138. #define HFA384X_MAGIC 0x8A32
  139. #endif
  140. static u16 hfa384x_read_reg(struct net_device *dev, u16 reg)
  141. {
  142. return HFA384X_INW(reg);
  143. }
  144. static void hfa384x_read_regs(struct net_device *dev,
  145. struct hfa384x_regs *regs)
  146. {
  147. regs->cmd = HFA384X_INW(HFA384X_CMD_OFF);
  148. regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
  149. regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF);
  150. regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF);
  151. regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF);
  152. }
  153. /**
  154. * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
  155. * @local: pointer to private Host AP driver data
  156. * @entry: Prism2 command queue entry to be freed
  157. * @del_req: request the entry to be removed
  158. *
  159. * Internal helper function for freeing Prism2 command queue entries.
  160. * Caller must have acquired local->cmdlock before calling this function.
  161. */
  162. static inline void __hostap_cmd_queue_free(local_info_t *local,
  163. struct hostap_cmd_queue *entry,
  164. int del_req)
  165. {
  166. if (del_req) {
  167. entry->del_req = 1;
  168. if (!list_empty(&entry->list)) {
  169. list_del_init(&entry->list);
  170. local->cmd_queue_len--;
  171. }
  172. }
  173. if (atomic_dec_and_test(&entry->usecnt) && entry->del_req)
  174. kfree(entry);
  175. }
  176. /**
  177. * hostap_cmd_queue_free - Free Prism2 command queue entry
  178. * @local: pointer to private Host AP driver data
  179. * @entry: Prism2 command queue entry to be freed
  180. * @del_req: request the entry to be removed
  181. *
  182. * Free a Prism2 command queue entry.
  183. */
  184. static inline void hostap_cmd_queue_free(local_info_t *local,
  185. struct hostap_cmd_queue *entry,
  186. int del_req)
  187. {
  188. unsigned long flags;
  189. spin_lock_irqsave(&local->cmdlock, flags);
  190. __hostap_cmd_queue_free(local, entry, del_req);
  191. spin_unlock_irqrestore(&local->cmdlock, flags);
  192. }
  193. /**
  194. * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
  195. * @local: pointer to private Host AP driver data
  196. */
  197. static void prism2_clear_cmd_queue(local_info_t *local)
  198. {
  199. struct list_head *ptr, *n;
  200. unsigned long flags;
  201. struct hostap_cmd_queue *entry;
  202. spin_lock_irqsave(&local->cmdlock, flags);
  203. list_for_each_safe(ptr, n, &local->cmd_queue) {
  204. entry = list_entry(ptr, struct hostap_cmd_queue, list);
  205. atomic_inc(&entry->usecnt);
  206. printk(KERN_DEBUG "%s: removed pending cmd_queue entry "
  207. "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
  208. local->dev->name, entry->type, entry->cmd,
  209. entry->param0);
  210. __hostap_cmd_queue_free(local, entry, 1);
  211. }
  212. if (local->cmd_queue_len) {
  213. /* This should not happen; print debug message and clear
  214. * queue length. */
  215. printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after "
  216. "flush\n", local->dev->name, local->cmd_queue_len);
  217. local->cmd_queue_len = 0;
  218. }
  219. spin_unlock_irqrestore(&local->cmdlock, flags);
  220. }
  221. /**
  222. * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
  223. * @dev: pointer to net_device
  224. * @entry: Prism2 command queue entry to be issued
  225. */
  226. static inline int hfa384x_cmd_issue(struct net_device *dev,
  227. struct hostap_cmd_queue *entry)
  228. {
  229. struct hostap_interface *iface;
  230. local_info_t *local;
  231. int tries;
  232. u16 reg;
  233. unsigned long flags;
  234. iface = netdev_priv(dev);
  235. local = iface->local;
  236. if (local->func->card_present && !local->func->card_present(local))
  237. return -ENODEV;
  238. if (entry->issued) {
  239. printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n",
  240. dev->name, entry);
  241. }
  242. /* wait until busy bit is clear; this should always be clear since the
  243. * commands are serialized */
  244. tries = HFA384X_CMD_BUSY_TIMEOUT;
  245. while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
  246. tries--;
  247. udelay(1);
  248. }
  249. #ifndef final_version
  250. if (tries != HFA384X_CMD_BUSY_TIMEOUT) {
  251. prism2_io_debug_error(dev, 1);
  252. printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy "
  253. "for %d usec\n", dev->name,
  254. HFA384X_CMD_BUSY_TIMEOUT - tries);
  255. }
  256. #endif
  257. if (tries == 0) {
  258. reg = HFA384X_INW(HFA384X_CMD_OFF);
  259. prism2_io_debug_error(dev, 2);
  260. printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - "
  261. "reg=0x%04x\n", dev->name, reg);
  262. return -ETIMEDOUT;
  263. }
  264. /* write command */
  265. spin_lock_irqsave(&local->cmdlock, flags);
  266. HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF);
  267. HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF);
  268. HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF);
  269. entry->issued = 1;
  270. spin_unlock_irqrestore(&local->cmdlock, flags);
  271. return 0;
  272. }
  273. /**
  274. * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
  275. * @dev: pointer to net_device
  276. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  277. * @param0: value for Param0 register
  278. * @param1: value for Param1 register (pointer; %NULL if not used)
  279. * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
  280. *
  281. * Issue given command (possibly after waiting in command queue) and sleep
  282. * until the command is completed (or timed out or interrupted). This can be
  283. * called only from user process context.
  284. */
  285. static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0,
  286. u16 *param1, u16 *resp0)
  287. {
  288. struct hostap_interface *iface;
  289. local_info_t *local;
  290. int err, res, issue, issued = 0;
  291. unsigned long flags;
  292. struct hostap_cmd_queue *entry;
  293. DECLARE_WAITQUEUE(wait, current);
  294. iface = netdev_priv(dev);
  295. local = iface->local;
  296. if (in_interrupt()) {
  297. printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt "
  298. "context\n", dev->name);
  299. return -1;
  300. }
  301. if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
  302. printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
  303. dev->name);
  304. return -1;
  305. }
  306. if (signal_pending(current))
  307. return -EINTR;
  308. entry = (struct hostap_cmd_queue *)
  309. kmalloc(sizeof(*entry), GFP_ATOMIC);
  310. if (entry == NULL) {
  311. printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n",
  312. dev->name);
  313. return -ENOMEM;
  314. }
  315. memset(entry, 0, sizeof(*entry));
  316. atomic_set(&entry->usecnt, 1);
  317. entry->type = CMD_SLEEP;
  318. entry->cmd = cmd;
  319. entry->param0 = param0;
  320. if (param1)
  321. entry->param1 = *param1;
  322. init_waitqueue_head(&entry->compl);
  323. /* prepare to wait for command completion event, but do not sleep yet
  324. */
  325. add_wait_queue(&entry->compl, &wait);
  326. set_current_state(TASK_INTERRUPTIBLE);
  327. spin_lock_irqsave(&local->cmdlock, flags);
  328. issue = list_empty(&local->cmd_queue);
  329. if (issue)
  330. entry->issuing = 1;
  331. list_add_tail(&entry->list, &local->cmd_queue);
  332. local->cmd_queue_len++;
  333. spin_unlock_irqrestore(&local->cmdlock, flags);
  334. err = 0;
  335. if (!issue)
  336. goto wait_completion;
  337. if (signal_pending(current))
  338. err = -EINTR;
  339. if (!err) {
  340. if (hfa384x_cmd_issue(dev, entry))
  341. err = -ETIMEDOUT;
  342. else
  343. issued = 1;
  344. }
  345. wait_completion:
  346. if (!err && entry->type != CMD_COMPLETED) {
  347. /* sleep until command is completed or timed out */
  348. res = schedule_timeout(2 * HZ);
  349. } else
  350. res = -1;
  351. if (!err && signal_pending(current))
  352. err = -EINTR;
  353. if (err && issued) {
  354. /* the command was issued, so a CmdCompl event should occur
  355. * soon; however, there's a pending signal and
  356. * schedule_timeout() would be interrupted; wait a short period
  357. * of time to avoid removing entry from the list before
  358. * CmdCompl event */
  359. udelay(300);
  360. }
  361. set_current_state(TASK_RUNNING);
  362. remove_wait_queue(&entry->compl, &wait);
  363. /* If entry->list is still in the list, it must be removed
  364. * first and in this case prism2_cmd_ev() does not yet have
  365. * local reference to it, and the data can be kfree()'d
  366. * here. If the command completion event is still generated,
  367. * it will be assigned to next (possibly) pending command, but
  368. * the driver will reset the card anyway due to timeout
  369. *
  370. * If the entry is not in the list prism2_cmd_ev() has a local
  371. * reference to it, but keeps cmdlock as long as the data is
  372. * needed, so the data can be kfree()'d here. */
  373. /* FIX: if the entry->list is in the list, it has not been completed
  374. * yet, so removing it here is somewhat wrong.. this could cause
  375. * references to freed memory and next list_del() causing NULL pointer
  376. * dereference.. it would probably be better to leave the entry in the
  377. * list and the list should be emptied during hw reset */
  378. spin_lock_irqsave(&local->cmdlock, flags);
  379. if (!list_empty(&entry->list)) {
  380. printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? "
  381. "(entry=%p, type=%d, res=%d)\n", dev->name, entry,
  382. entry->type, res);
  383. list_del_init(&entry->list);
  384. local->cmd_queue_len--;
  385. }
  386. spin_unlock_irqrestore(&local->cmdlock, flags);
  387. if (err) {
  388. printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n",
  389. dev->name, err);
  390. res = err;
  391. goto done;
  392. }
  393. if (entry->type != CMD_COMPLETED) {
  394. u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
  395. printk(KERN_DEBUG "%s: hfa384x_cmd: command was not "
  396. "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
  397. "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name,
  398. res, entry, entry->type, entry->cmd, entry->param0, reg,
  399. HFA384X_INW(HFA384X_INTEN_OFF));
  400. if (reg & HFA384X_EV_CMD) {
  401. /* Command completion event is pending, but the
  402. * interrupt was not delivered - probably an issue
  403. * with pcmcia-cs configuration. */
  404. printk(KERN_WARNING "%s: interrupt delivery does not "
  405. "seem to work\n", dev->name);
  406. }
  407. prism2_io_debug_error(dev, 3);
  408. res = -ETIMEDOUT;
  409. goto done;
  410. }
  411. if (resp0 != NULL)
  412. *resp0 = entry->resp0;
  413. #ifndef final_version
  414. if (entry->res) {
  415. printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, "
  416. "resp0=0x%04x\n",
  417. dev->name, cmd, entry->res, entry->resp0);
  418. }
  419. #endif /* final_version */
  420. res = entry->res;
  421. done:
  422. hostap_cmd_queue_free(local, entry, 1);
  423. return res;
  424. }
  425. /**
  426. * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
  427. * @dev: pointer to net_device
  428. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  429. * @param0: value for Param0 register
  430. * @callback: command completion callback function (%NULL = no callback)
  431. * @context: data pointer to be given to callback function
  432. *
  433. * Issue given command (possibly after waiting in command queue) and use
  434. * callback function to indicate command completion. This can be called both
  435. * from user and interrupt context. The callback function will be called in
  436. * hardware IRQ context. It can be %NULL, when no function is called when
  437. * command is completed.
  438. */
  439. static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0,
  440. void (*callback)(struct net_device *dev,
  441. void *context, u16 resp0,
  442. u16 status),
  443. void *context)
  444. {
  445. struct hostap_interface *iface;
  446. local_info_t *local;
  447. int issue, ret;
  448. unsigned long flags;
  449. struct hostap_cmd_queue *entry;
  450. iface = netdev_priv(dev);
  451. local = iface->local;
  452. if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
  453. printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
  454. dev->name);
  455. return -1;
  456. }
  457. entry = (struct hostap_cmd_queue *)
  458. kmalloc(sizeof(*entry), GFP_ATOMIC);
  459. if (entry == NULL) {
  460. printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc "
  461. "failed\n", dev->name);
  462. return -ENOMEM;
  463. }
  464. memset(entry, 0, sizeof(*entry));
  465. atomic_set(&entry->usecnt, 1);
  466. entry->type = CMD_CALLBACK;
  467. entry->cmd = cmd;
  468. entry->param0 = param0;
  469. entry->callback = callback;
  470. entry->context = context;
  471. spin_lock_irqsave(&local->cmdlock, flags);
  472. issue = list_empty(&local->cmd_queue);
  473. if (issue)
  474. entry->issuing = 1;
  475. list_add_tail(&entry->list, &local->cmd_queue);
  476. local->cmd_queue_len++;
  477. spin_unlock_irqrestore(&local->cmdlock, flags);
  478. if (issue && hfa384x_cmd_issue(dev, entry))
  479. ret = -ETIMEDOUT;
  480. else
  481. ret = 0;
  482. hostap_cmd_queue_free(local, entry, ret);
  483. return ret;
  484. }
  485. /**
  486. * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
  487. * @dev: pointer to net_device
  488. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  489. * @param0: value for Param0 register
  490. * @io_debug_num: I/O debug error number
  491. *
  492. * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
  493. */
  494. static int __hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0,
  495. int io_debug_num)
  496. {
  497. int tries;
  498. u16 reg;
  499. /* wait until busy bit is clear; this should always be clear since the
  500. * commands are serialized */
  501. tries = HFA384X_CMD_BUSY_TIMEOUT;
  502. while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
  503. tries--;
  504. udelay(1);
  505. }
  506. if (tries == 0) {
  507. reg = HFA384X_INW(HFA384X_CMD_OFF);
  508. prism2_io_debug_error(dev, io_debug_num);
  509. printk(KERN_DEBUG "%s: __hfa384x_cmd_no_wait(%d) - timeout - "
  510. "reg=0x%04x\n", dev->name, io_debug_num, reg);
  511. return -ETIMEDOUT;
  512. }
  513. /* write command */
  514. HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
  515. HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
  516. return 0;
  517. }
  518. /**
  519. * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
  520. * @dev: pointer to net_device
  521. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  522. * @param0: value for Param0 register
  523. */
  524. static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0)
  525. {
  526. int res, tries;
  527. u16 reg;
  528. res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4);
  529. if (res)
  530. return res;
  531. /* wait for command completion */
  532. if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD)
  533. tries = HFA384X_DL_COMPL_TIMEOUT;
  534. else
  535. tries = HFA384X_CMD_COMPL_TIMEOUT;
  536. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  537. tries > 0) {
  538. tries--;
  539. udelay(10);
  540. }
  541. if (tries == 0) {
  542. reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
  543. prism2_io_debug_error(dev, 5);
  544. printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - "
  545. "reg=0x%04x\n", dev->name, reg);
  546. return -ETIMEDOUT;
  547. }
  548. res = (HFA384X_INW(HFA384X_STATUS_OFF) &
  549. (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
  550. BIT(8))) >> 8;
  551. #ifndef final_version
  552. if (res) {
  553. printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n",
  554. dev->name, cmd, res);
  555. }
  556. #endif
  557. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  558. return res;
  559. }
  560. /**
  561. * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
  562. * @dev: pointer to net_device
  563. * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
  564. * @param0: value for Param0 register
  565. */
  566. static inline int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd,
  567. u16 param0)
  568. {
  569. return __hfa384x_cmd_no_wait(dev, cmd, param0, 6);
  570. }
  571. /**
  572. * prism2_cmd_ev - Prism2 command completion event handler
  573. * @dev: pointer to net_device
  574. *
  575. * Interrupt handler for command completion events. Called by the main
  576. * interrupt handler in hardware IRQ context. Read Resp0 and status registers
  577. * from the hardware and ACK the event. Depending on the issued command type
  578. * either wake up the sleeping process that is waiting for command completion
  579. * or call the callback function. Issue the next command, if one is pending.
  580. */
  581. static void prism2_cmd_ev(struct net_device *dev)
  582. {
  583. struct hostap_interface *iface;
  584. local_info_t *local;
  585. struct hostap_cmd_queue *entry = NULL;
  586. iface = netdev_priv(dev);
  587. local = iface->local;
  588. spin_lock(&local->cmdlock);
  589. if (!list_empty(&local->cmd_queue)) {
  590. entry = list_entry(local->cmd_queue.next,
  591. struct hostap_cmd_queue, list);
  592. atomic_inc(&entry->usecnt);
  593. list_del_init(&entry->list);
  594. local->cmd_queue_len--;
  595. if (!entry->issued) {
  596. printk(KERN_DEBUG "%s: Command completion event, but "
  597. "cmd not issued\n", dev->name);
  598. __hostap_cmd_queue_free(local, entry, 1);
  599. entry = NULL;
  600. }
  601. }
  602. spin_unlock(&local->cmdlock);
  603. if (!entry) {
  604. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  605. printk(KERN_DEBUG "%s: Command completion event, but no "
  606. "pending commands\n", dev->name);
  607. return;
  608. }
  609. entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF);
  610. entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) &
  611. (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
  612. BIT(9) | BIT(8))) >> 8;
  613. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  614. /* TODO: rest of the CmdEv handling could be moved to tasklet */
  615. if (entry->type == CMD_SLEEP) {
  616. entry->type = CMD_COMPLETED;
  617. wake_up_interruptible(&entry->compl);
  618. } else if (entry->type == CMD_CALLBACK) {
  619. if (entry->callback)
  620. entry->callback(dev, entry->context, entry->resp0,
  621. entry->res);
  622. } else {
  623. printk(KERN_DEBUG "%s: Invalid command completion type %d\n",
  624. dev->name, entry->type);
  625. }
  626. hostap_cmd_queue_free(local, entry, 1);
  627. /* issue next command, if pending */
  628. entry = NULL;
  629. spin_lock(&local->cmdlock);
  630. if (!list_empty(&local->cmd_queue)) {
  631. entry = list_entry(local->cmd_queue.next,
  632. struct hostap_cmd_queue, list);
  633. if (entry->issuing) {
  634. /* hfa384x_cmd() has already started issuing this
  635. * command, so do not start here */
  636. entry = NULL;
  637. }
  638. if (entry)
  639. atomic_inc(&entry->usecnt);
  640. }
  641. spin_unlock(&local->cmdlock);
  642. if (entry) {
  643. /* issue next command; if command issuing fails, remove the
  644. * entry from cmd_queue */
  645. int res = hfa384x_cmd_issue(dev, entry);
  646. spin_lock(&local->cmdlock);
  647. __hostap_cmd_queue_free(local, entry, res);
  648. spin_unlock(&local->cmdlock);
  649. }
  650. }
  651. static inline int hfa384x_wait_offset(struct net_device *dev, u16 o_off)
  652. {
  653. int tries = HFA384X_BAP_BUSY_TIMEOUT;
  654. int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
  655. while (res && tries > 0) {
  656. tries--;
  657. udelay(1);
  658. res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
  659. }
  660. return res;
  661. }
  662. /* Offset must be even */
  663. static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id,
  664. int offset)
  665. {
  666. u16 o_off, s_off;
  667. int ret = 0;
  668. if (offset % 2 || bap > 1)
  669. return -EINVAL;
  670. if (bap == BAP1) {
  671. o_off = HFA384X_OFFSET1_OFF;
  672. s_off = HFA384X_SELECT1_OFF;
  673. } else {
  674. o_off = HFA384X_OFFSET0_OFF;
  675. s_off = HFA384X_SELECT0_OFF;
  676. }
  677. if (hfa384x_wait_offset(dev, o_off)) {
  678. prism2_io_debug_error(dev, 7);
  679. printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n",
  680. dev->name);
  681. ret = -ETIMEDOUT;
  682. goto out;
  683. }
  684. HFA384X_OUTW(id, s_off);
  685. HFA384X_OUTW(offset, o_off);
  686. if (hfa384x_wait_offset(dev, o_off)) {
  687. prism2_io_debug_error(dev, 8);
  688. printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n",
  689. dev->name);
  690. ret = -ETIMEDOUT;
  691. goto out;
  692. }
  693. #ifndef final_version
  694. if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) {
  695. prism2_io_debug_error(dev, 9);
  696. printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error "
  697. "(%d,0x04%x,%d); reg=0x%04x\n",
  698. dev->name, bap, id, offset, HFA384X_INW(o_off));
  699. ret = -EINVAL;
  700. }
  701. #endif
  702. out:
  703. return ret;
  704. }
  705. static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len,
  706. int exact_len)
  707. {
  708. struct hostap_interface *iface;
  709. local_info_t *local;
  710. int res, rlen = 0;
  711. struct hfa384x_rid_hdr rec;
  712. iface = netdev_priv(dev);
  713. local = iface->local;
  714. if (local->no_pri) {
  715. printk(KERN_DEBUG "%s: cannot get RID %04x (len=%d) - no PRI "
  716. "f/w\n", dev->name, rid, len);
  717. return -ENOTTY; /* Well.. not really correct, but return
  718. * something unique enough.. */
  719. }
  720. if ((local->func->card_present && !local->func->card_present(local)) ||
  721. local->hw_downloading)
  722. return -ENODEV;
  723. res = down_interruptible(&local->rid_bap_sem);
  724. if (res)
  725. return res;
  726. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL);
  727. if (res) {
  728. printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
  729. "(res=%d, rid=%04x, len=%d)\n",
  730. dev->name, res, rid, len);
  731. up(&local->rid_bap_sem);
  732. return res;
  733. }
  734. spin_lock_bh(&local->baplock);
  735. res = hfa384x_setup_bap(dev, BAP0, rid, 0);
  736. if (!res)
  737. res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec));
  738. if (le16_to_cpu(rec.len) == 0) {
  739. /* RID not available */
  740. res = -ENODATA;
  741. }
  742. rlen = (le16_to_cpu(rec.len) - 1) * 2;
  743. if (!res && exact_len && rlen != len) {
  744. printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: "
  745. "rid=0x%04x, len=%d (expected %d)\n",
  746. dev->name, rid, rlen, len);
  747. res = -ENODATA;
  748. }
  749. if (!res)
  750. res = hfa384x_from_bap(dev, BAP0, buf, len);
  751. spin_unlock_bh(&local->baplock);
  752. up(&local->rid_bap_sem);
  753. if (res) {
  754. if (res != -ENODATA)
  755. printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, "
  756. "len=%d) - failed - res=%d\n", dev->name, rid,
  757. len, res);
  758. if (res == -ETIMEDOUT)
  759. prism2_hw_reset(dev);
  760. return res;
  761. }
  762. return rlen;
  763. }
  764. static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
  765. {
  766. struct hostap_interface *iface;
  767. local_info_t *local;
  768. struct hfa384x_rid_hdr rec;
  769. int res;
  770. iface = netdev_priv(dev);
  771. local = iface->local;
  772. if (local->no_pri) {
  773. printk(KERN_DEBUG "%s: cannot set RID %04x (len=%d) - no PRI "
  774. "f/w\n", dev->name, rid, len);
  775. return -ENOTTY; /* Well.. not really correct, but return
  776. * something unique enough.. */
  777. }
  778. if ((local->func->card_present && !local->func->card_present(local)) ||
  779. local->hw_downloading)
  780. return -ENODEV;
  781. rec.rid = cpu_to_le16(rid);
  782. /* RID len in words and +1 for rec.rid */
  783. rec.len = cpu_to_le16(len / 2 + len % 2 + 1);
  784. res = down_interruptible(&local->rid_bap_sem);
  785. if (res)
  786. return res;
  787. spin_lock_bh(&local->baplock);
  788. res = hfa384x_setup_bap(dev, BAP0, rid, 0);
  789. if (!res)
  790. res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec));
  791. if (!res)
  792. res = hfa384x_to_bap(dev, BAP0, buf, len);
  793. spin_unlock_bh(&local->baplock);
  794. if (res) {
  795. printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - "
  796. "failed - res=%d\n", dev->name, rid, len, res);
  797. up(&local->rid_bap_sem);
  798. return res;
  799. }
  800. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
  801. up(&local->rid_bap_sem);
  802. if (res) {
  803. printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
  804. "failed (res=%d, rid=%04x, len=%d)\n",
  805. dev->name, res, rid, len);
  806. return res;
  807. }
  808. if (res == -ETIMEDOUT)
  809. prism2_hw_reset(dev);
  810. return res;
  811. }
  812. static void hfa384x_disable_interrupts(struct net_device *dev)
  813. {
  814. /* disable interrupts and clear event status */
  815. HFA384X_OUTW(0, HFA384X_INTEN_OFF);
  816. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  817. }
  818. static void hfa384x_enable_interrupts(struct net_device *dev)
  819. {
  820. /* ack pending events and enable interrupts from selected events */
  821. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  822. HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
  823. }
  824. static void hfa384x_events_no_bap0(struct net_device *dev)
  825. {
  826. HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS,
  827. HFA384X_INTEN_OFF);
  828. }
  829. static void hfa384x_events_all(struct net_device *dev)
  830. {
  831. HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
  832. }
  833. static void hfa384x_events_only_cmd(struct net_device *dev)
  834. {
  835. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF);
  836. }
  837. static u16 hfa384x_allocate_fid(struct net_device *dev, int len)
  838. {
  839. u16 fid;
  840. unsigned long delay;
  841. /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
  842. * below would be handled like CmdCompl event (sleep here, wake up from
  843. * interrupt handler */
  844. if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) {
  845. printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n",
  846. dev->name, len);
  847. return 0xffff;
  848. }
  849. delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT;
  850. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) &&
  851. time_before(jiffies, delay))
  852. yield();
  853. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
  854. printk("%s: fid allocate, len=%d - timeout\n", dev->name, len);
  855. return 0xffff;
  856. }
  857. fid = HFA384X_INW(HFA384X_ALLOCFID_OFF);
  858. HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
  859. return fid;
  860. }
  861. static int prism2_reset_port(struct net_device *dev)
  862. {
  863. struct hostap_interface *iface;
  864. local_info_t *local;
  865. int res;
  866. iface = netdev_priv(dev);
  867. local = iface->local;
  868. if (!local->dev_enabled)
  869. return 0;
  870. res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0,
  871. NULL, NULL);
  872. if (res)
  873. printk(KERN_DEBUG "%s: reset port failed to disable port\n",
  874. dev->name);
  875. else {
  876. res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0,
  877. NULL, NULL);
  878. if (res)
  879. printk(KERN_DEBUG "%s: reset port failed to enable "
  880. "port\n", dev->name);
  881. }
  882. /* It looks like at least some STA firmware versions reset
  883. * fragmentation threshold back to 2346 after enable command. Restore
  884. * the configured value, if it differs from this default. */
  885. if (local->fragm_threshold != 2346 &&
  886. hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  887. local->fragm_threshold)) {
  888. printk(KERN_DEBUG "%s: failed to restore fragmentation "
  889. "threshold (%d) after Port0 enable\n",
  890. dev->name, local->fragm_threshold);
  891. }
  892. return res;
  893. }
  894. static int prism2_get_version_info(struct net_device *dev, u16 rid,
  895. const char *txt)
  896. {
  897. struct hfa384x_comp_ident comp;
  898. struct hostap_interface *iface;
  899. local_info_t *local;
  900. iface = netdev_priv(dev);
  901. local = iface->local;
  902. if (local->no_pri) {
  903. /* PRI f/w not yet available - cannot read RIDs */
  904. return -1;
  905. }
  906. if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
  907. printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
  908. return -1;
  909. }
  910. printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
  911. __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
  912. __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
  913. return 0;
  914. }
  915. static int prism2_setup_rids(struct net_device *dev)
  916. {
  917. struct hostap_interface *iface;
  918. local_info_t *local;
  919. u16 tmp;
  920. int ret = 0;
  921. iface = netdev_priv(dev);
  922. local = iface->local;
  923. hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
  924. if (!local->fw_ap) {
  925. tmp = hostap_get_porttype(local);
  926. ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
  927. if (ret) {
  928. printk("%s: Port type setting to %d failed\n",
  929. dev->name, tmp);
  930. goto fail;
  931. }
  932. }
  933. /* Setting SSID to empty string seems to kill the card in Host AP mode
  934. */
  935. if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
  936. ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
  937. local->essid);
  938. if (ret) {
  939. printk("%s: AP own SSID setting failed\n", dev->name);
  940. goto fail;
  941. }
  942. }
  943. ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
  944. PRISM2_DATA_MAXLEN);
  945. if (ret) {
  946. printk("%s: MAC data length setting to %d failed\n",
  947. dev->name, PRISM2_DATA_MAXLEN);
  948. goto fail;
  949. }
  950. if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
  951. printk("%s: Channel list read failed\n", dev->name);
  952. ret = -EINVAL;
  953. goto fail;
  954. }
  955. local->channel_mask = __le16_to_cpu(tmp);
  956. if (local->channel < 1 || local->channel > 14 ||
  957. !(local->channel_mask & (1 << (local->channel - 1)))) {
  958. printk(KERN_WARNING "%s: Channel setting out of range "
  959. "(%d)!\n", dev->name, local->channel);
  960. ret = -EBUSY;
  961. goto fail;
  962. }
  963. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
  964. if (ret) {
  965. printk("%s: Channel setting to %d failed\n",
  966. dev->name, local->channel);
  967. goto fail;
  968. }
  969. ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
  970. local->beacon_int);
  971. if (ret) {
  972. printk("%s: Beacon interval setting to %d failed\n",
  973. dev->name, local->beacon_int);
  974. /* this may fail with Symbol/Lucent firmware */
  975. if (ret == -ETIMEDOUT)
  976. goto fail;
  977. }
  978. ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
  979. local->dtim_period);
  980. if (ret) {
  981. printk("%s: DTIM period setting to %d failed\n",
  982. dev->name, local->dtim_period);
  983. /* this may fail with Symbol/Lucent firmware */
  984. if (ret == -ETIMEDOUT)
  985. goto fail;
  986. }
  987. ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
  988. local->is_promisc);
  989. if (ret)
  990. printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
  991. dev->name, local->is_promisc);
  992. if (!local->fw_ap) {
  993. ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
  994. local->essid);
  995. if (ret) {
  996. printk("%s: Desired SSID setting failed\n", dev->name);
  997. goto fail;
  998. }
  999. }
  1000. /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
  1001. * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
  1002. * rates */
  1003. if (local->tx_rate_control == 0) {
  1004. local->tx_rate_control =
  1005. HFA384X_RATES_1MBPS |
  1006. HFA384X_RATES_2MBPS |
  1007. HFA384X_RATES_5MBPS |
  1008. HFA384X_RATES_11MBPS;
  1009. }
  1010. if (local->basic_rates == 0)
  1011. local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS;
  1012. if (!local->fw_ap) {
  1013. ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
  1014. local->tx_rate_control);
  1015. if (ret) {
  1016. printk("%s: TXRateControl setting to %d failed\n",
  1017. dev->name, local->tx_rate_control);
  1018. goto fail;
  1019. }
  1020. ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
  1021. local->tx_rate_control);
  1022. if (ret) {
  1023. printk("%s: cnfSupportedRates setting to %d failed\n",
  1024. dev->name, local->tx_rate_control);
  1025. }
  1026. ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
  1027. local->basic_rates);
  1028. if (ret) {
  1029. printk("%s: cnfBasicRates setting to %d failed\n",
  1030. dev->name, local->basic_rates);
  1031. }
  1032. ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
  1033. if (ret) {
  1034. printk("%s: Create IBSS setting to 1 failed\n",
  1035. dev->name);
  1036. }
  1037. }
  1038. if (local->name_set)
  1039. (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
  1040. local->name);
  1041. if (hostap_set_encryption(local)) {
  1042. printk(KERN_INFO "%s: could not configure encryption\n",
  1043. dev->name);
  1044. }
  1045. (void) hostap_set_antsel(local);
  1046. if (hostap_set_roaming(local)) {
  1047. printk(KERN_INFO "%s: could not set host roaming\n",
  1048. dev->name);
  1049. }
  1050. if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
  1051. hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
  1052. printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
  1053. dev->name, local->enh_sec);
  1054. /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
  1055. * not working correctly (last seven counters report bogus values).
  1056. * This has been fixed in 0.8.2, so enable 32-bit tallies only
  1057. * beginning with that firmware version. Another bug fix for 32-bit
  1058. * tallies in 1.4.0; should 16-bit tallies be used for some other
  1059. * versions, too? */
  1060. if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
  1061. if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
  1062. printk(KERN_INFO "%s: cnfThirty2Tally setting "
  1063. "failed\n", dev->name);
  1064. local->tallies32 = 0;
  1065. } else
  1066. local->tallies32 = 1;
  1067. } else
  1068. local->tallies32 = 0;
  1069. hostap_set_auth_algs(local);
  1070. if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
  1071. local->fragm_threshold)) {
  1072. printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
  1073. "failed\n", dev->name, local->fragm_threshold);
  1074. }
  1075. if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
  1076. local->rts_threshold)) {
  1077. printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
  1078. dev->name, local->rts_threshold);
  1079. }
  1080. if (local->manual_retry_count >= 0 &&
  1081. hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
  1082. local->manual_retry_count)) {
  1083. printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
  1084. dev->name, local->manual_retry_count);
  1085. }
  1086. if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
  1087. hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) {
  1088. local->rssi_to_dBm = le16_to_cpu(tmp);
  1089. }
  1090. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
  1091. hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) {
  1092. printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n",
  1093. dev->name);
  1094. }
  1095. if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
  1096. hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT,
  1097. local->generic_elem, local->generic_elem_len)) {
  1098. printk(KERN_INFO "%s: setting genericElement failed\n",
  1099. dev->name);
  1100. }
  1101. fail:
  1102. return ret;
  1103. }
  1104. static int prism2_hw_init(struct net_device *dev, int initial)
  1105. {
  1106. struct hostap_interface *iface;
  1107. local_info_t *local;
  1108. int ret, first = 1;
  1109. unsigned long start, delay;
  1110. PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
  1111. iface = netdev_priv(dev);
  1112. local = iface->local;
  1113. clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
  1114. init:
  1115. /* initialize HFA 384x */
  1116. ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
  1117. if (ret) {
  1118. printk(KERN_INFO "%s: first command failed - assuming card "
  1119. "does not have primary firmware\n", dev_info);
  1120. }
  1121. if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1122. /* EvStat has Cmd bit set in some cases, so retry once if no
  1123. * wait was needed */
  1124. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1125. printk(KERN_DEBUG "%s: init command completed too quickly - "
  1126. "retrying\n", dev->name);
  1127. first = 0;
  1128. goto init;
  1129. }
  1130. start = jiffies;
  1131. delay = jiffies + HFA384X_INIT_TIMEOUT;
  1132. while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
  1133. time_before(jiffies, delay))
  1134. yield();
  1135. if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
  1136. printk(KERN_DEBUG "%s: assuming no Primary image in "
  1137. "flash - card initialization not completed\n",
  1138. dev_info);
  1139. local->no_pri = 1;
  1140. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1141. if (local->sram_type == -1)
  1142. local->sram_type = prism2_get_ram_size(local);
  1143. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1144. return 1;
  1145. }
  1146. local->no_pri = 0;
  1147. printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
  1148. (jiffies - start) * 1000 / HZ);
  1149. HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
  1150. return 0;
  1151. }
  1152. static int prism2_hw_init2(struct net_device *dev, int initial)
  1153. {
  1154. struct hostap_interface *iface;
  1155. local_info_t *local;
  1156. int i;
  1157. iface = netdev_priv(dev);
  1158. local = iface->local;
  1159. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1160. kfree(local->pda);
  1161. if (local->no_pri)
  1162. local->pda = NULL;
  1163. else
  1164. local->pda = prism2_read_pda(dev);
  1165. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1166. hfa384x_disable_interrupts(dev);
  1167. #ifndef final_version
  1168. HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
  1169. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  1170. printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
  1171. HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
  1172. goto failed;
  1173. }
  1174. #endif
  1175. if (initial || local->pri_only) {
  1176. hfa384x_events_only_cmd(dev);
  1177. /* get card version information */
  1178. if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
  1179. prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
  1180. hfa384x_disable_interrupts(dev);
  1181. goto failed;
  1182. }
  1183. if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
  1184. printk(KERN_DEBUG "%s: Failed to read STA f/w version "
  1185. "- only Primary f/w present\n", dev->name);
  1186. local->pri_only = 1;
  1187. return 0;
  1188. }
  1189. local->pri_only = 0;
  1190. hfa384x_disable_interrupts(dev);
  1191. }
  1192. /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
  1193. * enable interrupts before this. This would also require some sort of
  1194. * sleeping AllocEv waiting */
  1195. /* allocate TX FIDs */
  1196. local->txfid_len = PRISM2_TXFID_LEN;
  1197. for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
  1198. local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
  1199. if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
  1200. local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
  1201. if (local->txfid[i] != 0xffff) {
  1202. printk(KERN_DEBUG "%s: Using shorter TX FID "
  1203. "(1600 bytes)\n", dev->name);
  1204. local->txfid_len = 1600;
  1205. }
  1206. }
  1207. if (local->txfid[i] == 0xffff)
  1208. goto failed;
  1209. local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
  1210. }
  1211. hfa384x_events_only_cmd(dev);
  1212. if (initial) {
  1213. struct list_head *ptr;
  1214. prism2_check_sta_fw_version(local);
  1215. if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
  1216. &dev->dev_addr, 6, 1) < 0) {
  1217. printk("%s: could not get own MAC address\n",
  1218. dev->name);
  1219. }
  1220. list_for_each(ptr, &local->hostap_interfaces) {
  1221. iface = list_entry(ptr, struct hostap_interface, list);
  1222. memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN);
  1223. }
  1224. } else if (local->fw_ap)
  1225. prism2_check_sta_fw_version(local);
  1226. prism2_setup_rids(dev);
  1227. /* MAC is now configured, but port 0 is not yet enabled */
  1228. return 0;
  1229. failed:
  1230. if (!local->no_pri)
  1231. printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
  1232. return 1;
  1233. }
  1234. static int prism2_hw_enable(struct net_device *dev, int initial)
  1235. {
  1236. struct hostap_interface *iface;
  1237. local_info_t *local;
  1238. int was_resetting;
  1239. iface = netdev_priv(dev);
  1240. local = iface->local;
  1241. was_resetting = local->hw_resetting;
  1242. if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
  1243. printk("%s: MAC port 0 enabling failed\n", dev->name);
  1244. return 1;
  1245. }
  1246. local->hw_ready = 1;
  1247. local->hw_reset_tries = 0;
  1248. local->hw_resetting = 0;
  1249. hfa384x_enable_interrupts(dev);
  1250. /* at least D-Link DWL-650 seems to require additional port reset
  1251. * before it starts acting as an AP, so reset port automatically
  1252. * here just in case */
  1253. if (initial && prism2_reset_port(dev)) {
  1254. printk("%s: MAC port 0 reseting failed\n", dev->name);
  1255. return 1;
  1256. }
  1257. if (was_resetting && netif_queue_stopped(dev)) {
  1258. /* If hw_reset() was called during pending transmit, netif
  1259. * queue was stopped. Wake it up now since the wlan card has
  1260. * been resetted. */
  1261. netif_wake_queue(dev);
  1262. }
  1263. return 0;
  1264. }
  1265. static int prism2_hw_config(struct net_device *dev, int initial)
  1266. {
  1267. struct hostap_interface *iface;
  1268. local_info_t *local;
  1269. iface = netdev_priv(dev);
  1270. local = iface->local;
  1271. if (local->hw_downloading)
  1272. return 1;
  1273. if (prism2_hw_init(dev, initial)) {
  1274. return local->no_pri ? 0 : 1;
  1275. }
  1276. if (prism2_hw_init2(dev, initial))
  1277. return 1;
  1278. /* Enable firmware if secondary image is loaded and at least one of the
  1279. * netdevices is up. */
  1280. if (!local->pri_only &&
  1281. (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
  1282. if (!local->dev_enabled)
  1283. prism2_callback(local, PRISM2_CALLBACK_ENABLE);
  1284. local->dev_enabled = 1;
  1285. return prism2_hw_enable(dev, initial);
  1286. }
  1287. return 0;
  1288. }
  1289. static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
  1290. {
  1291. struct hostap_interface *iface;
  1292. local_info_t *local;
  1293. iface = netdev_priv(dev);
  1294. local = iface->local;
  1295. /* Allow only command completion events during disable */
  1296. hfa384x_events_only_cmd(dev);
  1297. local->hw_ready = 0;
  1298. if (local->dev_enabled)
  1299. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  1300. local->dev_enabled = 0;
  1301. if (local->func->card_present && !local->func->card_present(local)) {
  1302. printk(KERN_DEBUG "%s: card already removed or not configured "
  1303. "during shutdown\n", dev->name);
  1304. return;
  1305. }
  1306. if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
  1307. hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
  1308. printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
  1309. hfa384x_disable_interrupts(dev);
  1310. if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
  1311. hfa384x_events_only_cmd(dev);
  1312. else
  1313. prism2_clear_cmd_queue(local);
  1314. }
  1315. static void prism2_hw_reset(struct net_device *dev)
  1316. {
  1317. struct hostap_interface *iface;
  1318. local_info_t *local;
  1319. #if 0
  1320. static long last_reset = 0;
  1321. /* do not reset card more than once per second to avoid ending up in a
  1322. * busy loop reseting the card */
  1323. if (time_before_eq(jiffies, last_reset + HZ))
  1324. return;
  1325. last_reset = jiffies;
  1326. #endif
  1327. iface = netdev_priv(dev);
  1328. local = iface->local;
  1329. if (in_interrupt()) {
  1330. printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
  1331. "in interrupt context\n", dev->name);
  1332. return;
  1333. }
  1334. if (local->hw_downloading)
  1335. return;
  1336. if (local->hw_resetting) {
  1337. printk(KERN_WARNING "%s: %s: already resetting card - "
  1338. "ignoring reset request\n", dev_info, dev->name);
  1339. return;
  1340. }
  1341. local->hw_reset_tries++;
  1342. if (local->hw_reset_tries > 10) {
  1343. printk(KERN_WARNING "%s: too many reset tries, skipping\n",
  1344. dev->name);
  1345. return;
  1346. }
  1347. printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
  1348. hfa384x_disable_interrupts(dev);
  1349. local->hw_resetting = 1;
  1350. if (local->func->cor_sreset) {
  1351. /* Host system seems to hang in some cases with high traffic
  1352. * load or shared interrupts during COR sreset. Disable shared
  1353. * interrupts during reset to avoid these crashes. COS sreset
  1354. * takes quite a long time, so it is unfortunate that this
  1355. * seems to be needed. Anyway, I do not know of any better way
  1356. * of avoiding the crash. */
  1357. disable_irq(dev->irq);
  1358. local->func->cor_sreset(local);
  1359. enable_irq(dev->irq);
  1360. }
  1361. prism2_hw_shutdown(dev, 1);
  1362. prism2_hw_config(dev, 0);
  1363. local->hw_resetting = 0;
  1364. #ifdef PRISM2_DOWNLOAD_SUPPORT
  1365. if (local->dl_pri) {
  1366. printk(KERN_DEBUG "%s: persistent download of primary "
  1367. "firmware\n", dev->name);
  1368. if (prism2_download_genesis(local, local->dl_pri) < 0)
  1369. printk(KERN_WARNING "%s: download (PRI) failed\n",
  1370. dev->name);
  1371. }
  1372. if (local->dl_sec) {
  1373. printk(KERN_DEBUG "%s: persistent download of secondary "
  1374. "firmware\n", dev->name);
  1375. if (prism2_download_volatile(local, local->dl_sec) < 0)
  1376. printk(KERN_WARNING "%s: download (SEC) failed\n",
  1377. dev->name);
  1378. }
  1379. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  1380. /* TODO: restore beacon TIM bits for STAs that have buffered frames */
  1381. }
  1382. static void prism2_schedule_reset(local_info_t *local)
  1383. {
  1384. schedule_work(&local->reset_queue);
  1385. }
  1386. /* Called only as scheduled task after noticing card timeout in interrupt
  1387. * context */
  1388. static void handle_reset_queue(void *data)
  1389. {
  1390. local_info_t *local = (local_info_t *) data;
  1391. printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
  1392. prism2_hw_reset(local->dev);
  1393. if (netif_queue_stopped(local->dev)) {
  1394. int i;
  1395. for (i = 0; i < PRISM2_TXFID_COUNT; i++)
  1396. if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
  1397. PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
  1398. "wake up queue\n");
  1399. netif_wake_queue(local->dev);
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. static int prism2_get_txfid_idx(local_info_t *local)
  1405. {
  1406. int idx, end;
  1407. unsigned long flags;
  1408. spin_lock_irqsave(&local->txfidlock, flags);
  1409. end = idx = local->next_txfid;
  1410. do {
  1411. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1412. local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
  1413. spin_unlock_irqrestore(&local->txfidlock, flags);
  1414. return idx;
  1415. }
  1416. idx++;
  1417. if (idx >= PRISM2_TXFID_COUNT)
  1418. idx = 0;
  1419. } while (idx != end);
  1420. spin_unlock_irqrestore(&local->txfidlock, flags);
  1421. PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
  1422. "packet dropped\n");
  1423. local->stats.tx_dropped++;
  1424. return -1;
  1425. }
  1426. /* Called only from hardware IRQ */
  1427. static void prism2_transmit_cb(struct net_device *dev, void *context,
  1428. u16 resp0, u16 res)
  1429. {
  1430. struct hostap_interface *iface;
  1431. local_info_t *local;
  1432. int idx = (int) context;
  1433. iface = netdev_priv(dev);
  1434. local = iface->local;
  1435. if (res) {
  1436. printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
  1437. dev->name, res);
  1438. return;
  1439. }
  1440. if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
  1441. printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
  1442. "idx=%d\n", dev->name, idx);
  1443. return;
  1444. }
  1445. if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1446. printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
  1447. "with no pending transmit\n", dev->name);
  1448. }
  1449. if (netif_queue_stopped(dev)) {
  1450. /* ready for next TX, so wake up queue that was stopped in
  1451. * prism2_transmit() */
  1452. netif_wake_queue(dev);
  1453. }
  1454. spin_lock(&local->txfidlock);
  1455. /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
  1456. * will be automatically allocated for the next TX frame */
  1457. local->intransmitfid[idx] = resp0;
  1458. PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
  1459. "resp0=0x%04x, transmit_txfid=0x%04x\n",
  1460. dev->name, idx, local->txfid[idx],
  1461. resp0, local->intransmitfid[local->next_txfid]);
  1462. idx++;
  1463. if (idx >= PRISM2_TXFID_COUNT)
  1464. idx = 0;
  1465. local->next_txfid = idx;
  1466. /* check if all TX buffers are occupied */
  1467. do {
  1468. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
  1469. spin_unlock(&local->txfidlock);
  1470. return;
  1471. }
  1472. idx++;
  1473. if (idx >= PRISM2_TXFID_COUNT)
  1474. idx = 0;
  1475. } while (idx != local->next_txfid);
  1476. spin_unlock(&local->txfidlock);
  1477. /* no empty TX buffers, stop queue */
  1478. netif_stop_queue(dev);
  1479. }
  1480. /* Called only from software IRQ if PCI bus master is not used (with bus master
  1481. * this can be called both from software and hardware IRQ) */
  1482. static int prism2_transmit(struct net_device *dev, int idx)
  1483. {
  1484. struct hostap_interface *iface;
  1485. local_info_t *local;
  1486. int res;
  1487. iface = netdev_priv(dev);
  1488. local = iface->local;
  1489. /* The driver tries to stop netif queue so that there would not be
  1490. * more than one attempt to transmit frames going on; check that this
  1491. * is really the case */
  1492. if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  1493. printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
  1494. "when previous TX was pending\n", dev->name);
  1495. return -1;
  1496. }
  1497. /* stop the queue for the time that transmit is pending */
  1498. netif_stop_queue(dev);
  1499. /* transmit packet */
  1500. res = hfa384x_cmd_callback(
  1501. dev,
  1502. HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
  1503. local->txfid[idx],
  1504. prism2_transmit_cb, (void *) idx);
  1505. if (res) {
  1506. struct net_device_stats *stats;
  1507. printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
  1508. "failed (res=%d)\n", dev->name, res);
  1509. stats = hostap_get_stats(dev);
  1510. stats->tx_dropped++;
  1511. netif_wake_queue(dev);
  1512. return -1;
  1513. }
  1514. dev->trans_start = jiffies;
  1515. /* Since we did not wait for command completion, the card continues
  1516. * to process on the background and we will finish handling when
  1517. * command completion event is handled (prism2_cmd_ev() function) */
  1518. return 0;
  1519. }
  1520. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  1521. /* Called only from hardware IRQ */
  1522. static void prism2_tx_cb(struct net_device *dev, void *context,
  1523. u16 resp0, u16 res)
  1524. {
  1525. struct hostap_interface *iface;
  1526. local_info_t *local;
  1527. unsigned long addr;
  1528. int buf_len = (int) context;
  1529. iface = netdev_priv(dev);
  1530. local = iface->local;
  1531. if (res) {
  1532. printk(KERN_DEBUG "%s: prism2_tx_cb - res=0x%02x\n",
  1533. dev->name, res);
  1534. return;
  1535. }
  1536. addr = virt_to_phys(local->bus_m0_buf);
  1537. HFA384X_OUTW((addr & 0xffff0000) >> 16, HFA384X_PCI_M0_ADDRH_OFF);
  1538. HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF);
  1539. HFA384X_OUTW(buf_len / 2, HFA384X_PCI_M0_LEN_OFF);
  1540. HFA384X_OUTW(HFA384X_PCI_CTL_TO_BAP, HFA384X_PCI_M0_CTL_OFF);
  1541. }
  1542. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  1543. /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
  1544. * send the payload with this descriptor) */
  1545. /* Called only from software IRQ */
  1546. static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
  1547. {
  1548. struct hostap_interface *iface;
  1549. local_info_t *local;
  1550. struct hfa384x_tx_frame txdesc;
  1551. struct hostap_ieee80211_hdr *hdr;
  1552. struct hostap_skb_tx_data *meta;
  1553. int hdr_len, data_len, idx, res, ret = -1;
  1554. u16 tx_control, fc;
  1555. iface = netdev_priv(dev);
  1556. local = iface->local;
  1557. meta = (struct hostap_skb_tx_data *) skb->cb;
  1558. hdr = (struct hostap_ieee80211_hdr *) skb->data;
  1559. prism2_callback(local, PRISM2_CALLBACK_TX_START);
  1560. if ((local->func->card_present && !local->func->card_present(local)) ||
  1561. !local->hw_ready || local->hw_downloading || local->pri_only) {
  1562. if (net_ratelimit()) {
  1563. printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
  1564. " skipping\n", dev->name);
  1565. }
  1566. goto fail;
  1567. }
  1568. memset(&txdesc, 0, sizeof(txdesc));
  1569. /* skb->data starts with txdesc->frame_control */
  1570. hdr_len = 24;
  1571. memcpy(&txdesc.frame_control, skb->data, hdr_len);
  1572. fc = le16_to_cpu(txdesc.frame_control);
  1573. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
  1574. (fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS) && skb->len >= 30) {
  1575. /* Addr4 */
  1576. memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN);
  1577. hdr_len += ETH_ALEN;
  1578. }
  1579. tx_control = local->tx_control;
  1580. if (meta->tx_cb_idx) {
  1581. tx_control |= HFA384X_TX_CTRL_TX_OK;
  1582. txdesc.sw_support = cpu_to_le16(meta->tx_cb_idx);
  1583. }
  1584. txdesc.tx_control = cpu_to_le16(tx_control);
  1585. txdesc.tx_rate = meta->rate;
  1586. data_len = skb->len - hdr_len;
  1587. txdesc.data_len = cpu_to_le16(data_len);
  1588. txdesc.len = cpu_to_be16(data_len);
  1589. idx = prism2_get_txfid_idx(local);
  1590. if (idx < 0)
  1591. goto fail;
  1592. if (local->frame_dump & PRISM2_DUMP_TX_HDR)
  1593. hostap_dump_tx_header(dev->name, &txdesc);
  1594. spin_lock(&local->baplock);
  1595. res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
  1596. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  1597. if (!res && skb->len >= local->bus_master_threshold_tx) {
  1598. u8 *pos;
  1599. int buf_len;
  1600. local->bus_m0_tx_idx = idx;
  1601. /* FIX: BAP0 should be locked during bus master transfer, but
  1602. * baplock with BH's disabled is not OK for this; netif queue
  1603. * stopping is not enough since BAP0 is used also for RID
  1604. * read/write */
  1605. /* stop the queue for the time that bus mastering on BAP0 is
  1606. * in use */
  1607. netif_stop_queue(dev);
  1608. spin_unlock(&local->baplock);
  1609. /* Copy frame data to bus_m0_buf */
  1610. pos = local->bus_m0_buf;
  1611. memcpy(pos, &txdesc, sizeof(txdesc));
  1612. pos += sizeof(txdesc);
  1613. memcpy(pos, skb->data + hdr_len, skb->len - hdr_len);
  1614. pos += skb->len - hdr_len;
  1615. buf_len = pos - local->bus_m0_buf;
  1616. if (buf_len & 1)
  1617. buf_len++;
  1618. #ifdef PRISM2_ENABLE_BEFORE_TX_BUS_MASTER
  1619. /* Any RX packet seems to break something with TX bus
  1620. * mastering; enable command is enough to fix this.. */
  1621. if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_ENABLE, 0,
  1622. prism2_tx_cb, (void *) buf_len)) {
  1623. printk(KERN_DEBUG "%s: TX: enable port0 failed\n",
  1624. dev->name);
  1625. }
  1626. #else /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */
  1627. prism2_tx_cb(dev, (void *) buf_len, 0, 0);
  1628. #endif /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */
  1629. /* Bus master transfer will be started from command completion
  1630. * event handler and TX handling will be finished by calling
  1631. * prism2_transmit() from bus master event handler */
  1632. goto tx_stats;
  1633. }
  1634. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  1635. if (!res)
  1636. res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
  1637. if (!res)
  1638. res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len,
  1639. skb->len - hdr_len);
  1640. spin_unlock(&local->baplock);
  1641. if (!res)
  1642. res = prism2_transmit(dev, idx);
  1643. if (res) {
  1644. printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n",
  1645. dev->name);
  1646. local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
  1647. schedule_work(&local->reset_queue);
  1648. goto fail;
  1649. }
  1650. ret = 0;
  1651. fail:
  1652. prism2_callback(local, PRISM2_CALLBACK_TX_END);
  1653. return ret;
  1654. }
  1655. /* Some SMP systems have reported number of odd errors with hostap_pci. fid
  1656. * register has changed values between consecutive reads for an unknown reason.
  1657. * This should really not happen, so more debugging is needed. This test
  1658. * version is a big slower, but it will detect most of such register changes
  1659. * and will try to get the correct fid eventually. */
  1660. #define EXTRA_FID_READ_TESTS
  1661. static inline u16 prism2_read_fid_reg(struct net_device *dev, u16 reg)
  1662. {
  1663. #ifdef EXTRA_FID_READ_TESTS
  1664. u16 val, val2, val3;
  1665. int i;
  1666. for (i = 0; i < 10; i++) {
  1667. val = HFA384X_INW(reg);
  1668. val2 = HFA384X_INW(reg);
  1669. val3 = HFA384X_INW(reg);
  1670. if (val == val2 && val == val3)
  1671. return val;
  1672. printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):"
  1673. " %04x %04x %04x\n",
  1674. dev->name, i, reg, val, val2, val3);
  1675. if ((val == val2 || val == val3) && val != 0)
  1676. return val;
  1677. if (val2 == val3 && val2 != 0)
  1678. return val2;
  1679. }
  1680. printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg "
  1681. "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3);
  1682. return val;
  1683. #else /* EXTRA_FID_READ_TESTS */
  1684. return HFA384X_INW(reg);
  1685. #endif /* EXTRA_FID_READ_TESTS */
  1686. }
  1687. /* Called only as a tasklet (software IRQ) */
  1688. static void prism2_rx(local_info_t *local)
  1689. {
  1690. struct net_device *dev = local->dev;
  1691. int res, rx_pending = 0;
  1692. u16 len, hdr_len, rxfid, status, macport;
  1693. struct net_device_stats *stats;
  1694. struct hfa384x_rx_frame rxdesc;
  1695. struct sk_buff *skb = NULL;
  1696. prism2_callback(local, PRISM2_CALLBACK_RX_START);
  1697. stats = hostap_get_stats(dev);
  1698. rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
  1699. #ifndef final_version
  1700. if (rxfid == 0) {
  1701. rxfid = HFA384X_INW(HFA384X_RXFID_OFF);
  1702. printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n",
  1703. rxfid);
  1704. if (rxfid == 0) {
  1705. schedule_work(&local->reset_queue);
  1706. goto rx_dropped;
  1707. }
  1708. /* try to continue with the new rxfid value */
  1709. }
  1710. #endif
  1711. spin_lock(&local->baplock);
  1712. res = hfa384x_setup_bap(dev, BAP0, rxfid, 0);
  1713. if (!res)
  1714. res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc));
  1715. if (res) {
  1716. spin_unlock(&local->baplock);
  1717. printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name,
  1718. res);
  1719. if (res == -ETIMEDOUT) {
  1720. schedule_work(&local->reset_queue);
  1721. }
  1722. goto rx_dropped;
  1723. }
  1724. len = le16_to_cpu(rxdesc.data_len);
  1725. hdr_len = sizeof(rxdesc);
  1726. status = le16_to_cpu(rxdesc.status);
  1727. macport = (status >> 8) & 0x07;
  1728. /* Drop frames with too large reported payload length. Monitor mode
  1729. * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
  1730. * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
  1731. * macport 7 */
  1732. if (len > PRISM2_DATA_MAXLEN + 8 /* WEP */) {
  1733. if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) {
  1734. if (len >= (u16) -14) {
  1735. hdr_len -= 65535 - len;
  1736. hdr_len--;
  1737. }
  1738. len = 0;
  1739. } else {
  1740. spin_unlock(&local->baplock);
  1741. printk(KERN_DEBUG "%s: Received frame with invalid "
  1742. "length 0x%04x\n", dev->name, len);
  1743. hostap_dump_rx_header(dev->name, &rxdesc);
  1744. goto rx_dropped;
  1745. }
  1746. }
  1747. skb = dev_alloc_skb(len + hdr_len);
  1748. if (!skb) {
  1749. spin_unlock(&local->baplock);
  1750. printk(KERN_DEBUG "%s: RX failed to allocate skb\n",
  1751. dev->name);
  1752. goto rx_dropped;
  1753. }
  1754. skb->dev = dev;
  1755. memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len);
  1756. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  1757. if (len >= local->bus_master_threshold_rx) {
  1758. unsigned long addr;
  1759. hfa384x_events_no_bap1(dev);
  1760. local->rx_skb = skb;
  1761. /* Internal BAP0 offset points to the byte following rxdesc;
  1762. * copy rest of the data using bus master */
  1763. addr = virt_to_phys(skb_put(skb, len));
  1764. HFA384X_OUTW((addr & 0xffff0000) >> 16,
  1765. HFA384X_PCI_M0_ADDRH_OFF);
  1766. HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF);
  1767. if (len & 1)
  1768. len++;
  1769. HFA384X_OUTW(len / 2, HFA384X_PCI_M0_LEN_OFF);
  1770. HFA384X_OUTW(HFA384X_PCI_CTL_FROM_BAP, HFA384X_PCI_M0_CTL_OFF);
  1771. /* pci_bus_m1 event will be generated when data transfer is
  1772. * complete and the frame will then be added to rx_list and
  1773. * rx_tasklet is scheduled */
  1774. rx_pending = 1;
  1775. /* Have to release baplock before returning, although BAP0
  1776. * should really not be used before DMA transfer has been
  1777. * completed. */
  1778. spin_unlock(&local->baplock);
  1779. } else
  1780. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  1781. {
  1782. if (len > 0)
  1783. res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len),
  1784. len);
  1785. spin_unlock(&local->baplock);
  1786. if (res) {
  1787. printk(KERN_DEBUG "%s: RX failed to read "
  1788. "frame data\n", dev->name);
  1789. goto rx_dropped;
  1790. }
  1791. skb_queue_tail(&local->rx_list, skb);
  1792. tasklet_schedule(&local->rx_tasklet);
  1793. }
  1794. rx_exit:
  1795. prism2_callback(local, PRISM2_CALLBACK_RX_END);
  1796. if (!rx_pending) {
  1797. HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
  1798. }
  1799. return;
  1800. rx_dropped:
  1801. stats->rx_dropped++;
  1802. if (skb)
  1803. dev_kfree_skb(skb);
  1804. goto rx_exit;
  1805. }
  1806. /* Called only as a tasklet (software IRQ) */
  1807. static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb)
  1808. {
  1809. struct hfa384x_rx_frame *rxdesc;
  1810. struct net_device *dev = skb->dev;
  1811. struct hostap_80211_rx_status stats;
  1812. int hdrlen, rx_hdrlen;
  1813. rx_hdrlen = sizeof(*rxdesc);
  1814. if (skb->len < sizeof(*rxdesc)) {
  1815. /* Allow monitor mode to receive shorter frames */
  1816. if (local->iw_mode == IW_MODE_MONITOR &&
  1817. skb->len >= sizeof(*rxdesc) - 30) {
  1818. rx_hdrlen = skb->len;
  1819. } else {
  1820. dev_kfree_skb(skb);
  1821. return;
  1822. }
  1823. }
  1824. rxdesc = (struct hfa384x_rx_frame *) skb->data;
  1825. if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
  1826. skb->len >= sizeof(*rxdesc))
  1827. hostap_dump_rx_header(dev->name, rxdesc);
  1828. if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR &&
  1829. (!local->monitor_allow_fcserr ||
  1830. local->iw_mode != IW_MODE_MONITOR))
  1831. goto drop;
  1832. if (skb->len > PRISM2_DATA_MAXLEN) {
  1833. printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n",
  1834. dev->name, skb->len, PRISM2_DATA_MAXLEN);
  1835. goto drop;
  1836. }
  1837. stats.mac_time = le32_to_cpu(rxdesc->time);
  1838. stats.signal = rxdesc->signal - local->rssi_to_dBm;
  1839. stats.noise = rxdesc->silence - local->rssi_to_dBm;
  1840. stats.rate = rxdesc->rate;
  1841. /* Convert Prism2 RX structure into IEEE 802.11 header */
  1842. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control));
  1843. if (hdrlen > rx_hdrlen)
  1844. hdrlen = rx_hdrlen;
  1845. memmove(skb_pull(skb, rx_hdrlen - hdrlen),
  1846. &rxdesc->frame_control, hdrlen);
  1847. hostap_80211_rx(dev, skb, &stats);
  1848. return;
  1849. drop:
  1850. dev_kfree_skb(skb);
  1851. }
  1852. /* Called only as a tasklet (software IRQ) */
  1853. static void hostap_rx_tasklet(unsigned long data)
  1854. {
  1855. local_info_t *local = (local_info_t *) data;
  1856. struct sk_buff *skb;
  1857. while ((skb = skb_dequeue(&local->rx_list)) != NULL)
  1858. hostap_rx_skb(local, skb);
  1859. }
  1860. /* Called only from hardware IRQ */
  1861. static void prism2_alloc_ev(struct net_device *dev)
  1862. {
  1863. struct hostap_interface *iface;
  1864. local_info_t *local;
  1865. int idx;
  1866. u16 fid;
  1867. iface = netdev_priv(dev);
  1868. local = iface->local;
  1869. fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
  1870. PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid);
  1871. spin_lock(&local->txfidlock);
  1872. idx = local->next_alloc;
  1873. do {
  1874. if (local->txfid[idx] == fid) {
  1875. PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n",
  1876. idx);
  1877. #ifndef final_version
  1878. if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
  1879. printk("Already released txfid found at idx "
  1880. "%d\n", idx);
  1881. if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
  1882. printk("Already reserved txfid found at idx "
  1883. "%d\n", idx);
  1884. #endif
  1885. local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
  1886. idx++;
  1887. local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
  1888. idx;
  1889. if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
  1890. netif_queue_stopped(dev))
  1891. netif_wake_queue(dev);
  1892. spin_unlock(&local->txfidlock);
  1893. return;
  1894. }
  1895. idx++;
  1896. if (idx >= PRISM2_TXFID_COUNT)
  1897. idx = 0;
  1898. } while (idx != local->next_alloc);
  1899. printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new "
  1900. "read 0x%04x) for alloc event\n", dev->name, fid,
  1901. HFA384X_INW(HFA384X_ALLOCFID_OFF));
  1902. printk(KERN_DEBUG "TXFIDs:");
  1903. for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
  1904. printk(" %04x[%04x]", local->txfid[idx],
  1905. local->intransmitfid[idx]);
  1906. printk("\n");
  1907. spin_unlock(&local->txfidlock);
  1908. /* FIX: should probably schedule reset; reference to one txfid was lost
  1909. * completely.. Bad things will happen if we run out of txfids
  1910. * Actually, this will cause netdev watchdog to notice TX timeout and
  1911. * then card reset after all txfids have been leaked. */
  1912. }
  1913. /* Called only as a tasklet (software IRQ) */
  1914. static void hostap_tx_callback(local_info_t *local,
  1915. struct hfa384x_tx_frame *txdesc, int ok,
  1916. char *payload)
  1917. {
  1918. u16 sw_support, hdrlen, len;
  1919. struct sk_buff *skb;
  1920. struct hostap_tx_callback_info *cb;
  1921. /* Make sure that frame was from us. */
  1922. if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
  1923. printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
  1924. local->dev->name);
  1925. return;
  1926. }
  1927. sw_support = le16_to_cpu(txdesc->sw_support);
  1928. spin_lock(&local->lock);
  1929. cb = local->tx_callback;
  1930. while (cb != NULL && cb->idx != sw_support)
  1931. cb = cb->next;
  1932. spin_unlock(&local->lock);
  1933. if (cb == NULL) {
  1934. printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n",
  1935. local->dev->name, sw_support);
  1936. return;
  1937. }
  1938. hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
  1939. len = le16_to_cpu(txdesc->data_len);
  1940. skb = dev_alloc_skb(hdrlen + len);
  1941. if (skb == NULL) {
  1942. printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
  1943. "skb\n", local->dev->name);
  1944. return;
  1945. }
  1946. memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen);
  1947. if (payload)
  1948. memcpy(skb_put(skb, len), payload, len);
  1949. skb->dev = local->dev;
  1950. skb->mac.raw = skb->data;
  1951. cb->func(skb, ok, cb->data);
  1952. }
  1953. /* Called only as a tasklet (software IRQ) */
  1954. static int hostap_tx_compl_read(local_info_t *local, int error,
  1955. struct hfa384x_tx_frame *txdesc,
  1956. char **payload)
  1957. {
  1958. u16 fid, len;
  1959. int res, ret = 0;
  1960. struct net_device *dev = local->dev;
  1961. fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
  1962. PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
  1963. spin_lock(&local->baplock);
  1964. res = hfa384x_setup_bap(dev, BAP0, fid, 0);
  1965. if (!res)
  1966. res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc));
  1967. if (res) {
  1968. PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not "
  1969. "read txdesc\n", dev->name, error, fid);
  1970. if (res == -ETIMEDOUT) {
  1971. schedule_work(&local->reset_queue);
  1972. }
  1973. ret = -1;
  1974. goto fail;
  1975. }
  1976. if (txdesc->sw_support) {
  1977. len = le16_to_cpu(txdesc->data_len);
  1978. if (len < PRISM2_DATA_MAXLEN) {
  1979. *payload = (char *) kmalloc(len, GFP_ATOMIC);
  1980. if (*payload == NULL ||
  1981. hfa384x_from_bap(dev, BAP0, *payload, len)) {
  1982. PDEBUG(DEBUG_EXTRA, "%s: could not read TX "
  1983. "frame payload\n", dev->name);
  1984. kfree(*payload);
  1985. *payload = NULL;
  1986. ret = -1;
  1987. goto fail;
  1988. }
  1989. }
  1990. }
  1991. fail:
  1992. spin_unlock(&local->baplock);
  1993. return ret;
  1994. }
  1995. /* Called only as a tasklet (software IRQ) */
  1996. static void prism2_tx_ev(local_info_t *local)
  1997. {
  1998. struct net_device *dev = local->dev;
  1999. char *payload = NULL;
  2000. struct hfa384x_tx_frame txdesc;
  2001. if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
  2002. goto fail;
  2003. if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
  2004. PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x "
  2005. "retry_count=%d tx_rate=%d seq_ctrl=%d "
  2006. "duration_id=%d\n",
  2007. dev->name, le16_to_cpu(txdesc.status),
  2008. txdesc.retry_count, txdesc.tx_rate,
  2009. le16_to_cpu(txdesc.seq_ctrl),
  2010. le16_to_cpu(txdesc.duration_id));
  2011. }
  2012. if (txdesc.sw_support)
  2013. hostap_tx_callback(local, &txdesc, 1, payload);
  2014. kfree(payload);
  2015. fail:
  2016. HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF);
  2017. }
  2018. /* Called only as a tasklet (software IRQ) */
  2019. static void hostap_sta_tx_exc_tasklet(unsigned long data)
  2020. {
  2021. local_info_t *local = (local_info_t *) data;
  2022. struct sk_buff *skb;
  2023. while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) {
  2024. struct hfa384x_tx_frame *txdesc =
  2025. (struct hfa384x_tx_frame *) skb->data;
  2026. if (skb->len >= sizeof(*txdesc)) {
  2027. /* Convert Prism2 RX structure into IEEE 802.11 header
  2028. */
  2029. u16 fc = le16_to_cpu(txdesc->frame_control);
  2030. int hdrlen = hostap_80211_get_hdrlen(fc);
  2031. memmove(skb_pull(skb, sizeof(*txdesc) - hdrlen),
  2032. &txdesc->frame_control, hdrlen);
  2033. hostap_handle_sta_tx_exc(local, skb);
  2034. }
  2035. dev_kfree_skb(skb);
  2036. }
  2037. }
  2038. /* Called only as a tasklet (software IRQ) */
  2039. static void prism2_txexc(local_info_t *local)
  2040. {
  2041. struct net_device *dev = local->dev;
  2042. u16 status, fc;
  2043. int show_dump, res;
  2044. char *payload = NULL;
  2045. struct hfa384x_tx_frame txdesc;
  2046. show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
  2047. local->stats.tx_errors++;
  2048. res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
  2049. HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF);
  2050. if (res)
  2051. return;
  2052. status = le16_to_cpu(txdesc.status);
  2053. /* We produce a TXDROP event only for retry or lifetime
  2054. * exceeded, because that's the only status that really mean
  2055. * that this particular node went away.
  2056. * Other errors means that *we* screwed up. - Jean II */
  2057. if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR))
  2058. {
  2059. union iwreq_data wrqu;
  2060. /* Copy 802.11 dest address. */
  2061. memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN);
  2062. wrqu.addr.sa_family = ARPHRD_ETHER;
  2063. wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
  2064. } else
  2065. show_dump = 1;
  2066. if (local->iw_mode == IW_MODE_MASTER ||
  2067. local->iw_mode == IW_MODE_REPEAT ||
  2068. local->wds_type & HOSTAP_WDS_AP_CLIENT) {
  2069. struct sk_buff *skb;
  2070. skb = dev_alloc_skb(sizeof(txdesc));
  2071. if (skb) {
  2072. memcpy(skb_put(skb, sizeof(txdesc)), &txdesc,
  2073. sizeof(txdesc));
  2074. skb_queue_tail(&local->sta_tx_exc_list, skb);
  2075. tasklet_schedule(&local->sta_tx_exc_tasklet);
  2076. }
  2077. }
  2078. if (txdesc.sw_support)
  2079. hostap_tx_callback(local, &txdesc, 0, payload);
  2080. kfree(payload);
  2081. if (!show_dump)
  2082. return;
  2083. PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
  2084. " tx_control=%04x\n",
  2085. dev->name, status,
  2086. status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "",
  2087. status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "",
  2088. status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "",
  2089. status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "",
  2090. le16_to_cpu(txdesc.tx_control));
  2091. fc = le16_to_cpu(txdesc.frame_control);
  2092. PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x "
  2093. "(%s%s%s::%d%s%s)\n",
  2094. txdesc.retry_count, txdesc.tx_rate, fc,
  2095. WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT ? "Mgmt" : "",
  2096. WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_CTRL ? "Ctrl" : "",
  2097. WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA ? "Data" : "",
  2098. WLAN_FC_GET_STYPE(fc),
  2099. fc & WLAN_FC_TODS ? " ToDS" : "",
  2100. fc & WLAN_FC_FROMDS ? " FromDS" : "");
  2101. PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3="
  2102. MACSTR " A4=" MACSTR "\n",
  2103. MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2),
  2104. MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4));
  2105. }
  2106. /* Called only as a tasklet (software IRQ) */
  2107. static void hostap_info_tasklet(unsigned long data)
  2108. {
  2109. local_info_t *local = (local_info_t *) data;
  2110. struct sk_buff *skb;
  2111. while ((skb = skb_dequeue(&local->info_list)) != NULL) {
  2112. hostap_info_process(local, skb);
  2113. dev_kfree_skb(skb);
  2114. }
  2115. }
  2116. /* Called only as a tasklet (software IRQ) */
  2117. static void prism2_info(local_info_t *local)
  2118. {
  2119. struct net_device *dev = local->dev;
  2120. u16 fid;
  2121. int res, left;
  2122. struct hfa384x_info_frame info;
  2123. struct sk_buff *skb;
  2124. fid = HFA384X_INW(HFA384X_INFOFID_OFF);
  2125. spin_lock(&local->baplock);
  2126. res = hfa384x_setup_bap(dev, BAP0, fid, 0);
  2127. if (!res)
  2128. res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info));
  2129. if (res) {
  2130. spin_unlock(&local->baplock);
  2131. printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n",
  2132. fid);
  2133. if (res == -ETIMEDOUT) {
  2134. schedule_work(&local->reset_queue);
  2135. }
  2136. goto out;
  2137. }
  2138. le16_to_cpus(&info.len);
  2139. le16_to_cpus(&info.type);
  2140. left = (info.len - 1) * 2;
  2141. if (info.len & 0x8000 || info.len == 0 || left > 2060) {
  2142. /* data register seems to give 0x8000 in some error cases even
  2143. * though busy bit is not set in offset register;
  2144. * in addition, length must be at least 1 due to type field */
  2145. spin_unlock(&local->baplock);
  2146. printk(KERN_DEBUG "%s: Received info frame with invalid "
  2147. "length 0x%04x (type 0x%04x)\n", dev->name, info.len,
  2148. info.type);
  2149. goto out;
  2150. }
  2151. skb = dev_alloc_skb(sizeof(info) + left);
  2152. if (skb == NULL) {
  2153. spin_unlock(&local->baplock);
  2154. printk(KERN_DEBUG "%s: Could not allocate skb for info "
  2155. "frame\n", dev->name);
  2156. goto out;
  2157. }
  2158. memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info));
  2159. if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left))
  2160. {
  2161. spin_unlock(&local->baplock);
  2162. printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, "
  2163. "len=0x%04x, type=0x%04x\n",
  2164. dev->name, fid, info.len, info.type);
  2165. dev_kfree_skb(skb);
  2166. goto out;
  2167. }
  2168. spin_unlock(&local->baplock);
  2169. skb_queue_tail(&local->info_list, skb);
  2170. tasklet_schedule(&local->info_tasklet);
  2171. out:
  2172. HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF);
  2173. }
  2174. /* Called only as a tasklet (software IRQ) */
  2175. static void hostap_bap_tasklet(unsigned long data)
  2176. {
  2177. local_info_t *local = (local_info_t *) data;
  2178. struct net_device *dev = local->dev;
  2179. u16 ev;
  2180. int frames = 30;
  2181. if (local->func->card_present && !local->func->card_present(local))
  2182. return;
  2183. set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
  2184. /* Process all pending BAP events without generating new interrupts
  2185. * for them */
  2186. while (frames-- > 0) {
  2187. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2188. if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS))
  2189. break;
  2190. if (ev & HFA384X_EV_RX)
  2191. prism2_rx(local);
  2192. if (ev & HFA384X_EV_INFO)
  2193. prism2_info(local);
  2194. if (ev & HFA384X_EV_TX)
  2195. prism2_tx_ev(local);
  2196. if (ev & HFA384X_EV_TXEXC)
  2197. prism2_txexc(local);
  2198. }
  2199. set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
  2200. clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
  2201. /* Enable interrupts for new BAP events */
  2202. hfa384x_events_all(dev);
  2203. clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
  2204. }
  2205. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  2206. /* Called only from hardware IRQ */
  2207. static void prism2_bus_master_ev(struct net_device *dev, int bap)
  2208. {
  2209. struct hostap_interface *iface;
  2210. local_info_t *local;
  2211. iface = netdev_priv(dev);
  2212. local = iface->local;
  2213. if (bap == BAP1) {
  2214. /* FIX: frame payload was DMA'd to skb->data; might need to
  2215. * invalidate data cache for that memory area */
  2216. skb_queue_tail(&local->rx_list, local->rx_skb);
  2217. tasklet_schedule(&local->rx_tasklet);
  2218. HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
  2219. } else {
  2220. if (prism2_transmit(dev, local->bus_m0_tx_idx)) {
  2221. printk(KERN_DEBUG "%s: prism2_transmit() failed "
  2222. "when called from bus master event\n",
  2223. dev->name);
  2224. local->intransmitfid[local->bus_m0_tx_idx] =
  2225. PRISM2_TXFID_EMPTY;
  2226. schedule_work(&local->reset_queue);
  2227. }
  2228. }
  2229. }
  2230. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  2231. /* Called only from hardware IRQ */
  2232. static void prism2_infdrop(struct net_device *dev)
  2233. {
  2234. static unsigned long last_inquire = 0;
  2235. PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name);
  2236. /* some firmware versions seem to get stuck with
  2237. * full CommTallies in high traffic load cases; every
  2238. * packet will then cause INFDROP event and CommTallies
  2239. * info frame will not be sent automatically. Try to
  2240. * get out of this state by inquiring CommTallies. */
  2241. if (!last_inquire || time_after(jiffies, last_inquire + HZ)) {
  2242. hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE,
  2243. HFA384X_INFO_COMMTALLIES, NULL, NULL);
  2244. last_inquire = jiffies;
  2245. }
  2246. }
  2247. /* Called only from hardware IRQ */
  2248. static void prism2_ev_tick(struct net_device *dev)
  2249. {
  2250. struct hostap_interface *iface;
  2251. local_info_t *local;
  2252. u16 evstat, inten;
  2253. static int prev_stuck = 0;
  2254. iface = netdev_priv(dev);
  2255. local = iface->local;
  2256. if (time_after(jiffies, local->last_tick_timer + 5 * HZ) &&
  2257. local->last_tick_timer) {
  2258. evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2259. inten = HFA384X_INW(HFA384X_INTEN_OFF);
  2260. if (!prev_stuck) {
  2261. printk(KERN_INFO "%s: SW TICK stuck? "
  2262. "bits=0x%lx EvStat=%04x IntEn=%04x\n",
  2263. dev->name, local->bits, evstat, inten);
  2264. }
  2265. local->sw_tick_stuck++;
  2266. if ((evstat & HFA384X_BAP0_EVENTS) &&
  2267. (inten & HFA384X_BAP0_EVENTS)) {
  2268. printk(KERN_INFO "%s: trying to recover from IRQ "
  2269. "hang\n", dev->name);
  2270. hfa384x_events_no_bap0(dev);
  2271. }
  2272. prev_stuck = 1;
  2273. } else
  2274. prev_stuck = 0;
  2275. }
  2276. /* Called only from hardware IRQ */
  2277. static inline void prism2_check_magic(local_info_t *local)
  2278. {
  2279. /* at least PCI Prism2.5 with bus mastering seems to sometimes
  2280. * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
  2281. * register once or twice seems to get the correct value.. PCI cards
  2282. * cannot anyway be removed during normal operation, so there is not
  2283. * really any need for this verification with them. */
  2284. #ifndef PRISM2_PCI
  2285. #ifndef final_version
  2286. static unsigned long last_magic_err = 0;
  2287. struct net_device *dev = local->dev;
  2288. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
  2289. if (!local->hw_ready)
  2290. return;
  2291. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  2292. if (time_after(jiffies, last_magic_err + 10 * HZ)) {
  2293. printk("%s: Interrupt, but SWSUPPORT0 does not match: "
  2294. "%04X != %04X - card removed?\n", dev->name,
  2295. HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
  2296. HFA384X_MAGIC);
  2297. last_magic_err = jiffies;
  2298. } else if (net_ratelimit()) {
  2299. printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x "
  2300. "MAGIC=%04x\n", dev->name,
  2301. HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
  2302. HFA384X_MAGIC);
  2303. }
  2304. if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
  2305. schedule_work(&local->reset_queue);
  2306. return;
  2307. }
  2308. #endif /* final_version */
  2309. #endif /* !PRISM2_PCI */
  2310. }
  2311. /* Called only from hardware IRQ */
  2312. static irqreturn_t prism2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  2313. {
  2314. struct net_device *dev = (struct net_device *) dev_id;
  2315. struct hostap_interface *iface;
  2316. local_info_t *local;
  2317. int events = 0;
  2318. u16 ev;
  2319. iface = netdev_priv(dev);
  2320. local = iface->local;
  2321. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
  2322. if (local->func->card_present && !local->func->card_present(local)) {
  2323. if (net_ratelimit()) {
  2324. printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
  2325. dev->name);
  2326. }
  2327. return IRQ_HANDLED;
  2328. }
  2329. prism2_check_magic(local);
  2330. for (;;) {
  2331. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2332. if (ev == 0xffff) {
  2333. if (local->shutdown)
  2334. return IRQ_HANDLED;
  2335. HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
  2336. printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n",
  2337. dev->name);
  2338. return IRQ_HANDLED;
  2339. }
  2340. ev &= HFA384X_INW(HFA384X_INTEN_OFF);
  2341. if (ev == 0)
  2342. break;
  2343. if (ev & HFA384X_EV_CMD) {
  2344. prism2_cmd_ev(dev);
  2345. }
  2346. /* Above events are needed even before hw is ready, but other
  2347. * events should be skipped during initialization. This may
  2348. * change for AllocEv if allocate_fid is implemented without
  2349. * busy waiting. */
  2350. if (!local->hw_ready || local->hw_resetting ||
  2351. !local->dev_enabled) {
  2352. ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
  2353. if (ev & HFA384X_EV_CMD)
  2354. goto next_event;
  2355. if ((ev & HFA384X_EVENT_MASK) == 0)
  2356. return IRQ_HANDLED;
  2357. if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) &&
  2358. net_ratelimit()) {
  2359. printk(KERN_DEBUG "%s: prism2_interrupt: hw "
  2360. "not ready; skipping events 0x%04x "
  2361. "(IntEn=0x%04x)%s%s%s\n",
  2362. dev->name, ev,
  2363. HFA384X_INW(HFA384X_INTEN_OFF),
  2364. !local->hw_ready ? " (!hw_ready)" : "",
  2365. local->hw_resetting ?
  2366. " (hw_resetting)" : "",
  2367. !local->dev_enabled ?
  2368. " (!dev_enabled)" : "");
  2369. }
  2370. HFA384X_OUTW(ev, HFA384X_EVACK_OFF);
  2371. return IRQ_HANDLED;
  2372. }
  2373. if (ev & HFA384X_EV_TICK) {
  2374. prism2_ev_tick(dev);
  2375. HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF);
  2376. }
  2377. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  2378. if (ev & HFA384X_EV_PCI_M0) {
  2379. prism2_bus_master_ev(dev, BAP0);
  2380. HFA384X_OUTW(HFA384X_EV_PCI_M0, HFA384X_EVACK_OFF);
  2381. }
  2382. if (ev & HFA384X_EV_PCI_M1) {
  2383. /* previous RX has been copied can be ACKed now */
  2384. HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
  2385. prism2_bus_master_ev(dev, BAP1);
  2386. HFA384X_OUTW(HFA384X_EV_PCI_M1, HFA384X_EVACK_OFF);
  2387. }
  2388. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  2389. if (ev & HFA384X_EV_ALLOC) {
  2390. prism2_alloc_ev(dev);
  2391. HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
  2392. }
  2393. /* Reading data from the card is quite time consuming, so do it
  2394. * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
  2395. * and unmasked after needed data has been read completely. */
  2396. if (ev & HFA384X_BAP0_EVENTS) {
  2397. hfa384x_events_no_bap0(dev);
  2398. tasklet_schedule(&local->bap_tasklet);
  2399. }
  2400. #ifndef final_version
  2401. if (ev & HFA384X_EV_WTERR) {
  2402. PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name);
  2403. HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF);
  2404. }
  2405. #endif /* final_version */
  2406. if (ev & HFA384X_EV_INFDROP) {
  2407. prism2_infdrop(dev);
  2408. HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF);
  2409. }
  2410. next_event:
  2411. events++;
  2412. if (events >= PRISM2_MAX_INTERRUPT_EVENTS) {
  2413. PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events "
  2414. "(EvStat=0x%04x)\n",
  2415. PRISM2_MAX_INTERRUPT_EVENTS,
  2416. HFA384X_INW(HFA384X_EVSTAT_OFF));
  2417. break;
  2418. }
  2419. }
  2420. prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
  2421. return IRQ_RETVAL(events);
  2422. }
  2423. static void prism2_check_sta_fw_version(local_info_t *local)
  2424. {
  2425. struct hfa384x_comp_ident comp;
  2426. int id, variant, major, minor;
  2427. if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID,
  2428. &comp, sizeof(comp), 1) < 0)
  2429. return;
  2430. local->fw_ap = 0;
  2431. id = le16_to_cpu(comp.id);
  2432. if (id != HFA384X_COMP_ID_STA) {
  2433. if (id == HFA384X_COMP_ID_FW_AP)
  2434. local->fw_ap = 1;
  2435. return;
  2436. }
  2437. major = __le16_to_cpu(comp.major);
  2438. minor = __le16_to_cpu(comp.minor);
  2439. variant = __le16_to_cpu(comp.variant);
  2440. local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
  2441. /* Station firmware versions before 1.4.x seem to have a bug in
  2442. * firmware-based WEP encryption when using Host AP mode, so use
  2443. * host_encrypt as a default for them. Firmware version 1.4.9 is the
  2444. * first one that has been seen to produce correct encryption, but the
  2445. * bug might be fixed before that (although, at least 1.4.2 is broken).
  2446. */
  2447. local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
  2448. if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
  2449. !local->fw_encrypt_ok) {
  2450. printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
  2451. "a workaround for firmware bug in Host AP mode WEP\n",
  2452. local->dev->name);
  2453. local->host_encrypt = 1;
  2454. }
  2455. /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
  2456. * in station firmware versions before 1.5.x. With these versions, the
  2457. * driver uses a workaround with bogus frame format (4th address after
  2458. * the payload). This is not compatible with other AP devices. Since
  2459. * the firmware bug is fixed in the latest station firmware versions,
  2460. * automatically enable standard compliant mode for cards using station
  2461. * firmware version 1.5.0 or newer. */
  2462. if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
  2463. local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
  2464. else {
  2465. printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a "
  2466. "workaround for firmware bug in Host AP mode WDS\n",
  2467. local->dev->name);
  2468. }
  2469. hostap_check_sta_fw_version(local->ap, local->sta_fw_ver);
  2470. }
  2471. static void prism2_crypt_deinit_entries(local_info_t *local, int force)
  2472. {
  2473. struct list_head *ptr, *n;
  2474. struct prism2_crypt_data *entry;
  2475. for (ptr = local->crypt_deinit_list.next, n = ptr->next;
  2476. ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
  2477. entry = list_entry(ptr, struct prism2_crypt_data, list);
  2478. if (atomic_read(&entry->refcnt) != 0 && !force)
  2479. continue;
  2480. list_del(ptr);
  2481. if (entry->ops)
  2482. entry->ops->deinit(entry->priv);
  2483. kfree(entry);
  2484. }
  2485. }
  2486. static void prism2_crypt_deinit_handler(unsigned long data)
  2487. {
  2488. local_info_t *local = (local_info_t *) data;
  2489. unsigned long flags;
  2490. spin_lock_irqsave(&local->lock, flags);
  2491. prism2_crypt_deinit_entries(local, 0);
  2492. if (!list_empty(&local->crypt_deinit_list)) {
  2493. printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
  2494. "deletion list\n", local->dev->name);
  2495. local->crypt_deinit_timer.expires = jiffies + HZ;
  2496. add_timer(&local->crypt_deinit_timer);
  2497. }
  2498. spin_unlock_irqrestore(&local->lock, flags);
  2499. }
  2500. static void hostap_passive_scan(unsigned long data)
  2501. {
  2502. local_info_t *local = (local_info_t *) data;
  2503. struct net_device *dev = local->dev;
  2504. u16 channel;
  2505. if (local->passive_scan_interval <= 0)
  2506. return;
  2507. if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
  2508. int max_tries = 16;
  2509. /* Even though host system does not really know when the WLAN
  2510. * MAC is sending frames, try to avoid changing channels for
  2511. * passive scanning when a host-generated frame is being
  2512. * transmitted */
  2513. if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
  2514. printk(KERN_DEBUG "%s: passive scan detected pending "
  2515. "TX - delaying\n", dev->name);
  2516. local->passive_scan_timer.expires = jiffies + HZ / 10;
  2517. add_timer(&local->passive_scan_timer);
  2518. return;
  2519. }
  2520. do {
  2521. local->passive_scan_channel++;
  2522. if (local->passive_scan_channel > 14)
  2523. local->passive_scan_channel = 1;
  2524. max_tries--;
  2525. } while (!(local->channel_mask &
  2526. (1 << (local->passive_scan_channel - 1))) &&
  2527. max_tries > 0);
  2528. if (max_tries == 0) {
  2529. printk(KERN_INFO "%s: no allowed passive scan channels"
  2530. " found\n", dev->name);
  2531. return;
  2532. }
  2533. printk(KERN_DEBUG "%s: passive scan channel %d\n",
  2534. dev->name, local->passive_scan_channel);
  2535. channel = local->passive_scan_channel;
  2536. local->passive_scan_state = PASSIVE_SCAN_WAIT;
  2537. local->passive_scan_timer.expires = jiffies + HZ / 10;
  2538. } else {
  2539. channel = local->channel;
  2540. local->passive_scan_state = PASSIVE_SCAN_LISTEN;
  2541. local->passive_scan_timer.expires = jiffies +
  2542. local->passive_scan_interval * HZ;
  2543. }
  2544. if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
  2545. (HFA384X_TEST_CHANGE_CHANNEL << 8),
  2546. channel, NULL, NULL))
  2547. printk(KERN_ERR "%s: passive scan channel set %d "
  2548. "failed\n", dev->name, channel);
  2549. add_timer(&local->passive_scan_timer);
  2550. }
  2551. /* Called only as a scheduled task when communications quality values should
  2552. * be updated. */
  2553. static void handle_comms_qual_update(void *data)
  2554. {
  2555. local_info_t *local = data;
  2556. prism2_update_comms_qual(local->dev);
  2557. }
  2558. /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
  2559. * used to monitor that local->last_tick_timer is being updated. If not,
  2560. * interrupt busy-loop is assumed and driver tries to recover by masking out
  2561. * some events. */
  2562. static void hostap_tick_timer(unsigned long data)
  2563. {
  2564. static unsigned long last_inquire = 0;
  2565. local_info_t *local = (local_info_t *) data;
  2566. local->last_tick_timer = jiffies;
  2567. /* Inquire CommTallies every 10 seconds to keep the statistics updated
  2568. * more often during low load and when using 32-bit tallies. */
  2569. if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) &&
  2570. !local->hw_downloading && local->hw_ready &&
  2571. !local->hw_resetting && local->dev_enabled) {
  2572. hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE,
  2573. HFA384X_INFO_COMMTALLIES, NULL, NULL);
  2574. last_inquire = jiffies;
  2575. }
  2576. if ((local->last_comms_qual_update == 0 ||
  2577. time_after(jiffies, local->last_comms_qual_update + 10 * HZ)) &&
  2578. (local->iw_mode == IW_MODE_INFRA ||
  2579. local->iw_mode == IW_MODE_ADHOC)) {
  2580. schedule_work(&local->comms_qual_update);
  2581. }
  2582. local->tick_timer.expires = jiffies + 2 * HZ;
  2583. add_timer(&local->tick_timer);
  2584. }
  2585. #ifndef PRISM2_NO_PROCFS_DEBUG
  2586. static int prism2_registers_proc_read(char *page, char **start, off_t off,
  2587. int count, int *eof, void *data)
  2588. {
  2589. char *p = page;
  2590. local_info_t *local = (local_info_t *) data;
  2591. if (off != 0) {
  2592. *eof = 1;
  2593. return 0;
  2594. }
  2595. #define SHOW_REG(n) \
  2596. p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
  2597. SHOW_REG(CMD);
  2598. SHOW_REG(PARAM0);
  2599. SHOW_REG(PARAM1);
  2600. SHOW_REG(PARAM2);
  2601. SHOW_REG(STATUS);
  2602. SHOW_REG(RESP0);
  2603. SHOW_REG(RESP1);
  2604. SHOW_REG(RESP2);
  2605. SHOW_REG(INFOFID);
  2606. SHOW_REG(CONTROL);
  2607. SHOW_REG(SELECT0);
  2608. SHOW_REG(SELECT1);
  2609. SHOW_REG(OFFSET0);
  2610. SHOW_REG(OFFSET1);
  2611. SHOW_REG(RXFID);
  2612. SHOW_REG(ALLOCFID);
  2613. SHOW_REG(TXCOMPLFID);
  2614. SHOW_REG(SWSUPPORT0);
  2615. SHOW_REG(SWSUPPORT1);
  2616. SHOW_REG(SWSUPPORT2);
  2617. SHOW_REG(EVSTAT);
  2618. SHOW_REG(INTEN);
  2619. SHOW_REG(EVACK);
  2620. /* Do not read data registers, because they change the state of the
  2621. * MAC (offset += 2) */
  2622. /* SHOW_REG(DATA0); */
  2623. /* SHOW_REG(DATA1); */
  2624. SHOW_REG(AUXPAGE);
  2625. SHOW_REG(AUXOFFSET);
  2626. /* SHOW_REG(AUXDATA); */
  2627. #ifdef PRISM2_PCI
  2628. SHOW_REG(PCICOR);
  2629. SHOW_REG(PCIHCR);
  2630. SHOW_REG(PCI_M0_ADDRH);
  2631. SHOW_REG(PCI_M0_ADDRL);
  2632. SHOW_REG(PCI_M0_LEN);
  2633. SHOW_REG(PCI_M0_CTL);
  2634. SHOW_REG(PCI_STATUS);
  2635. SHOW_REG(PCI_M1_ADDRH);
  2636. SHOW_REG(PCI_M1_ADDRL);
  2637. SHOW_REG(PCI_M1_LEN);
  2638. SHOW_REG(PCI_M1_CTL);
  2639. #endif /* PRISM2_PCI */
  2640. return (p - page);
  2641. }
  2642. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2643. struct set_tim_data {
  2644. struct list_head list;
  2645. int aid;
  2646. int set;
  2647. };
  2648. static int prism2_set_tim(struct net_device *dev, int aid, int set)
  2649. {
  2650. struct list_head *ptr;
  2651. struct set_tim_data *new_entry;
  2652. struct hostap_interface *iface;
  2653. local_info_t *local;
  2654. iface = netdev_priv(dev);
  2655. local = iface->local;
  2656. new_entry = (struct set_tim_data *)
  2657. kmalloc(sizeof(*new_entry), GFP_ATOMIC);
  2658. if (new_entry == NULL) {
  2659. printk(KERN_DEBUG "%s: prism2_set_tim: kmalloc failed\n",
  2660. local->dev->name);
  2661. return -ENOMEM;
  2662. }
  2663. memset(new_entry, 0, sizeof(*new_entry));
  2664. new_entry->aid = aid;
  2665. new_entry->set = set;
  2666. spin_lock_bh(&local->set_tim_lock);
  2667. list_for_each(ptr, &local->set_tim_list) {
  2668. struct set_tim_data *entry =
  2669. list_entry(ptr, struct set_tim_data, list);
  2670. if (entry->aid == aid) {
  2671. PDEBUG(DEBUG_PS2, "%s: prism2_set_tim: aid=%d "
  2672. "set=%d ==> %d\n",
  2673. local->dev->name, aid, entry->set, set);
  2674. entry->set = set;
  2675. kfree(new_entry);
  2676. new_entry = NULL;
  2677. break;
  2678. }
  2679. }
  2680. if (new_entry)
  2681. list_add_tail(&new_entry->list, &local->set_tim_list);
  2682. spin_unlock_bh(&local->set_tim_lock);
  2683. schedule_work(&local->set_tim_queue);
  2684. return 0;
  2685. }
  2686. static void handle_set_tim_queue(void *data)
  2687. {
  2688. local_info_t *local = (local_info_t *) data;
  2689. struct set_tim_data *entry;
  2690. u16 val;
  2691. for (;;) {
  2692. entry = NULL;
  2693. spin_lock_bh(&local->set_tim_lock);
  2694. if (!list_empty(&local->set_tim_list)) {
  2695. entry = list_entry(local->set_tim_list.next,
  2696. struct set_tim_data, list);
  2697. list_del(&entry->list);
  2698. }
  2699. spin_unlock_bh(&local->set_tim_lock);
  2700. if (!entry)
  2701. break;
  2702. PDEBUG(DEBUG_PS2, "%s: handle_set_tim_queue: aid=%d set=%d\n",
  2703. local->dev->name, entry->aid, entry->set);
  2704. val = entry->aid;
  2705. if (entry->set)
  2706. val |= 0x8000;
  2707. if (hostap_set_word(local->dev, HFA384X_RID_CNFTIMCTRL, val)) {
  2708. printk(KERN_DEBUG "%s: set_tim failed (aid=%d "
  2709. "set=%d)\n",
  2710. local->dev->name, entry->aid, entry->set);
  2711. }
  2712. kfree(entry);
  2713. }
  2714. }
  2715. static void prism2_clear_set_tim_queue(local_info_t *local)
  2716. {
  2717. struct list_head *ptr, *n;
  2718. list_for_each_safe(ptr, n, &local->set_tim_list) {
  2719. struct set_tim_data *entry;
  2720. entry = list_entry(ptr, struct set_tim_data, list);
  2721. list_del(&entry->list);
  2722. kfree(entry);
  2723. }
  2724. }
  2725. static struct net_device *
  2726. prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
  2727. struct device *sdev)
  2728. {
  2729. struct net_device *dev;
  2730. struct hostap_interface *iface;
  2731. struct local_info *local;
  2732. int len, i, ret;
  2733. if (funcs == NULL)
  2734. return NULL;
  2735. len = strlen(dev_template);
  2736. if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
  2737. printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
  2738. dev_template);
  2739. return NULL;
  2740. }
  2741. len = sizeof(struct hostap_interface) +
  2742. 3 + sizeof(struct local_info) +
  2743. 3 + sizeof(struct ap_data);
  2744. dev = alloc_etherdev(len);
  2745. if (dev == NULL)
  2746. return NULL;
  2747. iface = netdev_priv(dev);
  2748. local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
  2749. local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
  2750. local->dev = iface->dev = dev;
  2751. iface->local = local;
  2752. iface->type = HOSTAP_INTERFACE_MASTER;
  2753. INIT_LIST_HEAD(&local->hostap_interfaces);
  2754. local->hw_module = THIS_MODULE;
  2755. #ifdef PRISM2_IO_DEBUG
  2756. local->io_debug_enabled = 1;
  2757. #endif /* PRISM2_IO_DEBUG */
  2758. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  2759. local->bus_m0_buf = (u8 *) kmalloc(sizeof(struct hfa384x_tx_frame) +
  2760. PRISM2_DATA_MAXLEN, GFP_DMA);
  2761. if (local->bus_m0_buf == NULL)
  2762. goto fail;
  2763. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  2764. local->func = funcs;
  2765. local->func->cmd = hfa384x_cmd;
  2766. local->func->read_regs = hfa384x_read_regs;
  2767. local->func->get_rid = hfa384x_get_rid;
  2768. local->func->set_rid = hfa384x_set_rid;
  2769. local->func->hw_enable = prism2_hw_enable;
  2770. local->func->hw_config = prism2_hw_config;
  2771. local->func->hw_reset = prism2_hw_reset;
  2772. local->func->hw_shutdown = prism2_hw_shutdown;
  2773. local->func->reset_port = prism2_reset_port;
  2774. local->func->schedule_reset = prism2_schedule_reset;
  2775. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2776. local->func->read_aux = prism2_download_aux_dump;
  2777. local->func->download = prism2_download;
  2778. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2779. local->func->tx = prism2_tx_80211;
  2780. local->func->set_tim = prism2_set_tim;
  2781. local->func->need_tx_headroom = 0; /* no need to add txdesc in
  2782. * skb->data (FIX: maybe for DMA bus
  2783. * mastering? */
  2784. local->mtu = mtu;
  2785. rwlock_init(&local->iface_lock);
  2786. spin_lock_init(&local->txfidlock);
  2787. spin_lock_init(&local->cmdlock);
  2788. spin_lock_init(&local->baplock);
  2789. spin_lock_init(&local->lock);
  2790. init_MUTEX(&local->rid_bap_sem);
  2791. if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
  2792. card_idx = 0;
  2793. local->card_idx = card_idx;
  2794. len = strlen(essid);
  2795. memcpy(local->essid, essid,
  2796. len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
  2797. local->essid[MAX_SSID_LEN] = '\0';
  2798. i = GET_INT_PARM(iw_mode, card_idx);
  2799. if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
  2800. i == IW_MODE_MONITOR) {
  2801. local->iw_mode = i;
  2802. } else {
  2803. printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
  2804. "IW_MODE_MASTER\n", i);
  2805. local->iw_mode = IW_MODE_MASTER;
  2806. }
  2807. local->channel = GET_INT_PARM(channel, card_idx);
  2808. local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
  2809. local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
  2810. local->wds_max_connections = 16;
  2811. local->tx_control = HFA384X_TX_CTRL_FLAGS;
  2812. local->manual_retry_count = -1;
  2813. local->rts_threshold = 2347;
  2814. local->fragm_threshold = 2346;
  2815. local->rssi_to_dBm = 100; /* default; to be overriden by
  2816. * cnfDbmAdjust, if available */
  2817. local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
  2818. local->sram_type = -1;
  2819. local->scan_channel_mask = 0xffff;
  2820. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  2821. local->bus_master_threshold_rx = GET_INT_PARM(bus_master_threshold_rx,
  2822. card_idx);
  2823. local->bus_master_threshold_tx = GET_INT_PARM(bus_master_threshold_tx,
  2824. card_idx);
  2825. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  2826. /* Initialize task queue structures */
  2827. INIT_WORK(&local->reset_queue, handle_reset_queue, local);
  2828. INIT_WORK(&local->set_multicast_list_queue,
  2829. hostap_set_multicast_list_queue, local->dev);
  2830. INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local);
  2831. INIT_LIST_HEAD(&local->set_tim_list);
  2832. spin_lock_init(&local->set_tim_lock);
  2833. INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local);
  2834. /* Initialize tasklets for handling hardware IRQ related operations
  2835. * outside hw IRQ handler */
  2836. #define HOSTAP_TASKLET_INIT(q, f, d) \
  2837. do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
  2838. while (0)
  2839. HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
  2840. (unsigned long) local);
  2841. HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
  2842. (unsigned long) local);
  2843. hostap_info_init(local);
  2844. HOSTAP_TASKLET_INIT(&local->rx_tasklet,
  2845. hostap_rx_tasklet, (unsigned long) local);
  2846. skb_queue_head_init(&local->rx_list);
  2847. HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
  2848. hostap_sta_tx_exc_tasklet, (unsigned long) local);
  2849. skb_queue_head_init(&local->sta_tx_exc_list);
  2850. INIT_LIST_HEAD(&local->cmd_queue);
  2851. init_waitqueue_head(&local->hostscan_wq);
  2852. INIT_LIST_HEAD(&local->crypt_deinit_list);
  2853. init_timer(&local->crypt_deinit_timer);
  2854. local->crypt_deinit_timer.data = (unsigned long) local;
  2855. local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
  2856. init_timer(&local->passive_scan_timer);
  2857. local->passive_scan_timer.data = (unsigned long) local;
  2858. local->passive_scan_timer.function = hostap_passive_scan;
  2859. init_timer(&local->tick_timer);
  2860. local->tick_timer.data = (unsigned long) local;
  2861. local->tick_timer.function = hostap_tick_timer;
  2862. local->tick_timer.expires = jiffies + 2 * HZ;
  2863. add_timer(&local->tick_timer);
  2864. INIT_LIST_HEAD(&local->bss_list);
  2865. hostap_setup_dev(dev, local, 1);
  2866. local->saved_eth_header_parse = dev->hard_header_parse;
  2867. dev->hard_start_xmit = hostap_master_start_xmit;
  2868. dev->type = ARPHRD_IEEE80211;
  2869. dev->hard_header_parse = hostap_80211_header_parse;
  2870. rtnl_lock();
  2871. ret = dev_alloc_name(dev, "wifi%d");
  2872. SET_NETDEV_DEV(dev, sdev);
  2873. if (ret >= 0)
  2874. ret = register_netdevice(dev);
  2875. rtnl_unlock();
  2876. if (ret < 0) {
  2877. printk(KERN_WARNING "%s: register netdevice failed!\n",
  2878. dev_info);
  2879. goto fail;
  2880. }
  2881. printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
  2882. #ifndef PRISM2_NO_PROCFS_DEBUG
  2883. create_proc_read_entry("registers", 0, local->proc,
  2884. prism2_registers_proc_read, local);
  2885. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2886. hostap_init_data(local);
  2887. return dev;
  2888. fail:
  2889. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  2890. kfree(local->bus_m0_buf);
  2891. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  2892. free_netdev(dev);
  2893. return NULL;
  2894. }
  2895. static int hostap_hw_ready(struct net_device *dev)
  2896. {
  2897. struct hostap_interface *iface;
  2898. struct local_info *local;
  2899. iface = netdev_priv(dev);
  2900. local = iface->local;
  2901. local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0,
  2902. "", dev_template);
  2903. if (local->ddev) {
  2904. if (local->iw_mode == IW_MODE_INFRA ||
  2905. local->iw_mode == IW_MODE_ADHOC) {
  2906. netif_carrier_off(local->dev);
  2907. netif_carrier_off(local->ddev);
  2908. }
  2909. hostap_init_proc(local);
  2910. hostap_init_ap_proc(local);
  2911. return 0;
  2912. }
  2913. return -1;
  2914. }
  2915. static void prism2_free_local_data(struct net_device *dev)
  2916. {
  2917. struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
  2918. int i;
  2919. struct hostap_interface *iface;
  2920. struct local_info *local;
  2921. struct list_head *ptr, *n;
  2922. if (dev == NULL)
  2923. return;
  2924. iface = netdev_priv(dev);
  2925. local = iface->local;
  2926. flush_scheduled_work();
  2927. if (timer_pending(&local->crypt_deinit_timer))
  2928. del_timer(&local->crypt_deinit_timer);
  2929. prism2_crypt_deinit_entries(local, 1);
  2930. if (timer_pending(&local->passive_scan_timer))
  2931. del_timer(&local->passive_scan_timer);
  2932. if (timer_pending(&local->tick_timer))
  2933. del_timer(&local->tick_timer);
  2934. prism2_clear_cmd_queue(local);
  2935. skb_queue_purge(&local->info_list);
  2936. skb_queue_purge(&local->rx_list);
  2937. skb_queue_purge(&local->sta_tx_exc_list);
  2938. if (local->dev_enabled)
  2939. prism2_callback(local, PRISM2_CALLBACK_DISABLE);
  2940. for (i = 0; i < WEP_KEYS; i++) {
  2941. struct prism2_crypt_data *crypt = local->crypt[i];
  2942. if (crypt) {
  2943. if (crypt->ops)
  2944. crypt->ops->deinit(crypt->priv);
  2945. kfree(crypt);
  2946. local->crypt[i] = NULL;
  2947. }
  2948. }
  2949. if (local->ap != NULL)
  2950. hostap_free_data(local->ap);
  2951. #ifndef PRISM2_NO_PROCFS_DEBUG
  2952. if (local->proc != NULL)
  2953. remove_proc_entry("registers", local->proc);
  2954. #endif /* PRISM2_NO_PROCFS_DEBUG */
  2955. hostap_remove_proc(local);
  2956. tx_cb = local->tx_callback;
  2957. while (tx_cb != NULL) {
  2958. tx_cb_prev = tx_cb;
  2959. tx_cb = tx_cb->next;
  2960. kfree(tx_cb_prev);
  2961. }
  2962. hostap_set_hostapd(local, 0, 0);
  2963. hostap_set_hostapd_sta(local, 0, 0);
  2964. for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
  2965. if (local->frag_cache[i].skb != NULL)
  2966. dev_kfree_skb(local->frag_cache[i].skb);
  2967. }
  2968. #ifdef PRISM2_DOWNLOAD_SUPPORT
  2969. prism2_download_free_data(local->dl_pri);
  2970. prism2_download_free_data(local->dl_sec);
  2971. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  2972. list_for_each_safe(ptr, n, &local->hostap_interfaces) {
  2973. iface = list_entry(ptr, struct hostap_interface, list);
  2974. if (iface->type == HOSTAP_INTERFACE_MASTER) {
  2975. /* special handling for this interface below */
  2976. continue;
  2977. }
  2978. hostap_remove_interface(iface->dev, 0, 1);
  2979. }
  2980. prism2_clear_set_tim_queue(local);
  2981. list_for_each_safe(ptr, n, &local->bss_list) {
  2982. struct hostap_bss_info *bss =
  2983. list_entry(ptr, struct hostap_bss_info, list);
  2984. kfree(bss);
  2985. }
  2986. #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
  2987. kfree(local->bus_m0_buf);
  2988. #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
  2989. kfree(local->pda);
  2990. kfree(local->last_scan_results);
  2991. kfree(local->generic_elem);
  2992. unregister_netdev(local->dev);
  2993. free_netdev(local->dev);
  2994. }
  2995. #ifndef PRISM2_PLX
  2996. static void prism2_suspend(struct net_device *dev)
  2997. {
  2998. struct hostap_interface *iface;
  2999. struct local_info *local;
  3000. union iwreq_data wrqu;
  3001. iface = dev->priv;
  3002. local = iface->local;
  3003. /* Send disconnect event, e.g., to trigger reassociation after resume
  3004. * if wpa_supplicant is used. */
  3005. memset(&wrqu, 0, sizeof(wrqu));
  3006. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  3007. wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
  3008. /* Disable hardware and firmware */
  3009. prism2_hw_shutdown(dev, 0);
  3010. }
  3011. #endif /* PRISM2_PLX */
  3012. /* These might at some point be compiled separately and used as separate
  3013. * kernel modules or linked into one */
  3014. #ifdef PRISM2_DOWNLOAD_SUPPORT
  3015. #include "hostap_download.c"
  3016. #endif /* PRISM2_DOWNLOAD_SUPPORT */
  3017. #ifdef PRISM2_CALLBACK
  3018. /* External hostap_callback.c file can be used to, e.g., blink activity led.
  3019. * This can use platform specific code and must define prism2_callback()
  3020. * function (if PRISM2_CALLBACK is not defined, these function calls are not
  3021. * used. */
  3022. #include "hostap_callback.c"
  3023. #endif /* PRISM2_CALLBACK */