hfa384x_usb.c 102 KB

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