0026-dwc_otg-fiq_fsm-Base-commit-for-driver-rewrite.patch 162 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862
  1. From d434f75bc6411d2964fce7fee50fe0ce49dd02eb Mon Sep 17 00:00:00 2001
  2. From: P33M <P33M@github.com>
  3. Date: Wed, 19 Mar 2014 12:58:23 +0000
  4. Subject: [PATCH 026/114] dwc_otg: fiq_fsm: Base commit for driver rewrite
  5. This commit removes the previous FIQ fixes entirely and adds fiq_fsm.
  6. This rewrite features much more complete support for split transactions
  7. and takes into account several OTG hardware bugs. High-speed
  8. isochronous transactions are also capable of being performed by fiq_fsm.
  9. All driver options have been removed and replaced with:
  10. - dwc_otg.fiq_enable (bool)
  11. - dwc_otg.fiq_fsm_enable (bool)
  12. - dwc_otg.fiq_fsm_mask (bitmask)
  13. - dwc_otg.nak_holdoff (unsigned int)
  14. Defaults are specified such that fiq_fsm behaves similarly to the
  15. previously implemented FIQ fixes.
  16. fiq_fsm: Push error recovery into the FIQ when fiq_fsm is used
  17. If the transfer associated with a QTD failed due to a bus error, the HCD
  18. would retry the transfer up to 3 times (implementing the USB2.0
  19. three-strikes retry in software).
  20. Due to the masking mechanism used by fiq_fsm, it is only possible to pass
  21. a single interrupt through to the HCD per-transfer.
  22. In this instance host channels would fall off the radar because the error
  23. reset would function, but the subsequent channel halt would be lost.
  24. Push the error count reset into the FIQ handler.
  25. fiq_fsm: Implement timeout mechanism
  26. For full-speed endpoints with a large packet size, interrupt latency
  27. runs the risk of the FIQ starting a transaction too late in a full-speed
  28. frame. If the device is still transmitting data when EOF2 for the
  29. downstream frame occurs, the hub will disable the port. This change is
  30. not reflected in the hub status endpoint and the device becomes
  31. unresponsive.
  32. Prevent high-bandwidth transactions from being started too late in a
  33. frame. The mechanism is not guaranteed: a combination of bit stuffing
  34. and hub latency may still result in a device overrunning.
  35. fiq_fsm: fix bounce buffer utilisation for Isochronous OUT
  36. Multi-packet isochronous OUT transactions were subject to a few bounday
  37. bugs. Fix them.
  38. Audio playback is now much more robust: however, an issue stands with
  39. devices that have adaptive sinks - ALSA plays samples too fast.
  40. dwc_otg: Return full-speed frame numbers in HS mode
  41. The frame counter increments on every *microframe* in high-speed mode.
  42. Most device drivers expect this number to be in full-speed frames - this
  43. caused considerable confusion to e.g. snd_usb_audio which uses the
  44. frame counter to estimate the number of samples played.
  45. fiq_fsm: save PID on completion of interrupt OUT transfers
  46. Also add edge case handling for interrupt transports.
  47. Note that for periodic split IN, data toggles are unimplemented in the
  48. OTG host hardware - it unconditionally accepts any PID.
  49. fiq_fsm: add missing case for fiq_fsm_tt_in_use()
  50. Certain combinations of bitrate and endpoint activity could
  51. result in a periodic transaction erroneously getting started
  52. while the previous Isochronous OUT was still active.
  53. fiq_fsm: clear hcintmsk for aborted transactions
  54. Prevents the FIQ from erroneously handling interrupts
  55. on a timed out channel.
  56. fiq_fsm: enable by default
  57. fiq_fsm: fix dequeues for non-periodic split transactions
  58. If a dequeue happened between the SSPLIT and CSPLIT phases of the
  59. transaction, the HCD would never receive an interrupt.
  60. fiq_fsm: Disable by default
  61. fiq_fsm: Handle HC babble errors
  62. The HCTSIZ transfer size field raises a babble interrupt if
  63. the counter wraps. Handle the resulting interrupt in this case.
  64. dwc_otg: fix interrupt registration for fiq_enable=0
  65. Additionally make the module parameter conditional for wherever
  66. hcd->fiq_state is touched.
  67. fiq_fsm: Enable by default
  68. ---
  69. arch/arm/mach-bcm2708/bcm2708.c | 24 +-
  70. drivers/usb/host/dwc_otg/Makefile | 3 +-
  71. drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c | 47 +-
  72. drivers/usb/host/dwc_otg/dwc_otg_driver.c | 51 +-
  73. drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c | 1290 ++++++++++++++++++++++++++
  74. drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h | 353 +++++++
  75. drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S | 80 ++
  76. drivers/usb/host/dwc_otg/dwc_otg_hcd.c | 775 +++++++++++++---
  77. drivers/usb/host/dwc_otg/dwc_otg_hcd.h | 11 +
  78. drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c | 999 ++++++++++----------
  79. drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c | 113 ++-
  80. drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c | 41 +-
  81. drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c | 113 ---
  82. drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h | 48 -
  83. drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c | 8 +-
  84. 15 files changed, 2991 insertions(+), 965 deletions(-)
  85. create mode 100644 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  86. create mode 100644 drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  87. create mode 100644 drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  88. delete mode 100755 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
  89. delete mode 100755 drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
  90. --- a/arch/arm/mach-bcm2708/bcm2708.c
  91. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  92. @@ -330,22 +330,13 @@ static struct resource bcm2708_usb_resou
  93. .end = IRQ_HOSTPORT,
  94. .flags = IORESOURCE_IRQ,
  95. },
  96. + [3] = {
  97. + .start = IRQ_USB,
  98. + .end = IRQ_USB,
  99. + .flags = IORESOURCE_IRQ,
  100. + },
  101. };
  102. -bool fiq_fix_enable = true;
  103. -
  104. -static struct resource bcm2708_usb_resources_no_fiq_fix[] = {
  105. - [0] = {
  106. - .start = USB_BASE,
  107. - .end = USB_BASE + SZ_128K - 1,
  108. - .flags = IORESOURCE_MEM,
  109. - },
  110. - [1] = {
  111. - .start = IRQ_USB,
  112. - .end = IRQ_USB,
  113. - .flags = IORESOURCE_IRQ,
  114. - },
  115. -};
  116. static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  117. @@ -701,11 +692,6 @@ void __init bcm2708_init(void)
  118. #endif
  119. bcm_register_device(&bcm2708_systemtimer_device);
  120. bcm_register_device(&bcm2708_fb_device);
  121. - if (!fiq_fix_enable)
  122. - {
  123. - bcm2708_usb_device.resource = bcm2708_usb_resources_no_fiq_fix;
  124. - bcm2708_usb_device.num_resources = ARRAY_SIZE(bcm2708_usb_resources_no_fiq_fix);
  125. - }
  126. bcm_register_device(&bcm2708_usb_device);
  127. bcm_register_device(&bcm2708_uart1_device);
  128. bcm_register_device(&bcm2708_powerman_device);
  129. --- a/drivers/usb/host/dwc_otg/Makefile
  130. +++ b/drivers/usb/host/dwc_otg/Makefile
  131. @@ -36,7 +36,8 @@ dwc_otg-objs += dwc_otg_cil.o dwc_otg_ci
  132. dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  133. dwc_otg-objs += dwc_otg_hcd.o dwc_otg_hcd_linux.o dwc_otg_hcd_intr.o dwc_otg_hcd_queue.o dwc_otg_hcd_ddma.o
  134. dwc_otg-objs += dwc_otg_adp.o
  135. -dwc_otg-objs += dwc_otg_mphi_fix.o
  136. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  137. +dwc_otg-objs += dwc_otg_fiq_stub.o
  138. ifneq ($(CFI),)
  139. dwc_otg-objs += dwc_otg_cfi.o
  140. endif
  141. --- a/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  142. +++ b/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  143. @@ -45,7 +45,6 @@
  144. #include "dwc_otg_driver.h"
  145. #include "dwc_otg_pcd.h"
  146. #include "dwc_otg_hcd.h"
  147. -#include "dwc_otg_mphi_fix.h"
  148. #ifdef DEBUG
  149. inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  150. @@ -1319,7 +1318,7 @@ static int32_t dwc_otg_handle_lpm_intr(d
  151. /**
  152. * This function returns the Core Interrupt register.
  153. */
  154. -static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk)
  155. +static inline uint32_t dwc_otg_read_common_intr(dwc_otg_core_if_t * core_if, gintmsk_data_t *reenable_gintmsk, dwc_otg_hcd_t *hcd)
  156. {
  157. gahbcfg_data_t gahbcfg = {.d32 = 0 };
  158. gintsts_data_t gintsts;
  159. @@ -1345,16 +1344,15 @@ static inline uint32_t dwc_otg_read_comm
  160. }
  161. gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  162. gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  163. - {
  164. - unsigned long flags;
  165. -
  166. - // Re-enable the saved interrupts
  167. - local_irq_save(flags);
  168. + if(fiq_enable) {
  169. local_fiq_disable();
  170. - gintmsk.d32 |= gintmsk_common.d32;
  171. - gintsts_saved.d32 &= ~gintmsk_common.d32;
  172. - reenable_gintmsk->d32 = gintmsk.d32;
  173. - local_irq_restore(flags);
  174. + /* Pull in the interrupts that the FIQ has masked */
  175. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  176. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  177. + reenable_gintmsk->d32 |= gintmsk.d32;
  178. + reenable_gintmsk->d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  179. + reenable_gintmsk->d32 &= gintmsk_common.d32;
  180. + local_fiq_enable();
  181. }
  182. gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  183. @@ -1366,13 +1364,15 @@ static inline uint32_t dwc_otg_read_comm
  184. gintsts.d32, gintmsk.d32);
  185. }
  186. #endif
  187. - if (!fiq_fix_enable){
  188. + if (!fiq_enable){
  189. if (gahbcfg.b.glblintrmsk)
  190. return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  191. else
  192. return 0;
  193. - }
  194. - else {
  195. + } else {
  196. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  197. + * Can't trust the global interrupt mask bit in this case.
  198. + */
  199. return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  200. }
  201. @@ -1406,7 +1406,7 @@ int32_t dwc_otg_handle_common_intr(void
  202. {
  203. int retval = 0;
  204. gintsts_data_t gintsts;
  205. - gintmsk_data_t reenable_gintmsk;
  206. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  207. gpwrdn_data_t gpwrdn = {.d32 = 0 };
  208. dwc_otg_device_t *otg_dev = dev;
  209. dwc_otg_core_if_t *core_if = otg_dev->core_if;
  210. @@ -1428,7 +1428,10 @@ int32_t dwc_otg_handle_common_intr(void
  211. }
  212. if (core_if->hibernation_suspend <= 0) {
  213. - gintsts.d32 = dwc_otg_read_common_intr(core_if, &reenable_gintmsk);
  214. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  215. + * of this handler - god only knows why it's done like this
  216. + */
  217. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  218. if (gintsts.b.modemismatch) {
  219. retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  220. @@ -1525,11 +1528,16 @@ int32_t dwc_otg_handle_common_intr(void
  221. gintsts.b.portintr = 1;
  222. DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  223. retval |= 1;
  224. - reenable_gintmsk.b.portintr = 1;
  225. + gintmsk_reenable.b.portintr = 1;
  226. }
  227. -
  228. - DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, reenable_gintmsk.d32);
  229. + /* Did we actually handle anything? if so, unmask the interrupt */
  230. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  231. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  232. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  233. + if (retval) {
  234. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  235. + }
  236. } else {
  237. DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  238. @@ -1583,6 +1591,5 @@ int32_t dwc_otg_handle_common_intr(void
  239. }
  240. if (core_if->lock)
  241. DWC_SPINUNLOCK(core_if->lock);
  242. -
  243. return retval;
  244. }
  245. --- a/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  246. +++ b/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  247. @@ -56,6 +56,7 @@
  248. #include "dwc_otg_core_if.h"
  249. #include "dwc_otg_pcd_if.h"
  250. #include "dwc_otg_hcd_if.h"
  251. +#include "dwc_otg_fiq_fsm.h"
  252. #define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  253. #define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  254. @@ -64,7 +65,6 @@ bool microframe_schedule=true;
  255. static const char dwc_driver_name[] = "dwc_otg";
  256. -extern void* dummy_send;
  257. extern int pcd_init(
  258. #ifdef LM_INTERFACE
  259. @@ -240,13 +240,14 @@ static struct dwc_otg_driver_module_para
  260. .adp_enable = -1,
  261. };
  262. -//Global variable to switch the fiq fix on or off (declared in bcm2708.c)
  263. -extern bool fiq_fix_enable;
  264. +//Global variable to switch the fiq fix on or off
  265. +bool fiq_enable = 1;
  266. // Global variable to enable the split transaction fix
  267. -bool fiq_split_enable = true;
  268. -//Global variable to switch the nak holdoff on or off
  269. -bool nak_holdoff_enable = true;
  270. +bool fiq_fsm_enable = true;
  271. +//Bulk split-transaction NAK holdoff in microframes
  272. +uint16_t nak_holdoff = 8;
  273. +unsigned short fiq_fsm_mask = 0x07;
  274. /**
  275. * This function shows the Driver Version.
  276. @@ -800,7 +801,7 @@ static int dwc_otg_driver_probe(
  277. dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  278. _dev->resource[0].end -
  279. _dev->resource[0].start+1);
  280. - if (fiq_fix_enable)
  281. + if (fiq_enable)
  282. {
  283. if (!request_mem_region(_dev->resource[1].start,
  284. _dev->resource[1].end - _dev->resource[1].start + 1,
  285. @@ -813,7 +814,6 @@ static int dwc_otg_driver_probe(
  286. dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  287. _dev->resource[1].end -
  288. _dev->resource[1].start + 1);
  289. - dummy_send = (void *) kmalloc(16, GFP_ATOMIC);
  290. }
  291. #else
  292. @@ -902,9 +902,9 @@ static int dwc_otg_driver_probe(
  293. */
  294. #if defined(PLATFORM_INTERFACE)
  295. - devirq = platform_get_irq(_dev, 0);
  296. + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
  297. #else
  298. - devirq = _dev->irq;
  299. + devirq = _dev->irq;
  300. #endif
  301. DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  302. devirq);
  303. @@ -1071,9 +1071,9 @@ static int __init dwc_otg_driver_init(vo
  304. int error;
  305. struct device_driver *drv;
  306. - if(fiq_split_enable && !fiq_fix_enable) {
  307. - printk(KERN_WARNING "dwc_otg: fiq_split_enable was set without fiq_fix_enable! Correcting.\n");
  308. - fiq_fix_enable = 1;
  309. + if(fiq_fsm_enable && !fiq_enable) {
  310. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  311. + fiq_enable = 1;
  312. }
  313. printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  314. @@ -1095,9 +1095,9 @@ static int __init dwc_otg_driver_init(vo
  315. printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  316. return retval;
  317. }
  318. - printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_fix_enable ? "enabled":"disabled");
  319. - printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff_enable ? "enabled":"disabled");
  320. - printk(KERN_DEBUG "dwc_otg: FIQ split fix %s\n", fiq_split_enable ? "enabled":"disabled");
  321. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  322. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  323. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  324. error = driver_create_file(drv, &driver_attr_version);
  325. #ifdef DEBUG
  326. @@ -1378,12 +1378,19 @@ MODULE_PARM_DESC(otg_ver, "OTG revision
  327. module_param(microframe_schedule, bool, 0444);
  328. MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  329. -module_param(fiq_fix_enable, bool, 0444);
  330. -MODULE_PARM_DESC(fiq_fix_enable, "Enable the fiq fix");
  331. -module_param(nak_holdoff_enable, bool, 0444);
  332. -MODULE_PARM_DESC(nak_holdoff_enable, "Enable the NAK holdoff");
  333. -module_param(fiq_split_enable, bool, 0444);
  334. -MODULE_PARM_DESC(fiq_split_enable, "Enable the FIQ fix on split transactions");
  335. +module_param(fiq_enable, bool, 0444);
  336. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  337. +module_param(nak_holdoff, ushort, 0644);
  338. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  339. +module_param(fiq_fsm_enable, bool, 0444);
  340. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  341. +module_param(fiq_fsm_mask, ushort, 0444);
  342. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  343. + "Bit 0 : Non-periodic split transactions\n"
  344. + "Bit 1 : Periodic split transactions\n"
  345. + "Bit 2 : High-speed multi-transfer isochronous\n"
  346. + "All other bits should be set 0.");
  347. +
  348. /** @page "Module Parameters"
  349. *
  350. --- /dev/null
  351. +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  352. @@ -0,0 +1,1290 @@
  353. +/*
  354. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  355. + *
  356. + * Copyright (c) 2013 Raspberry Pi Foundation
  357. + *
  358. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  359. + * All rights reserved.
  360. + *
  361. + * Redistribution and use in source and binary forms, with or without
  362. + * modification, are permitted provided that the following conditions are met:
  363. + * * Redistributions of source code must retain the above copyright
  364. + * notice, this list of conditions and the following disclaimer.
  365. + * * Redistributions in binary form must reproduce the above copyright
  366. + * notice, this list of conditions and the following disclaimer in the
  367. + * documentation and/or other materials provided with the distribution.
  368. + * * Neither the name of Raspberry Pi nor the
  369. + * names of its contributors may be used to endorse or promote products
  370. + * derived from this software without specific prior written permission.
  371. + *
  372. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  373. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  374. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  375. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  376. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  377. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  378. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  379. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  380. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  381. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  382. + *
  383. + * This FIQ implements functionality that performs split transactions on
  384. + * the dwc_otg hardware without any outside intervention. A split transaction
  385. + * is "queued" by nominating a specific host channel to perform the entirety
  386. + * of a split transaction. This FIQ will then perform the microframe-precise
  387. + * scheduling required in each phase of the transaction until completion.
  388. + *
  389. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  390. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  391. + * for a FSM-enabled channel.
  392. + *
  393. + * NB: Large parts of this implementation have architecture-specific code.
  394. + * For porting this functionality to other ARM machines, the minimum is required:
  395. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  396. + * to the FIQ
  397. + * - A method of forcing a software generated interrupt from FIQ mode that then
  398. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  399. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  400. + * processor core - there is no locking between the FIQ and IRQ (aside from
  401. + * local_fiq_disable)
  402. + *
  403. + */
  404. +
  405. +#include "dwc_otg_fiq_fsm.h"
  406. +
  407. +
  408. +char buffer[1000*16];
  409. +int wptr;
  410. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  411. +{
  412. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  413. + va_list args;
  414. + char text[17];
  415. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  416. +
  417. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  418. + {
  419. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  420. + va_start(args, fmt);
  421. + vsnprintf(text+8, 9, fmt, args);
  422. + va_end(args);
  423. +
  424. + memcpy(buffer + wptr, text, 16);
  425. + wptr = (wptr + 16) % sizeof(buffer);
  426. + }
  427. +}
  428. +
  429. +/**
  430. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  431. + * @channel: channel to re-enable
  432. + */
  433. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  434. +{
  435. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  436. +
  437. + hcchar.b.chen = 0;
  438. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  439. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  440. + /* Hardware bug workaround: update the ssplit index */
  441. + if (st->channel[n].hcsplt_copy.b.spltena)
  442. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  443. +
  444. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  445. + }
  446. +
  447. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  448. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  449. + hcchar.b.chen = 1;
  450. +
  451. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  452. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  453. +}
  454. +
  455. +/**
  456. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  457. + * @st: Pointer to the channel's state
  458. + * @n : channel number
  459. + *
  460. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  461. + * endpoint direction, set control regs up correctly.
  462. + */
  463. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  464. +{
  465. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  466. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  467. +
  468. + hcsplt.b.compsplt = 1;
  469. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  470. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  471. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  472. + } else {
  473. + // If OUT, the CSPLIT result contains handshake only.
  474. + hctsiz.b.xfersize = 0;
  475. + }
  476. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  477. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  478. + mb();
  479. +}
  480. +
  481. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  482. +{
  483. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  484. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  485. +
  486. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  487. + return st->channel[n].hctsiz_copy.b.xfersize;
  488. + } else {
  489. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  490. + }
  491. +
  492. +}
  493. +
  494. +
  495. +/**
  496. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  497. + *
  498. + * Of use only for IN periodic transfers.
  499. + */
  500. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  501. +{
  502. + hcdma_data_t hcdma;
  503. + int i = st->channel[n].dma_info.index;
  504. + int len;
  505. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  506. +
  507. + len = fiq_get_xfer_len(st, n);
  508. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  509. + st->channel[n].dma_info.slot_len[i] = len;
  510. + i++;
  511. + if (i > 6)
  512. + BUG();
  513. +
  514. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  515. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  516. + st->channel[n].dma_info.index = i;
  517. + return 0;
  518. +}
  519. +
  520. +/**
  521. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  522. + */
  523. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  524. +{
  525. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  526. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  527. + hctsiz.b.pktcnt = 1;
  528. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  529. +}
  530. +
  531. +/**
  532. + * fiq_iso_out_advance() - update DMA address and split position bits
  533. + * for isochronous OUT transactions.
  534. + *
  535. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  536. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  537. + *
  538. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  539. + */
  540. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  541. +{
  542. + hcsplt_data_t hcsplt;
  543. + hctsiz_data_t hctsiz;
  544. + hcdma_data_t hcdma;
  545. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  546. + int last = 0;
  547. + int i = st->channel[n].dma_info.index;
  548. +
  549. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  550. + i++;
  551. + if (i == 4)
  552. + last = 1;
  553. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  554. + last = 1;
  555. +
  556. + /* New DMA address - address of bounce buffer referred to in index */
  557. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  558. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  559. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  560. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  561. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  562. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  563. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  564. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  565. + /* Set up new packet length */
  566. + hctsiz.b.pktcnt = 1;
  567. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  568. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  569. +
  570. + st->channel[n].dma_info.index++;
  571. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  572. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  573. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  574. + return last;
  575. +}
  576. +
  577. +/**
  578. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  579. + *
  580. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  581. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  582. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  583. + * is very unlikely that filling the start-split FIFO will cause data loss.
  584. + * This allows much better interleaving of transactions in an order-independent way-
  585. + * there is no requirement to prioritise isochronous, just a state-space search has
  586. + * to be performed on each periodic start-split complete interrupt.
  587. + */
  588. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  589. +{
  590. + int hub_addr = st->channel[n].hub_addr;
  591. + int port_addr = st->channel[n].port_addr;
  592. + int i, poked = 0;
  593. + for (i = 0; i < num_channels; i++) {
  594. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  595. + continue;
  596. + if (st->channel[i].hub_addr == hub_addr &&
  597. + st->channel[i].port_addr == port_addr) {
  598. + switch (st->channel[i].fsm) {
  599. + case FIQ_PER_ISO_OUT_PENDING:
  600. + if (st->channel[i].nrpackets == 1) {
  601. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  602. + } else {
  603. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  604. + }
  605. + fiq_fsm_restart_channel(st, i, 0);
  606. + poked = 1;
  607. + break;
  608. +
  609. + default:
  610. + break;
  611. + }
  612. + }
  613. + if (poked)
  614. + break;
  615. + }
  616. + return poked;
  617. +}
  618. +
  619. +/**
  620. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  621. + * @n: Channel to use as reference
  622. + *
  623. + */
  624. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  625. +{
  626. + int hub_addr = st->channel[n].hub_addr;
  627. + int port_addr = st->channel[n].port_addr;
  628. + int i, in_use = 0;
  629. + for (i = 0; i < num_channels; i++) {
  630. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  631. + continue;
  632. + switch (st->channel[i].fsm) {
  633. + /* TT is reserved for channels that are in the middle of a periodic
  634. + * split transaction.
  635. + */
  636. + case FIQ_PER_SSPLIT_STARTED:
  637. + case FIQ_PER_CSPLIT_WAIT:
  638. + case FIQ_PER_CSPLIT_NYET1:
  639. + //case FIQ_PER_CSPLIT_POLL:
  640. + case FIQ_PER_ISO_OUT_ACTIVE:
  641. + case FIQ_PER_ISO_OUT_LAST:
  642. + if (st->channel[i].hub_addr == hub_addr &&
  643. + st->channel[i].port_addr == port_addr) {
  644. + in_use = 1;
  645. + }
  646. + break;
  647. + default:
  648. + break;
  649. + }
  650. + if (in_use)
  651. + break;
  652. + }
  653. + return in_use;
  654. +}
  655. +
  656. +/**
  657. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  658. + * to be issued for this IN transaction.
  659. + *
  660. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  661. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  662. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  663. + * size, but for endpoints that give variable-length data then we have to resort
  664. + * to heuristics.
  665. + *
  666. + * We also return whether this is the last CSPLIT to be queued, again based on
  667. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  668. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  669. + */
  670. +
  671. +/*
  672. + * We need some way of guaranteeing if a returned periodic packet of size X
  673. + * has a DATA0 PID.
  674. + * The heuristic value of 144 bytes assumes that the received data has maximal
  675. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  676. + * permissible limit. If the transfer length results in a final packet size
  677. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  678. + * Also used to ensure that an endpoint will nominally only return a single
  679. + * complete-split worth of data.
  680. + */
  681. +#define DATA0_PID_HEURISTIC 144
  682. +
  683. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  684. +{
  685. +
  686. + int i;
  687. + int total_len = 0;
  688. + int more_needed = 1;
  689. + struct fiq_channel_state *st = &state->channel[n];
  690. +
  691. + for (i = 0; i < st->dma_info.index; i++) {
  692. + total_len += st->dma_info.slot_len[i];
  693. + }
  694. +
  695. + *probably_last = 0;
  696. +
  697. + if (st->hcchar_copy.b.eptype == 0x3) {
  698. + /*
  699. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  700. + * then this is definitely the last CSPLIT.
  701. + */
  702. + *probably_last = 1;
  703. + } else {
  704. + /* Isoc IN. This is a bit risky if we are the first transaction:
  705. + * we may have been held off slightly. */
  706. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  707. + more_needed = 0;
  708. + }
  709. + /* If in the next uframe we will receive enough data to fill the endpoint,
  710. + * then only issue 1 more csplit.
  711. + */
  712. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  713. + *probably_last = 1;
  714. + }
  715. +
  716. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  717. + i == 6 || total_len == 0)
  718. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  719. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  720. + * - in these extreme cases we will pass through a truncated packet.
  721. + */
  722. + more_needed = 0;
  723. +
  724. + return more_needed;
  725. +}
  726. +
  727. +/**
  728. + * fiq_fsm_too_late() - Test transaction for lateness
  729. + *
  730. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  731. + * the hub will disable the port to the device and respond with ERR handshakes.
  732. + * The hub status endpoint will not reflect this change.
  733. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  734. + */
  735. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  736. +{
  737. + int uframe;
  738. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  739. + uframe = hfnum.b.frnum & 0x7;
  740. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  741. + return 1;
  742. + } else {
  743. + return 0;
  744. + }
  745. +}
  746. +
  747. +
  748. +/**
  749. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  750. + *
  751. + * Search pending transactions in the start-split pending state and queue them.
  752. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  753. + * Note: we specifically don't do isochronous OUT transactions first because better
  754. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  755. + */
  756. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  757. +{
  758. + int n;
  759. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  760. + if ((hfnum.b.frnum & 0x7) == 5)
  761. + return;
  762. + for (n = 0; n < num_channels; n++) {
  763. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  764. + /* Check to see if any other transactions are using this TT */
  765. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  766. + if (!fiq_fsm_too_late(st, n)) {
  767. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  768. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  769. + fiq_fsm_restart_channel(st, n, 0);
  770. + } else {
  771. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  772. + }
  773. + break;
  774. + }
  775. + }
  776. + }
  777. + for (n = 0; n < num_channels; n++) {
  778. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  779. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  780. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  781. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  782. + fiq_fsm_restart_channel(st, n, 0);
  783. + break;
  784. + }
  785. + }
  786. + }
  787. +}
  788. +
  789. +/**
  790. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  791. + * @state: Pointer to fiq_state
  792. + * @n: Channel transaction is active on
  793. + * @hcint: Copy of host channel interrupt register
  794. + *
  795. + * Returns 0 if there are no more transactions for this HC to do, 1
  796. + * otherwise.
  797. + */
  798. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  799. +{
  800. + struct fiq_channel_state *st = &state->channel[n];
  801. + int xfer_len = 0, nrpackets = 0;
  802. + hcdma_data_t hcdma;
  803. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  804. +
  805. + xfer_len = fiq_get_xfer_len(state, n);
  806. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  807. +
  808. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  809. +
  810. + st->hs_isoc_info.index++;
  811. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  812. + return 0;
  813. + }
  814. +
  815. + /* grab the next DMA address offset from the array */
  816. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  817. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  818. +
  819. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  820. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  821. + * this is always set to the maximum size of the endpoint. */
  822. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  823. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  824. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  825. + if (nrpackets == 0)
  826. + nrpackets = 1;
  827. + st->hcchar_copy.b.multicnt = nrpackets;
  828. + st->hctsiz_copy.b.pktcnt = nrpackets;
  829. +
  830. + /* Initial PID also needs to be set */
  831. + if (st->hcchar_copy.b.epdir == 0) {
  832. + st->hctsiz_copy.b.xfersize = xfer_len;
  833. + switch (st->hcchar_copy.b.multicnt) {
  834. + case 1:
  835. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  836. + break;
  837. + case 2:
  838. + case 3:
  839. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  840. + break;
  841. + }
  842. +
  843. + } else {
  844. + switch (st->hcchar_copy.b.multicnt) {
  845. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  846. + case 1:
  847. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  848. + break;
  849. + case 2:
  850. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  851. + break;
  852. + case 3:
  853. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  854. + break;
  855. + }
  856. + }
  857. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  858. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  859. + /* Channel is enabled on hcint handler exit */
  860. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  861. + return 1;
  862. +}
  863. +
  864. +
  865. +/**
  866. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  867. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  868. + * @num_channels: set according to the DWC hardware configuration
  869. + *
  870. + * The SOF handler in FSM mode has two functions
  871. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  872. + * nothing to do
  873. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  874. + * of holdoff.
  875. + *
  876. + * The second part is architecture-specific to mach-bcm2835 -
  877. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  878. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  879. + * number (USB) can be enabled. This means that certain parts of the USB specification
  880. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  881. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  882. + * the SOF "timer" (125uS) to perform this task.
  883. + */
  884. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  885. +{
  886. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  887. + int n;
  888. + int kick_irq = 0;
  889. +
  890. + if ((hfnum.b.frnum & 0x7) == 1) {
  891. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  892. + * Check to see if there are any transactions that are stale.
  893. + * Boot them out.
  894. + */
  895. + for (n = 0; n < num_channels; n++) {
  896. + switch (state->channel[n].fsm) {
  897. + case FIQ_PER_CSPLIT_WAIT:
  898. + case FIQ_PER_CSPLIT_NYET1:
  899. + case FIQ_PER_CSPLIT_POLL:
  900. + case FIQ_PER_CSPLIT_LAST:
  901. + /* Check if we are no longer in the same full-speed frame. */
  902. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  903. + (hfnum.b.frnum & ~0x7))
  904. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  905. + break;
  906. + default:
  907. + break;
  908. + }
  909. + }
  910. + }
  911. +
  912. + for (n = 0; n < num_channels; n++) {
  913. + switch (state->channel[n].fsm) {
  914. +
  915. + case FIQ_NP_SSPLIT_RETRY:
  916. + case FIQ_NP_IN_CSPLIT_RETRY:
  917. + case FIQ_NP_OUT_CSPLIT_RETRY:
  918. + fiq_fsm_restart_channel(state, n, 0);
  919. + break;
  920. +
  921. + case FIQ_HS_ISOC_SLEEPING:
  922. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  923. + fiq_fsm_restart_channel(state, n, 0);
  924. + break;
  925. +
  926. + case FIQ_PER_SSPLIT_QUEUED:
  927. + if ((hfnum.b.frnum & 0x7) == 5)
  928. + break;
  929. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  930. + if (!fiq_fsm_too_late(state, n)) {
  931. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  932. + fiq_fsm_restart_channel(state, n, 0);
  933. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  934. + } else {
  935. + /* Transaction cannot be started without risking a device babble error */
  936. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  937. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  938. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  939. + kick_irq |= 1;
  940. + }
  941. + }
  942. + break;
  943. +
  944. + case FIQ_PER_ISO_OUT_PENDING:
  945. + /* Ordinarily, this should be poked after the SSPLIT
  946. + * complete interrupt for a competing transfer on the same
  947. + * TT. Doesn't happen for aborted transactions though.
  948. + */
  949. + if ((hfnum.b.frnum & 0x7) >= 5)
  950. + break;
  951. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  952. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  953. + * that caused this.
  954. + */
  955. + fiq_fsm_restart_channel(state, n, 0);
  956. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  957. + if (state->channel[n].nrpackets == 1) {
  958. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  959. + } else {
  960. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  961. + }
  962. + }
  963. + break;
  964. +
  965. + case FIQ_PER_CSPLIT_WAIT:
  966. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  967. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  968. + * will utterly bugger this up though.
  969. + */
  970. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  971. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  972. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  973. + fiq_fsm_restart_channel(state, n, 0);
  974. + fiq_fsm_start_next_periodic(state, num_channels);
  975. +
  976. + }
  977. + break;
  978. +
  979. + case FIQ_PER_SPLIT_TIMEOUT:
  980. + case FIQ_DEQUEUE_ISSUED:
  981. + /* Ugly: we have to force a HCD interrupt.
  982. + * Poke the mask for the channel in question.
  983. + * We will take a fake SOF because of this, but
  984. + * that's OK.
  985. + */
  986. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  987. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  988. + kick_irq |= 1;
  989. + break;
  990. +
  991. + default:
  992. + break;
  993. + }
  994. + }
  995. +
  996. + if (state->kick_np_queues ||
  997. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  998. + kick_irq |= 1;
  999. +
  1000. + return !kick_irq;
  1001. +}
  1002. +
  1003. +
  1004. +/**
  1005. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  1006. + * @state: Pointer to the FIQ state struct
  1007. + * @num_channels: Number of channels as per hardware config
  1008. + * @n: channel for which HAINT(i) was raised
  1009. + *
  1010. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  1011. + */
  1012. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  1013. +{
  1014. + hcint_data_t hcint;
  1015. + hcintmsk_data_t hcintmsk;
  1016. + hcint_data_t hcint_probe;
  1017. + hcchar_data_t hcchar;
  1018. + int handled = 0;
  1019. + int restart = 0;
  1020. + int last_csplit = 0;
  1021. + int start_next_periodic = 0;
  1022. + struct fiq_channel_state *st = &state->channel[n];
  1023. + hfnum_data_t hfnum;
  1024. +
  1025. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  1026. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  1027. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  1028. +
  1029. + if (st->fsm != FIQ_PASSTHROUGH) {
  1030. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  1031. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  1032. + }
  1033. +
  1034. + switch (st->fsm) {
  1035. +
  1036. + case FIQ_PASSTHROUGH:
  1037. + case FIQ_DEQUEUE_ISSUED:
  1038. + /* doesn't belong to us, kick it upstairs */
  1039. + break;
  1040. +
  1041. + case FIQ_PASSTHROUGH_ERRORSTATE:
  1042. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  1043. + * Several interrupts are unmasked if a previous transaction failed - it's
  1044. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  1045. + * Emulate what the HCD does in this situation: mask and continue.
  1046. + * The FSM has no other state setup so this has to be handled out-of-band.
  1047. + */
  1048. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  1049. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  1050. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  1051. + st->nr_errors = 0;
  1052. + hcintmsk.b.nak = 0;
  1053. + hcintmsk.b.ack = 0;
  1054. + hcintmsk.b.datatglerr = 0;
  1055. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  1056. + return 1;
  1057. + }
  1058. + if (hcint_probe.b.chhltd) {
  1059. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  1060. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  1061. + return 0;
  1062. + }
  1063. + break;
  1064. +
  1065. + /* Non-periodic state groups */
  1066. + case FIQ_NP_SSPLIT_STARTED:
  1067. + case FIQ_NP_SSPLIT_RETRY:
  1068. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  1069. + if (hcint.b.ack) {
  1070. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  1071. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  1072. + */
  1073. + if(st->hcchar_copy.b.epdir == 1)
  1074. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  1075. + else
  1076. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  1077. + st->nr_errors = 0;
  1078. + handled = 1;
  1079. + fiq_fsm_setup_csplit(state, n);
  1080. + } else if (hcint.b.nak) {
  1081. + // No buffer space in TT. Retry on a uframe boundary.
  1082. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  1083. + handled = 1;
  1084. + } else if (hcint.b.xacterr) {
  1085. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  1086. + st->nr_errors++;
  1087. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  1088. + if (st->nr_errors >= 3) {
  1089. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1090. + } else {
  1091. + handled = 1;
  1092. + restart = 1;
  1093. + }
  1094. + } else {
  1095. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  1096. + handled = 0;
  1097. + restart = 0;
  1098. + }
  1099. + break;
  1100. +
  1101. + case FIQ_NP_IN_CSPLIT_RETRY:
  1102. + /* Received a CSPLIT done interrupt.
  1103. + * Expected Data/NAK/STALL/NYET for IN.
  1104. + */
  1105. + if (hcint.b.xfercomp) {
  1106. + /* For IN, data is present. */
  1107. + st->fsm = FIQ_NP_SPLIT_DONE;
  1108. + } else if (hcint.b.nak) {
  1109. + /* no endpoint data. Punt it upstairs */
  1110. + st->fsm = FIQ_NP_SPLIT_DONE;
  1111. + } else if (hcint.b.nyet) {
  1112. + /* CSPLIT NYET - retry on a uframe boundary. */
  1113. + handled = 1;
  1114. + st->nr_errors = 0;
  1115. + } else if (hcint.b.datatglerr) {
  1116. + /* data toggle errors do not set the xfercomp bit. */
  1117. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  1118. + } else if (hcint.b.xacterr) {
  1119. + /* HS error. Retry immediate */
  1120. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  1121. + st->nr_errors++;
  1122. + if (st->nr_errors >= 3) {
  1123. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1124. + } else {
  1125. + handled = 1;
  1126. + restart = 1;
  1127. + }
  1128. + } else if (hcint.b.stall || hcint.b.bblerr) {
  1129. + /* A STALL implies either a LS bus error or a genuine STALL. */
  1130. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  1131. + } else {
  1132. + /* Hardware bug. It's possible in some cases to
  1133. + * get a channel halt with nothing else set when
  1134. + * the response was a NYET. Treat as local 3-strikes retry.
  1135. + */
  1136. + hcint_data_t hcint_test = hcint;
  1137. + hcint_test.b.chhltd = 0;
  1138. + if (!hcint_test.d32) {
  1139. + st->nr_errors++;
  1140. + if (st->nr_errors >= 3) {
  1141. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1142. + } else {
  1143. + handled = 1;
  1144. + }
  1145. + } else {
  1146. + /* Bail out if something unexpected happened */
  1147. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1148. + }
  1149. + }
  1150. + break;
  1151. +
  1152. + case FIQ_NP_OUT_CSPLIT_RETRY:
  1153. + /* Received a CSPLIT done interrupt.
  1154. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  1155. + if (hcint.b.xfercomp) {
  1156. + st->fsm = FIQ_NP_SPLIT_DONE;
  1157. + } else if (hcint.b.nak) {
  1158. + // The HCD will implement the holdoff on frame boundaries.
  1159. + st->fsm = FIQ_NP_SPLIT_DONE;
  1160. + } else if (hcint.b.nyet) {
  1161. + // Hub still processing.
  1162. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  1163. + handled = 1;
  1164. + st->nr_errors = 0;
  1165. + //restart = 1;
  1166. + } else if (hcint.b.xacterr) {
  1167. + /* HS error. retry immediate */
  1168. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  1169. + st->nr_errors++;
  1170. + if (st->nr_errors >= 3) {
  1171. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1172. + } else {
  1173. + handled = 1;
  1174. + restart = 1;
  1175. + }
  1176. + } else if (hcint.b.stall) {
  1177. + /* LS bus error or genuine stall */
  1178. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  1179. + } else {
  1180. + /*
  1181. + * Hardware bug. It's possible in some cases to get a
  1182. + * channel halt with nothing else set when the response was a NYET.
  1183. + * Treat as local 3-strikes retry.
  1184. + */
  1185. + hcint_data_t hcint_test = hcint;
  1186. + hcint_test.b.chhltd = 0;
  1187. + if (!hcint_test.d32) {
  1188. + st->nr_errors++;
  1189. + if (st->nr_errors >= 3) {
  1190. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1191. + } else {
  1192. + handled = 1;
  1193. + }
  1194. + } else {
  1195. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  1196. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  1197. + }
  1198. + }
  1199. + break;
  1200. +
  1201. + /* Periodic split states (except isoc out) */
  1202. + case FIQ_PER_SSPLIT_STARTED:
  1203. + /* Expect an ACK or failure for SSPLIT */
  1204. + if (hcint.b.ack) {
  1205. + /*
  1206. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  1207. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  1208. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  1209. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  1210. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  1211. + * coincident with SOF for n+1.
  1212. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  1213. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  1214. + * State machine workaround.
  1215. + */
  1216. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  1217. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  1218. + fiq_fsm_setup_csplit(state, n);
  1219. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  1220. + * time. If not, then we're in the next SOF.
  1221. + */
  1222. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  1223. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  1224. + st->expected_uframe = hfnum.b.frnum;
  1225. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  1226. + } else {
  1227. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  1228. + /* For isochronous IN endpoints,
  1229. + * we need to hold off if we are expecting a lot of data */
  1230. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  1231. + start_next_periodic = 1;
  1232. + }
  1233. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  1234. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  1235. + * lag. Unmask the NYET interrupt.
  1236. + */
  1237. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  1238. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  1239. + restart = 1;
  1240. + }
  1241. + handled = 1;
  1242. + } else if (hcint.b.xacterr) {
  1243. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  1244. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  1245. + start_next_periodic = 1;
  1246. + } else {
  1247. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  1248. + start_next_periodic = 1;
  1249. + }
  1250. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  1251. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  1252. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  1253. + }
  1254. + break;
  1255. +
  1256. + case FIQ_PER_CSPLIT_NYET1:
  1257. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  1258. + * we are too late and the TT has dropped its CSPLIT fifo.
  1259. + */
  1260. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  1261. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  1262. + start_next_periodic = 1;
  1263. + if (hcint.b.nak) {
  1264. + st->fsm = FIQ_PER_SPLIT_DONE;
  1265. + } else if (hcint.b.xfercomp) {
  1266. + fiq_increment_dma_buf(state, num_channels, n);
  1267. + st->fsm = FIQ_PER_CSPLIT_POLL;
  1268. + st->nr_errors = 0;
  1269. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  1270. + handled = 1;
  1271. + restart = 1;
  1272. + if (!last_csplit)
  1273. + start_next_periodic = 0;
  1274. + } else {
  1275. + st->fsm = FIQ_PER_SPLIT_DONE;
  1276. + }
  1277. + } else if (hcint.b.nyet) {
  1278. + /* Doh. Data lost. */
  1279. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  1280. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  1281. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  1282. + } else {
  1283. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  1284. + }
  1285. + break;
  1286. +
  1287. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  1288. + /*
  1289. + * we got here because our host channel is in the delayed-interrupt
  1290. + * state and we cannot take a NYET interrupt any later than when it
  1291. + * occurred. Disable then re-enable the channel if this happens to force
  1292. + * CSPLITs to occur at the right time.
  1293. + */
  1294. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  1295. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  1296. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  1297. + if (hcint.b.nak) {
  1298. + st->fsm = FIQ_PER_SPLIT_DONE;
  1299. + start_next_periodic = 1;
  1300. + } else if (hcint.b.xfercomp) {
  1301. + fiq_increment_dma_buf(state, num_channels, n);
  1302. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  1303. + st->fsm = FIQ_PER_CSPLIT_POLL;
  1304. + handled = 1;
  1305. + restart = 1;
  1306. + start_next_periodic = 1;
  1307. + /* Reload HCTSIZ for the next transfer */
  1308. + fiq_fsm_reload_hctsiz(state, n);
  1309. + if (!last_csplit)
  1310. + start_next_periodic = 0;
  1311. + } else {
  1312. + st->fsm = FIQ_PER_SPLIT_DONE;
  1313. + }
  1314. + } else if (hcint.b.nyet) {
  1315. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  1316. + start_next_periodic = 1;
  1317. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  1318. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  1319. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  1320. + } else {
  1321. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  1322. + }
  1323. + break;
  1324. +
  1325. + case FIQ_PER_CSPLIT_POLL:
  1326. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  1327. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  1328. + start_next_periodic = 1;
  1329. + if (hcint.b.nak) {
  1330. + st->fsm = FIQ_PER_SPLIT_DONE;
  1331. + } else if (hcint.b.xfercomp) {
  1332. + fiq_increment_dma_buf(state, num_channels, n);
  1333. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  1334. + handled = 1;
  1335. + restart = 1;
  1336. + /* Reload HCTSIZ for the next transfer */
  1337. + fiq_fsm_reload_hctsiz(state, n);
  1338. + if (!last_csplit)
  1339. + start_next_periodic = 0;
  1340. + } else {
  1341. + st->fsm = FIQ_PER_SPLIT_DONE;
  1342. + }
  1343. + } else if (hcint.b.nyet) {
  1344. + /* Are we a NYET after the first data packet? */
  1345. + if (st->nrpackets == 0) {
  1346. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  1347. + handled = 1;
  1348. + restart = 1;
  1349. + } else {
  1350. + /* We got a NYET when polling CSPLITs. Can happen
  1351. + * if our heuristic fails, or if someone disables us
  1352. + * for any significant length of time.
  1353. + */
  1354. + if (st->nr_errors >= 3) {
  1355. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  1356. + } else {
  1357. + st->fsm = FIQ_PER_SPLIT_DONE;
  1358. + }
  1359. + }
  1360. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  1361. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  1362. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  1363. + } else {
  1364. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  1365. + }
  1366. + break;
  1367. +
  1368. + case FIQ_HS_ISOC_TURBO:
  1369. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  1370. + /* more transactions to come */
  1371. + handled = 1;
  1372. + restart = 1;
  1373. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  1374. + } else {
  1375. + st->fsm = FIQ_HS_ISOC_DONE;
  1376. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  1377. + }
  1378. + break;
  1379. +
  1380. + case FIQ_HS_ISOC_ABORTED:
  1381. + /* This abort is called by the driver rewriting the state mid-transaction
  1382. + * which allows the dequeue mechanism to work more effectively.
  1383. + */
  1384. + break;
  1385. +
  1386. + case FIQ_PER_ISO_OUT_ACTIVE:
  1387. + if (hcint.b.ack) {
  1388. + if(fiq_iso_out_advance(state, num_channels, n)) {
  1389. + /* last OUT transfer */
  1390. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  1391. + /*
  1392. + * Assuming the periodic FIFO in the dwc core
  1393. + * actually does its job properly, we can queue
  1394. + * the next ssplit now and in theory, the wire
  1395. + * transactions will be in-order.
  1396. + */
  1397. + // No it doesn't. It appears to process requests in host channel order.
  1398. + //start_next_periodic = 1;
  1399. + }
  1400. + handled = 1;
  1401. + restart = 1;
  1402. + } else {
  1403. + /*
  1404. + * Isochronous transactions carry on regardless. Log the error
  1405. + * and continue.
  1406. + */
  1407. + //explode += 1;
  1408. + st->nr_errors++;
  1409. + if(fiq_iso_out_advance(state, num_channels, n)) {
  1410. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  1411. + //start_next_periodic = 1;
  1412. + }
  1413. + handled = 1;
  1414. + restart = 1;
  1415. + }
  1416. + break;
  1417. +
  1418. + case FIQ_PER_ISO_OUT_LAST:
  1419. + if (hcint.b.ack) {
  1420. + /* All done here */
  1421. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  1422. + } else {
  1423. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  1424. + st->nr_errors++;
  1425. + }
  1426. + start_next_periodic = 1;
  1427. + break;
  1428. +
  1429. + case FIQ_PER_SPLIT_TIMEOUT:
  1430. + /* SOF kicked us because we overran. */
  1431. + start_next_periodic = 1;
  1432. + break;
  1433. +
  1434. + default:
  1435. + break;
  1436. + }
  1437. +
  1438. + if (handled) {
  1439. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  1440. + } else {
  1441. + /* Copy the regs into the state so the IRQ knows what to do */
  1442. + st->hcint_copy.d32 = hcint.d32;
  1443. + }
  1444. +
  1445. + if (restart) {
  1446. + /* Restart always implies handled. */
  1447. + if (restart == 2) {
  1448. + /* For complete-split INs, the show must go on.
  1449. + * Force a channel restart */
  1450. + fiq_fsm_restart_channel(state, n, 1);
  1451. + } else {
  1452. + fiq_fsm_restart_channel(state, n, 0);
  1453. + }
  1454. + }
  1455. + if (start_next_periodic) {
  1456. + fiq_fsm_start_next_periodic(state, num_channels);
  1457. + }
  1458. + if (st->fsm != FIQ_PASSTHROUGH)
  1459. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  1460. +
  1461. + return handled;
  1462. +}
  1463. +
  1464. +
  1465. +/**
  1466. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  1467. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  1468. + * @num_channels: set according to the DWC hardware configuration
  1469. + * @dma: pointer to DMA bounce buffers for split transaction slots
  1470. + *
  1471. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  1472. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  1473. + * interrupts each and every time a split transaction packet is received or sent successfully.
  1474. + * This results in either an interrupt storm when everything is working "properly", or
  1475. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  1476. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  1477. + * solves these problems.
  1478. + *
  1479. + * Return: void
  1480. + */
  1481. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  1482. +{
  1483. + gintsts_data_t gintsts, gintsts_handled;
  1484. + gintmsk_data_t gintmsk;
  1485. + //hfnum_data_t hfnum;
  1486. + haint_data_t haint, haint_handled;
  1487. + haintmsk_data_t haintmsk;
  1488. + int kick_irq = 0;
  1489. +
  1490. + gintsts_handled.d32 = 0;
  1491. + haint_handled.d32 = 0;
  1492. +
  1493. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  1494. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  1495. + gintsts.d32 &= gintmsk.d32;
  1496. +
  1497. + if (gintsts.b.sofintr) {
  1498. + /* For FSM mode, SOF is required to keep the state machine advance for
  1499. + * certain stages of the periodic pipeline. It's death to mask this
  1500. + * interrupt in that case.
  1501. + */
  1502. +
  1503. + if (!fiq_fsm_do_sof(state, num_channels)) {
  1504. + /* Kick IRQ once. Queue advancement means that all pending transactions
  1505. + * will get serviced when the IRQ finally executes.
  1506. + */
  1507. + if (state->gintmsk_saved.b.sofintr == 1)
  1508. + kick_irq |= 1;
  1509. + state->gintmsk_saved.b.sofintr = 0;
  1510. + }
  1511. + gintsts_handled.b.sofintr = 1;
  1512. + }
  1513. +
  1514. + if (gintsts.b.hcintr) {
  1515. + int i;
  1516. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  1517. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  1518. + haint.d32 &= haintmsk.d32;
  1519. + haint_handled.d32 = 0;
  1520. + for (i=0; i<num_channels; i++) {
  1521. + if (haint.b2.chint & (1 << i)) {
  1522. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  1523. + /* HCINT was not handled in FIQ
  1524. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  1525. + * Mask HAINT(i) but keep top-level hcint unmasked.
  1526. + */
  1527. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  1528. + } else {
  1529. + /* do_hcintr cleaned up after itself, but clear haint */
  1530. + haint_handled.b2.chint |= (1 << i);
  1531. + }
  1532. + }
  1533. + }
  1534. +
  1535. + if (haint_handled.b2.chint) {
  1536. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  1537. + }
  1538. +
  1539. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  1540. + /*
  1541. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  1542. + * where interrupts are held off and HCINTs start to pile up.
  1543. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  1544. + * masked.
  1545. + */
  1546. + haintmsk.d32 &= state->haintmsk_saved.d32;
  1547. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  1548. + kick_irq |= 1;
  1549. + }
  1550. + /* Top-Level interrupt - always handled because it's level-sensitive */
  1551. + gintsts_handled.b.hcintr = 1;
  1552. + }
  1553. +
  1554. +
  1555. + /* Clear the bits in the saved register that were not handled but were triggered. */
  1556. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  1557. +
  1558. + /* FIQ didn't handle something - mask has changed - write new mask */
  1559. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  1560. + gintmsk.d32 &= state->gintmsk_saved.d32;
  1561. + gintmsk.b.sofintr = 1;
  1562. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  1563. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  1564. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  1565. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  1566. + kick_irq |= 1;
  1567. + }
  1568. +
  1569. + if (gintsts_handled.d32) {
  1570. + /* Only applies to edge-sensitive bits in GINTSTS */
  1571. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  1572. + }
  1573. +
  1574. + /* We got an interrupt, didn't handle it. */
  1575. + if (kick_irq) {
  1576. + state->mphi_int_count++;
  1577. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  1578. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  1579. +
  1580. + }
  1581. + state->fiq_done++;
  1582. + mb();
  1583. +}
  1584. +
  1585. +
  1586. +/**
  1587. + * dwc_otg_fiq_nop() - FIQ "lite"
  1588. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  1589. + *
  1590. + * The "nop" handler does not intervene on any interrupts other than SOF.
  1591. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  1592. + * with non-periodic/periodic queues) needs to be kicked.
  1593. + *
  1594. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  1595. + *
  1596. + * Return: void
  1597. + */
  1598. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  1599. +{
  1600. + gintsts_data_t gintsts, gintsts_handled;
  1601. + gintmsk_data_t gintmsk;
  1602. + hfnum_data_t hfnum;
  1603. +
  1604. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  1605. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  1606. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  1607. + gintsts.d32 &= gintmsk.d32;
  1608. + gintsts_handled.d32 = 0;
  1609. +
  1610. + if (gintsts.b.sofintr) {
  1611. + if (!state->kick_np_queues &&
  1612. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  1613. + /* SOF handled, no work to do, just ACK interrupt */
  1614. + gintsts_handled.b.sofintr = 1;
  1615. + } else {
  1616. + /* Kick IRQ */
  1617. + state->gintmsk_saved.b.sofintr = 0;
  1618. + }
  1619. + }
  1620. +
  1621. + /* Reset handled interrupts */
  1622. + if(gintsts_handled.d32) {
  1623. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  1624. + }
  1625. +
  1626. + /* Clear the bits in the saved register that were not handled but were triggered. */
  1627. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  1628. +
  1629. + /* We got an interrupt, didn't handle it and want to mask it */
  1630. + if (~(state->gintmsk_saved.d32)) {
  1631. + state->mphi_int_count++;
  1632. + gintmsk.d32 &= state->gintmsk_saved.d32;
  1633. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  1634. + /* Force a clear before another dummy send */
  1635. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  1636. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  1637. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  1638. +
  1639. + }
  1640. + state->fiq_done++;
  1641. + mb();
  1642. +}
  1643. --- /dev/null
  1644. +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  1645. @@ -0,0 +1,353 @@
  1646. +/*
  1647. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  1648. + *
  1649. + * Copyright (c) 2013 Raspberry Pi Foundation
  1650. + *
  1651. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  1652. + * All rights reserved.
  1653. + *
  1654. + * Redistribution and use in source and binary forms, with or without
  1655. + * modification, are permitted provided that the following conditions are met:
  1656. + * * Redistributions of source code must retain the above copyright
  1657. + * notice, this list of conditions and the following disclaimer.
  1658. + * * Redistributions in binary form must reproduce the above copyright
  1659. + * notice, this list of conditions and the following disclaimer in the
  1660. + * documentation and/or other materials provided with the distribution.
  1661. + * * Neither the name of Raspberry Pi nor the
  1662. + * names of its contributors may be used to endorse or promote products
  1663. + * derived from this software without specific prior written permission.
  1664. + *
  1665. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  1666. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  1667. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  1668. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  1669. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  1670. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  1671. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  1672. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  1673. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  1674. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1675. + *
  1676. + * This FIQ implements functionality that performs split transactions on
  1677. + * the dwc_otg hardware without any outside intervention. A split transaction
  1678. + * is "queued" by nominating a specific host channel to perform the entirety
  1679. + * of a split transaction. This FIQ will then perform the microframe-precise
  1680. + * scheduling required in each phase of the transaction until completion.
  1681. + *
  1682. + * The FIQ functionality has been surgically implanted into the Synopsys
  1683. + * vendor-provided driver.
  1684. + *
  1685. + */
  1686. +
  1687. +#ifndef DWC_OTG_FIQ_FSM_H_
  1688. +#define DWC_OTG_FIQ_FSM_H_
  1689. +
  1690. +#include "dwc_otg_regs.h"
  1691. +#include "dwc_otg_cil.h"
  1692. +#include "dwc_otg_hcd.h"
  1693. +#include <linux/kernel.h>
  1694. +#include <linux/irqflags.h>
  1695. +#include <linux/string.h>
  1696. +#include <asm/barrier.h>
  1697. +
  1698. +#if 0
  1699. +#define FLAME_ON(x) \
  1700. +do { \
  1701. + int gpioreg; \
  1702. + \
  1703. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  1704. + gpioreg &= ~(7 << (x-20)*3); \
  1705. + gpioreg |= 0x1 << (x-20)*3; \
  1706. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  1707. + \
  1708. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  1709. +} while (0)
  1710. +
  1711. +#define FLAME_OFF(x) \
  1712. +do { \
  1713. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  1714. +} while (0)
  1715. +#else
  1716. +#define FLAME_ON(x) do { } while (0)
  1717. +#define FLAME_OFF(X) do { } while (0)
  1718. +#endif
  1719. +
  1720. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  1721. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  1722. + * reads and writes are executed in-order therefore the need for memory barriers
  1723. + * is obviated if we're only talking to USB.
  1724. + */
  1725. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  1726. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  1727. +
  1728. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  1729. +#define GINTSTS 0x014
  1730. +#define GINTMSK 0x018
  1731. +/* Debug register. Poll the top of the received packets FIFO. */
  1732. +#define GRXSTSR 0x01C
  1733. +#define HFNUM 0x408
  1734. +#define HAINT 0x414
  1735. +#define HAINTMSK 0x418
  1736. +#define HPRT0 0x440
  1737. +
  1738. +/* HC_regs start from an offset of 0x500 */
  1739. +#define HC_START 0x500
  1740. +#define HC_OFFSET 0x020
  1741. +
  1742. +#define HC_DMA 0x514
  1743. +
  1744. +#define HCCHAR 0x00
  1745. +#define HCSPLT 0x04
  1746. +#define HCINT 0x08
  1747. +#define HCINTMSK 0x0C
  1748. +#define HCTSIZ 0x10
  1749. +
  1750. +#define ISOC_XACTPOS_ALL 0b11
  1751. +#define ISOC_XACTPOS_BEGIN 0b10
  1752. +#define ISOC_XACTPOS_MID 0b00
  1753. +#define ISOC_XACTPOS_END 0b01
  1754. +
  1755. +#define DWC_PID_DATA2 0b01
  1756. +#define DWC_PID_MDATA 0b11
  1757. +#define DWC_PID_DATA1 0b10
  1758. +#define DWC_PID_DATA0 0b00
  1759. +
  1760. +typedef struct {
  1761. + volatile void* base;
  1762. + volatile void* ctrl;
  1763. + volatile void* outdda;
  1764. + volatile void* outddb;
  1765. + volatile void* intstat;
  1766. +} mphi_regs_t;
  1767. +
  1768. +
  1769. +enum fiq_debug_level {
  1770. + FIQDBG_SCHED = (1 << 0),
  1771. + FIQDBG_INT = (1 << 1),
  1772. + FIQDBG_ERR = (1 << 2),
  1773. + FIQDBG_PORTHUB = (1 << 3),
  1774. +};
  1775. +
  1776. +struct fiq_state;
  1777. +
  1778. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  1779. +#if 0
  1780. +#define fiq_print _fiq_print
  1781. +#else
  1782. +#define fiq_print(x, y, ...)
  1783. +#endif
  1784. +
  1785. +extern bool fiq_enable, fiq_fsm_enable;
  1786. +extern ushort nak_holdoff;
  1787. +
  1788. +/**
  1789. + * enum fiq_fsm_state - The FIQ FSM states.
  1790. + *
  1791. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  1792. + * USB2.0 specification for host responses to various transaction states.
  1793. + * There are modifications to this host state machine because of a variety of
  1794. + * quirks and limitations in the dwc_otg hardware.
  1795. + *
  1796. + * The fsm state is also used to communicate back to the driver on completion of
  1797. + * a split transaction. The end states are used in conjunction with the interrupts
  1798. + * raised by the final transaction.
  1799. + */
  1800. +enum fiq_fsm_state {
  1801. + /* FIQ isn't enabled for this host channel */
  1802. + FIQ_PASSTHROUGH = 0,
  1803. + /* For the first interrupt received for this channel,
  1804. + * the FIQ has to ack any interrupts indicating success. */
  1805. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  1806. + /* Nonperiodic state groups */
  1807. + FIQ_NP_SSPLIT_STARTED = 1,
  1808. + FIQ_NP_SSPLIT_RETRY = 2,
  1809. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  1810. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  1811. + FIQ_NP_SPLIT_DONE = 5,
  1812. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  1813. + /* This differentiates a HS transaction error from a LS one
  1814. + * (handling the hub state is different) */
  1815. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  1816. +
  1817. + /* Periodic state groups */
  1818. + /* Periodic transactions are either started directly by the IRQ handler
  1819. + * or deferred if the TT is already in use.
  1820. + */
  1821. + FIQ_PER_SSPLIT_QUEUED = 8,
  1822. + FIQ_PER_SSPLIT_STARTED = 9,
  1823. + FIQ_PER_SSPLIT_LAST = 10,
  1824. +
  1825. +
  1826. + FIQ_PER_ISO_OUT_PENDING = 11,
  1827. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  1828. + FIQ_PER_ISO_OUT_LAST = 13,
  1829. + FIQ_PER_ISO_OUT_DONE = 27,
  1830. +
  1831. + FIQ_PER_CSPLIT_WAIT = 14,
  1832. + FIQ_PER_CSPLIT_NYET1 = 15,
  1833. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  1834. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  1835. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  1836. + FIQ_PER_CSPLIT_POLL = 16,
  1837. + /* The last CSPLIT for a transaction has been issued, differentiates
  1838. + * for the state machine to queue the next packet.
  1839. + */
  1840. + FIQ_PER_CSPLIT_LAST = 17,
  1841. +
  1842. + FIQ_PER_SPLIT_DONE = 18,
  1843. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  1844. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  1845. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  1846. + /* Frame rollover has occurred without the transaction finishing. */
  1847. + FIQ_PER_SPLIT_TIMEOUT = 22,
  1848. +
  1849. + /* FIQ-accelerated HS Isochronous state groups */
  1850. + FIQ_HS_ISOC_TURBO = 23,
  1851. + /* For interval > 1, SOF wakes up the isochronous FSM */
  1852. + FIQ_HS_ISOC_SLEEPING = 24,
  1853. + FIQ_HS_ISOC_DONE = 25,
  1854. + FIQ_HS_ISOC_ABORTED = 26,
  1855. + FIQ_DEQUEUE_ISSUED = 30,
  1856. + FIQ_TEST = 32,
  1857. +};
  1858. +
  1859. +struct fiq_stack {
  1860. + int magic1;
  1861. + uint8_t stack[2048];
  1862. + int magic2;
  1863. +};
  1864. +
  1865. +
  1866. +/**
  1867. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  1868. + * @index: Number of slots reported used for IN transactions / number of slots
  1869. + * transmitted for an OUT transaction
  1870. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  1871. + *
  1872. + * Split transaction transfers can have variable length depending on other bus
  1873. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  1874. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  1875. + * can happen per-frame.
  1876. + */
  1877. +struct fiq_dma_info {
  1878. + u8 index;
  1879. + u8 slot_len[6];
  1880. +};
  1881. +
  1882. +struct __attribute__((packed)) fiq_split_dma_slot {
  1883. + u8 buf[188];
  1884. +};
  1885. +
  1886. +struct fiq_dma_channel {
  1887. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  1888. +};
  1889. +
  1890. +struct fiq_dma_blob {
  1891. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  1892. +};
  1893. +
  1894. +/**
  1895. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  1896. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  1897. + * @nrframes: Total length of iso_frame_desc array
  1898. + * @index: Current index (FIQ-maintained)
  1899. + *
  1900. + */
  1901. +struct fiq_hs_isoc_info {
  1902. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  1903. + unsigned int nrframes;
  1904. + unsigned int index;
  1905. +};
  1906. +
  1907. +/**
  1908. + * struct fiq_channel_state - FIQ state machine storage
  1909. + * @fsm: Current state of the channel as understood by the FIQ
  1910. + * @nr_errors: Number of transaction errors on this split-transaction
  1911. + * @hub_addr: SSPLIT/CSPLIT destination hub
  1912. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  1913. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  1914. + * split-IN, number of CSPLIT data packets that were received.
  1915. + * @hcchar_copy:
  1916. + * @hcsplt_copy:
  1917. + * @hcintmsk_copy:
  1918. + * @hctsiz_copy: Copies of the host channel registers.
  1919. + * For use as scratch, or for returning state.
  1920. + *
  1921. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  1922. + * FSM state is stored here. Members of this structure must only be set up by the
  1923. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  1924. + * has updated the state to either a COMPLETE state group or ABORT state group.
  1925. + */
  1926. +
  1927. +struct fiq_channel_state {
  1928. + enum fiq_fsm_state fsm;
  1929. + unsigned int nr_errors;
  1930. + unsigned int hub_addr;
  1931. + unsigned int port_addr;
  1932. + /* Hardware bug workaround: sometimes channel halt interrupts are
  1933. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  1934. + unsigned int expected_uframe;
  1935. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  1936. + unsigned int nrpackets;
  1937. + struct fiq_dma_info dma_info;
  1938. + struct fiq_hs_isoc_info hs_isoc_info;
  1939. + /* Copies of HC registers - in/out communication from/to IRQ handler
  1940. + * and for ease of channel setup. A bit of mungeing is performed - for
  1941. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  1942. + */
  1943. + hcchar_data_t hcchar_copy;
  1944. + hcsplt_data_t hcsplt_copy;
  1945. + hcint_data_t hcint_copy;
  1946. + hcintmsk_data_t hcintmsk_copy;
  1947. + hctsiz_data_t hctsiz_copy;
  1948. + hcdma_data_t hcdma_copy;
  1949. +};
  1950. +
  1951. +/**
  1952. + * struct fiq_state - top-level FIQ state machine storage
  1953. + * @mphi_regs: virtual address of the MPHI peripheral register file
  1954. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  1955. + * @dma_base: physical address for the base of the DMA bounce buffers
  1956. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  1957. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  1958. + * Used for determining which interrupts fired to set off the IRQ handler.
  1959. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  1960. + * @np_count: Non-periodic transactions in the active queue
  1961. + * @np_sent: Count of non-periodic transactions that have completed
  1962. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  1963. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  1964. + * passing SOF through to the driver until necessary.
  1965. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  1966. + * channels configured into the core logic.
  1967. + *
  1968. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  1969. + * It contains top-level state information.
  1970. + */
  1971. +struct fiq_state {
  1972. + mphi_regs_t mphi_regs;
  1973. + void *dwc_regs_base;
  1974. + dma_addr_t dma_base;
  1975. + struct fiq_dma_blob *fiq_dmab;
  1976. + void *dummy_send;
  1977. + gintmsk_data_t gintmsk_saved;
  1978. + haintmsk_data_t haintmsk_saved;
  1979. + int mphi_int_count;
  1980. + unsigned int fiq_done;
  1981. + unsigned int kick_np_queues;
  1982. + unsigned int next_sched_frame;
  1983. +#ifdef FIQ_DEBUG
  1984. + char * buffer;
  1985. + unsigned int bufsiz;
  1986. +#endif
  1987. + struct fiq_channel_state channel[0];
  1988. +};
  1989. +
  1990. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  1991. +
  1992. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  1993. +
  1994. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  1995. +
  1996. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  1997. +
  1998. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  1999. --- /dev/null
  2000. +++ b/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  2001. @@ -0,0 +1,80 @@
  2002. +/*
  2003. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  2004. + *
  2005. + * Copyright (c) 2013 Raspberry Pi Foundation
  2006. + *
  2007. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  2008. + * All rights reserved.
  2009. + *
  2010. + * Redistribution and use in source and binary forms, with or without
  2011. + * modification, are permitted provided that the following conditions are met:
  2012. + * * Redistributions of source code must retain the above copyright
  2013. + * notice, this list of conditions and the following disclaimer.
  2014. + * * Redistributions in binary form must reproduce the above copyright
  2015. + * notice, this list of conditions and the following disclaimer in the
  2016. + * documentation and/or other materials provided with the distribution.
  2017. + * * Neither the name of Raspberry Pi nor the
  2018. + * names of its contributors may be used to endorse or promote products
  2019. + * derived from this software without specific prior written permission.
  2020. + *
  2021. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  2022. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  2023. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  2024. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  2025. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  2026. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  2027. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  2028. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  2029. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  2030. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2031. + */
  2032. +
  2033. +
  2034. +#include <asm/assembler.h>
  2035. +#include <linux/linkage.h>
  2036. +
  2037. +
  2038. +.text
  2039. +
  2040. +.global _dwc_otg_fiq_stub_end;
  2041. +
  2042. +/**
  2043. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  2044. + * a C-style function call with arguments from the FIQ banked registers.
  2045. + * r0 = &hcd->fiq_state
  2046. + * r1 = &hcd->num_channels
  2047. + * r2 = &hcd->dma_buffers
  2048. + * Tramples: r0, r1, r2, r4, fp, ip
  2049. + */
  2050. +
  2051. +ENTRY(_dwc_otg_fiq_stub)
  2052. + /* Stash unbanked regs - SP will have been set up for us */
  2053. + mov ip, sp;
  2054. + stmdb sp!, {r0-r12, lr};
  2055. +#ifdef FIQ_DEBUG
  2056. + // Cycle profiling - read cycle counter at start
  2057. + mrc p15, 0, r5, c15, c12, 1;
  2058. +#endif
  2059. + /* r11 = fp, don't trample it */
  2060. + mov r4, fp;
  2061. + /* set EABI frame size */
  2062. + sub fp, ip, #512;
  2063. +
  2064. + /* for fiq NOP mode - just need state */
  2065. + mov r0, r8;
  2066. + /* r9 = num_channels */
  2067. + mov r1, r9;
  2068. + /* r10 = struct *dma_bufs */
  2069. +// mov r2, r10;
  2070. +
  2071. + /* r4 = &fiq_c_function */
  2072. + blx r4;
  2073. +#ifdef FIQ_DEBUG
  2074. + mrc p15, 0, r4, c15, c12, 1;
  2075. + subs r5, r5, r4;
  2076. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  2077. +#endif
  2078. + ldmia sp!, {r0-r12, lr};
  2079. + subs pc, lr, #4;
  2080. +_dwc_otg_fiq_stub_end:
  2081. +END(_dwc_otg_fiq_stub)
  2082. --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  2083. +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  2084. @@ -45,9 +45,10 @@
  2085. #include "dwc_otg_hcd.h"
  2086. #include "dwc_otg_regs.h"
  2087. -#include "dwc_otg_mphi_fix.h"
  2088. +#include "dwc_otg_fiq_fsm.h"
  2089. -extern bool microframe_schedule, nak_holdoff_enable;
  2090. +extern bool microframe_schedule;
  2091. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  2092. //#define DEBUG_HOST_CHANNELS
  2093. #ifdef DEBUG_HOST_CHANNELS
  2094. @@ -57,12 +58,6 @@ static int last_sel_trans_num_avail_hc_a
  2095. static int last_sel_trans_num_avail_hc_at_end = 0;
  2096. #endif /* DEBUG_HOST_CHANNELS */
  2097. -extern int g_next_sched_frame, g_np_count, g_np_sent;
  2098. -
  2099. -extern haint_data_t haint_saved;
  2100. -extern hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  2101. -extern hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  2102. -extern gintsts_data_t ginsts_saved;
  2103. dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  2104. {
  2105. @@ -295,7 +290,7 @@ static int32_t dwc_otg_hcd_disconnect_cb
  2106. */
  2107. dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  2108. dwc_otg_hcd->flags.b.port_connect_status = 0;
  2109. - if(fiq_fix_enable)
  2110. + if(fiq_enable)
  2111. local_fiq_disable();
  2112. /*
  2113. * Shutdown any transfers in process by clearing the Tx FIFO Empty
  2114. @@ -392,20 +387,15 @@ static int32_t dwc_otg_hcd_disconnect_cb
  2115. channel->qh = NULL;
  2116. }
  2117. }
  2118. - if(fiq_split_enable) {
  2119. + if(fiq_fsm_enable) {
  2120. for(i=0; i < 128; i++) {
  2121. dwc_otg_hcd->hub_port[i] = 0;
  2122. }
  2123. - haint_saved.d32 = 0;
  2124. - for(i=0; i < MAX_EPS_CHANNELS; i++) {
  2125. - hcint_saved[i].d32 = 0;
  2126. - hcintmsk_saved[i].d32 = 0;
  2127. - }
  2128. }
  2129. }
  2130. - if(fiq_fix_enable)
  2131. + if(fiq_enable)
  2132. local_fiq_enable();
  2133. if (dwc_otg_hcd->fops->disconnect) {
  2134. @@ -542,7 +532,7 @@ int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_
  2135. }
  2136. #endif
  2137. intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  2138. - if(!intr_mask.b.sofintr) needs_scheduling = 1;
  2139. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  2140. if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  2141. /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  2142. needs_scheduling = 0;
  2143. @@ -613,6 +603,7 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
  2144. if (urb_qtd->in_process && qh->channel) {
  2145. /* The QTD is in process (it has been assigned to a channel). */
  2146. if (hcd->flags.b.port_connect_status) {
  2147. + int n = qh->channel->hc_num;
  2148. /*
  2149. * If still connected (i.e. in host mode), halt the
  2150. * channel so it can be used for other transfers. If
  2151. @@ -620,10 +611,16 @@ int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_
  2152. * written to halt the channel since the core is in
  2153. * device mode.
  2154. */
  2155. - dwc_otg_hc_halt(hcd->core_if, qh->channel,
  2156. - DWC_OTG_HC_XFER_URB_DEQUEUE);
  2157. -
  2158. - dwc_otg_hcd_release_port(hcd, qh);
  2159. + /* In FIQ FSM mode, we need to shut down carefully.
  2160. + * The FIQ may attempt to restart a disabled channel */
  2161. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  2162. + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
  2163. + qh->channel->halt_pending = 1;
  2164. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  2165. + } else {
  2166. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  2167. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  2168. + }
  2169. }
  2170. }
  2171. @@ -759,7 +756,6 @@ static void completion_tasklet_func(void
  2172. usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  2173. - fiq_print(FIQDBG_PORTHUB, "COMPLETE");
  2174. DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  2175. }
  2176. @@ -854,6 +850,34 @@ void dwc_otg_hcd_power_up(void *ptr)
  2177. cil_hcd_start(core_if);
  2178. }
  2179. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  2180. +{
  2181. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  2182. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  2183. + int i;
  2184. +
  2185. + st->fsm = FIQ_PASSTHROUGH;
  2186. + st->hcchar_copy.d32 = 0;
  2187. + st->hcsplt_copy.d32 = 0;
  2188. + st->hcint_copy.d32 = 0;
  2189. + st->hcintmsk_copy.d32 = 0;
  2190. + st->hctsiz_copy.d32 = 0;
  2191. + st->hcdma_copy.d32 = 0;
  2192. + st->nr_errors = 0;
  2193. + st->hub_addr = 0;
  2194. + st->port_addr = 0;
  2195. + st->expected_uframe = 0;
  2196. + st->nrpackets = 0;
  2197. + st->dma_info.index = 0;
  2198. + for (i = 0; i < 6; i++)
  2199. + st->dma_info.slot_len[i] = 255;
  2200. + st->hs_isoc_info.index = 0;
  2201. + st->hs_isoc_info.iso_desc = NULL;
  2202. + st->hs_isoc_info.nrframes = 0;
  2203. +
  2204. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  2205. +}
  2206. +
  2207. /**
  2208. * Frees secondary storage associated with the dwc_otg_hcd structure contained
  2209. * in the struct usb_hcd field.
  2210. @@ -907,6 +931,7 @@ static void dwc_otg_hcd_free(dwc_otg_hcd
  2211. DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  2212. DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  2213. DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  2214. + DWC_FREE(dwc_otg_hcd->fiq_state);
  2215. #ifdef DWC_DEV_SRPCAP
  2216. if (dwc_otg_hcd->core_if->power_down == 2 &&
  2217. @@ -984,6 +1009,59 @@ int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd
  2218. channel);
  2219. }
  2220. + if (fiq_enable) {
  2221. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  2222. + if (!hcd->fiq_state) {
  2223. + retval = -DWC_E_NO_MEMORY;
  2224. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  2225. + dwc_otg_hcd_free(hcd);
  2226. + goto out;
  2227. + }
  2228. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  2229. +
  2230. + for (i = 0; i < num_channels; i++) {
  2231. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  2232. + }
  2233. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  2234. +
  2235. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  2236. + if (!hcd->fiq_stack) {
  2237. + retval = -DWC_E_NO_MEMORY;
  2238. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  2239. + dwc_otg_hcd_free(hcd);
  2240. + goto out;
  2241. + }
  2242. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  2243. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  2244. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  2245. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  2246. +
  2247. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  2248. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  2249. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  2250. + * moderately readable array casts.
  2251. + */
  2252. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  2253. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  2254. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  2255. + sizeof(struct fiq_dma_channel) * num_channels);
  2256. +
  2257. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  2258. +
  2259. + /* pointer for debug in fiq_print */
  2260. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  2261. + if (fiq_fsm_enable) {
  2262. + int i;
  2263. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  2264. + dwc_otg_cleanup_fiq_channel(hcd, i);
  2265. + }
  2266. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
  2267. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  2268. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  2269. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
  2270. + }
  2271. + }
  2272. +
  2273. /* Initialize the Connection timeout timer. */
  2274. hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  2275. dwc_otg_hcd_connect_timeout, 0);
  2276. @@ -1181,7 +1259,8 @@ static void assign_and_init_hc(dwc_otg_h
  2277. hc->do_split = 1;
  2278. hc->xact_pos = qtd->isoc_split_pos;
  2279. /* We don't need to do complete splits anymore */
  2280. - if(fiq_split_enable)
  2281. +// if(fiq_fsm_enable)
  2282. + if (0)
  2283. hc->complete_split = qtd->complete_split = 0;
  2284. else
  2285. hc->complete_split = qtd->complete_split;
  2286. @@ -1332,62 +1411,487 @@ static void assign_and_init_hc(dwc_otg_h
  2287. hc->qh = qh;
  2288. }
  2289. -/*
  2290. -** Check the transaction to see if the port / hub has already been assigned for
  2291. -** a split transaction
  2292. -**
  2293. -** Return 0 - Port is already in use
  2294. -*/
  2295. -int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  2296. +
  2297. +/**
  2298. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  2299. + * @qh: pointer to the endpoint's queue head
  2300. + *
  2301. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  2302. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  2303. + * This function's eligibility check is altered by debug parameter.
  2304. + *
  2305. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  2306. + */
  2307. +
  2308. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  2309. {
  2310. - uint32_t hub_addr, port_addr;
  2311. + if (qh->do_split) {
  2312. + switch (qh->ep_type) {
  2313. + case UE_CONTROL:
  2314. + case UE_BULK:
  2315. + if (fiq_fsm_mask & (1 << 0))
  2316. + return 1;
  2317. + break;
  2318. + case UE_INTERRUPT:
  2319. + case UE_ISOCHRONOUS:
  2320. + if (fiq_fsm_mask & (1 << 1))
  2321. + return 1;
  2322. + break;
  2323. + default:
  2324. + break;
  2325. + }
  2326. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  2327. + if (fiq_fsm_mask & (1 << 2)) {
  2328. + /* HS ISOCH support. We test for compatibility:
  2329. + * - DWORD aligned buffers
  2330. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  2331. + * If yes, then the fsm enqueue function will handle the state machine setup.
  2332. + */
  2333. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  2334. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  2335. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  2336. + int nr_iso_frames = urb->packet_count;
  2337. + int i;
  2338. + uint32_t ptr;
  2339. +
  2340. + if (nr_iso_frames < 2)
  2341. + return 0;
  2342. + for (i = 0; i < nr_iso_frames; i++) {
  2343. + ptr = urb->dma + iso_descs[i]->offset;
  2344. + if (ptr & 0x3) {
  2345. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  2346. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  2347. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  2348. + return 0;
  2349. + }
  2350. + }
  2351. + return 1;
  2352. + }
  2353. + }
  2354. + return 0;
  2355. +}
  2356. - if(!fiq_split_enable)
  2357. - return 0;
  2358. +/**
  2359. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  2360. + * @hcd: Pointer to the dwc_otg_hcd struct
  2361. + * @qh: Pointer to the endpoint's queue head
  2362. + *
  2363. + * Periodic split transactions are transmitted modulo 188 bytes.
  2364. + * This necessitates slicing data up into buckets for isochronous out
  2365. + * and fixing up the DMA address for all IN transfers.
  2366. + *
  2367. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  2368. + * HC buffer has been used.
  2369. + */
  2370. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  2371. + {
  2372. + int frame_length, i = 0;
  2373. + uint8_t *ptr = NULL;
  2374. + dwc_hc_t *hc = qh->channel;
  2375. + struct fiq_dma_blob *blob;
  2376. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  2377. - hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  2378. + for (i = 0; i < 6; i++) {
  2379. + st->dma_info.slot_len[i] = 255;
  2380. + }
  2381. + st->dma_info.index = 0;
  2382. + i = 0;
  2383. + if (hc->ep_is_in) {
  2384. + /*
  2385. + * Set dma_regs to bounce buffer. FIQ will update the
  2386. + * state depending on transaction progress.
  2387. + */
  2388. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  2389. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  2390. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  2391. + * a transaction if it fails.
  2392. + */
  2393. + frame_length = st->hcchar_copy.b.mps;
  2394. + do {
  2395. + i++;
  2396. + frame_length -= 188;
  2397. + } while (frame_length >= 0);
  2398. + st->nrpackets = i;
  2399. + return 1;
  2400. + } else {
  2401. + if (qh->ep_type == UE_ISOCHRONOUS) {
  2402. - if(hcd->hub_port[hub_addr] & (1 << port_addr))
  2403. - {
  2404. - fiq_print(FIQDBG_PORTHUB, "H%dP%d:S%02d", hub_addr, port_addr, qh->skip_count);
  2405. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  2406. - qh->skip_count++;
  2407. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  2408. + frame_length = frame_desc->length;
  2409. - if(qh->skip_count > 40000)
  2410. - {
  2411. - printk_once(KERN_ERR "Error: Having to skip port allocation");
  2412. - local_fiq_disable();
  2413. - BUG();
  2414. + /* Virtual address for bounce buffers */
  2415. + blob = hcd->fiq_dmab;
  2416. +
  2417. + ptr = qtd->urb->buf + frame_desc->offset;
  2418. + if (frame_length == 0) {
  2419. + /*
  2420. + * for isochronous transactions, we must still transmit a packet
  2421. + * even if the length is zero.
  2422. + */
  2423. + st->dma_info.slot_len[0] = 0;
  2424. + st->nrpackets = 1;
  2425. + } else {
  2426. + do {
  2427. + if (frame_length <= 188) {
  2428. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  2429. + st->dma_info.slot_len[i] = frame_length;
  2430. + ptr += frame_length;
  2431. + } else {
  2432. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  2433. + st->dma_info.slot_len[i] = 188;
  2434. + ptr += 188;
  2435. + }
  2436. + i++;
  2437. + frame_length -= 188;
  2438. + } while (frame_length > 0);
  2439. + st->nrpackets = i;
  2440. + }
  2441. + ptr = qtd->urb->buf + frame_desc->offset;
  2442. + /* Point the HC at the DMA address of the bounce buffers */
  2443. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  2444. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  2445. +
  2446. + /* fixup xfersize to the actual packet size */
  2447. + st->hctsiz_copy.b.pid = 0;
  2448. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  2449. + return 1;
  2450. + } else {
  2451. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  2452. return 0;
  2453. }
  2454. - return 1;
  2455. }
  2456. - else
  2457. - {
  2458. - qh->skip_count = 0;
  2459. - hcd->hub_port[hub_addr] |= 1 << port_addr;
  2460. - fiq_print(FIQDBG_PORTHUB, "H%dP%d:A %d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  2461. -#ifdef FIQ_DEBUG
  2462. - hcd->hub_port_alloc[hub_addr * 16 + port_addr] = dwc_otg_hcd_get_frame_number(hcd);
  2463. -#endif
  2464. +}
  2465. +
  2466. +/*
  2467. + * Pushing a periodic request into the queue near the EOF1 point
  2468. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  2469. + * Usually, the request goes out on the bus causing a transfer but
  2470. + * the core does not transfer the data to memory.
  2471. + * This guard interval (in number of 60MHz clocks) is required which
  2472. + * must cater for CPU latency between reading the value and enabling
  2473. + * the channel.
  2474. + */
  2475. +#define PERIODIC_FRREM_BACKOFF 1000
  2476. +
  2477. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  2478. +{
  2479. + dwc_hc_t *hc = qh->channel;
  2480. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  2481. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  2482. + int frame;
  2483. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  2484. + int xfer_len, nrpackets;
  2485. + hcdma_data_t hcdma;
  2486. + hfnum_data_t hfnum;
  2487. +
  2488. + if (st->fsm != FIQ_PASSTHROUGH)
  2489. return 0;
  2490. +
  2491. + st->nr_errors = 0;
  2492. +
  2493. + st->hcchar_copy.d32 = 0;
  2494. + st->hcchar_copy.b.mps = hc->max_packet;
  2495. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  2496. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  2497. + st->hcchar_copy.b.epnum = hc->ep_num;
  2498. + st->hcchar_copy.b.eptype = hc->ep_type;
  2499. +
  2500. + st->hcintmsk_copy.b.chhltd = 1;
  2501. +
  2502. + frame = dwc_otg_hcd_get_frame_number(hcd);
  2503. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  2504. +
  2505. + st->hcchar_copy.b.lspddev = 0;
  2506. + /* Enable the channel later as a final register write. */
  2507. +
  2508. + st->hcsplt_copy.d32 = 0;
  2509. +
  2510. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  2511. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  2512. + /* grab the next DMA address offset from the array */
  2513. + st->hcdma_copy.d32 = qtd->urb->dma;
  2514. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  2515. +
  2516. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  2517. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  2518. + * this is always set to the maximum size of the endpoint. */
  2519. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  2520. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  2521. + if (nrpackets == 0)
  2522. + nrpackets = 1;
  2523. + st->hcchar_copy.b.multicnt = nrpackets;
  2524. + st->hctsiz_copy.b.pktcnt = nrpackets;
  2525. +
  2526. + /* Initial PID also needs to be set */
  2527. + if (st->hcchar_copy.b.epdir == 0) {
  2528. + st->hctsiz_copy.b.xfersize = xfer_len;
  2529. + switch (st->hcchar_copy.b.multicnt) {
  2530. + case 1:
  2531. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  2532. + break;
  2533. + case 2:
  2534. + case 3:
  2535. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  2536. + break;
  2537. + }
  2538. +
  2539. + } else {
  2540. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  2541. + switch (st->hcchar_copy.b.multicnt) {
  2542. + case 1:
  2543. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  2544. + break;
  2545. + case 2:
  2546. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  2547. + break;
  2548. + case 3:
  2549. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  2550. + break;
  2551. + }
  2552. }
  2553. +
  2554. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  2555. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  2556. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  2557. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  2558. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  2559. + local_fiq_disable();
  2560. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  2561. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  2562. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  2563. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  2564. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  2565. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  2566. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  2567. + * split transaction is queued very close to EOF.
  2568. + */
  2569. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  2570. + } else {
  2571. + st->fsm = FIQ_HS_ISOC_TURBO;
  2572. + st->hcchar_copy.b.chen = 1;
  2573. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  2574. + }
  2575. + mb();
  2576. + st->hcchar_copy.b.chen = 0;
  2577. + local_fiq_enable();
  2578. + return 0;
  2579. }
  2580. -void dwc_otg_hcd_release_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh)
  2581. +
  2582. +
  2583. +/**
  2584. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  2585. + * @hcd: Pointer to the dwc_otg_hcd struct
  2586. + * @qh: Pointer to the endpoint's queue head
  2587. + *
  2588. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  2589. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  2590. + * for the nominated host channel.
  2591. + *
  2592. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  2593. + * start is possible. If not, then the FIQ is left to start the transfer.
  2594. + */
  2595. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  2596. {
  2597. - uint32_t hub_addr, port_addr;
  2598. + int start_immediate = 1, i;
  2599. + hfnum_data_t hfnum;
  2600. + dwc_hc_t *hc = qh->channel;
  2601. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  2602. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  2603. + int hub_addr, port_addr, frame, uframe;
  2604. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  2605. - if(!fiq_split_enable)
  2606. - return;
  2607. + if (st->fsm != FIQ_PASSTHROUGH)
  2608. + return 0;
  2609. + st->nr_errors = 0;
  2610. - hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  2611. + st->hcchar_copy.d32 = 0;
  2612. + st->hcchar_copy.b.mps = hc->max_packet;
  2613. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  2614. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  2615. + st->hcchar_copy.b.epnum = hc->ep_num;
  2616. + st->hcchar_copy.b.eptype = hc->ep_type;
  2617. + if (hc->ep_type & 0x1) {
  2618. + if (hc->ep_is_in)
  2619. + st->hcchar_copy.b.multicnt = 3;
  2620. + else
  2621. + /* Docs say set this to 1, but driver sets to 0! */
  2622. + st->hcchar_copy.b.multicnt = 0;
  2623. + } else {
  2624. + st->hcchar_copy.b.multicnt = 1;
  2625. + st->hcchar_copy.b.oddfrm = 0;
  2626. + }
  2627. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  2628. + /* Enable the channel later as a final register write. */
  2629. - hcd->hub_port[hub_addr] &= ~(1 << port_addr);
  2630. -#ifdef FIQ_DEBUG
  2631. - hcd->hub_port_alloc[hub_addr * 16 + port_addr] = -1;
  2632. -#endif
  2633. - fiq_print(FIQDBG_PORTHUB, "H%dP%d:RO%d", hub_addr, port_addr, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->pipe_info.ep_num);
  2634. + st->hcsplt_copy.d32 = 0;
  2635. + if(qh->do_split) {
  2636. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  2637. + st->hcsplt_copy.b.compsplt = 0;
  2638. + st->hcsplt_copy.b.spltena = 1;
  2639. + // XACTPOS is for isoc-out only but needs initialising anyway.
  2640. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  2641. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  2642. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  2643. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  2644. + * will update as necessary.
  2645. + */
  2646. + if (hc->xfer_len > 188) {
  2647. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  2648. + }
  2649. + }
  2650. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  2651. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  2652. + st->hub_addr = hub_addr;
  2653. + st->port_addr = port_addr;
  2654. + }
  2655. +
  2656. + st->hctsiz_copy.d32 = 0;
  2657. + st->hctsiz_copy.b.dopng = 0;
  2658. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  2659. +
  2660. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  2661. + hc->xfer_len = hc->max_packet;
  2662. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  2663. + hc->xfer_len = 188;
  2664. + }
  2665. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  2666. +
  2667. + st->hctsiz_copy.b.pktcnt = 1;
  2668. + if (hc->ep_type & 0x1) {
  2669. + /*
  2670. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  2671. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  2672. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  2673. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  2674. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  2675. + * must not touch internal driver state.
  2676. + */
  2677. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  2678. + if (hc->align_buff) {
  2679. + st->hcdma_copy.d32 = hc->align_buff;
  2680. + } else {
  2681. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  2682. + }
  2683. + }
  2684. + } else {
  2685. + if (hc->align_buff) {
  2686. + st->hcdma_copy.d32 = hc->align_buff;
  2687. + } else {
  2688. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  2689. + }
  2690. + }
  2691. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  2692. + * Fixup channel interrupt mask. */
  2693. + st->hcintmsk_copy.d32 = 0;
  2694. + st->hcintmsk_copy.b.chhltd = 1;
  2695. + st->hcintmsk_copy.b.ahberr = 1;
  2696. +
  2697. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  2698. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  2699. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  2700. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  2701. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  2702. +
  2703. + local_fiq_disable();
  2704. + mb();
  2705. +
  2706. + if (hc->ep_type & 0x1) {
  2707. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  2708. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  2709. + uframe = hfnum.b.frnum & 0x7;
  2710. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  2711. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  2712. + * split transaction is queued very close to EOF.
  2713. + */
  2714. + start_immediate = 0;
  2715. + } else if (uframe == 5) {
  2716. + start_immediate = 0;
  2717. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  2718. + start_immediate = 0;
  2719. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  2720. + start_immediate = 0;
  2721. + } else {
  2722. + /* Search through all host channels to determine if a transaction
  2723. + * is currently in progress */
  2724. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  2725. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  2726. + continue;
  2727. + switch (hcd->fiq_state->channel[i].fsm) {
  2728. + /* TT is reserved for channels that are in the middle of a periodic
  2729. + * split transaction.
  2730. + */
  2731. + case FIQ_PER_SSPLIT_STARTED:
  2732. + case FIQ_PER_CSPLIT_WAIT:
  2733. + case FIQ_PER_CSPLIT_NYET1:
  2734. + case FIQ_PER_CSPLIT_POLL:
  2735. + case FIQ_PER_ISO_OUT_ACTIVE:
  2736. + case FIQ_PER_ISO_OUT_LAST:
  2737. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  2738. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  2739. + start_immediate = 0;
  2740. + }
  2741. + break;
  2742. + default:
  2743. + break;
  2744. + }
  2745. + if (!start_immediate)
  2746. + break;
  2747. + }
  2748. + }
  2749. + }
  2750. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  2751. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  2752. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  2753. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  2754. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  2755. + switch (hc->ep_type) {
  2756. + case UE_CONTROL:
  2757. + case UE_BULK:
  2758. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  2759. + break;
  2760. + case UE_ISOCHRONOUS:
  2761. + if (hc->ep_is_in) {
  2762. + if (start_immediate) {
  2763. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  2764. + } else {
  2765. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  2766. + }
  2767. + } else {
  2768. + if (start_immediate) {
  2769. + /* Single-isoc OUT packets don't require FIQ involvement */
  2770. + if (st->nrpackets == 1) {
  2771. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  2772. + } else {
  2773. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  2774. + }
  2775. + } else {
  2776. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  2777. + }
  2778. + }
  2779. + break;
  2780. + case UE_INTERRUPT:
  2781. + if (start_immediate) {
  2782. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  2783. + } else {
  2784. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  2785. + }
  2786. + default:
  2787. + break;
  2788. + }
  2789. + if (start_immediate) {
  2790. + /* Set the oddfrm bit as close as possible to actual queueing */
  2791. + frame = dwc_otg_hcd_get_frame_number(hcd);
  2792. + st->expected_uframe = (frame + 1) & 0x3FFF;
  2793. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  2794. + st->hcchar_copy.b.chen = 1;
  2795. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  2796. + }
  2797. + mb();
  2798. + local_fiq_enable();
  2799. + return 0;
  2800. }
  2801. @@ -1404,16 +1908,11 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
  2802. {
  2803. dwc_list_link_t *qh_ptr;
  2804. dwc_otg_qh_t *qh;
  2805. - dwc_otg_qtd_t *qtd;
  2806. int num_channels;
  2807. dwc_irqflags_t flags;
  2808. dwc_spinlock_t *channel_lock = hcd->channel_lock;
  2809. dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  2810. -#ifdef DEBUG_SOF
  2811. - DWC_DEBUGPL(DBG_HCD, " Select Transactions\n");
  2812. -#endif
  2813. -
  2814. #ifdef DEBUG_HOST_CHANNELS
  2815. last_sel_trans_num_per_scheduled = 0;
  2816. last_sel_trans_num_nonper_scheduled = 0;
  2817. @@ -1428,26 +1927,11 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
  2818. qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  2819. - if(qh->do_split) {
  2820. - qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  2821. - if(!(qh->ep_type == UE_ISOCHRONOUS &&
  2822. - (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  2823. - qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END))) {
  2824. - if(dwc_otg_hcd_allocate_port(hcd, qh))
  2825. - {
  2826. - qh_ptr = DWC_LIST_NEXT(qh_ptr);
  2827. - g_next_sched_frame = dwc_frame_num_inc(dwc_otg_hcd_get_frame_number(hcd), 1);
  2828. - continue;
  2829. - }
  2830. - }
  2831. - }
  2832. -
  2833. if (microframe_schedule) {
  2834. // Make sure we leave one channel for non periodic transactions.
  2835. DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  2836. if (hcd->available_host_channels <= 1) {
  2837. DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  2838. - if(qh->do_split) dwc_otg_hcd_release_port(hcd, qh);
  2839. break;
  2840. }
  2841. hcd->available_host_channels--;
  2842. @@ -1483,27 +1967,24 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
  2843. !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  2844. qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  2845. -
  2846. /*
  2847. * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  2848. * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  2849. * cheeky devices that just hold off using NAKs
  2850. */
  2851. - if (nak_holdoff_enable && qh->do_split) {
  2852. - if (qh->nak_frame != 0xffff &&
  2853. - dwc_full_frame_num(qh->nak_frame) ==
  2854. - dwc_full_frame_num(dwc_otg_hcd_get_frame_number(hcd))) {
  2855. - /*
  2856. - * Revisit: Need to avoid trampling on periodic scheduling.
  2857. - * Currently we are safe because g_np_count != g_np_sent whenever we hit this,
  2858. - * but if this behaviour is changed then periodic endpoints will get a slower
  2859. - * polling rate.
  2860. - */
  2861. - g_next_sched_frame = ((qh->nak_frame + 8) & ~7) & DWC_HFNUM_MAX_FRNUM;
  2862. - qh_ptr = DWC_LIST_NEXT(qh_ptr);
  2863. - continue;
  2864. - } else {
  2865. - qh->nak_frame = 0xffff;
  2866. + if (nak_holdoff && qh->do_split) {
  2867. + if (qh->nak_frame != 0xffff) {
  2868. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  2869. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  2870. + if (dwc_frame_num_le(frame, next_frame)) {
  2871. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  2872. + hcd->fiq_state->next_sched_frame = next_frame;
  2873. + }
  2874. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  2875. + continue;
  2876. + } else {
  2877. + qh->nak_frame = 0xFFFF;
  2878. + }
  2879. }
  2880. }
  2881. @@ -1532,12 +2013,31 @@ dwc_otg_transaction_type_e dwc_otg_hcd_s
  2882. &qh->qh_list_entry);
  2883. DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  2884. - g_np_sent++;
  2885. if (!microframe_schedule)
  2886. hcd->non_periodic_channels++;
  2887. }
  2888. -
  2889. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  2890. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  2891. + * ran out of host channels.
  2892. + */
  2893. + if (fiq_enable) {
  2894. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  2895. + hcd->fiq_state->kick_np_queues = 0;
  2896. + } else {
  2897. + /* For each entry remaining in the NP inactive queue,
  2898. + * if this a NAK'd retransmit then don't set the kick flag.
  2899. + */
  2900. + if(nak_holdoff) {
  2901. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  2902. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  2903. + if (qh->nak_frame == 0xFFFF) {
  2904. + hcd->fiq_state->kick_np_queues = 1;
  2905. + }
  2906. + }
  2907. + }
  2908. + }
  2909. + }
  2910. if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  2911. ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  2912. @@ -1582,6 +2082,12 @@ static int queue_transaction(dwc_otg_hcd
  2913. hc->qh->ping_state = 0;
  2914. }
  2915. } else if (!hc->xfer_started) {
  2916. + if (fiq_fsm_enable && hc->error_state) {
  2917. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  2918. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  2919. + hcd->fiq_state->channel[hc->hc_num].fsm =
  2920. + FIQ_PASSTHROUGH_ERRORSTATE;
  2921. + }
  2922. dwc_otg_hc_start_transfer(hcd->core_if, hc);
  2923. hc->qh->ping_state = 0;
  2924. }
  2925. @@ -1634,7 +2140,7 @@ static void process_periodic_channels(dw
  2926. hptxsts_data_t tx_status;
  2927. dwc_list_link_t *qh_ptr;
  2928. dwc_otg_qh_t *qh;
  2929. - int status;
  2930. + int status = 0;
  2931. int no_queue_space = 0;
  2932. int no_fifo_space = 0;
  2933. @@ -1663,27 +2169,34 @@ static void process_periodic_channels(dw
  2934. // Do not send a split start transaction any later than frame .6
  2935. // Note, we have to schedule a periodic in .5 to make it go in .6
  2936. - if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  2937. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  2938. {
  2939. qh_ptr = qh_ptr->next;
  2940. - g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  2941. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  2942. continue;
  2943. }
  2944. - /*
  2945. - * Set a flag if we're queuing high-bandwidth in slave mode.
  2946. - * The flag prevents any halts to get into the request queue in
  2947. - * the middle of multiple high-bandwidth packets getting queued.
  2948. - */
  2949. - if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  2950. - hcd->core_if->queuing_high_bandwidth = 1;
  2951. - }
  2952. - status =
  2953. - queue_transaction(hcd, qh->channel,
  2954. - tx_status.b.ptxfspcavail);
  2955. - if (status < 0) {
  2956. - no_fifo_space = 1;
  2957. - break;
  2958. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  2959. + if (qh->do_split)
  2960. + fiq_fsm_queue_split_transaction(hcd, qh);
  2961. + else
  2962. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  2963. + } else {
  2964. +
  2965. + /*
  2966. + * Set a flag if we're queueing high-bandwidth in slave mode.
  2967. + * The flag prevents any halts to get into the request queue in
  2968. + * the middle of multiple high-bandwidth packets getting queued.
  2969. + */
  2970. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  2971. + hcd->core_if->queuing_high_bandwidth = 1;
  2972. + }
  2973. + status = queue_transaction(hcd, qh->channel,
  2974. + tx_status.b.ptxfspcavail);
  2975. + if (status < 0) {
  2976. + no_fifo_space = 1;
  2977. + break;
  2978. + }
  2979. }
  2980. /*
  2981. @@ -1800,25 +2313,19 @@ static void process_non_periodic_channel
  2982. qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  2983. qh_list_entry);
  2984. - // Do not send a split start transaction any later than frame .5
  2985. - // non periodic transactions will start immediately in this uframe
  2986. - if(fiq_split_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  2987. - {
  2988. - g_next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  2989. - break;
  2990. - }
  2991. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  2992. + fiq_fsm_queue_split_transaction(hcd, qh);
  2993. + } else {
  2994. + status = queue_transaction(hcd, qh->channel,
  2995. + tx_status.b.nptxfspcavail);
  2996. - status =
  2997. - queue_transaction(hcd, qh->channel,
  2998. - tx_status.b.nptxfspcavail);
  2999. -
  3000. - if (status > 0) {
  3001. - more_to_do = 1;
  3002. - } else if (status < 0) {
  3003. - no_fifo_space = 1;
  3004. - break;
  3005. + if (status > 0) {
  3006. + more_to_do = 1;
  3007. + } else if (status < 0) {
  3008. + no_fifo_space = 1;
  3009. + break;
  3010. + }
  3011. }
  3012. -
  3013. /* Advance to next QH, skipping start-of-list entry. */
  3014. hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  3015. if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  3016. --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  3017. +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  3018. @@ -40,6 +40,8 @@
  3019. #include "dwc_otg_core_if.h"
  3020. #include "dwc_list.h"
  3021. #include "dwc_otg_cil.h"
  3022. +#include "dwc_otg_fiq_fsm.h"
  3023. +
  3024. /**
  3025. * @file
  3026. @@ -585,6 +587,12 @@ struct dwc_otg_hcd {
  3027. /** Frame List DMA address */
  3028. dma_addr_t frame_list_dma;
  3029. + struct fiq_stack *fiq_stack;
  3030. + struct fiq_state *fiq_state;
  3031. +
  3032. + /** Virtual address for split transaction DMA bounce buffers */
  3033. + struct fiq_dma_blob *fiq_dmab;
  3034. +
  3035. #ifdef DEBUG
  3036. uint32_t frrem_samples;
  3037. uint64_t frrem_accum;
  3038. @@ -615,6 +623,9 @@ extern void dwc_otg_hcd_queue_transactio
  3039. int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  3040. void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  3041. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  3042. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  3043. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  3044. /** @} */
  3045. --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  3046. +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  3047. @@ -34,7 +34,6 @@
  3048. #include "dwc_otg_hcd.h"
  3049. #include "dwc_otg_regs.h"
  3050. -#include "dwc_otg_mphi_fix.h"
  3051. #include <linux/jiffies.h>
  3052. #include <mach/hardware.h>
  3053. @@ -47,33 +46,8 @@ extern bool microframe_schedule;
  3054. * This file contains the implementation of the HCD Interrupt handlers.
  3055. */
  3056. -/*
  3057. - * Some globals to communicate between the FIQ and INTERRUPT
  3058. - */
  3059. -
  3060. -void * dummy_send;
  3061. -mphi_regs_t c_mphi_regs;
  3062. -volatile void *dwc_regs_base;
  3063. int fiq_done, int_done;
  3064. -gintsts_data_t gintsts_saved = {.d32 = 0};
  3065. -hcint_data_t hcint_saved[MAX_EPS_CHANNELS];
  3066. -hcintmsk_data_t hcintmsk_saved[MAX_EPS_CHANNELS];
  3067. -int split_out_xfersize[MAX_EPS_CHANNELS];
  3068. -haint_data_t haint_saved;
  3069. -
  3070. -int g_next_sched_frame, g_np_count, g_np_sent;
  3071. -static int mphi_int_count = 0 ;
  3072. -
  3073. -hcchar_data_t nak_hcchar;
  3074. -hctsiz_data_t nak_hctsiz;
  3075. -hcsplt_data_t nak_hcsplt;
  3076. -int nak_count;
  3077. -
  3078. -int complete_sched[MAX_EPS_CHANNELS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  3079. -int split_start_frame[MAX_EPS_CHANNELS];
  3080. -int queued_port[MAX_EPS_CHANNELS];
  3081. -
  3082. #ifdef FIQ_DEBUG
  3083. char buffer[1000*16];
  3084. int wptr;
  3085. @@ -83,12 +57,10 @@ void notrace _fiq_print(FIQDBG_T dbg_lvl
  3086. va_list args;
  3087. char text[17];
  3088. hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  3089. - unsigned long flags;
  3090. - local_irq_save(flags);
  3091. - local_fiq_disable();
  3092. if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  3093. {
  3094. + local_fiq_disable();
  3095. snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  3096. va_start(args, fmt);
  3097. vsnprintf(text+8, 9, fmt, args);
  3098. @@ -96,410 +68,21 @@ void notrace _fiq_print(FIQDBG_T dbg_lvl
  3099. memcpy(buffer + wptr, text, 16);
  3100. wptr = (wptr + 16) % sizeof(buffer);
  3101. + local_fiq_enable();
  3102. }
  3103. - local_irq_restore(flags);
  3104. }
  3105. #endif
  3106. -void notrace fiq_queue_request(int channel, int odd_frame)
  3107. -{
  3108. - hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  3109. - hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  3110. - hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10) };
  3111. -
  3112. - if(hcsplt.b.spltena == 0)
  3113. - {
  3114. - fiq_print(FIQDBG_ERR, "SPLTENA ");
  3115. - BUG();
  3116. - }
  3117. -
  3118. - if(hcchar.b.epdir == 1)
  3119. - {
  3120. - fiq_print(FIQDBG_SCHED, "IN Ch %d", channel);
  3121. - }
  3122. - else
  3123. - {
  3124. - hctsiz.b.xfersize = 0;
  3125. - fiq_print(FIQDBG_SCHED, "OUT Ch %d", channel);
  3126. - }
  3127. - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x10), hctsiz.d32);
  3128. -
  3129. - hcsplt.b.compsplt = 1;
  3130. - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x4), hcsplt.d32);
  3131. -
  3132. - // Send the Split complete
  3133. - hcchar.b.chen = 1;
  3134. - hcchar.b.oddfrm = odd_frame ? 1 : 0;
  3135. -
  3136. - // Post this for transmit on the next frame for periodic or this frame for non-periodic
  3137. - fiq_print(FIQDBG_SCHED, "SND_%s", odd_frame ? "ODD " : "EVEN");
  3138. -
  3139. - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x0), hcchar.d32);
  3140. -}
  3141. -
  3142. -static int last_sof = -1;
  3143. -
  3144. -/*
  3145. -** Function to handle the start of frame interrupt, choose whether we need to do anything and
  3146. -** therefore trigger the main interrupt
  3147. -**
  3148. -** returns int != 0 - interrupt has been handled
  3149. -*/
  3150. -int diff;
  3151. -
  3152. -int notrace fiq_sof_handle(hfnum_data_t hfnum)
  3153. -{
  3154. - int handled = 0;
  3155. - int i;
  3156. -
  3157. - // Just check that once we're running we don't miss a SOF
  3158. - /*if(last_sof != -1 && (hfnum.b.frnum != ((last_sof + 1) & 0x3fff)))
  3159. - {
  3160. - fiq_print(FIQDBG_ERR, "LASTSOF ");
  3161. - fiq_print(FIQDBG_ERR, "%4d%d ", last_sof / 8, last_sof & 7);
  3162. - fiq_print(FIQDBG_ERR, "%4d%d ", hfnum.b.frnum / 8, hfnum.b.frnum & 7);
  3163. - BUG();
  3164. - }*/
  3165. -
  3166. - // Only start remembering the last sof when the interrupt has been
  3167. - // enabled (we don't check the mask to come in here...)
  3168. - if(last_sof != -1 || FIQ_READ(dwc_regs_base + 0x18) & (1<<3))
  3169. - last_sof = hfnum.b.frnum;
  3170. -
  3171. - for(i = 0; i < MAX_EPS_CHANNELS; i++)
  3172. - {
  3173. - if(complete_sched[i] != -1)
  3174. - {
  3175. - if(complete_sched[i] <= hfnum.b.frnum || (complete_sched[i] > 0x3f00 && hfnum.b.frnum < 0xf0))
  3176. - {
  3177. - fiq_queue_request(i, hfnum.b.frnum & 1);
  3178. - complete_sched[i] = -1;
  3179. - }
  3180. - }
  3181. -
  3182. - if(complete_sched[i] != -1)
  3183. - {
  3184. - // This is because we've seen a split complete occur with no start...
  3185. - // most likely because missed the complete 0x3fff frames ago!
  3186. -
  3187. - diff = (hfnum.b.frnum + 0x3fff - complete_sched[i]) & 0x3fff ;
  3188. - if(diff > 32 && diff < 0x3f00)
  3189. - {
  3190. - fiq_print(FIQDBG_ERR, "SPLTMISS");
  3191. - BUG();
  3192. - }
  3193. - }
  3194. - }
  3195. -
  3196. - if(g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  3197. - {
  3198. - /*
  3199. - * If np_count != np_sent that means we need to queue non-periodic (bulk) packets this packet
  3200. - * g_next_sched_frame is the next frame we have periodic packets for
  3201. - *
  3202. - * if neither of these are required for this frame then just clear the interrupt
  3203. - */
  3204. - handled = 1;
  3205. -
  3206. - }
  3207. -
  3208. - return handled;
  3209. -}
  3210. -
  3211. -int notrace port_id(hcsplt_data_t hcsplt)
  3212. -{
  3213. - return hcsplt.b.prtaddr + (hcsplt.b.hubaddr << 8);
  3214. -}
  3215. -
  3216. -int notrace fiq_hcintr_handle(int channel, hfnum_data_t hfnum)
  3217. -{
  3218. - hcchar_data_t hcchar = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x0) };
  3219. - hcsplt_data_t hcsplt = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x4) };
  3220. - hcint_data_t hcint = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x8) };
  3221. - hcintmsk_data_t hcintmsk = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0xc) };
  3222. - hctsiz_data_t hctsiz = { .d32 = FIQ_READ(dwc_regs_base + 0x500 + (channel * 0x20) + 0x10)};
  3223. -
  3224. - hcint_saved[channel].d32 |= hcint.d32;
  3225. - hcintmsk_saved[channel].d32 = hcintmsk.d32;
  3226. -
  3227. - if(hcsplt.b.spltena)
  3228. - {
  3229. - fiq_print(FIQDBG_PORTHUB, "ph: %4x", port_id(hcsplt));
  3230. - if(hcint.b.chhltd)
  3231. - {
  3232. - fiq_print(FIQDBG_SCHED, "CH HLT %d", channel);
  3233. - fiq_print(FIQDBG_SCHED, "%08x", hcint_saved[channel]);
  3234. - }
  3235. - if(hcint.b.stall || hcint.b.xacterr || hcint.b.bblerr || hcint.b.frmovrun || hcint.b.datatglerr)
  3236. - {
  3237. - queued_port[channel] = 0;
  3238. - fiq_print(FIQDBG_ERR, "CHAN ERR");
  3239. - }
  3240. - if(hcint.b.xfercomp)
  3241. - {
  3242. - // Clear the port allocation and transmit anything also on this port
  3243. - queued_port[channel] = 0;
  3244. - fiq_print(FIQDBG_SCHED, "XFERCOMP");
  3245. - }
  3246. - if(hcint.b.nak)
  3247. - {
  3248. - queued_port[channel] = 0;
  3249. - fiq_print(FIQDBG_SCHED, "NAK");
  3250. - }
  3251. - if(hcint.b.ack && !hcsplt.b.compsplt)
  3252. - {
  3253. - int i;
  3254. -
  3255. - // Do not complete isochronous out transactions
  3256. - if(hcchar.b.eptype == 1 && hcchar.b.epdir == 0)
  3257. - {
  3258. - queued_port[channel] = 0;
  3259. - fiq_print(FIQDBG_SCHED, "ISOC_OUT");
  3260. - }
  3261. - else
  3262. - {
  3263. - // Make sure we check the port / hub combination that we sent this split on.
  3264. - // Do not queue a second request to the same port
  3265. - for(i = 0; i < MAX_EPS_CHANNELS; i++)
  3266. - {
  3267. - if(port_id(hcsplt) == queued_port[i])
  3268. - {
  3269. - fiq_print(FIQDBG_ERR, "PORTERR ");
  3270. - //BUG();
  3271. - }
  3272. - }
  3273. -
  3274. - split_start_frame[channel] = (hfnum.b.frnum + 1) & ~7;
  3275. -
  3276. - // Note, the size of an OUT is in the start split phase, not
  3277. - // the complete split
  3278. - split_out_xfersize[channel] = hctsiz.b.xfersize;
  3279. -
  3280. - hcint_saved[channel].b.chhltd = 0;
  3281. - hcint_saved[channel].b.ack = 0;
  3282. -
  3283. - queued_port[channel] = port_id(hcsplt);
  3284. -
  3285. - if(hcchar.b.eptype & 1)
  3286. - {
  3287. - // Send the periodic complete in the same oddness frame as the ACK went...
  3288. - fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  3289. - // complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  3290. - }
  3291. - else
  3292. - {
  3293. - // Schedule the split complete to occur later
  3294. - complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 2);
  3295. - fiq_print(FIQDBG_SCHED, "ACK%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  3296. - }
  3297. - }
  3298. - }
  3299. - if(hcint.b.nyet)
  3300. - {
  3301. - fiq_print(FIQDBG_ERR, "NYETERR1");
  3302. - //BUG();
  3303. - // Can transmit a split complete up to uframe .0 of the next frame
  3304. - if(hfnum.b.frnum <= dwc_frame_num_inc(split_start_frame[channel], 8))
  3305. - {
  3306. - // Send it next frame
  3307. - if(hcchar.b.eptype & 1) // type 1 & 3 are interrupt & isoc
  3308. - {
  3309. - fiq_print(FIQDBG_SCHED, "NYT:SEND");
  3310. - fiq_queue_request(channel, !(hfnum.b.frnum & 1));
  3311. - }
  3312. - else
  3313. - {
  3314. - // Schedule non-periodic access for next frame (the odd-even bit doesn't effect NP)
  3315. - complete_sched[channel] = dwc_frame_num_inc(hfnum.b.frnum, 1);
  3316. - fiq_print(FIQDBG_SCHED, "NYT%04d%d", complete_sched[channel]/8, complete_sched[channel]%8);
  3317. - }
  3318. - hcint_saved[channel].b.chhltd = 0;
  3319. - hcint_saved[channel].b.nyet = 0;
  3320. - }
  3321. - else
  3322. - {
  3323. - queued_port[channel] = 0;
  3324. - fiq_print(FIQDBG_ERR, "NYETERR2");
  3325. - //BUG();
  3326. - }
  3327. - }
  3328. - }
  3329. - else
  3330. - {
  3331. - /*
  3332. - * If we have any of NAK, ACK, Datatlgerr active on a
  3333. - * non-split channel, the sole reason is to reset error
  3334. - * counts for a previously broken transaction. The FIQ
  3335. - * will thrash on NAK IN and ACK OUT in particular so
  3336. - * handle it "once" and allow the IRQ to do the rest.
  3337. - */
  3338. - hcint.d32 &= hcintmsk.d32;
  3339. - if(hcint.b.nak)
  3340. - {
  3341. - hcintmsk.b.nak = 0;
  3342. - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  3343. - }
  3344. - if (hcint.b.ack)
  3345. - {
  3346. - hcintmsk.b.ack = 0;
  3347. - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0xc), hcintmsk.d32);
  3348. - }
  3349. - }
  3350. -
  3351. - // Clear the interrupt, this will also clear the HAINT bit
  3352. - FIQ_WRITE((dwc_regs_base + 0x500 + (channel * 0x20) + 0x8), hcint.d32);
  3353. - return hcint_saved[channel].d32 == 0;
  3354. -}
  3355. -
  3356. -gintsts_data_t gintsts;
  3357. -gintmsk_data_t gintmsk;
  3358. -// triggered: The set of interrupts that were triggered
  3359. -// handled: The set of interrupts that have been handled (no IRQ is
  3360. -// required)
  3361. -// keep: The set of interrupts we want to keep unmasked even though we
  3362. -// want to trigger an IRQ to handle it (SOF and HCINTR)
  3363. -gintsts_data_t triggered, handled, keep;
  3364. -hfnum_data_t hfnum;
  3365. -
  3366. -void __attribute__ ((naked)) notrace dwc_otg_hcd_handle_fiq(void)
  3367. -{
  3368. -
  3369. - /* entry takes care to store registers we will be treading on here */
  3370. - asm __volatile__ (
  3371. - "mov ip, sp ;"
  3372. - /* stash FIQ and normal regs */
  3373. - "stmdb sp!, {r0-r12, lr};"
  3374. - /* !! THIS SETS THE FRAME, adjust to > sizeof locals */
  3375. - "sub fp, ip, #512 ;"
  3376. - );
  3377. -
  3378. - // Cannot put local variables at the beginning of the function
  3379. - // because otherwise 'C' will play with the stack pointer. any locals
  3380. - // need to be inside the following block
  3381. - do
  3382. - {
  3383. - fiq_done++;
  3384. - gintsts.d32 = FIQ_READ(dwc_regs_base + 0x14);
  3385. - gintmsk.d32 = FIQ_READ(dwc_regs_base + 0x18);
  3386. - hfnum.d32 = FIQ_READ(dwc_regs_base + 0x408);
  3387. - triggered.d32 = gintsts.d32 & gintmsk.d32;
  3388. - handled.d32 = 0;
  3389. - keep.d32 = 0;
  3390. - fiq_print(FIQDBG_INT, "FIQ ");
  3391. - fiq_print(FIQDBG_INT, "%08x", gintsts.d32);
  3392. - fiq_print(FIQDBG_INT, "%08x", gintmsk.d32);
  3393. - if(gintsts.d32)
  3394. - {
  3395. - // If port enabled
  3396. - if((FIQ_READ(dwc_regs_base + 0x440) & 0xf) == 0x5)
  3397. - {
  3398. - if(gintsts.b.sofintr)
  3399. - {
  3400. - if(fiq_sof_handle(hfnum))
  3401. - {
  3402. - handled.b.sofintr = 1; /* Handled in FIQ */
  3403. - }
  3404. - else
  3405. - {
  3406. - /* Keer interrupt unmasked */
  3407. - keep.b.sofintr = 1;
  3408. - }
  3409. - {
  3410. - // Need to make sure the read and clearing of the SOF interrupt is as close as possible to avoid the possibility of missing
  3411. - // a start of frame interrupt
  3412. - gintsts_data_t gintsts = { .b.sofintr = 1 };
  3413. - FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  3414. - }
  3415. - }
  3416. -
  3417. - if(fiq_split_enable && gintsts.b.hcintr)
  3418. - {
  3419. - int i;
  3420. - haint_data_t haint;
  3421. - haintmsk_data_t haintmsk;
  3422. -
  3423. - haint.d32 = FIQ_READ(dwc_regs_base + 0x414);
  3424. - haintmsk.d32 = FIQ_READ(dwc_regs_base + 0x418);
  3425. - haint.d32 &= haintmsk.d32;
  3426. - haint_saved.d32 |= haint.d32;
  3427. -
  3428. - fiq_print(FIQDBG_INT, "hcintr");
  3429. - fiq_print(FIQDBG_INT, "%08x", FIQ_READ(dwc_regs_base + 0x414));
  3430. -
  3431. - // Go through each channel that has an enabled interrupt
  3432. - for(i = 0; i < 16; i++)
  3433. - if((haint.d32 >> i) & 1)
  3434. - if(fiq_hcintr_handle(i, hfnum))
  3435. - haint_saved.d32 &= ~(1 << i); /* this was handled */
  3436. -
  3437. - /* If we've handled all host channel interrupts then don't trigger the interrupt */
  3438. - if(haint_saved.d32 == 0)
  3439. - {
  3440. - handled.b.hcintr = 1;
  3441. - }
  3442. - else
  3443. - {
  3444. - /* Make sure we keep the channel interrupt unmasked when triggering the IRQ */
  3445. - keep.b.hcintr = 1;
  3446. - }
  3447. -
  3448. - {
  3449. - gintsts_data_t gintsts = { .b.hcintr = 1 };
  3450. -
  3451. - // Always clear the channel interrupt
  3452. - FIQ_WRITE((dwc_regs_base + 0x14), gintsts.d32);
  3453. - }
  3454. - }
  3455. - }
  3456. - else
  3457. - {
  3458. - last_sof = -1;
  3459. - }
  3460. - }
  3461. -
  3462. - // Mask out the interrupts triggered - those handled - don't mask out the ones we want to keep
  3463. - gintmsk.d32 = keep.d32 | (gintmsk.d32 & ~(triggered.d32 & ~handled.d32));
  3464. - // Save those that were triggered but not handled
  3465. - gintsts_saved.d32 |= triggered.d32 & ~handled.d32;
  3466. - FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  3467. -
  3468. - // Clear and save any unhandled interrupts and trigger the interrupt
  3469. - if(gintsts_saved.d32)
  3470. - {
  3471. - /* To enable the MPHI interrupt (INT 32)
  3472. - */
  3473. - FIQ_WRITE( c_mphi_regs.outdda, (int) dummy_send);
  3474. - FIQ_WRITE( c_mphi_regs.outddb, (1 << 29));
  3475. -
  3476. - mphi_int_count++;
  3477. - }
  3478. - }
  3479. - while(0);
  3480. -
  3481. - mb();
  3482. -
  3483. - /* exit back to normal mode restoring everything */
  3484. - asm __volatile__ (
  3485. - /* return FIQ regs back to pristine state
  3486. - * and get normal regs back
  3487. - */
  3488. - "ldmia sp!, {r0-r12, lr};"
  3489. -
  3490. - /* return */
  3491. - "subs pc, lr, #4;"
  3492. - );
  3493. -}
  3494. -
  3495. /** This function handles interrupts for the HCD. */
  3496. int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  3497. {
  3498. int retval = 0;
  3499. static int last_time;
  3500. -
  3501. dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  3502. gintsts_data_t gintsts;
  3503. gintmsk_data_t gintmsk;
  3504. hfnum_data_t hfnum;
  3505. + haintmsk_data_t haintmsk;
  3506. #ifdef DEBUG
  3507. dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  3508. @@ -516,15 +99,29 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
  3509. DWC_SPINLOCK(dwc_otg_hcd->lock);
  3510. /* Check if HOST Mode */
  3511. if (dwc_otg_is_host_mode(core_if)) {
  3512. - local_fiq_disable();
  3513. - gintmsk.d32 |= gintsts_saved.d32;
  3514. - gintsts.d32 |= gintsts_saved.d32;
  3515. - gintsts_saved.d32 = 0;
  3516. - local_fiq_enable();
  3517. + if (fiq_enable) {
  3518. + local_fiq_disable();
  3519. + /* Pull in from the FIQ's disabled mask */
  3520. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  3521. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  3522. + }
  3523. +
  3524. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  3525. + gintsts.b.hcintr = 1;
  3526. + }
  3527. +
  3528. + /* Danger will robinson: fake a SOF if necessary */
  3529. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  3530. + gintsts.b.sofintr = 1;
  3531. + }
  3532. + gintsts.d32 &= gintmsk.d32;
  3533. +
  3534. + if (fiq_enable)
  3535. + local_fiq_enable();
  3536. +
  3537. if (!gintsts.d32) {
  3538. goto exit_handler_routine;
  3539. }
  3540. - gintsts.d32 &= gintmsk.d32;
  3541. #ifdef DEBUG
  3542. // We should be OK doing this because the common interrupts should already have been serviced
  3543. @@ -544,12 +141,7 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
  3544. gintsts.d32, core_if);
  3545. #endif
  3546. hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  3547. - if (gintsts.b.sofintr && g_np_count == g_np_sent && dwc_frame_num_gt(g_next_sched_frame, hfnum.b.frnum))
  3548. - {
  3549. - /* Note, we should never get here if the FIQ is doing it's job properly*/
  3550. - retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  3551. - }
  3552. - else if (gintsts.b.sofintr) {
  3553. + if (gintsts.b.sofintr) {
  3554. retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  3555. }
  3556. @@ -604,37 +196,43 @@ int32_t dwc_otg_hcd_handle_intr(dwc_otg_
  3557. }
  3558. exit_handler_routine:
  3559. -
  3560. - if (fiq_fix_enable)
  3561. - {
  3562. + if (fiq_enable) {
  3563. + gintmsk_data_t gintmsk_new;
  3564. + haintmsk_data_t haintmsk_new;
  3565. local_fiq_disable();
  3566. - // Make sure that we don't clear the interrupt if we've still got pending work to do
  3567. - if(gintsts_saved.d32 == 0)
  3568. - {
  3569. - /* Clear the MPHI interrupt */
  3570. - DWC_WRITE_REG32(c_mphi_regs.intstat, (1<<16));
  3571. - if (mphi_int_count >= 60)
  3572. - {
  3573. - DWC_WRITE_REG32(c_mphi_regs.ctrl, ((1<<31) + (1<<16)));
  3574. - while(!(DWC_READ_REG32(c_mphi_regs.ctrl) & (1 << 17)))
  3575. - ;
  3576. - DWC_WRITE_REG32(c_mphi_regs.ctrl, (1<<31));
  3577. - mphi_int_count = 0;
  3578. - }
  3579. - int_done++;
  3580. - }
  3581. -
  3582. - // Unmask handled interrupts
  3583. - FIQ_WRITE(dwc_regs_base + 0x18, gintmsk.d32);
  3584. - //DWC_MODIFY_REG32((uint32_t *)IO_ADDRESS(USB_BASE + 0x8), 0 , 1);
  3585. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  3586. + if(fiq_fsm_enable)
  3587. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  3588. + else
  3589. + haintmsk_new.d32 = 0x0000FFFF;
  3590. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  3591. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  3592. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  3593. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  3594. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  3595. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  3596. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  3597. + ;
  3598. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  3599. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  3600. + }
  3601. + int_done++;
  3602. + }
  3603. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  3604. + /* Re-enable interrupts that the FIQ masked (first time round) */
  3605. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  3606. local_fiq_enable();
  3607. - if((jiffies / HZ) > last_time)
  3608. - {
  3609. + if ((jiffies / HZ) > last_time) {
  3610. + //dwc_otg_qh_t *qh;
  3611. + //dwc_list_link_t *cur;
  3612. /* Once a second output the fiq and irq numbers, useful for debug */
  3613. last_time = jiffies / HZ;
  3614. - DWC_DEBUGPL(DBG_USER, "int_done = %d fiq_done = %d\n", int_done, fiq_done);
  3615. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  3616. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  3617. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  3618. + //printk(KERN_WARNING "Periodic queues:\n");
  3619. }
  3620. }
  3621. @@ -686,6 +284,7 @@ static inline void track_missed_sofs(uin
  3622. int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  3623. {
  3624. hfnum_data_t hfnum;
  3625. + gintsts_data_t gintsts = { .d32 = 0 };
  3626. dwc_list_link_t *qh_entry;
  3627. dwc_otg_qh_t *qh;
  3628. dwc_otg_transaction_type_e tr_type;
  3629. @@ -732,8 +331,8 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
  3630. }
  3631. }
  3632. }
  3633. -
  3634. - g_next_sched_frame = next_sched_frame;
  3635. + if (fiq_enable)
  3636. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  3637. tr_type = dwc_otg_hcd_select_transactions(hcd);
  3638. if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  3639. @@ -741,10 +340,11 @@ int32_t dwc_otg_hcd_handle_sof_intr(dwc_
  3640. did_something = 1;
  3641. }
  3642. - /* Clear interrupt */
  3643. - gintsts.b.sofintr = 1;
  3644. - DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  3645. -
  3646. + /* Clear interrupt - but do not trample on the FIQ sof */
  3647. + if (!fiq_fsm_enable) {
  3648. + gintsts.b.sofintr = 1;
  3649. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  3650. + }
  3651. return 1;
  3652. }
  3653. @@ -1020,19 +620,21 @@ int32_t dwc_otg_hcd_handle_hc_intr(dwc_o
  3654. {
  3655. int i;
  3656. int retval = 0;
  3657. - haint_data_t haint;
  3658. + haint_data_t haint = { .d32 = 0 } ;
  3659. /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  3660. * GINTSTS */
  3661. - haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  3662. + if (!fiq_fsm_enable)
  3663. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  3664. // Overwrite with saved interrupts from fiq handler
  3665. - if(fiq_split_enable)
  3666. + if(fiq_fsm_enable)
  3667. {
  3668. + /* check the mask? */
  3669. local_fiq_disable();
  3670. - haint.d32 = haint_saved.d32;
  3671. - haint_saved.d32 = 0;
  3672. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  3673. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  3674. local_fiq_enable();
  3675. }
  3676. @@ -1076,9 +678,7 @@ static uint32_t get_actual_xfer_length(d
  3677. *short_read = (hctsiz.b.xfersize != 0);
  3678. }
  3679. } else if (hc->qh->do_split) {
  3680. - if(fiq_split_enable)
  3681. - length = split_out_xfersize[hc->hc_num];
  3682. - else
  3683. + //length = split_out_xfersize[hc->hc_num];
  3684. length = qtd->ssplit_out_xfer_count;
  3685. } else {
  3686. length = hc->xfer_len;
  3687. @@ -1325,19 +925,17 @@ static void release_channel(dwc_otg_hcd_
  3688. int free_qtd;
  3689. dwc_irqflags_t flags;
  3690. dwc_spinlock_t *channel_lock = hcd->channel_lock;
  3691. -#ifdef FIQ_DEBUG
  3692. - int endp = qtd->urb ? qtd->urb->pipe_info.ep_num : 0;
  3693. -#endif
  3694. +
  3695. int hog_port = 0;
  3696. DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  3697. __func__, hc->hc_num, halt_status, hc->xfer_len);
  3698. - if(fiq_split_enable && hc->do_split) {
  3699. + if(fiq_fsm_enable && hc->do_split) {
  3700. if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  3701. if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  3702. hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  3703. - hog_port = 1;
  3704. + hog_port = 0;
  3705. }
  3706. }
  3707. }
  3708. @@ -1394,6 +992,8 @@ cleanup:
  3709. * function clears the channel interrupt enables and conditions, so
  3710. * there's no need to clear the Channel Halted interrupt separately.
  3711. */
  3712. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  3713. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  3714. dwc_otg_hc_cleanup(hcd->core_if, hc);
  3715. DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  3716. @@ -1416,27 +1016,10 @@ cleanup:
  3717. DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  3718. hcd->available_host_channels++;
  3719. - fiq_print(FIQDBG_PORTHUB, "AHC = %d ", hcd->available_host_channels);
  3720. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  3721. DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  3722. }
  3723. - if(fiq_split_enable && hc->do_split)
  3724. - {
  3725. - if(!(hcd->hub_port[hc->hub_addr] & (1 << hc->port_addr)))
  3726. - {
  3727. - fiq_print(FIQDBG_ERR, "PRTNOTAL");
  3728. - //BUG();
  3729. - }
  3730. - if(!hog_port && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC ||
  3731. - hc->ep_type == DWC_OTG_EP_TYPE_INTR)) {
  3732. - hcd->hub_port[hc->hub_addr] &= ~(1 << hc->port_addr);
  3733. -#ifdef FIQ_DEBUG
  3734. - hcd->hub_port_alloc[hc->hub_addr * 16 + hc->port_addr] = -1;
  3735. -#endif
  3736. - fiq_print(FIQDBG_PORTHUB, "H%dP%d:RR%d", hc->hub_addr, hc->port_addr, endp);
  3737. - }
  3738. - }
  3739. -
  3740. /* Try to queue more transfers now that there's a free channel. */
  3741. tr_type = dwc_otg_hcd_select_transactions(hcd);
  3742. if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  3743. @@ -1858,7 +1441,7 @@ static int32_t handle_hc_nak_intr(dwc_ot
  3744. switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  3745. case UE_BULK:
  3746. case UE_CONTROL:
  3747. - if (nak_holdoff_enable)
  3748. + if (nak_holdoff && qtd->qh->do_split)
  3749. hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  3750. }
  3751. @@ -2074,7 +1657,7 @@ static int32_t handle_hc_nyet_intr(dwc_o
  3752. // With the FIQ running we only ever see the failed NYET
  3753. if (dwc_full_frame_num(frnum) !=
  3754. dwc_full_frame_num(hc->qh->sched_frame) ||
  3755. - fiq_split_enable) {
  3756. + fiq_fsm_enable) {
  3757. /*
  3758. * No longer in the same full speed frame.
  3759. * Treat this as a transaction error.
  3760. @@ -2460,12 +2043,11 @@ static inline int halt_status_ok(dwc_otg
  3761. static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  3762. dwc_hc_t * hc,
  3763. dwc_otg_hc_regs_t * hc_regs,
  3764. - dwc_otg_qtd_t * qtd,
  3765. - hcint_data_t hcint,
  3766. - hcintmsk_data_t hcintmsk)
  3767. + dwc_otg_qtd_t * qtd)
  3768. {
  3769. int out_nak_enh = 0;
  3770. -
  3771. + hcint_data_t hcint;
  3772. + hcintmsk_data_t hcintmsk;
  3773. /* For core with OUT NAK enhancement, the flow for high-
  3774. * speed CONTROL/BULK OUT is handled a little differently.
  3775. */
  3776. @@ -2495,11 +2077,9 @@ static void handle_hc_chhltd_intr_dma(dw
  3777. }
  3778. /* Read the HCINTn register to determine the cause for the halt. */
  3779. - if(!fiq_split_enable)
  3780. - {
  3781. - hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  3782. - hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  3783. - }
  3784. +
  3785. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  3786. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  3787. if (hcint.b.xfercomp) {
  3788. /** @todo This is here because of a possible hardware bug. Spec
  3789. @@ -2624,15 +2204,13 @@ static void handle_hc_chhltd_intr_dma(dw
  3790. static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  3791. dwc_hc_t * hc,
  3792. dwc_otg_hc_regs_t * hc_regs,
  3793. - dwc_otg_qtd_t * qtd,
  3794. - hcint_data_t hcint,
  3795. - hcintmsk_data_t hcintmsk)
  3796. + dwc_otg_qtd_t * qtd)
  3797. {
  3798. DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  3799. "Channel Halted--\n", hc->hc_num);
  3800. if (hcd->core_if->dma_enable) {
  3801. - handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd, hcint, hcintmsk);
  3802. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  3803. } else {
  3804. #ifdef DEBUG
  3805. if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  3806. @@ -2645,11 +2223,372 @@ static int32_t handle_hc_chhltd_intr(dwc
  3807. return 1;
  3808. }
  3809. +
  3810. +/**
  3811. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  3812. + * FIQ transfer completion
  3813. + * @hcd: Pointer to dwc_otg_hcd struct
  3814. + * @num: Host channel number
  3815. + *
  3816. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  3817. + * 2. Copy it from the dwc_otg_urb into the real URB
  3818. + */
  3819. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  3820. +{
  3821. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  3822. + int nr_frames = dwc_urb->packet_count;
  3823. + int i;
  3824. + hcint_data_t frame_hcint;
  3825. +
  3826. + for (i = 0; i < nr_frames; i++) {
  3827. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  3828. + if (frame_hcint.b.xfercomp) {
  3829. + dwc_urb->iso_descs[i].status = 0;
  3830. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  3831. + } else if (frame_hcint.b.frmovrun) {
  3832. + if (qh->ep_is_in)
  3833. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  3834. + else
  3835. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  3836. + dwc_urb->error_count++;
  3837. + dwc_urb->iso_descs[i].actual_length = 0;
  3838. + } else if (frame_hcint.b.xacterr) {
  3839. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  3840. + dwc_urb->error_count++;
  3841. + dwc_urb->iso_descs[i].actual_length = 0;
  3842. + } else if (frame_hcint.b.bblerr) {
  3843. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  3844. + dwc_urb->error_count++;
  3845. + dwc_urb->iso_descs[i].actual_length = 0;
  3846. + } else {
  3847. + /* Something went wrong */
  3848. + dwc_urb->iso_descs[i].status = -1;
  3849. + dwc_urb->iso_descs[i].actual_length = 0;
  3850. + dwc_urb->error_count++;
  3851. + }
  3852. + }
  3853. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  3854. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  3855. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  3856. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  3857. +}
  3858. +
  3859. +/**
  3860. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  3861. + * @hcd: Pointer to dwc_otg_hcd struct
  3862. + * @num: Host channel number
  3863. + *
  3864. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  3865. + * Returns total length of data or -1 if the buffers were not used.
  3866. + *
  3867. + */
  3868. +int dwc_otg_fiq_unsetup_per_dma(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  3869. +{
  3870. + dwc_hc_t *hc = qh->channel;
  3871. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  3872. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  3873. + uint8_t *ptr = NULL;
  3874. + int index = 0, len = 0;
  3875. + int i = 0;
  3876. + if (hc->ep_is_in) {
  3877. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  3878. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  3879. + ptr = qtd->urb->buf;
  3880. + if (qh->ep_type == UE_ISOCHRONOUS) {
  3881. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  3882. + index = qtd->isoc_frame_index;
  3883. + ptr += qtd->urb->iso_descs[index].offset;
  3884. + } else {
  3885. + /* Need to increment by actual_length for interrupt IN */
  3886. + ptr += qtd->urb->actual_length;
  3887. + }
  3888. +
  3889. + for (i = 0; i < st->dma_info.index; i++) {
  3890. + len += st->dma_info.slot_len[i];
  3891. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  3892. + ptr += st->dma_info.slot_len[i];
  3893. + }
  3894. + return len;
  3895. + } else {
  3896. + /* OUT endpoints - nothing to do. */
  3897. + return -1;
  3898. + }
  3899. +
  3900. +}
  3901. +/**
  3902. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  3903. + * from a channel handled in the FIQ
  3904. + * @hcd: Pointer to dwc_otg_hcd struct
  3905. + * @num: Host channel number
  3906. + *
  3907. + * If a host channel interrupt was received by the IRQ and this was a channel
  3908. + * used by the FIQ, the execution flow for transfer completion is substantially
  3909. + * different from the normal (messy) path. This function and its friends handles
  3910. + * channel cleanup and transaction completion from a FIQ transaction.
  3911. + */
  3912. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  3913. +{
  3914. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  3915. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  3916. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  3917. + dwc_otg_qh_t *qh = hc->qh;
  3918. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  3919. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  3920. + int hostchannels = 0;
  3921. + int ret = 0;
  3922. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  3923. +
  3924. + hostchannels = hcd->available_host_channels;
  3925. + switch (st->fsm) {
  3926. + case FIQ_TEST:
  3927. + break;
  3928. +
  3929. + case FIQ_DEQUEUE_ISSUED:
  3930. + /* hc_halt was called. QTD no longer exists. */
  3931. + /* TODO: for a nonperiodic split transaction, need to issue a
  3932. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  3933. + */
  3934. + release_channel(hcd, hc, NULL, hc->halt_status);
  3935. + ret = 1;
  3936. + break;
  3937. +
  3938. + case FIQ_NP_SPLIT_DONE:
  3939. + /* Nonperiodic transaction complete. */
  3940. + if (!hc->ep_is_in) {
  3941. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  3942. + }
  3943. + if (hcint.b.xfercomp) {
  3944. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  3945. + } else if (hcint.b.nak) {
  3946. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  3947. + }
  3948. + ret = 1;
  3949. + break;
  3950. +
  3951. + case FIQ_NP_SPLIT_HS_ABORTED:
  3952. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  3953. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  3954. + * because there's no guarantee which order a non-periodic split happened in.
  3955. + * We could end up clearing a perfectly good transaction out of the buffer.
  3956. + */
  3957. + if (hcint.b.xacterr) {
  3958. + qtd->error_count += st->nr_errors;
  3959. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  3960. + } else if (hcint.b.ahberr) {
  3961. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  3962. + } else {
  3963. + local_fiq_disable();
  3964. + BUG();
  3965. + }
  3966. + break;
  3967. +
  3968. + case FIQ_NP_SPLIT_LS_ABORTED:
  3969. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  3970. + * STALL/data toggle error response on a CSPLIT */
  3971. + if (hcint.b.stall) {
  3972. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  3973. + } else if (hcint.b.datatglerr) {
  3974. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  3975. + } else if (hcint.b.bblerr) {
  3976. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  3977. + } else if (hcint.b.ahberr) {
  3978. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  3979. + } else {
  3980. + local_fiq_disable();
  3981. + BUG();
  3982. + }
  3983. + break;
  3984. +
  3985. + case FIQ_PER_SPLIT_DONE:
  3986. + /* Isoc IN or Interrupt IN/OUT */
  3987. +
  3988. + /* Flow control here is different from the normal execution by the driver.
  3989. + * We need to completely ignore most of the driver's method of handling
  3990. + * split transactions and do it ourselves.
  3991. + */
  3992. + if (hc->ep_type == UE_INTERRUPT) {
  3993. + if (hcint.b.nak) {
  3994. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  3995. + } else if (hc->ep_is_in) {
  3996. + int len;
  3997. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  3998. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  3999. + qtd->urb->actual_length += len;
  4000. + if (qtd->urb->actual_length >= qtd->urb->length) {
  4001. + qtd->urb->status = 0;
  4002. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  4003. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4004. + } else {
  4005. + /* Interrupt transfer not complete yet - is it a short read? */
  4006. + if (len < hc->max_packet) {
  4007. + /* Interrupt transaction complete */
  4008. + qtd->urb->status = 0;
  4009. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  4010. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4011. + } else {
  4012. + /* Further transactions required */
  4013. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  4014. + }
  4015. + }
  4016. + } else {
  4017. + /* Interrupt OUT complete. */
  4018. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  4019. + qtd->urb->actual_length += hc->xfer_len;
  4020. + if (qtd->urb->actual_length >= qtd->urb->length) {
  4021. + qtd->urb->status = 0;
  4022. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  4023. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4024. + } else {
  4025. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  4026. + }
  4027. + }
  4028. + } else {
  4029. + /* ISOC IN complete. */
  4030. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  4031. + int len = 0;
  4032. + /* Record errors, update qtd. */
  4033. + if (st->nr_errors) {
  4034. + frame_desc->actual_length = 0;
  4035. + frame_desc->status = -DWC_E_PROTOCOL;
  4036. + } else {
  4037. + frame_desc->status = 0;
  4038. + /* Unswizzle dma */
  4039. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  4040. + frame_desc->actual_length = len;
  4041. + }
  4042. + qtd->isoc_frame_index++;
  4043. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  4044. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  4045. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4046. + } else {
  4047. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  4048. + }
  4049. + }
  4050. + break;
  4051. +
  4052. + case FIQ_PER_ISO_OUT_DONE: {
  4053. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  4054. + /* Record errors, update qtd. */
  4055. + if (st->nr_errors) {
  4056. + frame_desc->actual_length = 0;
  4057. + frame_desc->status = -DWC_E_PROTOCOL;
  4058. + } else {
  4059. + frame_desc->status = 0;
  4060. + frame_desc->actual_length = frame_desc->length;
  4061. + }
  4062. + qtd->isoc_frame_index++;
  4063. + qtd->isoc_split_offset = 0;
  4064. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  4065. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  4066. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4067. + } else {
  4068. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  4069. + }
  4070. + }
  4071. + break;
  4072. +
  4073. + case FIQ_PER_SPLIT_NYET_ABORTED:
  4074. + /* Doh. lost the data. */
  4075. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  4076. + "- FIQ reported NYET. Data may have been lost.\n",
  4077. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  4078. + if (hc->ep_type == UE_ISOCHRONOUS) {
  4079. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  4080. + /* Record errors, update qtd. */
  4081. + frame_desc->actual_length = 0;
  4082. + frame_desc->status = -DWC_E_PROTOCOL;
  4083. + qtd->isoc_frame_index++;
  4084. + qtd->isoc_split_offset = 0;
  4085. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  4086. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  4087. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4088. + } else {
  4089. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  4090. + }
  4091. + } else {
  4092. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  4093. + }
  4094. + break;
  4095. +
  4096. + case FIQ_HS_ISOC_DONE:
  4097. + /* The FIQ has performed a whole pile of isochronous transactions.
  4098. + * The status is recorded as the interrupt state should the transaction
  4099. + * fail.
  4100. + */
  4101. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  4102. + break;
  4103. +
  4104. + case FIQ_PER_SPLIT_LS_ABORTED:
  4105. + if (hcint.b.xacterr) {
  4106. + /* Hub has responded with an ERR packet. Device
  4107. + * has been unplugged or the port has been disabled.
  4108. + * TODO: need to issue a reset to the hub port. */
  4109. + qtd->error_count += 3;
  4110. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  4111. + } else if (hcint.b.stall) {
  4112. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  4113. + } else if (hcint.b.bblerr) {
  4114. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  4115. + } else {
  4116. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  4117. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  4118. + st->fsm, hc->dev_addr, hc->ep_num);
  4119. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  4120. + }
  4121. + break;
  4122. +
  4123. + case FIQ_PER_SPLIT_HS_ABORTED:
  4124. + /* Either the SSPLIT phase suffered transaction errors or something
  4125. + * unexpected happened.
  4126. + */
  4127. + qtd->error_count += 3;
  4128. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  4129. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  4130. + break;
  4131. +
  4132. + case FIQ_PER_SPLIT_TIMEOUT:
  4133. + /* Couldn't complete in the nominated frame */
  4134. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  4135. + "- FIQ timed out. Data may have been lost.\n",
  4136. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  4137. + if (hc->ep_type == UE_ISOCHRONOUS) {
  4138. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  4139. + /* Record errors, update qtd. */
  4140. + frame_desc->actual_length = 0;
  4141. + if (hc->ep_is_in) {
  4142. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  4143. + } else {
  4144. + frame_desc->status = -DWC_E_COMMUNICATION;
  4145. + }
  4146. + qtd->isoc_frame_index++;
  4147. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  4148. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  4149. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  4150. + } else {
  4151. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  4152. + }
  4153. + } else {
  4154. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  4155. + }
  4156. + break;
  4157. +
  4158. + default:
  4159. + local_fiq_disable();
  4160. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  4161. + BUG();
  4162. + }
  4163. + //if (hostchannels != hcd->available_host_channels) {
  4164. + /* should have incremented by now! */
  4165. + // BUG();
  4166. +// }
  4167. + return ret;
  4168. +}
  4169. +
  4170. /** Handles interrupt for a specific Host Channel */
  4171. int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  4172. {
  4173. int retval = 0;
  4174. - hcint_data_t hcint, hcint_orig;
  4175. + hcint_data_t hcint;
  4176. hcintmsk_data_t hcintmsk;
  4177. dwc_hc_t *hc;
  4178. dwc_otg_hc_regs_t *hc_regs;
  4179. @@ -2668,24 +2607,32 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
  4180. }
  4181. qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  4182. + /*
  4183. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  4184. + * Execution path is fundamentally different for the channels after a FIQ has completed
  4185. + * a split transaction.
  4186. + */
  4187. + if (fiq_fsm_enable) {
  4188. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  4189. + case FIQ_PASSTHROUGH:
  4190. + break;
  4191. + case FIQ_PASSTHROUGH_ERRORSTATE:
  4192. + /* Hook into the error count */
  4193. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  4194. + if (dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  4195. + qtd->error_count = 0;
  4196. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  4197. + }
  4198. + break;
  4199. + default:
  4200. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  4201. + return 1;
  4202. + }
  4203. + }
  4204. +
  4205. hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  4206. - hcint_orig = hcint;
  4207. hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  4208. - DWC_DEBUGPL(DBG_HCDV,
  4209. - " hcint 0x%08x, hcintmsk 0x%08x, hcint&hcintmsk 0x%08x\n",
  4210. - hcint.d32, hcintmsk.d32, (hcint.d32 & hcintmsk.d32));
  4211. hcint.d32 = hcint.d32 & hcintmsk.d32;
  4212. -
  4213. - if(fiq_split_enable)
  4214. - {
  4215. - // replace with the saved interrupts from the fiq handler
  4216. - local_fiq_disable();
  4217. - hcint_orig.d32 = hcint_saved[num].d32;
  4218. - hcint.d32 = hcint_orig.d32 & hcintmsk_saved[num].d32;
  4219. - hcint_saved[num].d32 = 0;
  4220. - local_fiq_enable();
  4221. - }
  4222. -
  4223. if (!dwc_otg_hcd->core_if->dma_enable) {
  4224. if (hcint.b.chhltd && hcint.d32 != 0x2) {
  4225. hcint.b.chhltd = 0;
  4226. @@ -2703,7 +2650,7 @@ int32_t dwc_otg_hcd_handle_hc_n_intr(dwc
  4227. hcint.b.nyet = 0;
  4228. }
  4229. if (hcint.b.chhltd) {
  4230. - retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd, hcint_orig, hcintmsk_saved[num]);
  4231. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  4232. }
  4233. if (hcint.b.ahberr) {
  4234. retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  4235. --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  4236. +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  4237. @@ -58,6 +58,7 @@
  4238. #else
  4239. #include <linux/usb/hcd.h>
  4240. #endif
  4241. +#include <asm/bug.h>
  4242. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  4243. #define USB_URB_EP_LINKING 1
  4244. @@ -69,7 +70,8 @@
  4245. #include "dwc_otg_dbg.h"
  4246. #include "dwc_otg_driver.h"
  4247. #include "dwc_otg_hcd.h"
  4248. -#include "dwc_otg_mphi_fix.h"
  4249. +
  4250. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  4251. /**
  4252. * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  4253. @@ -80,7 +82,7 @@
  4254. static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  4255. -extern bool fiq_fix_enable;
  4256. +extern bool fiq_enable;
  4257. /** @name Linux HC Driver API Functions */
  4258. /** @{ */
  4259. @@ -351,7 +353,6 @@ static int _complete(dwc_otg_hcd_t * hcd
  4260. urb);
  4261. }
  4262. }
  4263. -
  4264. DWC_FREE(dwc_otg_urb);
  4265. if (!new_entry) {
  4266. DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  4267. @@ -395,13 +396,9 @@ static struct dwc_otg_hcd_function_ops h
  4268. static struct fiq_handler fh = {
  4269. .name = "usb_fiq",
  4270. };
  4271. -struct fiq_stack_s {
  4272. - int magic1;
  4273. - uint8_t stack[2048];
  4274. - int magic2;
  4275. -} fiq_stack;
  4276. -extern mphi_regs_t c_mphi_regs;
  4277. +
  4278. +
  4279. /**
  4280. * Initializes the HCD. This function allocates memory for and initializes the
  4281. * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  4282. @@ -433,20 +430,6 @@ int hcd_init(dwc_bus_dev_t *_dev)
  4283. pci_set_consistent_dma_mask(_dev, dmamask);
  4284. #endif
  4285. - if (fiq_fix_enable)
  4286. - {
  4287. - // Set up fiq
  4288. - claim_fiq(&fh);
  4289. - set_fiq_handler(__FIQ_Branch, 4);
  4290. - memset(&regs,0,sizeof(regs));
  4291. - regs.ARM_r8 = (long)dwc_otg_hcd_handle_fiq;
  4292. - regs.ARM_r9 = (long)0;
  4293. - regs.ARM_sp = (long)fiq_stack.stack + sizeof(fiq_stack.stack) - 4;
  4294. - set_fiq_regs(&regs);
  4295. - fiq_stack.magic1 = 0xdeadbeef;
  4296. - fiq_stack.magic2 = 0xaa995566;
  4297. - }
  4298. -
  4299. /*
  4300. * Allocate memory for the base HCD plus the DWC OTG HCD.
  4301. * Initialize the base HCD.
  4302. @@ -466,30 +449,7 @@ int hcd_init(dwc_bus_dev_t *_dev)
  4303. hcd->regs = otg_dev->os_dep.base;
  4304. - if (fiq_fix_enable)
  4305. - {
  4306. - volatile extern void *dwc_regs_base;
  4307. -
  4308. - //Set the mphi periph to the required registers
  4309. - c_mphi_regs.base = otg_dev->os_dep.mphi_base;
  4310. - c_mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  4311. - c_mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  4312. - c_mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  4313. - c_mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  4314. -
  4315. - dwc_regs_base = otg_dev->os_dep.base;
  4316. - //Enable mphi peripheral
  4317. - writel((1<<31),c_mphi_regs.ctrl);
  4318. -#ifdef DEBUG
  4319. - if (readl(c_mphi_regs.ctrl) & 0x80000000)
  4320. - DWC_DEBUGPL(DBG_USER, "MPHI periph has been enabled\n");
  4321. - else
  4322. - DWC_DEBUGPL(DBG_USER, "MPHI periph has NOT been enabled\n");
  4323. -#endif
  4324. - // Enable FIQ interrupt from USB peripheral
  4325. - enable_fiq(INTERRUPT_VC_USB);
  4326. - }
  4327. /* Initialize the DWC OTG HCD. */
  4328. dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  4329. if (!dwc_otg_hcd) {
  4330. @@ -503,6 +463,55 @@ int hcd_init(dwc_bus_dev_t *_dev)
  4331. goto error2;
  4332. }
  4333. + if (fiq_enable)
  4334. + {
  4335. + if (claim_fiq(&fh)) {
  4336. + DWC_ERROR("Can't claim FIQ");
  4337. + goto error2;
  4338. + }
  4339. +
  4340. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  4341. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  4342. +
  4343. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  4344. + memset(&regs,0,sizeof(regs));
  4345. +
  4346. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  4347. + if (fiq_fsm_enable) {
  4348. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  4349. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  4350. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  4351. + } else {
  4352. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  4353. + }
  4354. +
  4355. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  4356. +
  4357. +// __show_regs(&regs);
  4358. + set_fiq_regs(&regs);
  4359. +
  4360. + //Set the mphi periph to the required registers
  4361. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  4362. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  4363. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  4364. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  4365. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  4366. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  4367. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  4368. + //Enable mphi peripheral
  4369. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  4370. +#ifdef DEBUG
  4371. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  4372. + DWC_WARN("MPHI periph has been enabled");
  4373. + else
  4374. + DWC_WARN("MPHI periph has NOT been enabled");
  4375. +#endif
  4376. + // Enable FIQ interrupt from USB peripheral
  4377. + enable_fiq(INTERRUPT_VC_USB);
  4378. + local_fiq_enable();
  4379. + }
  4380. +
  4381. +
  4382. otg_dev->hcd->otg_dev = otg_dev;
  4383. hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  4384. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  4385. @@ -518,9 +527,9 @@ int hcd_init(dwc_bus_dev_t *_dev)
  4386. * IRQ line, and calls hcd_start method.
  4387. */
  4388. #ifdef PLATFORM_INTERFACE
  4389. - retval = usb_add_hcd(hcd, platform_get_irq(_dev, 0), IRQF_SHARED | IRQF_DISABLED);
  4390. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
  4391. #else
  4392. - retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  4393. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  4394. #endif
  4395. if (retval < 0) {
  4396. goto error2;
  4397. @@ -617,9 +626,13 @@ void hcd_stop(struct usb_hcd *hcd)
  4398. /** Returns the current frame number. */
  4399. static int get_frame_number(struct usb_hcd *hcd)
  4400. {
  4401. + hprt0_data_t hprt0;
  4402. dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  4403. -
  4404. - return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  4405. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  4406. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  4407. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  4408. + else
  4409. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  4410. }
  4411. #ifdef DEBUG
  4412. --- a/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  4413. +++ b/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  4414. @@ -41,7 +41,6 @@
  4415. #include "dwc_otg_hcd.h"
  4416. #include "dwc_otg_regs.h"
  4417. -#include "dwc_otg_mphi_fix.h"
  4418. extern bool microframe_schedule;
  4419. @@ -577,7 +576,6 @@ static int check_max_xfer_size(dwc_otg_h
  4420. }
  4421. -extern int g_next_sched_frame, g_np_count, g_np_sent;
  4422. /**
  4423. * Schedules an interrupt or isochronous transfer in the periodic schedule.
  4424. @@ -637,9 +635,9 @@ static int schedule_periodic(dwc_otg_hcd
  4425. DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  4426. }
  4427. else {
  4428. - if(DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, g_next_sched_frame))
  4429. + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
  4430. {
  4431. - g_next_sched_frame = qh->sched_frame;
  4432. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  4433. }
  4434. /* Always start in the inactive schedule. */
  4435. @@ -680,7 +678,7 @@ int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * h
  4436. /* Always start in the inactive schedule. */
  4437. DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  4438. &qh->qh_list_entry);
  4439. - g_np_count++;
  4440. + //hcd->fiq_state->kick_np_queues = 1;
  4441. } else {
  4442. status = schedule_periodic(hcd, qh);
  4443. if ( !hcd->periodic_qh_count ) {
  4444. @@ -740,13 +738,12 @@ void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t
  4445. hcd->non_periodic_qh_ptr->next;
  4446. }
  4447. DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  4448. -
  4449. - // If we've removed the last non-periodic entry then there are none left!
  4450. - g_np_count = g_np_sent;
  4451. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  4452. + // hcd->fiq_state->kick_np_queues = 1;
  4453. } else {
  4454. deschedule_periodic(hcd, qh);
  4455. hcd->periodic_qh_count--;
  4456. - if( !hcd->periodic_qh_count ) {
  4457. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  4458. intr_mask.b.sofintr = 1;
  4459. DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  4460. intr_mask.d32, 0);
  4461. @@ -771,28 +768,11 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
  4462. int sched_next_periodic_split)
  4463. {
  4464. if (dwc_qh_is_non_per(qh)) {
  4465. -
  4466. - dwc_otg_qh_t *qh_tmp;
  4467. - dwc_list_link_t *qh_list;
  4468. - DWC_LIST_FOREACH(qh_list, &hcd->non_periodic_sched_inactive)
  4469. - {
  4470. - qh_tmp = DWC_LIST_ENTRY(qh_list, struct dwc_otg_qh, qh_list_entry);
  4471. - if(qh_tmp == qh)
  4472. - {
  4473. - /*
  4474. - * FIQ is being disabled because this one nevers gets a np_count increment
  4475. - * This is still not absolutely correct, but it should fix itself with
  4476. - * just an unnecessary extra interrupt
  4477. - */
  4478. - g_np_sent = g_np_count;
  4479. - }
  4480. - }
  4481. -
  4482. -
  4483. dwc_otg_hcd_qh_remove(hcd, qh);
  4484. if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  4485. /* Add back to inactive non-periodic schedule. */
  4486. dwc_otg_hcd_qh_add(hcd, qh);
  4487. + //hcd->fiq_state->kick_np_queues = 1;
  4488. }
  4489. } else {
  4490. uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  4491. @@ -851,9 +831,9 @@ void dwc_otg_hcd_qh_deactivate(dwc_otg_h
  4492. DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  4493. &qh->qh_list_entry);
  4494. } else {
  4495. - if(!dwc_frame_num_le(g_next_sched_frame, qh->sched_frame))
  4496. + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  4497. {
  4498. - g_next_sched_frame = qh->sched_frame;
  4499. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  4500. }
  4501. DWC_LIST_MOVE_HEAD
  4502. @@ -944,6 +924,9 @@ int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t *
  4503. if (*qh == NULL) {
  4504. retval = -DWC_E_NO_MEMORY;
  4505. goto done;
  4506. + } else {
  4507. + if (fiq_enable)
  4508. + hcd->fiq_state->kick_np_queues = 1;
  4509. }
  4510. }
  4511. retval = dwc_otg_hcd_qh_add(hcd, *qh);
  4512. --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.c
  4513. +++ /dev/null
  4514. @@ -1,113 +0,0 @@
  4515. -#include "dwc_otg_regs.h"
  4516. -#include "dwc_otg_dbg.h"
  4517. -
  4518. -void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name)
  4519. -{
  4520. - DWC_DEBUGPL(DBG_USER, "*** Debugging from within the %s function: ***\n"
  4521. - "curmode: %1i Modemismatch: %1i otgintr: %1i sofintr: %1i\n"
  4522. - "rxstsqlvl: %1i nptxfempty : %1i ginnakeff: %1i goutnakeff: %1i\n"
  4523. - "ulpickint: %1i i2cintr: %1i erlysuspend:%1i usbsuspend: %1i\n"
  4524. - "usbreset: %1i enumdone: %1i isooutdrop: %1i eopframe: %1i\n"
  4525. - "restoredone: %1i epmismatch: %1i inepint: %1i outepintr: %1i\n"
  4526. - "incomplisoin:%1i incomplisoout:%1i fetsusp: %1i resetdet: %1i\n"
  4527. - "portintr: %1i hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i\n"
  4528. - "conidstschng:%1i disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  4529. - function_name,
  4530. - gintsts.b.curmode,
  4531. - gintsts.b.modemismatch,
  4532. - gintsts.b.otgintr,
  4533. - gintsts.b.sofintr,
  4534. - gintsts.b.rxstsqlvl,
  4535. - gintsts.b.nptxfempty,
  4536. - gintsts.b.ginnakeff,
  4537. - gintsts.b.goutnakeff,
  4538. - gintsts.b.ulpickint,
  4539. - gintsts.b.i2cintr,
  4540. - gintsts.b.erlysuspend,
  4541. - gintsts.b.usbsuspend,
  4542. - gintsts.b.usbreset,
  4543. - gintsts.b.enumdone,
  4544. - gintsts.b.isooutdrop,
  4545. - gintsts.b.eopframe,
  4546. - gintsts.b.restoredone,
  4547. - gintsts.b.epmismatch,
  4548. - gintsts.b.inepint,
  4549. - gintsts.b.outepintr,
  4550. - gintsts.b.incomplisoin,
  4551. - gintsts.b.incomplisoout,
  4552. - gintsts.b.fetsusp,
  4553. - gintsts.b.resetdet,
  4554. - gintsts.b.portintr,
  4555. - gintsts.b.hcintr,
  4556. - gintsts.b.ptxfempty,
  4557. - gintsts.b.lpmtranrcvd,
  4558. - gintsts.b.conidstschng,
  4559. - gintsts.b.disconnect,
  4560. - gintsts.b.sessreqintr,
  4561. - gintsts.b.wkupintr);
  4562. - return;
  4563. -}
  4564. -
  4565. -void dwc_debug_core_int_mask(gintmsk_data_t gintmsk, const char* function_name)
  4566. -{
  4567. - DWC_DEBUGPL(DBG_USER, "Interrupt Mask status (called from %s) :\n"
  4568. - "modemismatch: %1i otgintr: %1i sofintr: %1i rxstsqlvl: %1i\n"
  4569. - "nptxfempty: %1i ginnakeff: %1i goutnakeff: %1i ulpickint: %1i\n"
  4570. - "i2cintr: %1i erlysuspend:%1i usbsuspend: %1i usbreset: %1i\n"
  4571. - "enumdone: %1i isooutdrop: %1i eopframe: %1i restoredone: %1i\n"
  4572. - "epmismatch: %1i inepintr: %1i outepintr: %1i incomplisoin:%1i\n"
  4573. - "incomplisoout:%1i fetsusp: %1i resetdet: %1i portintr: %1i\n"
  4574. - "hcintr: %1i ptxfempty: %1i lpmtranrcvd:%1i conidstschng:%1i\n"
  4575. - "disconnect: %1i sessreqintr:%1i wkupintr: %1i\n",
  4576. - function_name,
  4577. - gintmsk.b.modemismatch,
  4578. - gintmsk.b.otgintr,
  4579. - gintmsk.b.sofintr,
  4580. - gintmsk.b.rxstsqlvl,
  4581. - gintmsk.b.nptxfempty,
  4582. - gintmsk.b.ginnakeff,
  4583. - gintmsk.b.goutnakeff,
  4584. - gintmsk.b.ulpickint,
  4585. - gintmsk.b.i2cintr,
  4586. - gintmsk.b.erlysuspend,
  4587. - gintmsk.b.usbsuspend,
  4588. - gintmsk.b.usbreset,
  4589. - gintmsk.b.enumdone,
  4590. - gintmsk.b.isooutdrop,
  4591. - gintmsk.b.eopframe,
  4592. - gintmsk.b.restoredone,
  4593. - gintmsk.b.epmismatch,
  4594. - gintmsk.b.inepintr,
  4595. - gintmsk.b.outepintr,
  4596. - gintmsk.b.incomplisoin,
  4597. - gintmsk.b.incomplisoout,
  4598. - gintmsk.b.fetsusp,
  4599. - gintmsk.b.resetdet,
  4600. - gintmsk.b.portintr,
  4601. - gintmsk.b.hcintr,
  4602. - gintmsk.b.ptxfempty,
  4603. - gintmsk.b.lpmtranrcvd,
  4604. - gintmsk.b.conidstschng,
  4605. - gintmsk.b.disconnect,
  4606. - gintmsk.b.sessreqintr,
  4607. - gintmsk.b.wkupintr);
  4608. - return;
  4609. -}
  4610. -
  4611. -void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name)
  4612. -{
  4613. - DWC_DEBUGPL(DBG_USER, "otg int register (from %s function):\n"
  4614. - "sesenddet:%1i sesreqsucstschung:%2i hstnegsucstschng:%1i\n"
  4615. - "hstnegdet:%1i adevtoutchng: %2i debdone: %1i\n"
  4616. - "mvic: %1i\n",
  4617. - function_name,
  4618. - gotgint.b.sesenddet,
  4619. - gotgint.b.sesreqsucstschng,
  4620. - gotgint.b.hstnegsucstschng,
  4621. - gotgint.b.hstnegdet,
  4622. - gotgint.b.adevtoutchng,
  4623. - gotgint.b.debdone,
  4624. - gotgint.b.mvic);
  4625. -
  4626. - return;
  4627. -}
  4628. --- a/drivers/usb/host/dwc_otg/dwc_otg_mphi_fix.h
  4629. +++ /dev/null
  4630. @@ -1,48 +0,0 @@
  4631. -#ifndef __DWC_OTG_MPHI_FIX_H__
  4632. -#define __DWC_OTG_MPHI_FIX_H__
  4633. -#define FIQ_WRITE(_addr_,_data_) (*(volatile uint32_t *) (_addr_) = (_data_))
  4634. -#define FIQ_READ(_addr_) (*(volatile uint32_t *) (_addr_))
  4635. -
  4636. -typedef struct {
  4637. - volatile void* base;
  4638. - volatile void* ctrl;
  4639. - volatile void* outdda;
  4640. - volatile void* outddb;
  4641. - volatile void* intstat;
  4642. -} mphi_regs_t;
  4643. -
  4644. -void dwc_debug_print_core_int_reg(gintsts_data_t gintsts, const char* function_name);
  4645. -void dwc_debug_core_int_mask(gintsts_data_t gintmsk, const char* function_name);
  4646. -void dwc_debug_otg_int(gotgint_data_t gotgint, const char* function_name);
  4647. -
  4648. -extern gintsts_data_t gintsts_saved;
  4649. -
  4650. -#ifdef DEBUG
  4651. -#define DWC_DBG_PRINT_CORE_INT(_arg_) dwc_debug_print_core_int_reg(_arg_,__func__)
  4652. -#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_) dwc_debug_core_int_mask(_arg_,__func__)
  4653. -#define DWC_DBG_PRINT_OTG_INT(_arg_) dwc_debug_otg_int(_arg_,__func__)
  4654. -
  4655. -#else
  4656. -#define DWC_DBG_PRINT_CORE_INT(_arg_)
  4657. -#define DWC_DBG_PRINT_CORE_INT_MASK(_arg_)
  4658. -#define DWC_DBG_PRINT_OTG_INT(_arg_)
  4659. -
  4660. -#endif
  4661. -
  4662. -typedef enum {
  4663. - FIQDBG_SCHED = (1 << 0),
  4664. - FIQDBG_INT = (1 << 1),
  4665. - FIQDBG_ERR = (1 << 2),
  4666. - FIQDBG_PORTHUB = (1 << 3),
  4667. -} FIQDBG_T;
  4668. -
  4669. -void _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...);
  4670. -#ifdef FIQ_DEBUG
  4671. -#define fiq_print _fiq_print
  4672. -#else
  4673. -#define fiq_print(x, y, ...)
  4674. -#endif
  4675. -
  4676. -extern bool fiq_fix_enable, nak_holdoff_enable, fiq_split_enable;
  4677. -
  4678. -#endif
  4679. --- a/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  4680. +++ b/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  4681. @@ -59,6 +59,8 @@
  4682. #include "dwc_otg_driver.h"
  4683. #include "dwc_otg_dbg.h"
  4684. +extern bool fiq_enable;
  4685. +
  4686. static struct gadget_wrapper {
  4687. dwc_otg_pcd_t *pcd;
  4688. @@ -1222,13 +1224,13 @@ int pcd_init(dwc_bus_dev_t *_dev)
  4689. */
  4690. #ifdef PLATFORM_INTERFACE
  4691. DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  4692. - platform_get_irq(_dev, 0));
  4693. - retval = request_irq(platform_get_irq(_dev, 0), dwc_otg_pcd_irq,
  4694. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  4695. + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
  4696. IRQF_SHARED, gadget_wrapper->gadget.name,
  4697. otg_dev->pcd);
  4698. if (retval != 0) {
  4699. DWC_ERROR("request of irq%d failed\n",
  4700. - platform_get_irq(_dev, 0));
  4701. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  4702. free_wrapper(gadget_wrapper);
  4703. return -EBUSY;
  4704. }