hfa384x_usb.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127
  1. /* src/prism2/driver/hfa384x_usb.c
  2. *
  3. * Functions that talk to the USB variantof the Intersil hfa384x MAC
  4. *
  5. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  6. * --------------------------------------------------------------------
  7. *
  8. * linux-wlan
  9. *
  10. * The contents of this file are subject to the Mozilla Public
  11. * License Version 1.1 (the "License"); you may not use this file
  12. * except in compliance with the License. You may obtain a copy of
  13. * the License at http://www.mozilla.org/MPL/
  14. *
  15. * Software distributed under the License is distributed on an "AS
  16. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  17. * implied. See the License for the specific language governing
  18. * rights and limitations under the License.
  19. *
  20. * Alternatively, the contents of this file may be used under the
  21. * terms of the GNU Public License version 2 (the "GPL"), in which
  22. * case the provisions of the GPL are applicable instead of the
  23. * above. If you wish to allow the use of your version of this file
  24. * only under the terms of the GPL and not to allow others to use
  25. * your version of this file under the MPL, indicate your decision
  26. * by deleting the provisions above and replace them with the notice
  27. * and other provisions required by the GPL. If you do not delete
  28. * the provisions above, a recipient may use your version of this
  29. * file under either the MPL or the GPL.
  30. *
  31. * --------------------------------------------------------------------
  32. *
  33. * Inquiries regarding the linux-wlan Open Source project can be
  34. * made directly to:
  35. *
  36. * AbsoluteValue Systems Inc.
  37. * info@linux-wlan.com
  38. * http://www.linux-wlan.com
  39. *
  40. * --------------------------------------------------------------------
  41. *
  42. * Portions of the development of this software were funded by
  43. * Intersil Corporation as part of PRISM(R) chipset product development.
  44. *
  45. * --------------------------------------------------------------------
  46. *
  47. * This file implements functions that correspond to the prism2/hfa384x
  48. * 802.11 MAC hardware and firmware host interface.
  49. *
  50. * The functions can be considered to represent several levels of
  51. * abstraction. The lowest level functions are simply C-callable wrappers
  52. * around the register accesses. The next higher level represents C-callable
  53. * prism2 API functions that match the Intersil documentation as closely
  54. * as is reasonable. The next higher layer implements common sequences
  55. * of invocations of the API layer (e.g. write to bap, followed by cmd).
  56. *
  57. * Common sequences:
  58. * hfa384x_drvr_xxx Highest level abstractions provided by the
  59. * hfa384x code. They are driver defined wrappers
  60. * for common sequences. These functions generally
  61. * use the services of the lower levels.
  62. *
  63. * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These
  64. * functions are wrappers for the RID get/set
  65. * sequence. They call copy_[to|from]_bap() and
  66. * cmd_access(). These functions operate on the
  67. * RIDs and buffers without validation. The caller
  68. * is responsible for that.
  69. *
  70. * API wrapper functions:
  71. * hfa384x_cmd_xxx functions that provide access to the f/w commands.
  72. * The function arguments correspond to each command
  73. * argument, even command arguments that get packed
  74. * into single registers. These functions _just_
  75. * issue the command by setting the cmd/parm regs
  76. * & reading the status/resp regs. Additional
  77. * activities required to fully use a command
  78. * (read/write from/to bap, get/set int status etc.)
  79. * are implemented separately. Think of these as
  80. * C-callable prism2 commands.
  81. *
  82. * Lowest Layer Functions:
  83. * hfa384x_docmd_xxx These functions implement the sequence required
  84. * to issue any prism2 command. Primarily used by the
  85. * hfa384x_cmd_xxx functions.
  86. *
  87. * hfa384x_bap_xxx BAP read/write access functions.
  88. * Note: we usually use BAP0 for non-interrupt context
  89. * and BAP1 for interrupt context.
  90. *
  91. * hfa384x_dl_xxx download related functions.
  92. *
  93. * Driver State Issues:
  94. * Note that there are two pairs of functions that manage the
  95. * 'initialized' and 'running' states of the hw/MAC combo. The four
  96. * functions are create(), destroy(), start(), and stop(). create()
  97. * sets up the data structures required to support the hfa384x_*
  98. * functions and destroy() cleans them up. The start() function gets
  99. * the actual hardware running and enables the interrupts. The stop()
  100. * function shuts the hardware down. The sequence should be:
  101. * create()
  102. * start()
  103. * .
  104. * . Do interesting things w/ the hardware
  105. * .
  106. * stop()
  107. * destroy()
  108. *
  109. * Note that destroy() can be called without calling stop() first.
  110. * --------------------------------------------------------------------
  111. */
  112. #include <linux/module.h>
  113. #include <linux/kernel.h>
  114. #include <linux/sched.h>
  115. #include <linux/types.h>
  116. #include <linux/slab.h>
  117. #include <linux/wireless.h>
  118. #include <linux/netdevice.h>
  119. #include <linux/timer.h>
  120. #include <linux/io.h>
  121. #include <linux/delay.h>
  122. #include <asm/byteorder.h>
  123. #include <linux/bitops.h>
  124. #include <linux/list.h>
  125. #include <linux/usb.h>
  126. #include <linux/byteorder/generic.h>
  127. #define SUBMIT_URB(u, f) usb_submit_urb(u, f)
  128. #include "p80211types.h"
  129. #include "p80211hdr.h"
  130. #include "p80211mgmt.h"
  131. #include "p80211conv.h"
  132. #include "p80211msg.h"
  133. #include "p80211netdev.h"
  134. #include "p80211req.h"
  135. #include "p80211metadef.h"
  136. #include "p80211metastruct.h"
  137. #include "hfa384x.h"
  138. #include "prism2mgmt.h"
  139. enum cmd_mode {
  140. DOWAIT = 0,
  141. DOASYNC
  142. };
  143. #define THROTTLE_JIFFIES (HZ/8)
  144. #define URB_ASYNC_UNLINK 0
  145. #define USB_QUEUE_BULK 0
  146. #define ROUNDUP64(a) (((a)+63)&~63)
  147. #ifdef DEBUG_USB
  148. static void dbprint_urb(struct urb *urb);
  149. #endif
  150. static void
  151. hfa384x_int_rxmonitor(wlandevice_t *wlandev, hfa384x_usb_rxfrm_t *rxfrm);
  152. static void hfa384x_usb_defer(struct work_struct *data);
  153. static int submit_rx_urb(hfa384x_t *hw, gfp_t flags);
  154. static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t flags);
  155. /*---------------------------------------------------*/
  156. /* Callbacks */
  157. static void hfa384x_usbout_callback(struct urb *urb);
  158. static void hfa384x_ctlxout_callback(struct urb *urb);
  159. static void hfa384x_usbin_callback(struct urb *urb);
  160. static void
  161. hfa384x_usbin_txcompl(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
  162. static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb);
  163. static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin);
  164. static void
  165. hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout);
  166. static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
  167. int urb_status);
  168. /*---------------------------------------------------*/
  169. /* Functions to support the prism2 usb command queue */
  170. static void hfa384x_usbctlxq_run(hfa384x_t *hw);
  171. static void hfa384x_usbctlx_reqtimerfn(unsigned long data);
  172. static void hfa384x_usbctlx_resptimerfn(unsigned long data);
  173. static void hfa384x_usb_throttlefn(unsigned long data);
  174. static void hfa384x_usbctlx_completion_task(unsigned long data);
  175. static void hfa384x_usbctlx_reaper_task(unsigned long data);
  176. static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
  177. static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
  178. struct usbctlx_completor {
  179. int (*complete)(struct usbctlx_completor *);
  180. };
  181. static int
  182. hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
  183. hfa384x_usbctlx_t *ctlx,
  184. struct usbctlx_completor *completor);
  185. static int
  186. unlocked_usbctlx_cancel_async(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
  187. static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
  188. static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx);
  189. static int
  190. usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
  191. hfa384x_cmdresult_t *result);
  192. static void
  193. usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
  194. hfa384x_rridresult_t *result);
  195. /*---------------------------------------------------*/
  196. /* Low level req/resp CTLX formatters and submitters */
  197. static int
  198. hfa384x_docmd(hfa384x_t *hw,
  199. enum cmd_mode mode,
  200. hfa384x_metacmd_t *cmd,
  201. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
  202. static int
  203. hfa384x_dorrid(hfa384x_t *hw,
  204. enum cmd_mode mode,
  205. u16 rid,
  206. void *riddata,
  207. unsigned int riddatalen,
  208. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
  209. static int
  210. hfa384x_dowrid(hfa384x_t *hw,
  211. enum cmd_mode mode,
  212. u16 rid,
  213. void *riddata,
  214. unsigned int riddatalen,
  215. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
  216. static int
  217. hfa384x_dormem(hfa384x_t *hw,
  218. enum cmd_mode mode,
  219. u16 page,
  220. u16 offset,
  221. void *data,
  222. unsigned int len,
  223. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
  224. static int
  225. hfa384x_dowmem(hfa384x_t *hw,
  226. enum cmd_mode mode,
  227. u16 page,
  228. u16 offset,
  229. void *data,
  230. unsigned int len,
  231. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data);
  232. static int hfa384x_isgood_pdrcode(u16 pdrcode);
  233. static inline const char *ctlxstr(CTLX_STATE s)
  234. {
  235. static const char * const ctlx_str[] = {
  236. "Initial state",
  237. "Complete",
  238. "Request failed",
  239. "Request pending",
  240. "Request packet submitted",
  241. "Request packet completed",
  242. "Response packet completed"
  243. };
  244. return ctlx_str[s];
  245. };
  246. static inline hfa384x_usbctlx_t *get_active_ctlx(hfa384x_t *hw)
  247. {
  248. return list_entry(hw->ctlxq.active.next, hfa384x_usbctlx_t, list);
  249. }
  250. #ifdef DEBUG_USB
  251. void dbprint_urb(struct urb *urb)
  252. {
  253. pr_debug("urb->pipe=0x%08x\n", urb->pipe);
  254. pr_debug("urb->status=0x%08x\n", urb->status);
  255. pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags);
  256. pr_debug("urb->transfer_buffer=0x%08x\n",
  257. (unsigned int)urb->transfer_buffer);
  258. pr_debug("urb->transfer_buffer_length=0x%08x\n",
  259. urb->transfer_buffer_length);
  260. pr_debug("urb->actual_length=0x%08x\n", urb->actual_length);
  261. pr_debug("urb->bandwidth=0x%08x\n", urb->bandwidth);
  262. pr_debug("urb->setup_packet(ctl)=0x%08x\n",
  263. (unsigned int)urb->setup_packet);
  264. pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame);
  265. pr_debug("urb->interval(irq)=0x%08x\n", urb->interval);
  266. pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count);
  267. pr_debug("urb->timeout=0x%08x\n", urb->timeout);
  268. pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context);
  269. pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete);
  270. }
  271. #endif
  272. /*----------------------------------------------------------------
  273. * submit_rx_urb
  274. *
  275. * Listen for input data on the BULK-IN pipe. If the pipe has
  276. * stalled then schedule it to be reset.
  277. *
  278. * Arguments:
  279. * hw device struct
  280. * memflags memory allocation flags
  281. *
  282. * Returns:
  283. * error code from submission
  284. *
  285. * Call context:
  286. * Any
  287. ----------------------------------------------------------------*/
  288. static int submit_rx_urb(hfa384x_t *hw, gfp_t memflags)
  289. {
  290. struct sk_buff *skb;
  291. int result;
  292. skb = dev_alloc_skb(sizeof(hfa384x_usbin_t));
  293. if (skb == NULL) {
  294. result = -ENOMEM;
  295. goto done;
  296. }
  297. /* Post the IN urb */
  298. usb_fill_bulk_urb(&hw->rx_urb, hw->usb,
  299. hw->endp_in,
  300. skb->data, sizeof(hfa384x_usbin_t),
  301. hfa384x_usbin_callback, hw->wlandev);
  302. hw->rx_urb_skb = skb;
  303. result = -ENOLINK;
  304. if (!hw->wlandev->hwremoved &&
  305. !test_bit(WORK_RX_HALT, &hw->usb_flags)) {
  306. result = SUBMIT_URB(&hw->rx_urb, memflags);
  307. /* Check whether we need to reset the RX pipe */
  308. if (result == -EPIPE) {
  309. netdev_warn(hw->wlandev->netdev,
  310. "%s rx pipe stalled: requesting reset\n",
  311. hw->wlandev->netdev->name);
  312. if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
  313. schedule_work(&hw->usb_work);
  314. }
  315. }
  316. /* Don't leak memory if anything should go wrong */
  317. if (result != 0) {
  318. dev_kfree_skb(skb);
  319. hw->rx_urb_skb = NULL;
  320. }
  321. done:
  322. return result;
  323. }
  324. /*----------------------------------------------------------------
  325. * submit_tx_urb
  326. *
  327. * Prepares and submits the URB of transmitted data. If the
  328. * submission fails then it will schedule the output pipe to
  329. * be reset.
  330. *
  331. * Arguments:
  332. * hw device struct
  333. * tx_urb URB of data for transmission
  334. * memflags memory allocation flags
  335. *
  336. * Returns:
  337. * error code from submission
  338. *
  339. * Call context:
  340. * Any
  341. ----------------------------------------------------------------*/
  342. static int submit_tx_urb(hfa384x_t *hw, struct urb *tx_urb, gfp_t memflags)
  343. {
  344. struct net_device *netdev = hw->wlandev->netdev;
  345. int result;
  346. result = -ENOLINK;
  347. if (netif_running(netdev)) {
  348. if (!hw->wlandev->hwremoved &&
  349. !test_bit(WORK_TX_HALT, &hw->usb_flags)) {
  350. result = SUBMIT_URB(tx_urb, memflags);
  351. /* Test whether we need to reset the TX pipe */
  352. if (result == -EPIPE) {
  353. netdev_warn(hw->wlandev->netdev,
  354. "%s tx pipe stalled: requesting reset\n",
  355. netdev->name);
  356. set_bit(WORK_TX_HALT, &hw->usb_flags);
  357. schedule_work(&hw->usb_work);
  358. } else if (result == 0) {
  359. netif_stop_queue(netdev);
  360. }
  361. }
  362. }
  363. return result;
  364. }
  365. /*----------------------------------------------------------------
  366. * hfa394x_usb_defer
  367. *
  368. * There are some things that the USB stack cannot do while
  369. * in interrupt context, so we arrange this function to run
  370. * in process context.
  371. *
  372. * Arguments:
  373. * hw device structure
  374. *
  375. * Returns:
  376. * nothing
  377. *
  378. * Call context:
  379. * process (by design)
  380. ----------------------------------------------------------------*/
  381. static void hfa384x_usb_defer(struct work_struct *data)
  382. {
  383. hfa384x_t *hw = container_of(data, struct hfa384x, usb_work);
  384. struct net_device *netdev = hw->wlandev->netdev;
  385. /* Don't bother trying to reset anything if the plug
  386. * has been pulled ...
  387. */
  388. if (hw->wlandev->hwremoved)
  389. return;
  390. /* Reception has stopped: try to reset the input pipe */
  391. if (test_bit(WORK_RX_HALT, &hw->usb_flags)) {
  392. int ret;
  393. usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */
  394. ret = usb_clear_halt(hw->usb, hw->endp_in);
  395. if (ret != 0) {
  396. netdev_err(hw->wlandev->netdev,
  397. "Failed to clear rx pipe for %s: err=%d\n",
  398. netdev->name, ret);
  399. } else {
  400. netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n",
  401. netdev->name);
  402. clear_bit(WORK_RX_HALT, &hw->usb_flags);
  403. set_bit(WORK_RX_RESUME, &hw->usb_flags);
  404. }
  405. }
  406. /* Resume receiving data back from the device. */
  407. if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) {
  408. int ret;
  409. ret = submit_rx_urb(hw, GFP_KERNEL);
  410. if (ret != 0) {
  411. netdev_err(hw->wlandev->netdev,
  412. "Failed to resume %s rx pipe.\n",
  413. netdev->name);
  414. } else {
  415. clear_bit(WORK_RX_RESUME, &hw->usb_flags);
  416. }
  417. }
  418. /* Transmission has stopped: try to reset the output pipe */
  419. if (test_bit(WORK_TX_HALT, &hw->usb_flags)) {
  420. int ret;
  421. usb_kill_urb(&hw->tx_urb);
  422. ret = usb_clear_halt(hw->usb, hw->endp_out);
  423. if (ret != 0) {
  424. netdev_err(hw->wlandev->netdev,
  425. "Failed to clear tx pipe for %s: err=%d\n",
  426. netdev->name, ret);
  427. } else {
  428. netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n",
  429. netdev->name);
  430. clear_bit(WORK_TX_HALT, &hw->usb_flags);
  431. set_bit(WORK_TX_RESUME, &hw->usb_flags);
  432. /* Stopping the BULK-OUT pipe also blocked
  433. * us from sending any more CTLX URBs, so
  434. * we need to re-run our queue ...
  435. */
  436. hfa384x_usbctlxq_run(hw);
  437. }
  438. }
  439. /* Resume transmitting. */
  440. if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags))
  441. netif_wake_queue(hw->wlandev->netdev);
  442. }
  443. /*----------------------------------------------------------------
  444. * hfa384x_create
  445. *
  446. * Sets up the hfa384x_t data structure for use. Note this
  447. * does _not_ initialize the actual hardware, just the data structures
  448. * we use to keep track of its state.
  449. *
  450. * Arguments:
  451. * hw device structure
  452. * irq device irq number
  453. * iobase i/o base address for register access
  454. * membase memory base address for register access
  455. *
  456. * Returns:
  457. * nothing
  458. *
  459. * Side effects:
  460. *
  461. * Call context:
  462. * process
  463. ----------------------------------------------------------------*/
  464. void hfa384x_create(hfa384x_t *hw, struct usb_device *usb)
  465. {
  466. memset(hw, 0, sizeof(hfa384x_t));
  467. hw->usb = usb;
  468. /* set up the endpoints */
  469. hw->endp_in = usb_rcvbulkpipe(usb, 1);
  470. hw->endp_out = usb_sndbulkpipe(usb, 2);
  471. /* Set up the waitq */
  472. init_waitqueue_head(&hw->cmdq);
  473. /* Initialize the command queue */
  474. spin_lock_init(&hw->ctlxq.lock);
  475. INIT_LIST_HEAD(&hw->ctlxq.pending);
  476. INIT_LIST_HEAD(&hw->ctlxq.active);
  477. INIT_LIST_HEAD(&hw->ctlxq.completing);
  478. INIT_LIST_HEAD(&hw->ctlxq.reapable);
  479. /* Initialize the authentication queue */
  480. skb_queue_head_init(&hw->authq);
  481. tasklet_init(&hw->reaper_bh,
  482. hfa384x_usbctlx_reaper_task, (unsigned long)hw);
  483. tasklet_init(&hw->completion_bh,
  484. hfa384x_usbctlx_completion_task, (unsigned long)hw);
  485. INIT_WORK(&hw->link_bh, prism2sta_processing_defer);
  486. INIT_WORK(&hw->usb_work, hfa384x_usb_defer);
  487. setup_timer(&hw->throttle, hfa384x_usb_throttlefn, (unsigned long)hw);
  488. setup_timer(&hw->resptimer, hfa384x_usbctlx_resptimerfn,
  489. (unsigned long)hw);
  490. setup_timer(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn,
  491. (unsigned long)hw);
  492. usb_init_urb(&hw->rx_urb);
  493. usb_init_urb(&hw->tx_urb);
  494. usb_init_urb(&hw->ctlx_urb);
  495. hw->link_status = HFA384x_LINK_NOTCONNECTED;
  496. hw->state = HFA384x_STATE_INIT;
  497. INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer);
  498. setup_timer(&hw->commsqual_timer, prism2sta_commsqual_timer,
  499. (unsigned long)hw);
  500. }
  501. /*----------------------------------------------------------------
  502. * hfa384x_destroy
  503. *
  504. * Partner to hfa384x_create(). This function cleans up the hw
  505. * structure so that it can be freed by the caller using a simple
  506. * kfree. Currently, this function is just a placeholder. If, at some
  507. * point in the future, an hw in the 'shutdown' state requires a 'deep'
  508. * kfree, this is where it should be done. Note that if this function
  509. * is called on a _running_ hw structure, the drvr_stop() function is
  510. * called.
  511. *
  512. * Arguments:
  513. * hw device structure
  514. *
  515. * Returns:
  516. * nothing, this function is not allowed to fail.
  517. *
  518. * Side effects:
  519. *
  520. * Call context:
  521. * process
  522. ----------------------------------------------------------------*/
  523. void hfa384x_destroy(hfa384x_t *hw)
  524. {
  525. struct sk_buff *skb;
  526. if (hw->state == HFA384x_STATE_RUNNING)
  527. hfa384x_drvr_stop(hw);
  528. hw->state = HFA384x_STATE_PREINIT;
  529. kfree(hw->scanresults);
  530. hw->scanresults = NULL;
  531. /* Now to clean out the auth queue */
  532. while ((skb = skb_dequeue(&hw->authq)))
  533. dev_kfree_skb(skb);
  534. }
  535. static hfa384x_usbctlx_t *usbctlx_alloc(void)
  536. {
  537. hfa384x_usbctlx_t *ctlx;
  538. ctlx = kzalloc(sizeof(*ctlx),
  539. in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
  540. if (ctlx != NULL)
  541. init_completion(&ctlx->done);
  542. return ctlx;
  543. }
  544. static int
  545. usbctlx_get_status(const hfa384x_usb_cmdresp_t *cmdresp,
  546. hfa384x_cmdresult_t *result)
  547. {
  548. result->status = le16_to_cpu(cmdresp->status);
  549. result->resp0 = le16_to_cpu(cmdresp->resp0);
  550. result->resp1 = le16_to_cpu(cmdresp->resp1);
  551. result->resp2 = le16_to_cpu(cmdresp->resp2);
  552. pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n",
  553. result->status, result->resp0, result->resp1, result->resp2);
  554. return result->status & HFA384x_STATUS_RESULT;
  555. }
  556. static void
  557. usbctlx_get_rridresult(const hfa384x_usb_rridresp_t *rridresp,
  558. hfa384x_rridresult_t *result)
  559. {
  560. result->rid = le16_to_cpu(rridresp->rid);
  561. result->riddata = rridresp->data;
  562. result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2);
  563. }
  564. /*----------------------------------------------------------------
  565. * Completor object:
  566. * This completor must be passed to hfa384x_usbctlx_complete_sync()
  567. * when processing a CTLX that returns a hfa384x_cmdresult_t structure.
  568. ----------------------------------------------------------------*/
  569. struct usbctlx_cmd_completor {
  570. struct usbctlx_completor head;
  571. const hfa384x_usb_cmdresp_t *cmdresp;
  572. hfa384x_cmdresult_t *result;
  573. };
  574. static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head)
  575. {
  576. struct usbctlx_cmd_completor *complete;
  577. complete = (struct usbctlx_cmd_completor *)head;
  578. return usbctlx_get_status(complete->cmdresp, complete->result);
  579. }
  580. static inline struct usbctlx_completor *init_cmd_completor(
  581. struct usbctlx_cmd_completor
  582. *completor,
  583. const hfa384x_usb_cmdresp_t
  584. *cmdresp,
  585. hfa384x_cmdresult_t *result)
  586. {
  587. completor->head.complete = usbctlx_cmd_completor_fn;
  588. completor->cmdresp = cmdresp;
  589. completor->result = result;
  590. return &(completor->head);
  591. }
  592. /*----------------------------------------------------------------
  593. * Completor object:
  594. * This completor must be passed to hfa384x_usbctlx_complete_sync()
  595. * when processing a CTLX that reads a RID.
  596. ----------------------------------------------------------------*/
  597. struct usbctlx_rrid_completor {
  598. struct usbctlx_completor head;
  599. const hfa384x_usb_rridresp_t *rridresp;
  600. void *riddata;
  601. unsigned int riddatalen;
  602. };
  603. static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head)
  604. {
  605. struct usbctlx_rrid_completor *complete;
  606. hfa384x_rridresult_t rridresult;
  607. complete = (struct usbctlx_rrid_completor *)head;
  608. usbctlx_get_rridresult(complete->rridresp, &rridresult);
  609. /* Validate the length, note body len calculation in bytes */
  610. if (rridresult.riddata_len != complete->riddatalen) {
  611. pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n",
  612. rridresult.rid,
  613. complete->riddatalen, rridresult.riddata_len);
  614. return -ENODATA;
  615. }
  616. memcpy(complete->riddata, rridresult.riddata, complete->riddatalen);
  617. return 0;
  618. }
  619. static inline struct usbctlx_completor *init_rrid_completor(
  620. struct usbctlx_rrid_completor
  621. *completor,
  622. const hfa384x_usb_rridresp_t
  623. *rridresp,
  624. void *riddata,
  625. unsigned int riddatalen)
  626. {
  627. completor->head.complete = usbctlx_rrid_completor_fn;
  628. completor->rridresp = rridresp;
  629. completor->riddata = riddata;
  630. completor->riddatalen = riddatalen;
  631. return &(completor->head);
  632. }
  633. /*----------------------------------------------------------------
  634. * Completor object:
  635. * Interprets the results of a synchronous RID-write
  636. ----------------------------------------------------------------*/
  637. #define init_wrid_completor init_cmd_completor
  638. /*----------------------------------------------------------------
  639. * Completor object:
  640. * Interprets the results of a synchronous memory-write
  641. ----------------------------------------------------------------*/
  642. #define init_wmem_completor init_cmd_completor
  643. /*----------------------------------------------------------------
  644. * Completor object:
  645. * Interprets the results of a synchronous memory-read
  646. ----------------------------------------------------------------*/
  647. struct usbctlx_rmem_completor {
  648. struct usbctlx_completor head;
  649. const hfa384x_usb_rmemresp_t *rmemresp;
  650. void *data;
  651. unsigned int len;
  652. };
  653. static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head)
  654. {
  655. struct usbctlx_rmem_completor *complete =
  656. (struct usbctlx_rmem_completor *)head;
  657. pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen);
  658. memcpy(complete->data, complete->rmemresp->data, complete->len);
  659. return 0;
  660. }
  661. static inline struct usbctlx_completor *init_rmem_completor(
  662. struct usbctlx_rmem_completor
  663. *completor,
  664. hfa384x_usb_rmemresp_t
  665. *rmemresp,
  666. void *data,
  667. unsigned int len)
  668. {
  669. completor->head.complete = usbctlx_rmem_completor_fn;
  670. completor->rmemresp = rmemresp;
  671. completor->data = data;
  672. completor->len = len;
  673. return &(completor->head);
  674. }
  675. /*----------------------------------------------------------------
  676. * hfa384x_cb_status
  677. *
  678. * Ctlx_complete handler for async CMD type control exchanges.
  679. * mark the hw struct as such.
  680. *
  681. * Note: If the handling is changed here, it should probably be
  682. * changed in docmd as well.
  683. *
  684. * Arguments:
  685. * hw hw struct
  686. * ctlx completed CTLX
  687. *
  688. * Returns:
  689. * nothing
  690. *
  691. * Side effects:
  692. *
  693. * Call context:
  694. * interrupt
  695. ----------------------------------------------------------------*/
  696. static void hfa384x_cb_status(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
  697. {
  698. if (ctlx->usercb != NULL) {
  699. hfa384x_cmdresult_t cmdresult;
  700. if (ctlx->state != CTLX_COMPLETE) {
  701. memset(&cmdresult, 0, sizeof(cmdresult));
  702. cmdresult.status =
  703. HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR);
  704. } else {
  705. usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult);
  706. }
  707. ctlx->usercb(hw, &cmdresult, ctlx->usercb_data);
  708. }
  709. }
  710. /*----------------------------------------------------------------
  711. * hfa384x_cb_rrid
  712. *
  713. * CTLX completion handler for async RRID type control exchanges.
  714. *
  715. * Note: If the handling is changed here, it should probably be
  716. * changed in dorrid as well.
  717. *
  718. * Arguments:
  719. * hw hw struct
  720. * ctlx completed CTLX
  721. *
  722. * Returns:
  723. * nothing
  724. *
  725. * Side effects:
  726. *
  727. * Call context:
  728. * interrupt
  729. ----------------------------------------------------------------*/
  730. static void hfa384x_cb_rrid(hfa384x_t *hw, const hfa384x_usbctlx_t *ctlx)
  731. {
  732. if (ctlx->usercb != NULL) {
  733. hfa384x_rridresult_t rridresult;
  734. if (ctlx->state != CTLX_COMPLETE) {
  735. memset(&rridresult, 0, sizeof(rridresult));
  736. rridresult.rid = le16_to_cpu(ctlx->outbuf.rridreq.rid);
  737. } else {
  738. usbctlx_get_rridresult(&ctlx->inbuf.rridresp,
  739. &rridresult);
  740. }
  741. ctlx->usercb(hw, &rridresult, ctlx->usercb_data);
  742. }
  743. }
  744. static inline int hfa384x_docmd_wait(hfa384x_t *hw, hfa384x_metacmd_t *cmd)
  745. {
  746. return hfa384x_docmd(hw, DOWAIT, cmd, NULL, NULL, NULL);
  747. }
  748. static inline int
  749. hfa384x_docmd_async(hfa384x_t *hw,
  750. hfa384x_metacmd_t *cmd,
  751. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
  752. {
  753. return hfa384x_docmd(hw, DOASYNC, cmd, cmdcb, usercb, usercb_data);
  754. }
  755. static inline int
  756. hfa384x_dorrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
  757. unsigned int riddatalen)
  758. {
  759. return hfa384x_dorrid(hw, DOWAIT,
  760. rid, riddata, riddatalen, NULL, NULL, NULL);
  761. }
  762. static inline int
  763. hfa384x_dorrid_async(hfa384x_t *hw,
  764. u16 rid, void *riddata, unsigned int riddatalen,
  765. ctlx_cmdcb_t cmdcb,
  766. ctlx_usercb_t usercb, void *usercb_data)
  767. {
  768. return hfa384x_dorrid(hw, DOASYNC,
  769. rid, riddata, riddatalen,
  770. cmdcb, usercb, usercb_data);
  771. }
  772. static inline int
  773. hfa384x_dowrid_wait(hfa384x_t *hw, u16 rid, void *riddata,
  774. unsigned int riddatalen)
  775. {
  776. return hfa384x_dowrid(hw, DOWAIT,
  777. rid, riddata, riddatalen, NULL, NULL, NULL);
  778. }
  779. static inline int
  780. hfa384x_dowrid_async(hfa384x_t *hw,
  781. u16 rid, void *riddata, unsigned int riddatalen,
  782. ctlx_cmdcb_t cmdcb,
  783. ctlx_usercb_t usercb, void *usercb_data)
  784. {
  785. return hfa384x_dowrid(hw, DOASYNC,
  786. rid, riddata, riddatalen,
  787. cmdcb, usercb, usercb_data);
  788. }
  789. static inline int
  790. hfa384x_dormem_wait(hfa384x_t *hw,
  791. u16 page, u16 offset, void *data, unsigned int len)
  792. {
  793. return hfa384x_dormem(hw, DOWAIT,
  794. page, offset, data, len, NULL, NULL, NULL);
  795. }
  796. static inline int
  797. hfa384x_dormem_async(hfa384x_t *hw,
  798. u16 page, u16 offset, void *data, unsigned int len,
  799. ctlx_cmdcb_t cmdcb,
  800. ctlx_usercb_t usercb, void *usercb_data)
  801. {
  802. return hfa384x_dormem(hw, DOASYNC,
  803. page, offset, data, len,
  804. cmdcb, usercb, usercb_data);
  805. }
  806. static inline int
  807. hfa384x_dowmem_wait(hfa384x_t *hw,
  808. u16 page, u16 offset, void *data, unsigned int len)
  809. {
  810. return hfa384x_dowmem(hw, DOWAIT,
  811. page, offset, data, len, NULL, NULL, NULL);
  812. }
  813. static inline int
  814. hfa384x_dowmem_async(hfa384x_t *hw,
  815. u16 page,
  816. u16 offset,
  817. void *data,
  818. unsigned int len,
  819. ctlx_cmdcb_t cmdcb,
  820. ctlx_usercb_t usercb, void *usercb_data)
  821. {
  822. return hfa384x_dowmem(hw, DOASYNC,
  823. page, offset, data, len,
  824. cmdcb, usercb, usercb_data);
  825. }
  826. /*----------------------------------------------------------------
  827. * hfa384x_cmd_initialize
  828. *
  829. * Issues the initialize command and sets the hw->state based
  830. * on the result.
  831. *
  832. * Arguments:
  833. * hw device structure
  834. *
  835. * Returns:
  836. * 0 success
  837. * >0 f/w reported error - f/w status code
  838. * <0 driver reported error
  839. *
  840. * Side effects:
  841. *
  842. * Call context:
  843. * process
  844. ----------------------------------------------------------------*/
  845. int hfa384x_cmd_initialize(hfa384x_t *hw)
  846. {
  847. int result = 0;
  848. int i;
  849. hfa384x_metacmd_t cmd;
  850. cmd.cmd = HFA384x_CMDCODE_INIT;
  851. cmd.parm0 = 0;
  852. cmd.parm1 = 0;
  853. cmd.parm2 = 0;
  854. result = hfa384x_docmd_wait(hw, &cmd);
  855. pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n",
  856. cmd.result.status,
  857. cmd.result.resp0, cmd.result.resp1, cmd.result.resp2);
  858. if (result == 0) {
  859. for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
  860. hw->port_enabled[i] = 0;
  861. }
  862. hw->link_status = HFA384x_LINK_NOTCONNECTED;
  863. return result;
  864. }
  865. /*----------------------------------------------------------------
  866. * hfa384x_cmd_disable
  867. *
  868. * Issues the disable command to stop communications on one of
  869. * the MACs 'ports'.
  870. *
  871. * Arguments:
  872. * hw device structure
  873. * macport MAC port number (host order)
  874. *
  875. * Returns:
  876. * 0 success
  877. * >0 f/w reported failure - f/w status code
  878. * <0 driver reported error (timeout|bad arg)
  879. *
  880. * Side effects:
  881. *
  882. * Call context:
  883. * process
  884. ----------------------------------------------------------------*/
  885. int hfa384x_cmd_disable(hfa384x_t *hw, u16 macport)
  886. {
  887. int result = 0;
  888. hfa384x_metacmd_t cmd;
  889. cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) |
  890. HFA384x_CMD_MACPORT_SET(macport);
  891. cmd.parm0 = 0;
  892. cmd.parm1 = 0;
  893. cmd.parm2 = 0;
  894. result = hfa384x_docmd_wait(hw, &cmd);
  895. return result;
  896. }
  897. /*----------------------------------------------------------------
  898. * hfa384x_cmd_enable
  899. *
  900. * Issues the enable command to enable communications on one of
  901. * the MACs 'ports'.
  902. *
  903. * Arguments:
  904. * hw device structure
  905. * macport MAC port number
  906. *
  907. * Returns:
  908. * 0 success
  909. * >0 f/w reported failure - f/w status code
  910. * <0 driver reported error (timeout|bad arg)
  911. *
  912. * Side effects:
  913. *
  914. * Call context:
  915. * process
  916. ----------------------------------------------------------------*/
  917. int hfa384x_cmd_enable(hfa384x_t *hw, u16 macport)
  918. {
  919. int result = 0;
  920. hfa384x_metacmd_t cmd;
  921. cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) |
  922. HFA384x_CMD_MACPORT_SET(macport);
  923. cmd.parm0 = 0;
  924. cmd.parm1 = 0;
  925. cmd.parm2 = 0;
  926. result = hfa384x_docmd_wait(hw, &cmd);
  927. return result;
  928. }
  929. /*----------------------------------------------------------------
  930. * hfa384x_cmd_monitor
  931. *
  932. * Enables the 'monitor mode' of the MAC. Here's the description of
  933. * monitor mode that I've received thus far:
  934. *
  935. * "The "monitor mode" of operation is that the MAC passes all
  936. * frames for which the PLCP checks are correct. All received
  937. * MPDUs are passed to the host with MAC Port = 7, with a
  938. * receive status of good, FCS error, or undecryptable. Passing
  939. * certain MPDUs is a violation of the 802.11 standard, but useful
  940. * for a debugging tool." Normal communication is not possible
  941. * while monitor mode is enabled.
  942. *
  943. * Arguments:
  944. * hw device structure
  945. * enable a code (0x0b|0x0f) that enables/disables
  946. * monitor mode. (host order)
  947. *
  948. * Returns:
  949. * 0 success
  950. * >0 f/w reported failure - f/w status code
  951. * <0 driver reported error (timeout|bad arg)
  952. *
  953. * Side effects:
  954. *
  955. * Call context:
  956. * process
  957. ----------------------------------------------------------------*/
  958. int hfa384x_cmd_monitor(hfa384x_t *hw, u16 enable)
  959. {
  960. int result = 0;
  961. hfa384x_metacmd_t cmd;
  962. cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) |
  963. HFA384x_CMD_AINFO_SET(enable);
  964. cmd.parm0 = 0;
  965. cmd.parm1 = 0;
  966. cmd.parm2 = 0;
  967. result = hfa384x_docmd_wait(hw, &cmd);
  968. return result;
  969. }
  970. /*----------------------------------------------------------------
  971. * hfa384x_cmd_download
  972. *
  973. * Sets the controls for the MAC controller code/data download
  974. * process. The arguments set the mode and address associated
  975. * with a download. Note that the aux registers should be enabled
  976. * prior to setting one of the download enable modes.
  977. *
  978. * Arguments:
  979. * hw device structure
  980. * mode 0 - Disable programming and begin code exec
  981. * 1 - Enable volatile mem programming
  982. * 2 - Enable non-volatile mem programming
  983. * 3 - Program non-volatile section from NV download
  984. * buffer.
  985. * (host order)
  986. * lowaddr
  987. * highaddr For mode 1, sets the high & low order bits of
  988. * the "destination address". This address will be
  989. * the execution start address when download is
  990. * subsequently disabled.
  991. * For mode 2, sets the high & low order bits of
  992. * the destination in NV ram.
  993. * For modes 0 & 3, should be zero. (host order)
  994. * NOTE: these are CMD format.
  995. * codelen Length of the data to write in mode 2,
  996. * zero otherwise. (host order)
  997. *
  998. * Returns:
  999. * 0 success
  1000. * >0 f/w reported failure - f/w status code
  1001. * <0 driver reported error (timeout|bad arg)
  1002. *
  1003. * Side effects:
  1004. *
  1005. * Call context:
  1006. * process
  1007. ----------------------------------------------------------------*/
  1008. int hfa384x_cmd_download(hfa384x_t *hw, u16 mode, u16 lowaddr,
  1009. u16 highaddr, u16 codelen)
  1010. {
  1011. int result = 0;
  1012. hfa384x_metacmd_t cmd;
  1013. pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n",
  1014. mode, lowaddr, highaddr, codelen);
  1015. cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) |
  1016. HFA384x_CMD_PROGMODE_SET(mode));
  1017. cmd.parm0 = lowaddr;
  1018. cmd.parm1 = highaddr;
  1019. cmd.parm2 = codelen;
  1020. result = hfa384x_docmd_wait(hw, &cmd);
  1021. return result;
  1022. }
  1023. /*----------------------------------------------------------------
  1024. * hfa384x_corereset
  1025. *
  1026. * Perform a reset of the hfa38xx MAC core. We assume that the hw
  1027. * structure is in its "created" state. That is, it is initialized
  1028. * with proper values. Note that if a reset is done after the
  1029. * device has been active for awhile, the caller might have to clean
  1030. * up some leftover cruft in the hw structure.
  1031. *
  1032. * Arguments:
  1033. * hw device structure
  1034. * holdtime how long (in ms) to hold the reset
  1035. * settletime how long (in ms) to wait after releasing
  1036. * the reset
  1037. *
  1038. * Returns:
  1039. * nothing
  1040. *
  1041. * Side effects:
  1042. *
  1043. * Call context:
  1044. * process
  1045. ----------------------------------------------------------------*/
  1046. int hfa384x_corereset(hfa384x_t *hw, int holdtime, int settletime, int genesis)
  1047. {
  1048. int result;
  1049. result = usb_reset_device(hw->usb);
  1050. if (result < 0) {
  1051. netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n",
  1052. result);
  1053. }
  1054. return result;
  1055. }
  1056. /*----------------------------------------------------------------
  1057. * hfa384x_usbctlx_complete_sync
  1058. *
  1059. * Waits for a synchronous CTLX object to complete,
  1060. * and then handles the response.
  1061. *
  1062. * Arguments:
  1063. * hw device structure
  1064. * ctlx CTLX ptr
  1065. * completor functor object to decide what to
  1066. * do with the CTLX's result.
  1067. *
  1068. * Returns:
  1069. * 0 Success
  1070. * -ERESTARTSYS Interrupted by a signal
  1071. * -EIO CTLX failed
  1072. * -ENODEV Adapter was unplugged
  1073. * ??? Result from completor
  1074. *
  1075. * Side effects:
  1076. *
  1077. * Call context:
  1078. * process
  1079. ----------------------------------------------------------------*/
  1080. static int hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
  1081. hfa384x_usbctlx_t *ctlx,
  1082. struct usbctlx_completor *completor)
  1083. {
  1084. unsigned long flags;
  1085. int result;
  1086. result = wait_for_completion_interruptible(&ctlx->done);
  1087. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  1088. /*
  1089. * We can only handle the CTLX if the USB disconnect
  1090. * function has not run yet ...
  1091. */
  1092. cleanup:
  1093. if (hw->wlandev->hwremoved) {
  1094. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  1095. result = -ENODEV;
  1096. } else if (result != 0) {
  1097. int runqueue = 0;
  1098. /*
  1099. * We were probably interrupted, so delete
  1100. * this CTLX asynchronously, kill the timers
  1101. * and the URB, and then start the next
  1102. * pending CTLX.
  1103. *
  1104. * NOTE: We can only delete the timers and
  1105. * the URB if this CTLX is active.
  1106. */
  1107. if (ctlx == get_active_ctlx(hw)) {
  1108. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  1109. del_singleshot_timer_sync(&hw->reqtimer);
  1110. del_singleshot_timer_sync(&hw->resptimer);
  1111. hw->req_timer_done = 1;
  1112. hw->resp_timer_done = 1;
  1113. usb_kill_urb(&hw->ctlx_urb);
  1114. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  1115. runqueue = 1;
  1116. /*
  1117. * This scenario is so unlikely that I'm
  1118. * happy with a grubby "goto" solution ...
  1119. */
  1120. if (hw->wlandev->hwremoved)
  1121. goto cleanup;
  1122. }
  1123. /*
  1124. * The completion task will send this CTLX
  1125. * to the reaper the next time it runs. We
  1126. * are no longer in a hurry.
  1127. */
  1128. ctlx->reapable = 1;
  1129. ctlx->state = CTLX_REQ_FAILED;
  1130. list_move_tail(&ctlx->list, &hw->ctlxq.completing);
  1131. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  1132. if (runqueue)
  1133. hfa384x_usbctlxq_run(hw);
  1134. } else {
  1135. if (ctlx->state == CTLX_COMPLETE) {
  1136. result = completor->complete(completor);
  1137. } else {
  1138. netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n",
  1139. le16_to_cpu(ctlx->outbuf.type),
  1140. ctlxstr(ctlx->state));
  1141. result = -EIO;
  1142. }
  1143. list_del(&ctlx->list);
  1144. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  1145. kfree(ctlx);
  1146. }
  1147. return result;
  1148. }
  1149. /*----------------------------------------------------------------
  1150. * hfa384x_docmd
  1151. *
  1152. * Constructs a command CTLX and submits it.
  1153. *
  1154. * NOTE: Any changes to the 'post-submit' code in this function
  1155. * need to be carried over to hfa384x_cbcmd() since the handling
  1156. * is virtually identical.
  1157. *
  1158. * Arguments:
  1159. * hw device structure
  1160. * mode DOWAIT or DOASYNC
  1161. * cmd cmd structure. Includes all arguments and result
  1162. * data points. All in host order. in host order
  1163. * cmdcb command-specific callback
  1164. * usercb user callback for async calls, NULL for DOWAIT calls
  1165. * usercb_data user supplied data pointer for async calls, NULL
  1166. * for DOASYNC calls
  1167. *
  1168. * Returns:
  1169. * 0 success
  1170. * -EIO CTLX failure
  1171. * -ERESTARTSYS Awakened on signal
  1172. * >0 command indicated error, Status and Resp0-2 are
  1173. * in hw structure.
  1174. *
  1175. * Side effects:
  1176. *
  1177. *
  1178. * Call context:
  1179. * process
  1180. ----------------------------------------------------------------*/
  1181. static int
  1182. hfa384x_docmd(hfa384x_t *hw,
  1183. enum cmd_mode mode,
  1184. hfa384x_metacmd_t *cmd,
  1185. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
  1186. {
  1187. int result;
  1188. hfa384x_usbctlx_t *ctlx;
  1189. ctlx = usbctlx_alloc();
  1190. if (ctlx == NULL) {
  1191. result = -ENOMEM;
  1192. goto done;
  1193. }
  1194. /* Initialize the command */
  1195. ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ);
  1196. ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd);
  1197. ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0);
  1198. ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1);
  1199. ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2);
  1200. ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq);
  1201. pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n",
  1202. cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2);
  1203. ctlx->reapable = mode;
  1204. ctlx->cmdcb = cmdcb;
  1205. ctlx->usercb = usercb;
  1206. ctlx->usercb_data = usercb_data;
  1207. result = hfa384x_usbctlx_submit(hw, ctlx);
  1208. if (result != 0) {
  1209. kfree(ctlx);
  1210. } else if (mode == DOWAIT) {
  1211. struct usbctlx_cmd_completor completor;
  1212. result =
  1213. hfa384x_usbctlx_complete_sync(hw, ctlx,
  1214. init_cmd_completor(&completor,
  1215. &ctlx->
  1216. inbuf.
  1217. cmdresp,
  1218. &cmd->
  1219. result));
  1220. }
  1221. done:
  1222. return result;
  1223. }
  1224. /*----------------------------------------------------------------
  1225. * hfa384x_dorrid
  1226. *
  1227. * Constructs a read rid CTLX and issues it.
  1228. *
  1229. * NOTE: Any changes to the 'post-submit' code in this function
  1230. * need to be carried over to hfa384x_cbrrid() since the handling
  1231. * is virtually identical.
  1232. *
  1233. * Arguments:
  1234. * hw device structure
  1235. * mode DOWAIT or DOASYNC
  1236. * rid Read RID number (host order)
  1237. * riddata Caller supplied buffer that MAC formatted RID.data
  1238. * record will be written to for DOWAIT calls. Should
  1239. * be NULL for DOASYNC calls.
  1240. * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls.
  1241. * cmdcb command callback for async calls, NULL for DOWAIT calls
  1242. * usercb user callback for async calls, NULL for DOWAIT calls
  1243. * usercb_data user supplied data pointer for async calls, NULL
  1244. * for DOWAIT calls
  1245. *
  1246. * Returns:
  1247. * 0 success
  1248. * -EIO CTLX failure
  1249. * -ERESTARTSYS Awakened on signal
  1250. * -ENODATA riddatalen != macdatalen
  1251. * >0 command indicated error, Status and Resp0-2 are
  1252. * in hw structure.
  1253. *
  1254. * Side effects:
  1255. *
  1256. * Call context:
  1257. * interrupt (DOASYNC)
  1258. * process (DOWAIT or DOASYNC)
  1259. ----------------------------------------------------------------*/
  1260. static int
  1261. hfa384x_dorrid(hfa384x_t *hw,
  1262. enum cmd_mode mode,
  1263. u16 rid,
  1264. void *riddata,
  1265. unsigned int riddatalen,
  1266. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
  1267. {
  1268. int result;
  1269. hfa384x_usbctlx_t *ctlx;
  1270. ctlx = usbctlx_alloc();
  1271. if (ctlx == NULL) {
  1272. result = -ENOMEM;
  1273. goto done;
  1274. }
  1275. /* Initialize the command */
  1276. ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ);
  1277. ctlx->outbuf.rridreq.frmlen =
  1278. cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid));
  1279. ctlx->outbuf.rridreq.rid = cpu_to_le16(rid);
  1280. ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq);
  1281. ctlx->reapable = mode;
  1282. ctlx->cmdcb = cmdcb;
  1283. ctlx->usercb = usercb;
  1284. ctlx->usercb_data = usercb_data;
  1285. /* Submit the CTLX */
  1286. result = hfa384x_usbctlx_submit(hw, ctlx);
  1287. if (result != 0) {
  1288. kfree(ctlx);
  1289. } else if (mode == DOWAIT) {
  1290. struct usbctlx_rrid_completor completor;
  1291. result =
  1292. hfa384x_usbctlx_complete_sync(hw, ctlx,
  1293. init_rrid_completor
  1294. (&completor,
  1295. &ctlx->inbuf.rridresp,
  1296. riddata, riddatalen));
  1297. }
  1298. done:
  1299. return result;
  1300. }
  1301. /*----------------------------------------------------------------
  1302. * hfa384x_dowrid
  1303. *
  1304. * Constructs a write rid CTLX and issues it.
  1305. *
  1306. * NOTE: Any changes to the 'post-submit' code in this function
  1307. * need to be carried over to hfa384x_cbwrid() since the handling
  1308. * is virtually identical.
  1309. *
  1310. * Arguments:
  1311. * hw device structure
  1312. * enum cmd_mode DOWAIT or DOASYNC
  1313. * rid RID code
  1314. * riddata Data portion of RID formatted for MAC
  1315. * riddatalen Length of the data portion in bytes
  1316. * cmdcb command callback for async calls, NULL for DOWAIT calls
  1317. * usercb user callback for async calls, NULL for DOWAIT calls
  1318. * usercb_data user supplied data pointer for async calls
  1319. *
  1320. * Returns:
  1321. * 0 success
  1322. * -ETIMEDOUT timed out waiting for register ready or
  1323. * command completion
  1324. * >0 command indicated error, Status and Resp0-2 are
  1325. * in hw structure.
  1326. *
  1327. * Side effects:
  1328. *
  1329. * Call context:
  1330. * interrupt (DOASYNC)
  1331. * process (DOWAIT or DOASYNC)
  1332. ----------------------------------------------------------------*/
  1333. static int
  1334. hfa384x_dowrid(hfa384x_t *hw,
  1335. enum cmd_mode mode,
  1336. u16 rid,
  1337. void *riddata,
  1338. unsigned int riddatalen,
  1339. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
  1340. {
  1341. int result;
  1342. hfa384x_usbctlx_t *ctlx;
  1343. ctlx = usbctlx_alloc();
  1344. if (ctlx == NULL) {
  1345. result = -ENOMEM;
  1346. goto done;
  1347. }
  1348. /* Initialize the command */
  1349. ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ);
  1350. ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof
  1351. (ctlx->outbuf.wridreq.rid) +
  1352. riddatalen + 1) / 2);
  1353. ctlx->outbuf.wridreq.rid = cpu_to_le16(rid);
  1354. memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen);
  1355. ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) +
  1356. sizeof(ctlx->outbuf.wridreq.frmlen) +
  1357. sizeof(ctlx->outbuf.wridreq.rid) + riddatalen;
  1358. ctlx->reapable = mode;
  1359. ctlx->cmdcb = cmdcb;
  1360. ctlx->usercb = usercb;
  1361. ctlx->usercb_data = usercb_data;
  1362. /* Submit the CTLX */
  1363. result = hfa384x_usbctlx_submit(hw, ctlx);
  1364. if (result != 0) {
  1365. kfree(ctlx);
  1366. } else if (mode == DOWAIT) {
  1367. struct usbctlx_cmd_completor completor;
  1368. hfa384x_cmdresult_t wridresult;
  1369. result = hfa384x_usbctlx_complete_sync(hw,
  1370. ctlx,
  1371. init_wrid_completor
  1372. (&completor,
  1373. &ctlx->inbuf.wridresp,
  1374. &wridresult));
  1375. }
  1376. done:
  1377. return result;
  1378. }
  1379. /*----------------------------------------------------------------
  1380. * hfa384x_dormem
  1381. *
  1382. * Constructs a readmem CTLX and issues it.
  1383. *
  1384. * NOTE: Any changes to the 'post-submit' code in this function
  1385. * need to be carried over to hfa384x_cbrmem() since the handling
  1386. * is virtually identical.
  1387. *
  1388. * Arguments:
  1389. * hw device structure
  1390. * mode DOWAIT or DOASYNC
  1391. * page MAC address space page (CMD format)
  1392. * offset MAC address space offset
  1393. * data Ptr to data buffer to receive read
  1394. * len Length of the data to read (max == 2048)
  1395. * cmdcb command callback for async calls, NULL for DOWAIT calls
  1396. * usercb user callback for async calls, NULL for DOWAIT calls
  1397. * usercb_data user supplied data pointer for async calls
  1398. *
  1399. * Returns:
  1400. * 0 success
  1401. * -ETIMEDOUT timed out waiting for register ready or
  1402. * command completion
  1403. * >0 command indicated error, Status and Resp0-2 are
  1404. * in hw structure.
  1405. *
  1406. * Side effects:
  1407. *
  1408. * Call context:
  1409. * interrupt (DOASYNC)
  1410. * process (DOWAIT or DOASYNC)
  1411. ----------------------------------------------------------------*/
  1412. static int
  1413. hfa384x_dormem(hfa384x_t *hw,
  1414. enum cmd_mode mode,
  1415. u16 page,
  1416. u16 offset,
  1417. void *data,
  1418. unsigned int len,
  1419. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
  1420. {
  1421. int result;
  1422. hfa384x_usbctlx_t *ctlx;
  1423. ctlx = usbctlx_alloc();
  1424. if (ctlx == NULL) {
  1425. result = -ENOMEM;
  1426. goto done;
  1427. }
  1428. /* Initialize the command */
  1429. ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ);
  1430. ctlx->outbuf.rmemreq.frmlen =
  1431. cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) +
  1432. sizeof(ctlx->outbuf.rmemreq.page) + len);
  1433. ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset);
  1434. ctlx->outbuf.rmemreq.page = cpu_to_le16(page);
  1435. ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq);
  1436. pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n",
  1437. ctlx->outbuf.rmemreq.type,
  1438. ctlx->outbuf.rmemreq.frmlen,
  1439. ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page);
  1440. pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq)));
  1441. ctlx->reapable = mode;
  1442. ctlx->cmdcb = cmdcb;
  1443. ctlx->usercb = usercb;
  1444. ctlx->usercb_data = usercb_data;
  1445. result = hfa384x_usbctlx_submit(hw, ctlx);
  1446. if (result != 0) {
  1447. kfree(ctlx);
  1448. } else if (mode == DOWAIT) {
  1449. struct usbctlx_rmem_completor completor;
  1450. result =
  1451. hfa384x_usbctlx_complete_sync(hw, ctlx,
  1452. init_rmem_completor
  1453. (&completor,
  1454. &ctlx->inbuf.rmemresp, data,
  1455. len));
  1456. }
  1457. done:
  1458. return result;
  1459. }
  1460. /*----------------------------------------------------------------
  1461. * hfa384x_dowmem
  1462. *
  1463. * Constructs a writemem CTLX and issues it.
  1464. *
  1465. * NOTE: Any changes to the 'post-submit' code in this function
  1466. * need to be carried over to hfa384x_cbwmem() since the handling
  1467. * is virtually identical.
  1468. *
  1469. * Arguments:
  1470. * hw device structure
  1471. * mode DOWAIT or DOASYNC
  1472. * page MAC address space page (CMD format)
  1473. * offset MAC address space offset
  1474. * data Ptr to data buffer containing write data
  1475. * len Length of the data to read (max == 2048)
  1476. * cmdcb command callback for async calls, NULL for DOWAIT calls
  1477. * usercb user callback for async calls, NULL for DOWAIT calls
  1478. * usercb_data user supplied data pointer for async calls.
  1479. *
  1480. * Returns:
  1481. * 0 success
  1482. * -ETIMEDOUT timed out waiting for register ready or
  1483. * command completion
  1484. * >0 command indicated error, Status and Resp0-2 are
  1485. * in hw structure.
  1486. *
  1487. * Side effects:
  1488. *
  1489. * Call context:
  1490. * interrupt (DOWAIT)
  1491. * process (DOWAIT or DOASYNC)
  1492. ----------------------------------------------------------------*/
  1493. static int
  1494. hfa384x_dowmem(hfa384x_t *hw,
  1495. enum cmd_mode mode,
  1496. u16 page,
  1497. u16 offset,
  1498. void *data,
  1499. unsigned int len,
  1500. ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data)
  1501. {
  1502. int result;
  1503. hfa384x_usbctlx_t *ctlx;
  1504. pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len);
  1505. ctlx = usbctlx_alloc();
  1506. if (ctlx == NULL) {
  1507. result = -ENOMEM;
  1508. goto done;
  1509. }
  1510. /* Initialize the command */
  1511. ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ);
  1512. ctlx->outbuf.wmemreq.frmlen =
  1513. cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) +
  1514. sizeof(ctlx->outbuf.wmemreq.page) + len);
  1515. ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset);
  1516. ctlx->outbuf.wmemreq.page = cpu_to_le16(page);
  1517. memcpy(ctlx->outbuf.wmemreq.data, data, len);
  1518. ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) +
  1519. sizeof(ctlx->outbuf.wmemreq.frmlen) +
  1520. sizeof(ctlx->outbuf.wmemreq.offset) +
  1521. sizeof(ctlx->outbuf.wmemreq.page) + len;
  1522. ctlx->reapable = mode;
  1523. ctlx->cmdcb = cmdcb;
  1524. ctlx->usercb = usercb;
  1525. ctlx->usercb_data = usercb_data;
  1526. result = hfa384x_usbctlx_submit(hw, ctlx);
  1527. if (result != 0) {
  1528. kfree(ctlx);
  1529. } else if (mode == DOWAIT) {
  1530. struct usbctlx_cmd_completor completor;
  1531. hfa384x_cmdresult_t wmemresult;
  1532. result = hfa384x_usbctlx_complete_sync(hw,
  1533. ctlx,
  1534. init_wmem_completor
  1535. (&completor,
  1536. &ctlx->inbuf.wmemresp,
  1537. &wmemresult));
  1538. }
  1539. done:
  1540. return result;
  1541. }
  1542. /*----------------------------------------------------------------
  1543. * hfa384x_drvr_commtallies
  1544. *
  1545. * Send a commtallies inquiry to the MAC. Note that this is an async
  1546. * call that will result in an info frame arriving sometime later.
  1547. *
  1548. * Arguments:
  1549. * hw device structure
  1550. *
  1551. * Returns:
  1552. * zero success.
  1553. *
  1554. * Side effects:
  1555. *
  1556. * Call context:
  1557. * process
  1558. ----------------------------------------------------------------*/
  1559. int hfa384x_drvr_commtallies(hfa384x_t *hw)
  1560. {
  1561. hfa384x_metacmd_t cmd;
  1562. cmd.cmd = HFA384x_CMDCODE_INQ;
  1563. cmd.parm0 = HFA384x_IT_COMMTALLIES;
  1564. cmd.parm1 = 0;
  1565. cmd.parm2 = 0;
  1566. hfa384x_docmd_async(hw, &cmd, NULL, NULL, NULL);
  1567. return 0;
  1568. }
  1569. /*----------------------------------------------------------------
  1570. * hfa384x_drvr_disable
  1571. *
  1572. * Issues the disable command to stop communications on one of
  1573. * the MACs 'ports'. Only macport 0 is valid for stations.
  1574. * APs may also disable macports 1-6. Only ports that have been
  1575. * previously enabled may be disabled.
  1576. *
  1577. * Arguments:
  1578. * hw device structure
  1579. * macport MAC port number (host order)
  1580. *
  1581. * Returns:
  1582. * 0 success
  1583. * >0 f/w reported failure - f/w status code
  1584. * <0 driver reported error (timeout|bad arg)
  1585. *
  1586. * Side effects:
  1587. *
  1588. * Call context:
  1589. * process
  1590. ----------------------------------------------------------------*/
  1591. int hfa384x_drvr_disable(hfa384x_t *hw, u16 macport)
  1592. {
  1593. int result = 0;
  1594. if ((!hw->isap && macport != 0) ||
  1595. (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
  1596. !(hw->port_enabled[macport])) {
  1597. result = -EINVAL;
  1598. } else {
  1599. result = hfa384x_cmd_disable(hw, macport);
  1600. if (result == 0)
  1601. hw->port_enabled[macport] = 0;
  1602. }
  1603. return result;
  1604. }
  1605. /*----------------------------------------------------------------
  1606. * hfa384x_drvr_enable
  1607. *
  1608. * Issues the enable command to enable communications on one of
  1609. * the MACs 'ports'. Only macport 0 is valid for stations.
  1610. * APs may also enable macports 1-6. Only ports that are currently
  1611. * disabled may be enabled.
  1612. *
  1613. * Arguments:
  1614. * hw device structure
  1615. * macport MAC port number
  1616. *
  1617. * Returns:
  1618. * 0 success
  1619. * >0 f/w reported failure - f/w status code
  1620. * <0 driver reported error (timeout|bad arg)
  1621. *
  1622. * Side effects:
  1623. *
  1624. * Call context:
  1625. * process
  1626. ----------------------------------------------------------------*/
  1627. int hfa384x_drvr_enable(hfa384x_t *hw, u16 macport)
  1628. {
  1629. int result = 0;
  1630. if ((!hw->isap && macport != 0) ||
  1631. (hw->isap && !(macport <= HFA384x_PORTID_MAX)) ||
  1632. (hw->port_enabled[macport])) {
  1633. result = -EINVAL;
  1634. } else {
  1635. result = hfa384x_cmd_enable(hw, macport);
  1636. if (result == 0)
  1637. hw->port_enabled[macport] = 1;
  1638. }
  1639. return result;
  1640. }
  1641. /*----------------------------------------------------------------
  1642. * hfa384x_drvr_flashdl_enable
  1643. *
  1644. * Begins the flash download state. Checks to see that we're not
  1645. * already in a download state and that a port isn't enabled.
  1646. * Sets the download state and retrieves the flash download
  1647. * buffer location, buffer size, and timeout length.
  1648. *
  1649. * Arguments:
  1650. * hw device structure
  1651. *
  1652. * Returns:
  1653. * 0 success
  1654. * >0 f/w reported error - f/w status code
  1655. * <0 driver reported error
  1656. *
  1657. * Side effects:
  1658. *
  1659. * Call context:
  1660. * process
  1661. ----------------------------------------------------------------*/
  1662. int hfa384x_drvr_flashdl_enable(hfa384x_t *hw)
  1663. {
  1664. int result = 0;
  1665. int i;
  1666. /* Check that a port isn't active */
  1667. for (i = 0; i < HFA384x_PORTID_MAX; i++) {
  1668. if (hw->port_enabled[i]) {
  1669. pr_debug("called when port enabled.\n");
  1670. return -EINVAL;
  1671. }
  1672. }
  1673. /* Check that we're not already in a download state */
  1674. if (hw->dlstate != HFA384x_DLSTATE_DISABLED)
  1675. return -EINVAL;
  1676. /* Retrieve the buffer loc&size and timeout */
  1677. result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER,
  1678. &(hw->bufinfo), sizeof(hw->bufinfo));
  1679. if (result)
  1680. return result;
  1681. hw->bufinfo.page = le16_to_cpu(hw->bufinfo.page);
  1682. hw->bufinfo.offset = le16_to_cpu(hw->bufinfo.offset);
  1683. hw->bufinfo.len = le16_to_cpu(hw->bufinfo.len);
  1684. result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME,
  1685. &(hw->dltimeout));
  1686. if (result)
  1687. return result;
  1688. hw->dltimeout = le16_to_cpu(hw->dltimeout);
  1689. pr_debug("flashdl_enable\n");
  1690. hw->dlstate = HFA384x_DLSTATE_FLASHENABLED;
  1691. return result;
  1692. }
  1693. /*----------------------------------------------------------------
  1694. * hfa384x_drvr_flashdl_disable
  1695. *
  1696. * Ends the flash download state. Note that this will cause the MAC
  1697. * firmware to restart.
  1698. *
  1699. * Arguments:
  1700. * hw device structure
  1701. *
  1702. * Returns:
  1703. * 0 success
  1704. * >0 f/w reported error - f/w status code
  1705. * <0 driver reported error
  1706. *
  1707. * Side effects:
  1708. *
  1709. * Call context:
  1710. * process
  1711. ----------------------------------------------------------------*/
  1712. int hfa384x_drvr_flashdl_disable(hfa384x_t *hw)
  1713. {
  1714. /* Check that we're already in the download state */
  1715. if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
  1716. return -EINVAL;
  1717. pr_debug("flashdl_enable\n");
  1718. /* There isn't much we can do at this point, so I don't */
  1719. /* bother w/ the return value */
  1720. hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
  1721. hw->dlstate = HFA384x_DLSTATE_DISABLED;
  1722. return 0;
  1723. }
  1724. /*----------------------------------------------------------------
  1725. * hfa384x_drvr_flashdl_write
  1726. *
  1727. * Performs a FLASH download of a chunk of data. First checks to see
  1728. * that we're in the FLASH download state, then sets the download
  1729. * mode, uses the aux functions to 1) copy the data to the flash
  1730. * buffer, 2) sets the download 'write flash' mode, 3) readback and
  1731. * compare. Lather rinse, repeat as many times an necessary to get
  1732. * all the given data into flash.
  1733. * When all data has been written using this function (possibly
  1734. * repeatedly), call drvr_flashdl_disable() to end the download state
  1735. * and restart the MAC.
  1736. *
  1737. * Arguments:
  1738. * hw device structure
  1739. * daddr Card address to write to. (host order)
  1740. * buf Ptr to data to write.
  1741. * len Length of data (host order).
  1742. *
  1743. * Returns:
  1744. * 0 success
  1745. * >0 f/w reported error - f/w status code
  1746. * <0 driver reported error
  1747. *
  1748. * Side effects:
  1749. *
  1750. * Call context:
  1751. * process
  1752. ----------------------------------------------------------------*/
  1753. int hfa384x_drvr_flashdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
  1754. {
  1755. int result = 0;
  1756. u32 dlbufaddr;
  1757. int nburns;
  1758. u32 burnlen;
  1759. u32 burndaddr;
  1760. u16 burnlo;
  1761. u16 burnhi;
  1762. int nwrites;
  1763. u8 *writebuf;
  1764. u16 writepage;
  1765. u16 writeoffset;
  1766. u32 writelen;
  1767. int i;
  1768. int j;
  1769. pr_debug("daddr=0x%08x len=%d\n", daddr, len);
  1770. /* Check that we're in the flash download state */
  1771. if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED)
  1772. return -EINVAL;
  1773. netdev_info(hw->wlandev->netdev,
  1774. "Download %d bytes to flash @0x%06x\n", len, daddr);
  1775. /* Convert to flat address for arithmetic */
  1776. /* NOTE: dlbuffer RID stores the address in AUX format */
  1777. dlbufaddr =
  1778. HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset);
  1779. pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n",
  1780. hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr);
  1781. /* Calculations to determine how many fills of the dlbuffer to do
  1782. * and how many USB wmemreq's to do for each fill. At this point
  1783. * in time, the dlbuffer size and the wmemreq size are the same.
  1784. * Therefore, nwrites should always be 1. The extra complexity
  1785. * here is a hedge against future changes.
  1786. */
  1787. /* Figure out how many times to do the flash programming */
  1788. nburns = len / hw->bufinfo.len;
  1789. nburns += (len % hw->bufinfo.len) ? 1 : 0;
  1790. /* For each flash program cycle, how many USB wmemreq's are needed? */
  1791. nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN;
  1792. nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0;
  1793. /* For each burn */
  1794. for (i = 0; i < nburns; i++) {
  1795. /* Get the dest address and len */
  1796. burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ?
  1797. hw->bufinfo.len : (len - (hw->bufinfo.len * i));
  1798. burndaddr = daddr + (hw->bufinfo.len * i);
  1799. burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr);
  1800. burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr);
  1801. netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n",
  1802. burnlen, burndaddr);
  1803. /* Set the download mode */
  1804. result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV,
  1805. burnlo, burnhi, burnlen);
  1806. if (result) {
  1807. netdev_err(hw->wlandev->netdev,
  1808. "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
  1809. burnlo, burnhi, burnlen, result);
  1810. goto exit_proc;
  1811. }
  1812. /* copy the data to the flash download buffer */
  1813. for (j = 0; j < nwrites; j++) {
  1814. writebuf = buf +
  1815. (i * hw->bufinfo.len) +
  1816. (j * HFA384x_USB_RWMEM_MAXLEN);
  1817. writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr +
  1818. (j * HFA384x_USB_RWMEM_MAXLEN));
  1819. writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr +
  1820. (j * HFA384x_USB_RWMEM_MAXLEN));
  1821. writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN);
  1822. writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ?
  1823. HFA384x_USB_RWMEM_MAXLEN : writelen;
  1824. result = hfa384x_dowmem_wait(hw,
  1825. writepage,
  1826. writeoffset,
  1827. writebuf, writelen);
  1828. }
  1829. /* set the download 'write flash' mode */
  1830. result = hfa384x_cmd_download(hw,
  1831. HFA384x_PROGMODE_NVWRITE,
  1832. 0, 0, 0);
  1833. if (result) {
  1834. netdev_err(hw->wlandev->netdev,
  1835. "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n",
  1836. burnlo, burnhi, burnlen, result);
  1837. goto exit_proc;
  1838. }
  1839. /* TODO: We really should do a readback and compare. */
  1840. }
  1841. exit_proc:
  1842. /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */
  1843. /* actually disable programming mode. Remember, that will cause the */
  1844. /* the firmware to effectively reset itself. */
  1845. return result;
  1846. }
  1847. /*----------------------------------------------------------------
  1848. * hfa384x_drvr_getconfig
  1849. *
  1850. * Performs the sequence necessary to read a config/info item.
  1851. *
  1852. * Arguments:
  1853. * hw device structure
  1854. * rid config/info record id (host order)
  1855. * buf host side record buffer. Upon return it will
  1856. * contain the body portion of the record (minus the
  1857. * RID and len).
  1858. * len buffer length (in bytes, should match record length)
  1859. *
  1860. * Returns:
  1861. * 0 success
  1862. * >0 f/w reported error - f/w status code
  1863. * <0 driver reported error
  1864. * -ENODATA length mismatch between argument and retrieved
  1865. * record.
  1866. *
  1867. * Side effects:
  1868. *
  1869. * Call context:
  1870. * process
  1871. ----------------------------------------------------------------*/
  1872. int hfa384x_drvr_getconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
  1873. {
  1874. return hfa384x_dorrid_wait(hw, rid, buf, len);
  1875. }
  1876. /*----------------------------------------------------------------
  1877. * hfa384x_drvr_getconfig_async
  1878. *
  1879. * Performs the sequence necessary to perform an async read of
  1880. * of a config/info item.
  1881. *
  1882. * Arguments:
  1883. * hw device structure
  1884. * rid config/info record id (host order)
  1885. * buf host side record buffer. Upon return it will
  1886. * contain the body portion of the record (minus the
  1887. * RID and len).
  1888. * len buffer length (in bytes, should match record length)
  1889. * cbfn caller supplied callback, called when the command
  1890. * is done (successful or not).
  1891. * cbfndata pointer to some caller supplied data that will be
  1892. * passed in as an argument to the cbfn.
  1893. *
  1894. * Returns:
  1895. * nothing the cbfn gets a status argument identifying if
  1896. * any errors occur.
  1897. * Side effects:
  1898. * Queues an hfa384x_usbcmd_t for subsequent execution.
  1899. *
  1900. * Call context:
  1901. * Any
  1902. ----------------------------------------------------------------*/
  1903. int
  1904. hfa384x_drvr_getconfig_async(hfa384x_t *hw,
  1905. u16 rid, ctlx_usercb_t usercb, void *usercb_data)
  1906. {
  1907. return hfa384x_dorrid_async(hw, rid, NULL, 0,
  1908. hfa384x_cb_rrid, usercb, usercb_data);
  1909. }
  1910. /*----------------------------------------------------------------
  1911. * hfa384x_drvr_setconfig_async
  1912. *
  1913. * Performs the sequence necessary to write a config/info item.
  1914. *
  1915. * Arguments:
  1916. * hw device structure
  1917. * rid config/info record id (in host order)
  1918. * buf host side record buffer
  1919. * len buffer length (in bytes)
  1920. * usercb completion callback
  1921. * usercb_data completion callback argument
  1922. *
  1923. * Returns:
  1924. * 0 success
  1925. * >0 f/w reported error - f/w status code
  1926. * <0 driver reported error
  1927. *
  1928. * Side effects:
  1929. *
  1930. * Call context:
  1931. * process
  1932. ----------------------------------------------------------------*/
  1933. int
  1934. hfa384x_drvr_setconfig_async(hfa384x_t *hw,
  1935. u16 rid,
  1936. void *buf,
  1937. u16 len, ctlx_usercb_t usercb, void *usercb_data)
  1938. {
  1939. return hfa384x_dowrid_async(hw, rid, buf, len,
  1940. hfa384x_cb_status, usercb, usercb_data);
  1941. }
  1942. /*----------------------------------------------------------------
  1943. * hfa384x_drvr_ramdl_disable
  1944. *
  1945. * Ends the ram download state.
  1946. *
  1947. * Arguments:
  1948. * hw device structure
  1949. *
  1950. * Returns:
  1951. * 0 success
  1952. * >0 f/w reported error - f/w status code
  1953. * <0 driver reported error
  1954. *
  1955. * Side effects:
  1956. *
  1957. * Call context:
  1958. * process
  1959. ----------------------------------------------------------------*/
  1960. int hfa384x_drvr_ramdl_disable(hfa384x_t *hw)
  1961. {
  1962. /* Check that we're already in the download state */
  1963. if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
  1964. return -EINVAL;
  1965. pr_debug("ramdl_disable()\n");
  1966. /* There isn't much we can do at this point, so I don't */
  1967. /* bother w/ the return value */
  1968. hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0);
  1969. hw->dlstate = HFA384x_DLSTATE_DISABLED;
  1970. return 0;
  1971. }
  1972. /*----------------------------------------------------------------
  1973. * hfa384x_drvr_ramdl_enable
  1974. *
  1975. * Begins the ram download state. Checks to see that we're not
  1976. * already in a download state and that a port isn't enabled.
  1977. * Sets the download state and calls cmd_download with the
  1978. * ENABLE_VOLATILE subcommand and the exeaddr argument.
  1979. *
  1980. * Arguments:
  1981. * hw device structure
  1982. * exeaddr the card execution address that will be
  1983. * jumped to when ramdl_disable() is called
  1984. * (host order).
  1985. *
  1986. * Returns:
  1987. * 0 success
  1988. * >0 f/w reported error - f/w status code
  1989. * <0 driver reported error
  1990. *
  1991. * Side effects:
  1992. *
  1993. * Call context:
  1994. * process
  1995. ----------------------------------------------------------------*/
  1996. int hfa384x_drvr_ramdl_enable(hfa384x_t *hw, u32 exeaddr)
  1997. {
  1998. int result = 0;
  1999. u16 lowaddr;
  2000. u16 hiaddr;
  2001. int i;
  2002. /* Check that a port isn't active */
  2003. for (i = 0; i < HFA384x_PORTID_MAX; i++) {
  2004. if (hw->port_enabled[i]) {
  2005. netdev_err(hw->wlandev->netdev,
  2006. "Can't download with a macport enabled.\n");
  2007. return -EINVAL;
  2008. }
  2009. }
  2010. /* Check that we're not already in a download state */
  2011. if (hw->dlstate != HFA384x_DLSTATE_DISABLED) {
  2012. netdev_err(hw->wlandev->netdev, "Download state not disabled.\n");
  2013. return -EINVAL;
  2014. }
  2015. pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr);
  2016. /* Call the download(1,addr) function */
  2017. lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr);
  2018. hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr);
  2019. result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM,
  2020. lowaddr, hiaddr, 0);
  2021. if (result == 0) {
  2022. /* Set the download state */
  2023. hw->dlstate = HFA384x_DLSTATE_RAMENABLED;
  2024. } else {
  2025. pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n",
  2026. lowaddr, hiaddr, result);
  2027. }
  2028. return result;
  2029. }
  2030. /*----------------------------------------------------------------
  2031. * hfa384x_drvr_ramdl_write
  2032. *
  2033. * Performs a RAM download of a chunk of data. First checks to see
  2034. * that we're in the RAM download state, then uses the [read|write]mem USB
  2035. * commands to 1) copy the data, 2) readback and compare. The download
  2036. * state is unaffected. When all data has been written using
  2037. * this function, call drvr_ramdl_disable() to end the download state
  2038. * and restart the MAC.
  2039. *
  2040. * Arguments:
  2041. * hw device structure
  2042. * daddr Card address to write to. (host order)
  2043. * buf Ptr to data to write.
  2044. * len Length of data (host order).
  2045. *
  2046. * Returns:
  2047. * 0 success
  2048. * >0 f/w reported error - f/w status code
  2049. * <0 driver reported error
  2050. *
  2051. * Side effects:
  2052. *
  2053. * Call context:
  2054. * process
  2055. ----------------------------------------------------------------*/
  2056. int hfa384x_drvr_ramdl_write(hfa384x_t *hw, u32 daddr, void *buf, u32 len)
  2057. {
  2058. int result = 0;
  2059. int nwrites;
  2060. u8 *data = buf;
  2061. int i;
  2062. u32 curraddr;
  2063. u16 currpage;
  2064. u16 curroffset;
  2065. u16 currlen;
  2066. /* Check that we're in the ram download state */
  2067. if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED)
  2068. return -EINVAL;
  2069. netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n",
  2070. len, daddr);
  2071. /* How many dowmem calls? */
  2072. nwrites = len / HFA384x_USB_RWMEM_MAXLEN;
  2073. nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0;
  2074. /* Do blocking wmem's */
  2075. for (i = 0; i < nwrites; i++) {
  2076. /* make address args */
  2077. curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN);
  2078. currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr);
  2079. curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr);
  2080. currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN);
  2081. if (currlen > HFA384x_USB_RWMEM_MAXLEN)
  2082. currlen = HFA384x_USB_RWMEM_MAXLEN;
  2083. /* Do blocking ctlx */
  2084. result = hfa384x_dowmem_wait(hw,
  2085. currpage,
  2086. curroffset,
  2087. data +
  2088. (i * HFA384x_USB_RWMEM_MAXLEN),
  2089. currlen);
  2090. if (result)
  2091. break;
  2092. /* TODO: We really should have a readback. */
  2093. }
  2094. return result;
  2095. }
  2096. /*----------------------------------------------------------------
  2097. * hfa384x_drvr_readpda
  2098. *
  2099. * Performs the sequence to read the PDA space. Note there is no
  2100. * drvr_writepda() function. Writing a PDA is
  2101. * generally implemented by a calling component via calls to
  2102. * cmd_download and writing to the flash download buffer via the
  2103. * aux regs.
  2104. *
  2105. * Arguments:
  2106. * hw device structure
  2107. * buf buffer to store PDA in
  2108. * len buffer length
  2109. *
  2110. * Returns:
  2111. * 0 success
  2112. * >0 f/w reported error - f/w status code
  2113. * <0 driver reported error
  2114. * -ETIMEDOUT timeout waiting for the cmd regs to become
  2115. * available, or waiting for the control reg
  2116. * to indicate the Aux port is enabled.
  2117. * -ENODATA the buffer does NOT contain a valid PDA.
  2118. * Either the card PDA is bad, or the auxdata
  2119. * reads are giving us garbage.
  2120. *
  2121. * Side effects:
  2122. *
  2123. * Call context:
  2124. * process or non-card interrupt.
  2125. ----------------------------------------------------------------*/
  2126. int hfa384x_drvr_readpda(hfa384x_t *hw, void *buf, unsigned int len)
  2127. {
  2128. int result = 0;
  2129. u16 *pda = buf;
  2130. int pdaok = 0;
  2131. int morepdrs = 1;
  2132. int currpdr = 0; /* word offset of the current pdr */
  2133. size_t i;
  2134. u16 pdrlen; /* pdr length in bytes, host order */
  2135. u16 pdrcode; /* pdr code, host order */
  2136. u16 currpage;
  2137. u16 curroffset;
  2138. struct pdaloc {
  2139. u32 cardaddr;
  2140. u16 auxctl;
  2141. } pdaloc[] = {
  2142. {
  2143. HFA3842_PDA_BASE, 0}, {
  2144. HFA3841_PDA_BASE, 0}, {
  2145. HFA3841_PDA_BOGUS_BASE, 0}
  2146. };
  2147. /* Read the pda from each known address. */
  2148. for (i = 0; i < ARRAY_SIZE(pdaloc); i++) {
  2149. /* Make address */
  2150. currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr);
  2151. curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr);
  2152. /* units of bytes */
  2153. result = hfa384x_dormem_wait(hw, currpage, curroffset, buf,
  2154. len);
  2155. if (result) {
  2156. netdev_warn(hw->wlandev->netdev,
  2157. "Read from index %zd failed, continuing\n",
  2158. i);
  2159. continue;
  2160. }
  2161. /* Test for garbage */
  2162. pdaok = 1; /* initially assume good */
  2163. morepdrs = 1;
  2164. while (pdaok && morepdrs) {
  2165. pdrlen = le16_to_cpu(pda[currpdr]) * 2;
  2166. pdrcode = le16_to_cpu(pda[currpdr + 1]);
  2167. /* Test the record length */
  2168. if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) {
  2169. netdev_err(hw->wlandev->netdev,
  2170. "pdrlen invalid=%d\n", pdrlen);
  2171. pdaok = 0;
  2172. break;
  2173. }
  2174. /* Test the code */
  2175. if (!hfa384x_isgood_pdrcode(pdrcode)) {
  2176. netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n",
  2177. pdrcode);
  2178. pdaok = 0;
  2179. break;
  2180. }
  2181. /* Test for completion */
  2182. if (pdrcode == HFA384x_PDR_END_OF_PDA)
  2183. morepdrs = 0;
  2184. /* Move to the next pdr (if necessary) */
  2185. if (morepdrs) {
  2186. /* note the access to pda[], need words here */
  2187. currpdr += le16_to_cpu(pda[currpdr]) + 1;
  2188. }
  2189. }
  2190. if (pdaok) {
  2191. netdev_info(hw->wlandev->netdev,
  2192. "PDA Read from 0x%08x in %s space.\n",
  2193. pdaloc[i].cardaddr,
  2194. pdaloc[i].auxctl == 0 ? "EXTDS" :
  2195. pdaloc[i].auxctl == 1 ? "NV" :
  2196. pdaloc[i].auxctl == 2 ? "PHY" :
  2197. pdaloc[i].auxctl == 3 ? "ICSRAM" :
  2198. "<bogus auxctl>");
  2199. break;
  2200. }
  2201. }
  2202. result = pdaok ? 0 : -ENODATA;
  2203. if (result)
  2204. pr_debug("Failure: pda is not okay\n");
  2205. return result;
  2206. }
  2207. /*----------------------------------------------------------------
  2208. * hfa384x_drvr_setconfig
  2209. *
  2210. * Performs the sequence necessary to write a config/info item.
  2211. *
  2212. * Arguments:
  2213. * hw device structure
  2214. * rid config/info record id (in host order)
  2215. * buf host side record buffer
  2216. * len buffer length (in bytes)
  2217. *
  2218. * Returns:
  2219. * 0 success
  2220. * >0 f/w reported error - f/w status code
  2221. * <0 driver reported error
  2222. *
  2223. * Side effects:
  2224. *
  2225. * Call context:
  2226. * process
  2227. ----------------------------------------------------------------*/
  2228. int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len)
  2229. {
  2230. return hfa384x_dowrid_wait(hw, rid, buf, len);
  2231. }
  2232. /*----------------------------------------------------------------
  2233. * hfa384x_drvr_start
  2234. *
  2235. * Issues the MAC initialize command, sets up some data structures,
  2236. * and enables the interrupts. After this function completes, the
  2237. * low-level stuff should be ready for any/all commands.
  2238. *
  2239. * Arguments:
  2240. * hw device structure
  2241. * Returns:
  2242. * 0 success
  2243. * >0 f/w reported error - f/w status code
  2244. * <0 driver reported error
  2245. *
  2246. * Side effects:
  2247. *
  2248. * Call context:
  2249. * process
  2250. ----------------------------------------------------------------*/
  2251. int hfa384x_drvr_start(hfa384x_t *hw)
  2252. {
  2253. int result, result1, result2;
  2254. u16 status;
  2255. might_sleep();
  2256. /* Clear endpoint stalls - but only do this if the endpoint
  2257. * is showing a stall status. Some prism2 cards seem to behave
  2258. * badly if a clear_halt is called when the endpoint is already
  2259. * ok
  2260. */
  2261. result =
  2262. usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, &status);
  2263. if (result < 0) {
  2264. netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n");
  2265. goto done;
  2266. }
  2267. if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in))
  2268. netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n");
  2269. result =
  2270. usb_get_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, &status);
  2271. if (result < 0) {
  2272. netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n");
  2273. goto done;
  2274. }
  2275. if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out))
  2276. netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n");
  2277. /* Synchronous unlink, in case we're trying to restart the driver */
  2278. usb_kill_urb(&hw->rx_urb);
  2279. /* Post the IN urb */
  2280. result = submit_rx_urb(hw, GFP_KERNEL);
  2281. if (result != 0) {
  2282. netdev_err(hw->wlandev->netdev,
  2283. "Fatal, failed to submit RX URB, result=%d\n",
  2284. result);
  2285. goto done;
  2286. }
  2287. /* Call initialize twice, with a 1 second sleep in between.
  2288. * This is a nasty work-around since many prism2 cards seem to
  2289. * need time to settle after an init from cold. The second
  2290. * call to initialize in theory is not necessary - but we call
  2291. * it anyway as a double insurance policy:
  2292. * 1) If the first init should fail, the second may well succeed
  2293. * and the card can still be used
  2294. * 2) It helps ensures all is well with the card after the first
  2295. * init and settle time.
  2296. */
  2297. result1 = hfa384x_cmd_initialize(hw);
  2298. msleep(1000);
  2299. result = hfa384x_cmd_initialize(hw);
  2300. result2 = result;
  2301. if (result1 != 0) {
  2302. if (result2 != 0) {
  2303. netdev_err(hw->wlandev->netdev,
  2304. "cmd_initialize() failed on two attempts, results %d and %d\n",
  2305. result1, result2);
  2306. usb_kill_urb(&hw->rx_urb);
  2307. goto done;
  2308. } else {
  2309. pr_debug("First cmd_initialize() failed (result %d),\n",
  2310. result1);
  2311. pr_debug("but second attempt succeeded. All should be ok\n");
  2312. }
  2313. } else if (result2 != 0) {
  2314. netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n",
  2315. result2);
  2316. netdev_warn(hw->wlandev->netdev,
  2317. "Most likely the card will be functional\n");
  2318. goto done;
  2319. }
  2320. hw->state = HFA384x_STATE_RUNNING;
  2321. done:
  2322. return result;
  2323. }
  2324. /*----------------------------------------------------------------
  2325. * hfa384x_drvr_stop
  2326. *
  2327. * Shuts down the MAC to the point where it is safe to unload the
  2328. * driver. Any subsystem that may be holding a data or function
  2329. * ptr into the driver must be cleared/deinitialized.
  2330. *
  2331. * Arguments:
  2332. * hw device structure
  2333. * Returns:
  2334. * 0 success
  2335. * >0 f/w reported error - f/w status code
  2336. * <0 driver reported error
  2337. *
  2338. * Side effects:
  2339. *
  2340. * Call context:
  2341. * process
  2342. ----------------------------------------------------------------*/
  2343. int hfa384x_drvr_stop(hfa384x_t *hw)
  2344. {
  2345. int i;
  2346. might_sleep();
  2347. /* There's no need for spinlocks here. The USB "disconnect"
  2348. * function sets this "removed" flag and then calls us.
  2349. */
  2350. if (!hw->wlandev->hwremoved) {
  2351. /* Call initialize to leave the MAC in its 'reset' state */
  2352. hfa384x_cmd_initialize(hw);
  2353. /* Cancel the rxurb */
  2354. usb_kill_urb(&hw->rx_urb);
  2355. }
  2356. hw->link_status = HFA384x_LINK_NOTCONNECTED;
  2357. hw->state = HFA384x_STATE_INIT;
  2358. del_timer_sync(&hw->commsqual_timer);
  2359. /* Clear all the port status */
  2360. for (i = 0; i < HFA384x_NUMPORTS_MAX; i++)
  2361. hw->port_enabled[i] = 0;
  2362. return 0;
  2363. }
  2364. /*----------------------------------------------------------------
  2365. * hfa384x_drvr_txframe
  2366. *
  2367. * Takes a frame from prism2sta and queues it for transmission.
  2368. *
  2369. * Arguments:
  2370. * hw device structure
  2371. * skb packet buffer struct. Contains an 802.11
  2372. * data frame.
  2373. * p80211_hdr points to the 802.11 header for the packet.
  2374. * Returns:
  2375. * 0 Success and more buffs available
  2376. * 1 Success but no more buffs
  2377. * 2 Allocation failure
  2378. * 4 Buffer full or queue busy
  2379. *
  2380. * Side effects:
  2381. *
  2382. * Call context:
  2383. * interrupt
  2384. ----------------------------------------------------------------*/
  2385. int hfa384x_drvr_txframe(hfa384x_t *hw, struct sk_buff *skb,
  2386. union p80211_hdr *p80211_hdr,
  2387. struct p80211_metawep *p80211_wep)
  2388. {
  2389. int usbpktlen = sizeof(hfa384x_tx_frame_t);
  2390. int result;
  2391. int ret;
  2392. char *ptr;
  2393. if (hw->tx_urb.status == -EINPROGRESS) {
  2394. netdev_warn(hw->wlandev->netdev, "TX URB already in use\n");
  2395. result = 3;
  2396. goto exit;
  2397. }
  2398. /* Build Tx frame structure */
  2399. /* Set up the control field */
  2400. memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc));
  2401. /* Setup the usb type field */
  2402. hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM);
  2403. /* Set up the sw_support field to identify this frame */
  2404. hw->txbuff.txfrm.desc.sw_support = 0x0123;
  2405. /* Tx complete and Tx exception disable per dleach. Might be causing
  2406. * buf depletion
  2407. */
  2408. /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */
  2409. #if defined(DOBOTH)
  2410. hw->txbuff.txfrm.desc.tx_control =
  2411. HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
  2412. HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1);
  2413. #elif defined(DOEXC)
  2414. hw->txbuff.txfrm.desc.tx_control =
  2415. HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
  2416. HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0);
  2417. #else
  2418. hw->txbuff.txfrm.desc.tx_control =
  2419. HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) |
  2420. HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0);
  2421. #endif
  2422. hw->txbuff.txfrm.desc.tx_control =
  2423. cpu_to_le16(hw->txbuff.txfrm.desc.tx_control);
  2424. /* copy the header over to the txdesc */
  2425. memcpy(&(hw->txbuff.txfrm.desc.frame_control), p80211_hdr,
  2426. sizeof(union p80211_hdr));
  2427. /* if we're using host WEP, increase size by IV+ICV */
  2428. if (p80211_wep->data) {
  2429. hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8);
  2430. usbpktlen += 8;
  2431. } else {
  2432. hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len);
  2433. }
  2434. usbpktlen += skb->len;
  2435. /* copy over the WEP IV if we are using host WEP */
  2436. ptr = hw->txbuff.txfrm.data;
  2437. if (p80211_wep->data) {
  2438. memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv));
  2439. ptr += sizeof(p80211_wep->iv);
  2440. memcpy(ptr, p80211_wep->data, skb->len);
  2441. } else {
  2442. memcpy(ptr, skb->data, skb->len);
  2443. }
  2444. /* copy over the packet data */
  2445. ptr += skb->len;
  2446. /* copy over the WEP ICV if we are using host WEP */
  2447. if (p80211_wep->data)
  2448. memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv));
  2449. /* Send the USB packet */
  2450. usb_fill_bulk_urb(&(hw->tx_urb), hw->usb,
  2451. hw->endp_out,
  2452. &(hw->txbuff), ROUNDUP64(usbpktlen),
  2453. hfa384x_usbout_callback, hw->wlandev);
  2454. hw->tx_urb.transfer_flags |= USB_QUEUE_BULK;
  2455. result = 1;
  2456. ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC);
  2457. if (ret != 0) {
  2458. netdev_err(hw->wlandev->netdev,
  2459. "submit_tx_urb() failed, error=%d\n", ret);
  2460. result = 3;
  2461. }
  2462. exit:
  2463. return result;
  2464. }
  2465. void hfa384x_tx_timeout(wlandevice_t *wlandev)
  2466. {
  2467. hfa384x_t *hw = wlandev->priv;
  2468. unsigned long flags;
  2469. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  2470. if (!hw->wlandev->hwremoved) {
  2471. int sched;
  2472. sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags);
  2473. sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags);
  2474. if (sched)
  2475. schedule_work(&hw->usb_work);
  2476. }
  2477. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  2478. }
  2479. /*----------------------------------------------------------------
  2480. * hfa384x_usbctlx_reaper_task
  2481. *
  2482. * Tasklet to delete dead CTLX objects
  2483. *
  2484. * Arguments:
  2485. * data ptr to a hfa384x_t
  2486. *
  2487. * Returns:
  2488. *
  2489. * Call context:
  2490. * Interrupt
  2491. ----------------------------------------------------------------*/
  2492. static void hfa384x_usbctlx_reaper_task(unsigned long data)
  2493. {
  2494. hfa384x_t *hw = (hfa384x_t *)data;
  2495. struct list_head *entry;
  2496. struct list_head *temp;
  2497. unsigned long flags;
  2498. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  2499. /* This list is guaranteed to be empty if someone
  2500. * has unplugged the adapter.
  2501. */
  2502. list_for_each_safe(entry, temp, &hw->ctlxq.reapable) {
  2503. hfa384x_usbctlx_t *ctlx;
  2504. ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
  2505. list_del(&ctlx->list);
  2506. kfree(ctlx);
  2507. }
  2508. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  2509. }
  2510. /*----------------------------------------------------------------
  2511. * hfa384x_usbctlx_completion_task
  2512. *
  2513. * Tasklet to call completion handlers for returned CTLXs
  2514. *
  2515. * Arguments:
  2516. * data ptr to hfa384x_t
  2517. *
  2518. * Returns:
  2519. * Nothing
  2520. *
  2521. * Call context:
  2522. * Interrupt
  2523. ----------------------------------------------------------------*/
  2524. static void hfa384x_usbctlx_completion_task(unsigned long data)
  2525. {
  2526. hfa384x_t *hw = (hfa384x_t *)data;
  2527. struct list_head *entry;
  2528. struct list_head *temp;
  2529. unsigned long flags;
  2530. int reap = 0;
  2531. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  2532. /* This list is guaranteed to be empty if someone
  2533. * has unplugged the adapter ...
  2534. */
  2535. list_for_each_safe(entry, temp, &hw->ctlxq.completing) {
  2536. hfa384x_usbctlx_t *ctlx;
  2537. ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
  2538. /* Call the completion function that this
  2539. * command was assigned, assuming it has one.
  2540. */
  2541. if (ctlx->cmdcb != NULL) {
  2542. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  2543. ctlx->cmdcb(hw, ctlx);
  2544. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  2545. /* Make sure we don't try and complete
  2546. * this CTLX more than once!
  2547. */
  2548. ctlx->cmdcb = NULL;
  2549. /* Did someone yank the adapter out
  2550. * while our list was (briefly) unlocked?
  2551. */
  2552. if (hw->wlandev->hwremoved) {
  2553. reap = 0;
  2554. break;
  2555. }
  2556. }
  2557. /*
  2558. * "Reapable" CTLXs are ones which don't have any
  2559. * threads waiting for them to die. Hence they must
  2560. * be delivered to The Reaper!
  2561. */
  2562. if (ctlx->reapable) {
  2563. /* Move the CTLX off the "completing" list (hopefully)
  2564. * on to the "reapable" list where the reaper task
  2565. * can find it. And "reapable" means that this CTLX
  2566. * isn't sitting on a wait-queue somewhere.
  2567. */
  2568. list_move_tail(&ctlx->list, &hw->ctlxq.reapable);
  2569. reap = 1;
  2570. }
  2571. complete(&ctlx->done);
  2572. }
  2573. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  2574. if (reap)
  2575. tasklet_schedule(&hw->reaper_bh);
  2576. }
  2577. /*----------------------------------------------------------------
  2578. * unlocked_usbctlx_cancel_async
  2579. *
  2580. * Mark the CTLX dead asynchronously, and ensure that the
  2581. * next command on the queue is run afterwards.
  2582. *
  2583. * Arguments:
  2584. * hw ptr to the hfa384x_t structure
  2585. * ctlx ptr to a CTLX structure
  2586. *
  2587. * Returns:
  2588. * 0 the CTLX's URB is inactive
  2589. * -EINPROGRESS the URB is currently being unlinked
  2590. *
  2591. * Call context:
  2592. * Either process or interrupt, but presumably interrupt
  2593. ----------------------------------------------------------------*/
  2594. static int unlocked_usbctlx_cancel_async(hfa384x_t *hw,
  2595. hfa384x_usbctlx_t *ctlx)
  2596. {
  2597. int ret;
  2598. /*
  2599. * Try to delete the URB containing our request packet.
  2600. * If we succeed, then its completion handler will be
  2601. * called with a status of -ECONNRESET.
  2602. */
  2603. hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
  2604. ret = usb_unlink_urb(&hw->ctlx_urb);
  2605. if (ret != -EINPROGRESS) {
  2606. /*
  2607. * The OUT URB had either already completed
  2608. * or was still in the pending queue, so the
  2609. * URB's completion function will not be called.
  2610. * We will have to complete the CTLX ourselves.
  2611. */
  2612. ctlx->state = CTLX_REQ_FAILED;
  2613. unlocked_usbctlx_complete(hw, ctlx);
  2614. ret = 0;
  2615. }
  2616. return ret;
  2617. }
  2618. /*----------------------------------------------------------------
  2619. * unlocked_usbctlx_complete
  2620. *
  2621. * A CTLX has completed. It may have been successful, it may not
  2622. * have been. At this point, the CTLX should be quiescent. The URBs
  2623. * aren't active and the timers should have been stopped.
  2624. *
  2625. * The CTLX is migrated to the "completing" queue, and the completing
  2626. * tasklet is scheduled.
  2627. *
  2628. * Arguments:
  2629. * hw ptr to a hfa384x_t structure
  2630. * ctlx ptr to a ctlx structure
  2631. *
  2632. * Returns:
  2633. * nothing
  2634. *
  2635. * Side effects:
  2636. *
  2637. * Call context:
  2638. * Either, assume interrupt
  2639. ----------------------------------------------------------------*/
  2640. static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
  2641. {
  2642. /* Timers have been stopped, and ctlx should be in
  2643. * a terminal state. Retire it from the "active"
  2644. * queue.
  2645. */
  2646. list_move_tail(&ctlx->list, &hw->ctlxq.completing);
  2647. tasklet_schedule(&hw->completion_bh);
  2648. switch (ctlx->state) {
  2649. case CTLX_COMPLETE:
  2650. case CTLX_REQ_FAILED:
  2651. /* This are the correct terminating states. */
  2652. break;
  2653. default:
  2654. netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n",
  2655. le16_to_cpu(ctlx->outbuf.type),
  2656. ctlxstr(ctlx->state));
  2657. break;
  2658. } /* switch */
  2659. }
  2660. /*----------------------------------------------------------------
  2661. * hfa384x_usbctlxq_run
  2662. *
  2663. * Checks to see if the head item is running. If not, starts it.
  2664. *
  2665. * Arguments:
  2666. * hw ptr to hfa384x_t
  2667. *
  2668. * Returns:
  2669. * nothing
  2670. *
  2671. * Side effects:
  2672. *
  2673. * Call context:
  2674. * any
  2675. ----------------------------------------------------------------*/
  2676. static void hfa384x_usbctlxq_run(hfa384x_t *hw)
  2677. {
  2678. unsigned long flags;
  2679. /* acquire lock */
  2680. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  2681. /* Only one active CTLX at any one time, because there's no
  2682. * other (reliable) way to match the response URB to the
  2683. * correct CTLX.
  2684. *
  2685. * Don't touch any of these CTLXs if the hardware
  2686. * has been removed or the USB subsystem is stalled.
  2687. */
  2688. if (!list_empty(&hw->ctlxq.active) ||
  2689. test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved)
  2690. goto unlock;
  2691. while (!list_empty(&hw->ctlxq.pending)) {
  2692. hfa384x_usbctlx_t *head;
  2693. int result;
  2694. /* This is the first pending command */
  2695. head = list_entry(hw->ctlxq.pending.next,
  2696. hfa384x_usbctlx_t, list);
  2697. /* We need to split this off to avoid a race condition */
  2698. list_move_tail(&head->list, &hw->ctlxq.active);
  2699. /* Fill the out packet */
  2700. usb_fill_bulk_urb(&(hw->ctlx_urb), hw->usb,
  2701. hw->endp_out,
  2702. &(head->outbuf), ROUNDUP64(head->outbufsize),
  2703. hfa384x_ctlxout_callback, hw);
  2704. hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK;
  2705. /* Now submit the URB and update the CTLX's state */
  2706. result = SUBMIT_URB(&hw->ctlx_urb, GFP_ATOMIC);
  2707. if (result == 0) {
  2708. /* This CTLX is now running on the active queue */
  2709. head->state = CTLX_REQ_SUBMITTED;
  2710. /* Start the OUT wait timer */
  2711. hw->req_timer_done = 0;
  2712. hw->reqtimer.expires = jiffies + HZ;
  2713. add_timer(&hw->reqtimer);
  2714. /* Start the IN wait timer */
  2715. hw->resp_timer_done = 0;
  2716. hw->resptimer.expires = jiffies + 2 * HZ;
  2717. add_timer(&hw->resptimer);
  2718. break;
  2719. }
  2720. if (result == -EPIPE) {
  2721. /* The OUT pipe needs resetting, so put
  2722. * this CTLX back in the "pending" queue
  2723. * and schedule a reset ...
  2724. */
  2725. netdev_warn(hw->wlandev->netdev,
  2726. "%s tx pipe stalled: requesting reset\n",
  2727. hw->wlandev->netdev->name);
  2728. list_move(&head->list, &hw->ctlxq.pending);
  2729. set_bit(WORK_TX_HALT, &hw->usb_flags);
  2730. schedule_work(&hw->usb_work);
  2731. break;
  2732. }
  2733. if (result == -ESHUTDOWN) {
  2734. netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n",
  2735. hw->wlandev->netdev->name);
  2736. break;
  2737. }
  2738. netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n",
  2739. le16_to_cpu(head->outbuf.type), result);
  2740. unlocked_usbctlx_complete(hw, head);
  2741. } /* while */
  2742. unlock:
  2743. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  2744. }
  2745. /*----------------------------------------------------------------
  2746. * hfa384x_usbin_callback
  2747. *
  2748. * Callback for URBs on the BULKIN endpoint.
  2749. *
  2750. * Arguments:
  2751. * urb ptr to the completed urb
  2752. *
  2753. * Returns:
  2754. * nothing
  2755. *
  2756. * Side effects:
  2757. *
  2758. * Call context:
  2759. * interrupt
  2760. ----------------------------------------------------------------*/
  2761. static void hfa384x_usbin_callback(struct urb *urb)
  2762. {
  2763. wlandevice_t *wlandev = urb->context;
  2764. hfa384x_t *hw;
  2765. hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)urb->transfer_buffer;
  2766. struct sk_buff *skb = NULL;
  2767. int result;
  2768. int urb_status;
  2769. u16 type;
  2770. enum USBIN_ACTION {
  2771. HANDLE,
  2772. RESUBMIT,
  2773. ABORT
  2774. } action;
  2775. if (!wlandev || !wlandev->netdev || wlandev->hwremoved)
  2776. goto exit;
  2777. hw = wlandev->priv;
  2778. if (!hw)
  2779. goto exit;
  2780. skb = hw->rx_urb_skb;
  2781. BUG_ON(!skb || (skb->data != urb->transfer_buffer));
  2782. hw->rx_urb_skb = NULL;
  2783. /* Check for error conditions within the URB */
  2784. switch (urb->status) {
  2785. case 0:
  2786. action = HANDLE;
  2787. /* Check for short packet */
  2788. if (urb->actual_length == 0) {
  2789. wlandev->netdev->stats.rx_errors++;
  2790. wlandev->netdev->stats.rx_length_errors++;
  2791. action = RESUBMIT;
  2792. }
  2793. break;
  2794. case -EPIPE:
  2795. netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n",
  2796. wlandev->netdev->name);
  2797. if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags))
  2798. schedule_work(&hw->usb_work);
  2799. wlandev->netdev->stats.rx_errors++;
  2800. action = ABORT;
  2801. break;
  2802. case -EILSEQ:
  2803. case -ETIMEDOUT:
  2804. case -EPROTO:
  2805. if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) &&
  2806. !timer_pending(&hw->throttle)) {
  2807. mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES);
  2808. }
  2809. wlandev->netdev->stats.rx_errors++;
  2810. action = ABORT;
  2811. break;
  2812. case -EOVERFLOW:
  2813. wlandev->netdev->stats.rx_over_errors++;
  2814. action = RESUBMIT;
  2815. break;
  2816. case -ENODEV:
  2817. case -ESHUTDOWN:
  2818. pr_debug("status=%d, device removed.\n", urb->status);
  2819. action = ABORT;
  2820. break;
  2821. case -ENOENT:
  2822. case -ECONNRESET:
  2823. pr_debug("status=%d, urb explicitly unlinked.\n", urb->status);
  2824. action = ABORT;
  2825. break;
  2826. default:
  2827. pr_debug("urb status=%d, transfer flags=0x%x\n",
  2828. urb->status, urb->transfer_flags);
  2829. wlandev->netdev->stats.rx_errors++;
  2830. action = RESUBMIT;
  2831. break;
  2832. }
  2833. urb_status = urb->status;
  2834. if (action != ABORT) {
  2835. /* Repost the RX URB */
  2836. result = submit_rx_urb(hw, GFP_ATOMIC);
  2837. if (result != 0) {
  2838. netdev_err(hw->wlandev->netdev,
  2839. "Fatal, failed to resubmit rx_urb. error=%d\n",
  2840. result);
  2841. }
  2842. }
  2843. /* Handle any USB-IN packet */
  2844. /* Note: the check of the sw_support field, the type field doesn't
  2845. * have bit 12 set like the docs suggest.
  2846. */
  2847. type = le16_to_cpu(usbin->type);
  2848. if (HFA384x_USB_ISRXFRM(type)) {
  2849. if (action == HANDLE) {
  2850. if (usbin->txfrm.desc.sw_support == 0x0123) {
  2851. hfa384x_usbin_txcompl(wlandev, usbin);
  2852. } else {
  2853. skb_put(skb, sizeof(*usbin));
  2854. hfa384x_usbin_rx(wlandev, skb);
  2855. skb = NULL;
  2856. }
  2857. }
  2858. goto exit;
  2859. }
  2860. if (HFA384x_USB_ISTXFRM(type)) {
  2861. if (action == HANDLE)
  2862. hfa384x_usbin_txcompl(wlandev, usbin);
  2863. goto exit;
  2864. }
  2865. switch (type) {
  2866. case HFA384x_USB_INFOFRM:
  2867. if (action == ABORT)
  2868. goto exit;
  2869. if (action == HANDLE)
  2870. hfa384x_usbin_info(wlandev, usbin);
  2871. break;
  2872. case HFA384x_USB_CMDRESP:
  2873. case HFA384x_USB_WRIDRESP:
  2874. case HFA384x_USB_RRIDRESP:
  2875. case HFA384x_USB_WMEMRESP:
  2876. case HFA384x_USB_RMEMRESP:
  2877. /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */
  2878. hfa384x_usbin_ctlx(hw, usbin, urb_status);
  2879. break;
  2880. case HFA384x_USB_BUFAVAIL:
  2881. pr_debug("Received BUFAVAIL packet, frmlen=%d\n",
  2882. usbin->bufavail.frmlen);
  2883. break;
  2884. case HFA384x_USB_ERROR:
  2885. pr_debug("Received USB_ERROR packet, errortype=%d\n",
  2886. usbin->usberror.errortype);
  2887. break;
  2888. default:
  2889. pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n",
  2890. usbin->type, urb_status);
  2891. break;
  2892. } /* switch */
  2893. exit:
  2894. if (skb)
  2895. dev_kfree_skb(skb);
  2896. }
  2897. /*----------------------------------------------------------------
  2898. * hfa384x_usbin_ctlx
  2899. *
  2900. * We've received a URB containing a Prism2 "response" message.
  2901. * This message needs to be matched up with a CTLX on the active
  2902. * queue and our state updated accordingly.
  2903. *
  2904. * Arguments:
  2905. * hw ptr to hfa384x_t
  2906. * usbin ptr to USB IN packet
  2907. * urb_status status of this Bulk-In URB
  2908. *
  2909. * Returns:
  2910. * nothing
  2911. *
  2912. * Side effects:
  2913. *
  2914. * Call context:
  2915. * interrupt
  2916. ----------------------------------------------------------------*/
  2917. static void hfa384x_usbin_ctlx(hfa384x_t *hw, hfa384x_usbin_t *usbin,
  2918. int urb_status)
  2919. {
  2920. hfa384x_usbctlx_t *ctlx;
  2921. int run_queue = 0;
  2922. unsigned long flags;
  2923. retry:
  2924. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  2925. /* There can be only one CTLX on the active queue
  2926. * at any one time, and this is the CTLX that the
  2927. * timers are waiting for.
  2928. */
  2929. if (list_empty(&hw->ctlxq.active))
  2930. goto unlock;
  2931. /* Remove the "response timeout". It's possible that
  2932. * we are already too late, and that the timeout is
  2933. * already running. And that's just too bad for us,
  2934. * because we could lose our CTLX from the active
  2935. * queue here ...
  2936. */
  2937. if (del_timer(&hw->resptimer) == 0) {
  2938. if (hw->resp_timer_done == 0) {
  2939. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  2940. goto retry;
  2941. }
  2942. } else {
  2943. hw->resp_timer_done = 1;
  2944. }
  2945. ctlx = get_active_ctlx(hw);
  2946. if (urb_status != 0) {
  2947. /*
  2948. * Bad CTLX, so get rid of it. But we only
  2949. * remove it from the active queue if we're no
  2950. * longer expecting the OUT URB to complete.
  2951. */
  2952. if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
  2953. run_queue = 1;
  2954. } else {
  2955. const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000));
  2956. /*
  2957. * Check that our message is what we're expecting ...
  2958. */
  2959. if (ctlx->outbuf.type != intype) {
  2960. netdev_warn(hw->wlandev->netdev,
  2961. "Expected IN[%d], received IN[%d] - ignored.\n",
  2962. le16_to_cpu(ctlx->outbuf.type),
  2963. le16_to_cpu(intype));
  2964. goto unlock;
  2965. }
  2966. /* This URB has succeeded, so grab the data ... */
  2967. memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf));
  2968. switch (ctlx->state) {
  2969. case CTLX_REQ_SUBMITTED:
  2970. /*
  2971. * We have received our response URB before
  2972. * our request has been acknowledged. Odd,
  2973. * but our OUT URB is still alive...
  2974. */
  2975. pr_debug("Causality violation: please reboot Universe\n");
  2976. ctlx->state = CTLX_RESP_COMPLETE;
  2977. break;
  2978. case CTLX_REQ_COMPLETE:
  2979. /*
  2980. * This is the usual path: our request
  2981. * has already been acknowledged, and
  2982. * now we have received the reply too.
  2983. */
  2984. ctlx->state = CTLX_COMPLETE;
  2985. unlocked_usbctlx_complete(hw, ctlx);
  2986. run_queue = 1;
  2987. break;
  2988. default:
  2989. /*
  2990. * Throw this CTLX away ...
  2991. */
  2992. netdev_err(hw->wlandev->netdev,
  2993. "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n",
  2994. le16_to_cpu(ctlx->outbuf.type),
  2995. ctlxstr(ctlx->state));
  2996. if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0)
  2997. run_queue = 1;
  2998. break;
  2999. } /* switch */
  3000. }
  3001. unlock:
  3002. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3003. if (run_queue)
  3004. hfa384x_usbctlxq_run(hw);
  3005. }
  3006. /*----------------------------------------------------------------
  3007. * hfa384x_usbin_txcompl
  3008. *
  3009. * At this point we have the results of a previous transmit.
  3010. *
  3011. * Arguments:
  3012. * wlandev wlan device
  3013. * usbin ptr to the usb transfer buffer
  3014. *
  3015. * Returns:
  3016. * nothing
  3017. *
  3018. * Side effects:
  3019. *
  3020. * Call context:
  3021. * interrupt
  3022. ----------------------------------------------------------------*/
  3023. static void hfa384x_usbin_txcompl(wlandevice_t *wlandev,
  3024. hfa384x_usbin_t *usbin)
  3025. {
  3026. u16 status;
  3027. status = le16_to_cpu(usbin->type); /* yeah I know it says type... */
  3028. /* Was there an error? */
  3029. if (HFA384x_TXSTATUS_ISERROR(status))
  3030. prism2sta_ev_txexc(wlandev, status);
  3031. else
  3032. prism2sta_ev_tx(wlandev, status);
  3033. }
  3034. /*----------------------------------------------------------------
  3035. * hfa384x_usbin_rx
  3036. *
  3037. * At this point we have a successful received a rx frame packet.
  3038. *
  3039. * Arguments:
  3040. * wlandev wlan device
  3041. * usbin ptr to the usb transfer buffer
  3042. *
  3043. * Returns:
  3044. * nothing
  3045. *
  3046. * Side effects:
  3047. *
  3048. * Call context:
  3049. * interrupt
  3050. ----------------------------------------------------------------*/
  3051. static void hfa384x_usbin_rx(wlandevice_t *wlandev, struct sk_buff *skb)
  3052. {
  3053. hfa384x_usbin_t *usbin = (hfa384x_usbin_t *)skb->data;
  3054. hfa384x_t *hw = wlandev->priv;
  3055. int hdrlen;
  3056. struct p80211_rxmeta *rxmeta;
  3057. u16 data_len;
  3058. u16 fc;
  3059. /* Byte order convert once up front. */
  3060. usbin->rxfrm.desc.status = le16_to_cpu(usbin->rxfrm.desc.status);
  3061. usbin->rxfrm.desc.time = le32_to_cpu(usbin->rxfrm.desc.time);
  3062. /* Now handle frame based on port# */
  3063. switch (HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status)) {
  3064. case 0:
  3065. fc = le16_to_cpu(usbin->rxfrm.desc.frame_control);
  3066. /* If exclude and we receive an unencrypted, drop it */
  3067. if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) &&
  3068. !WLAN_GET_FC_ISWEP(fc)) {
  3069. break;
  3070. }
  3071. data_len = le16_to_cpu(usbin->rxfrm.desc.data_len);
  3072. /* How much header data do we have? */
  3073. hdrlen = p80211_headerlen(fc);
  3074. /* Pull off the descriptor */
  3075. skb_pull(skb, sizeof(hfa384x_rx_frame_t));
  3076. /* Now shunt the header block up against the data block
  3077. * with an "overlapping" copy
  3078. */
  3079. memmove(skb_push(skb, hdrlen),
  3080. &usbin->rxfrm.desc.frame_control, hdrlen);
  3081. skb->dev = wlandev->netdev;
  3082. skb->dev->last_rx = jiffies;
  3083. /* And set the frame length properly */
  3084. skb_trim(skb, data_len + hdrlen);
  3085. /* The prism2 series does not return the CRC */
  3086. memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN);
  3087. skb_reset_mac_header(skb);
  3088. /* Attach the rxmeta, set some stuff */
  3089. p80211skb_rxmeta_attach(wlandev, skb);
  3090. rxmeta = P80211SKB_RXMETA(skb);
  3091. rxmeta->mactime = usbin->rxfrm.desc.time;
  3092. rxmeta->rxrate = usbin->rxfrm.desc.rate;
  3093. rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust;
  3094. rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust;
  3095. prism2sta_ev_rx(wlandev, skb);
  3096. break;
  3097. case 7:
  3098. if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) {
  3099. /* Copy to wlansnif skb */
  3100. hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm);
  3101. dev_kfree_skb(skb);
  3102. } else {
  3103. pr_debug("Received monitor frame: FCSerr set\n");
  3104. }
  3105. break;
  3106. default:
  3107. netdev_warn(hw->wlandev->netdev, "Received frame on unsupported port=%d\n",
  3108. HFA384x_RXSTATUS_MACPORT_GET(
  3109. usbin->rxfrm.desc.status));
  3110. break;
  3111. }
  3112. }
  3113. /*----------------------------------------------------------------
  3114. * hfa384x_int_rxmonitor
  3115. *
  3116. * Helper function for int_rx. Handles monitor frames.
  3117. * Note that this function allocates space for the FCS and sets it
  3118. * to 0xffffffff. The hfa384x doesn't give us the FCS value but the
  3119. * higher layers expect it. 0xffffffff is used as a flag to indicate
  3120. * the FCS is bogus.
  3121. *
  3122. * Arguments:
  3123. * wlandev wlan device structure
  3124. * rxfrm rx descriptor read from card in int_rx
  3125. *
  3126. * Returns:
  3127. * nothing
  3128. *
  3129. * Side effects:
  3130. * Allocates an skb and passes it up via the PF_PACKET interface.
  3131. * Call context:
  3132. * interrupt
  3133. ----------------------------------------------------------------*/
  3134. static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
  3135. hfa384x_usb_rxfrm_t *rxfrm)
  3136. {
  3137. hfa384x_rx_frame_t *rxdesc = &(rxfrm->desc);
  3138. unsigned int hdrlen = 0;
  3139. unsigned int datalen = 0;
  3140. unsigned int skblen = 0;
  3141. u8 *datap;
  3142. u16 fc;
  3143. struct sk_buff *skb;
  3144. hfa384x_t *hw = wlandev->priv;
  3145. /* Remember the status, time, and data_len fields are in host order */
  3146. /* Figure out how big the frame is */
  3147. fc = le16_to_cpu(rxdesc->frame_control);
  3148. hdrlen = p80211_headerlen(fc);
  3149. datalen = le16_to_cpu(rxdesc->data_len);
  3150. /* Allocate an ind message+framesize skb */
  3151. skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN;
  3152. /* sanity check the length */
  3153. if (skblen >
  3154. (sizeof(struct p80211_caphdr) +
  3155. WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) {
  3156. pr_debug("overlen frm: len=%zd\n",
  3157. skblen - sizeof(struct p80211_caphdr));
  3158. }
  3159. skb = dev_alloc_skb(skblen);
  3160. if (skb == NULL)
  3161. return;
  3162. /* only prepend the prism header if in the right mode */
  3163. if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
  3164. (hw->sniffhdr != 0)) {
  3165. struct p80211_caphdr *caphdr;
  3166. /* The NEW header format! */
  3167. datap = skb_put(skb, sizeof(struct p80211_caphdr));
  3168. caphdr = (struct p80211_caphdr *)datap;
  3169. caphdr->version = htonl(P80211CAPTURE_VERSION);
  3170. caphdr->length = htonl(sizeof(struct p80211_caphdr));
  3171. caphdr->mactime = __cpu_to_be64(rxdesc->time) * 1000;
  3172. caphdr->hosttime = __cpu_to_be64(jiffies);
  3173. caphdr->phytype = htonl(4); /* dss_dot11_b */
  3174. caphdr->channel = htonl(hw->sniff_channel);
  3175. caphdr->datarate = htonl(rxdesc->rate);
  3176. caphdr->antenna = htonl(0); /* unknown */
  3177. caphdr->priority = htonl(0); /* unknown */
  3178. caphdr->ssi_type = htonl(3); /* rssi_raw */
  3179. caphdr->ssi_signal = htonl(rxdesc->signal);
  3180. caphdr->ssi_noise = htonl(rxdesc->silence);
  3181. caphdr->preamble = htonl(0); /* unknown */
  3182. caphdr->encoding = htonl(1); /* cck */
  3183. }
  3184. /* Copy the 802.11 header to the skb
  3185. (ctl frames may be less than a full header) */
  3186. datap = skb_put(skb, hdrlen);
  3187. memcpy(datap, &(rxdesc->frame_control), hdrlen);
  3188. /* If any, copy the data from the card to the skb */
  3189. if (datalen > 0) {
  3190. datap = skb_put(skb, datalen);
  3191. memcpy(datap, rxfrm->data, datalen);
  3192. /* check for unencrypted stuff if WEP bit set. */
  3193. if (*(datap - hdrlen + 1) & 0x40) /* wep set */
  3194. if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa))
  3195. /* clear wep; it's the 802.2 header! */
  3196. *(datap - hdrlen + 1) &= 0xbf;
  3197. }
  3198. if (hw->sniff_fcs) {
  3199. /* Set the FCS */
  3200. datap = skb_put(skb, WLAN_CRC_LEN);
  3201. memset(datap, 0xff, WLAN_CRC_LEN);
  3202. }
  3203. /* pass it back up */
  3204. prism2sta_ev_rx(wlandev, skb);
  3205. }
  3206. /*----------------------------------------------------------------
  3207. * hfa384x_usbin_info
  3208. *
  3209. * At this point we have a successful received a Prism2 info frame.
  3210. *
  3211. * Arguments:
  3212. * wlandev wlan device
  3213. * usbin ptr to the usb transfer buffer
  3214. *
  3215. * Returns:
  3216. * nothing
  3217. *
  3218. * Side effects:
  3219. *
  3220. * Call context:
  3221. * interrupt
  3222. ----------------------------------------------------------------*/
  3223. static void hfa384x_usbin_info(wlandevice_t *wlandev, hfa384x_usbin_t *usbin)
  3224. {
  3225. usbin->infofrm.info.framelen =
  3226. le16_to_cpu(usbin->infofrm.info.framelen);
  3227. prism2sta_ev_info(wlandev, &usbin->infofrm.info);
  3228. }
  3229. /*----------------------------------------------------------------
  3230. * hfa384x_usbout_callback
  3231. *
  3232. * Callback for URBs on the BULKOUT endpoint.
  3233. *
  3234. * Arguments:
  3235. * urb ptr to the completed urb
  3236. *
  3237. * Returns:
  3238. * nothing
  3239. *
  3240. * Side effects:
  3241. *
  3242. * Call context:
  3243. * interrupt
  3244. ----------------------------------------------------------------*/
  3245. static void hfa384x_usbout_callback(struct urb *urb)
  3246. {
  3247. wlandevice_t *wlandev = urb->context;
  3248. hfa384x_usbout_t *usbout = urb->transfer_buffer;
  3249. #ifdef DEBUG_USB
  3250. dbprint_urb(urb);
  3251. #endif
  3252. if (wlandev && wlandev->netdev) {
  3253. switch (urb->status) {
  3254. case 0:
  3255. hfa384x_usbout_tx(wlandev, usbout);
  3256. break;
  3257. case -EPIPE:
  3258. {
  3259. hfa384x_t *hw = wlandev->priv;
  3260. netdev_warn(hw->wlandev->netdev,
  3261. "%s tx pipe stalled: requesting reset\n",
  3262. wlandev->netdev->name);
  3263. if (!test_and_set_bit
  3264. (WORK_TX_HALT, &hw->usb_flags))
  3265. schedule_work(&hw->usb_work);
  3266. wlandev->netdev->stats.tx_errors++;
  3267. break;
  3268. }
  3269. case -EPROTO:
  3270. case -ETIMEDOUT:
  3271. case -EILSEQ:
  3272. {
  3273. hfa384x_t *hw = wlandev->priv;
  3274. if (!test_and_set_bit
  3275. (THROTTLE_TX, &hw->usb_flags) &&
  3276. !timer_pending(&hw->throttle)) {
  3277. mod_timer(&hw->throttle,
  3278. jiffies + THROTTLE_JIFFIES);
  3279. }
  3280. wlandev->netdev->stats.tx_errors++;
  3281. netif_stop_queue(wlandev->netdev);
  3282. break;
  3283. }
  3284. case -ENOENT:
  3285. case -ESHUTDOWN:
  3286. /* Ignorable errors */
  3287. break;
  3288. default:
  3289. netdev_info(wlandev->netdev, "unknown urb->status=%d\n",
  3290. urb->status);
  3291. wlandev->netdev->stats.tx_errors++;
  3292. break;
  3293. } /* switch */
  3294. }
  3295. }
  3296. /*----------------------------------------------------------------
  3297. * hfa384x_ctlxout_callback
  3298. *
  3299. * Callback for control data on the BULKOUT endpoint.
  3300. *
  3301. * Arguments:
  3302. * urb ptr to the completed urb
  3303. *
  3304. * Returns:
  3305. * nothing
  3306. *
  3307. * Side effects:
  3308. *
  3309. * Call context:
  3310. * interrupt
  3311. ----------------------------------------------------------------*/
  3312. static void hfa384x_ctlxout_callback(struct urb *urb)
  3313. {
  3314. hfa384x_t *hw = urb->context;
  3315. int delete_resptimer = 0;
  3316. int timer_ok = 1;
  3317. int run_queue = 0;
  3318. hfa384x_usbctlx_t *ctlx;
  3319. unsigned long flags;
  3320. pr_debug("urb->status=%d\n", urb->status);
  3321. #ifdef DEBUG_USB
  3322. dbprint_urb(urb);
  3323. #endif
  3324. if ((urb->status == -ESHUTDOWN) ||
  3325. (urb->status == -ENODEV) || (hw == NULL))
  3326. return;
  3327. retry:
  3328. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  3329. /*
  3330. * Only one CTLX at a time on the "active" list, and
  3331. * none at all if we are unplugged. However, we can
  3332. * rely on the disconnect function to clean everything
  3333. * up if someone unplugged the adapter.
  3334. */
  3335. if (list_empty(&hw->ctlxq.active)) {
  3336. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3337. return;
  3338. }
  3339. /*
  3340. * Having something on the "active" queue means
  3341. * that we have timers to worry about ...
  3342. */
  3343. if (del_timer(&hw->reqtimer) == 0) {
  3344. if (hw->req_timer_done == 0) {
  3345. /*
  3346. * This timer was actually running while we
  3347. * were trying to delete it. Let it terminate
  3348. * gracefully instead.
  3349. */
  3350. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3351. goto retry;
  3352. }
  3353. } else {
  3354. hw->req_timer_done = 1;
  3355. }
  3356. ctlx = get_active_ctlx(hw);
  3357. if (urb->status == 0) {
  3358. /* Request portion of a CTLX is successful */
  3359. switch (ctlx->state) {
  3360. case CTLX_REQ_SUBMITTED:
  3361. /* This OUT-ACK received before IN */
  3362. ctlx->state = CTLX_REQ_COMPLETE;
  3363. break;
  3364. case CTLX_RESP_COMPLETE:
  3365. /* IN already received before this OUT-ACK,
  3366. * so this command must now be complete.
  3367. */
  3368. ctlx->state = CTLX_COMPLETE;
  3369. unlocked_usbctlx_complete(hw, ctlx);
  3370. run_queue = 1;
  3371. break;
  3372. default:
  3373. /* This is NOT a valid CTLX "success" state! */
  3374. netdev_err(hw->wlandev->netdev,
  3375. "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n",
  3376. le16_to_cpu(ctlx->outbuf.type),
  3377. ctlxstr(ctlx->state), urb->status);
  3378. break;
  3379. } /* switch */
  3380. } else {
  3381. /* If the pipe has stalled then we need to reset it */
  3382. if ((urb->status == -EPIPE) &&
  3383. !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) {
  3384. netdev_warn(hw->wlandev->netdev,
  3385. "%s tx pipe stalled: requesting reset\n",
  3386. hw->wlandev->netdev->name);
  3387. schedule_work(&hw->usb_work);
  3388. }
  3389. /* If someone cancels the OUT URB then its status
  3390. * should be either -ECONNRESET or -ENOENT.
  3391. */
  3392. ctlx->state = CTLX_REQ_FAILED;
  3393. unlocked_usbctlx_complete(hw, ctlx);
  3394. delete_resptimer = 1;
  3395. run_queue = 1;
  3396. }
  3397. delresp:
  3398. if (delete_resptimer) {
  3399. timer_ok = del_timer(&hw->resptimer);
  3400. if (timer_ok != 0)
  3401. hw->resp_timer_done = 1;
  3402. }
  3403. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3404. if (!timer_ok && (hw->resp_timer_done == 0)) {
  3405. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  3406. goto delresp;
  3407. }
  3408. if (run_queue)
  3409. hfa384x_usbctlxq_run(hw);
  3410. }
  3411. /*----------------------------------------------------------------
  3412. * hfa384x_usbctlx_reqtimerfn
  3413. *
  3414. * Timer response function for CTLX request timeouts. If this
  3415. * function is called, it means that the callback for the OUT
  3416. * URB containing a Prism2.x XXX_Request was never called.
  3417. *
  3418. * Arguments:
  3419. * data a ptr to the hfa384x_t
  3420. *
  3421. * Returns:
  3422. * nothing
  3423. *
  3424. * Side effects:
  3425. *
  3426. * Call context:
  3427. * interrupt
  3428. ----------------------------------------------------------------*/
  3429. static void hfa384x_usbctlx_reqtimerfn(unsigned long data)
  3430. {
  3431. hfa384x_t *hw = (hfa384x_t *)data;
  3432. unsigned long flags;
  3433. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  3434. hw->req_timer_done = 1;
  3435. /* Removing the hardware automatically empties
  3436. * the active list ...
  3437. */
  3438. if (!list_empty(&hw->ctlxq.active)) {
  3439. /*
  3440. * We must ensure that our URB is removed from
  3441. * the system, if it hasn't already expired.
  3442. */
  3443. hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK;
  3444. if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) {
  3445. hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
  3446. ctlx->state = CTLX_REQ_FAILED;
  3447. /* This URB was active, but has now been
  3448. * cancelled. It will now have a status of
  3449. * -ECONNRESET in the callback function.
  3450. *
  3451. * We are cancelling this CTLX, so we're
  3452. * not going to need to wait for a response.
  3453. * The URB's callback function will check
  3454. * that this timer is truly dead.
  3455. */
  3456. if (del_timer(&hw->resptimer) != 0)
  3457. hw->resp_timer_done = 1;
  3458. }
  3459. }
  3460. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3461. }
  3462. /*----------------------------------------------------------------
  3463. * hfa384x_usbctlx_resptimerfn
  3464. *
  3465. * Timer response function for CTLX response timeouts. If this
  3466. * function is called, it means that the callback for the IN
  3467. * URB containing a Prism2.x XXX_Response was never called.
  3468. *
  3469. * Arguments:
  3470. * data a ptr to the hfa384x_t
  3471. *
  3472. * Returns:
  3473. * nothing
  3474. *
  3475. * Side effects:
  3476. *
  3477. * Call context:
  3478. * interrupt
  3479. ----------------------------------------------------------------*/
  3480. static void hfa384x_usbctlx_resptimerfn(unsigned long data)
  3481. {
  3482. hfa384x_t *hw = (hfa384x_t *)data;
  3483. unsigned long flags;
  3484. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  3485. hw->resp_timer_done = 1;
  3486. /* The active list will be empty if the
  3487. * adapter has been unplugged ...
  3488. */
  3489. if (!list_empty(&hw->ctlxq.active)) {
  3490. hfa384x_usbctlx_t *ctlx = get_active_ctlx(hw);
  3491. if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) {
  3492. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3493. hfa384x_usbctlxq_run(hw);
  3494. return;
  3495. }
  3496. }
  3497. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3498. }
  3499. /*----------------------------------------------------------------
  3500. * hfa384x_usb_throttlefn
  3501. *
  3502. *
  3503. * Arguments:
  3504. * data ptr to hw
  3505. *
  3506. * Returns:
  3507. * Nothing
  3508. *
  3509. * Side effects:
  3510. *
  3511. * Call context:
  3512. * Interrupt
  3513. ----------------------------------------------------------------*/
  3514. static void hfa384x_usb_throttlefn(unsigned long data)
  3515. {
  3516. hfa384x_t *hw = (hfa384x_t *)data;
  3517. unsigned long flags;
  3518. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  3519. /*
  3520. * We need to check BOTH the RX and the TX throttle controls,
  3521. * so we use the bitwise OR instead of the logical OR.
  3522. */
  3523. pr_debug("flags=0x%lx\n", hw->usb_flags);
  3524. if (!hw->wlandev->hwremoved &&
  3525. ((test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) &&
  3526. !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags))
  3527. |
  3528. (test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) &&
  3529. !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags))
  3530. )) {
  3531. schedule_work(&hw->usb_work);
  3532. }
  3533. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3534. }
  3535. /*----------------------------------------------------------------
  3536. * hfa384x_usbctlx_submit
  3537. *
  3538. * Called from the doxxx functions to submit a CTLX to the queue
  3539. *
  3540. * Arguments:
  3541. * hw ptr to the hw struct
  3542. * ctlx ctlx structure to enqueue
  3543. *
  3544. * Returns:
  3545. * -ENODEV if the adapter is unplugged
  3546. * 0
  3547. *
  3548. * Side effects:
  3549. *
  3550. * Call context:
  3551. * process or interrupt
  3552. ----------------------------------------------------------------*/
  3553. static int hfa384x_usbctlx_submit(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx)
  3554. {
  3555. unsigned long flags;
  3556. spin_lock_irqsave(&hw->ctlxq.lock, flags);
  3557. if (hw->wlandev->hwremoved) {
  3558. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3559. return -ENODEV;
  3560. }
  3561. ctlx->state = CTLX_PENDING;
  3562. list_add_tail(&ctlx->list, &hw->ctlxq.pending);
  3563. spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
  3564. hfa384x_usbctlxq_run(hw);
  3565. return 0;
  3566. }
  3567. /*----------------------------------------------------------------
  3568. * hfa384x_usbout_tx
  3569. *
  3570. * At this point we have finished a send of a frame. Mark the URB
  3571. * as available and call ev_alloc to notify higher layers we're
  3572. * ready for more.
  3573. *
  3574. * Arguments:
  3575. * wlandev wlan device
  3576. * usbout ptr to the usb transfer buffer
  3577. *
  3578. * Returns:
  3579. * nothing
  3580. *
  3581. * Side effects:
  3582. *
  3583. * Call context:
  3584. * interrupt
  3585. ----------------------------------------------------------------*/
  3586. static void hfa384x_usbout_tx(wlandevice_t *wlandev, hfa384x_usbout_t *usbout)
  3587. {
  3588. prism2sta_ev_alloc(wlandev);
  3589. }
  3590. /*----------------------------------------------------------------
  3591. * hfa384x_isgood_pdrcore
  3592. *
  3593. * Quick check of PDR codes.
  3594. *
  3595. * Arguments:
  3596. * pdrcode PDR code number (host order)
  3597. *
  3598. * Returns:
  3599. * zero not good.
  3600. * one is good.
  3601. *
  3602. * Side effects:
  3603. *
  3604. * Call context:
  3605. ----------------------------------------------------------------*/
  3606. static int hfa384x_isgood_pdrcode(u16 pdrcode)
  3607. {
  3608. switch (pdrcode) {
  3609. case HFA384x_PDR_END_OF_PDA:
  3610. case HFA384x_PDR_PCB_PARTNUM:
  3611. case HFA384x_PDR_PDAVER:
  3612. case HFA384x_PDR_NIC_SERIAL:
  3613. case HFA384x_PDR_MKK_MEASUREMENTS:
  3614. case HFA384x_PDR_NIC_RAMSIZE:
  3615. case HFA384x_PDR_MFISUPRANGE:
  3616. case HFA384x_PDR_CFISUPRANGE:
  3617. case HFA384x_PDR_NICID:
  3618. case HFA384x_PDR_MAC_ADDRESS:
  3619. case HFA384x_PDR_REGDOMAIN:
  3620. case HFA384x_PDR_ALLOWED_CHANNEL:
  3621. case HFA384x_PDR_DEFAULT_CHANNEL:
  3622. case HFA384x_PDR_TEMPTYPE:
  3623. case HFA384x_PDR_IFR_SETTING:
  3624. case HFA384x_PDR_RFR_SETTING:
  3625. case HFA384x_PDR_HFA3861_BASELINE:
  3626. case HFA384x_PDR_HFA3861_SHADOW:
  3627. case HFA384x_PDR_HFA3861_IFRF:
  3628. case HFA384x_PDR_HFA3861_CHCALSP:
  3629. case HFA384x_PDR_HFA3861_CHCALI:
  3630. case HFA384x_PDR_3842_NIC_CONFIG:
  3631. case HFA384x_PDR_USB_ID:
  3632. case HFA384x_PDR_PCI_ID:
  3633. case HFA384x_PDR_PCI_IFCONF:
  3634. case HFA384x_PDR_PCI_PMCONF:
  3635. case HFA384x_PDR_RFENRGY:
  3636. case HFA384x_PDR_HFA3861_MANF_TESTSP:
  3637. case HFA384x_PDR_HFA3861_MANF_TESTI:
  3638. /* code is OK */
  3639. return 1;
  3640. default:
  3641. if (pdrcode < 0x1000) {
  3642. /* code is OK, but we don't know exactly what it is */
  3643. pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n",
  3644. pdrcode);
  3645. return 1;
  3646. }
  3647. break;
  3648. }
  3649. /* bad code */
  3650. pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n",
  3651. pdrcode);
  3652. return 0;
  3653. }