hostap_hw.c 94 KB

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