cris.patch 189 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751
  1. diff -Nur linux-2.6.29.1.orig/arch/cris/Kconfig linux-2.6.29.1/arch/cris/Kconfig
  2. --- linux-2.6.29.1.orig/arch/cris/Kconfig 2009-04-02 22:55:27.000000000 +0200
  3. +++ linux-2.6.29.1/arch/cris/Kconfig 2009-05-09 01:52:49.814118199 +0200
  4. @@ -168,6 +168,12 @@
  5. help
  6. Size of DRAM (decimal in MB) typically 2, 8 or 16.
  7. +config ETRAX_MTD_SIZE
  8. + hex "MTD size (hex)"
  9. + default "0x00800000"
  10. + help
  11. + Size of MTD device typically 4 or 8 MB.
  12. +
  13. config ETRAX_VMEM_SIZE
  14. int "Video memory size (dec, in MB)"
  15. depends on ETRAX_ARCH_V32 && !ETRAXFS
  16. @@ -273,7 +279,7 @@
  17. select MTD_CFI_AMDSTD
  18. select MTD_JEDECPROBE if ETRAX_ARCH_V32
  19. select MTD_CHAR
  20. - select MTD_BLOCK
  21. + select MTD_BLOCK_RO
  22. select MTD_PARTITIONS
  23. select MTD_CONCAT
  24. select MTD_COMPLEX_MAPPINGS
  25. @@ -662,6 +668,11 @@
  26. source "drivers/ide/Kconfig"
  27. +#mysteriously part of this standard linux driver was removed from cris build! - info@crisos.org
  28. +source "drivers/scsi/Kconfig"
  29. +
  30. +source "drivers/media/Kconfig"
  31. +
  32. source "drivers/net/Kconfig"
  33. source "drivers/i2c/Kconfig"
  34. diff -Nur linux-2.6.29.1.orig/arch/cris/Makefile linux-2.6.29.1/arch/cris/Makefile
  35. --- linux-2.6.29.1.orig/arch/cris/Makefile 2009-04-02 22:55:27.000000000 +0200
  36. +++ linux-2.6.29.1/arch/cris/Makefile 2009-05-09 01:53:12.795556299 +0200
  37. @@ -40,12 +40,12 @@
  38. LD = $(CROSS_COMPILE)ld -mcrislinux
  39. -OBJCOPYFLAGS := -O binary -R .note -R .comment -S
  40. +OBJCOPYFLAGS := -O binary -R .note -R .note.gnu.build-id -R .comment
  41. CPPFLAGS_vmlinux.lds = -DDRAM_VIRTUAL_BASE=0x$(CONFIG_ETRAX_DRAM_VIRTUAL_BASE)
  42. KBUILD_AFLAGS += -mlinux -march=$(arch-y) $(inc)
  43. -KBUILD_CFLAGS += -mlinux -march=$(arch-y) -pipe $(inc)
  44. +KBUILD_CFLAGS += -mlinux -march=$(arch-y) -pipe -fno-peephole2 $(inc)
  45. KBUILD_CPPFLAGS += $(inc)
  46. ifdef CONFIG_FRAME_POINTER
  47. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/boot/Makefile linux-2.6.29.1/arch/cris/arch-v10/boot/Makefile
  48. --- linux-2.6.29.1.orig/arch/cris/arch-v10/boot/Makefile 2009-04-02 22:55:27.000000000 +0200
  49. +++ linux-2.6.29.1/arch/cris/arch-v10/boot/Makefile 2009-05-09 01:52:50.030131736 +0200
  50. @@ -2,10 +2,8 @@
  51. # arch/cris/arch-v10/boot/Makefile
  52. #
  53. -OBJCOPYFLAGS = -O binary --remove-section=.bss
  54. -
  55. subdir- := compressed rescue
  56. -targets := Image
  57. +targets := Image zImage
  58. $(obj)/Image: vmlinux FORCE
  59. $(call if_changed,objcopy)
  60. @@ -13,7 +11,6 @@
  61. $(obj)/compressed/vmlinux: $(obj)/Image FORCE
  62. $(Q)$(MAKE) $(build)=$(obj)/compressed $@
  63. - $(Q)$(MAKE) $(build)=$(obj)/rescue $(obj)/rescue/rescue.bin
  64. $(obj)/zImage: $(obj)/compressed/vmlinux
  65. @cp $< $@
  66. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/boot/compressed/Makefile linux-2.6.29.1/arch/cris/arch-v10/boot/compressed/Makefile
  67. --- linux-2.6.29.1.orig/arch/cris/arch-v10/boot/compressed/Makefile 2009-04-02 22:55:27.000000000 +0200
  68. +++ linux-2.6.29.1/arch/cris/arch-v10/boot/compressed/Makefile 2009-05-09 01:52:50.102136724 +0200
  69. @@ -6,7 +6,6 @@
  70. ccflags-y += -O2 $(LINUXINCLUDE)
  71. ldflags-y += -T $(srctree)/$(src)/decompress.lds
  72. OBJECTS = $(obj)/head.o $(obj)/misc.o
  73. -OBJCOPYFLAGS = -O binary --remove-section=.bss
  74. quiet_cmd_image = BUILD $@
  75. cmd_image = cat $(obj)/decompress.bin $(obj)/piggy.gz > $@
  76. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/boot/compressed/misc.c linux-2.6.29.1/arch/cris/arch-v10/boot/compressed/misc.c
  77. --- linux-2.6.29.1.orig/arch/cris/arch-v10/boot/compressed/misc.c 2009-04-02 22:55:27.000000000 +0200
  78. +++ linux-2.6.29.1/arch/cris/arch-v10/boot/compressed/misc.c 2009-05-09 01:52:50.126138666 +0200
  79. @@ -5,7 +5,7 @@
  80. * adapted for Linux.
  81. *
  82. * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
  83. - * puts by Nick Holloway 1993, better puts by Martin Mares 1995
  84. + * putstr by Nick Holloway 1993, better putstr by Martin Mares 1995
  85. * adaptation for Linux/CRIS Axis Communications AB, 1999
  86. *
  87. */
  88. @@ -102,7 +102,7 @@
  89. static long bytes_out = 0;
  90. static uch *output_data;
  91. static unsigned long output_ptr = 0;
  92. -static void puts(const char *);
  93. +static void putstr(const char *);
  94. /* the "heap" is put directly after the BSS ends, at end */
  95. @@ -115,7 +115,7 @@
  96. /* decompressor info and error messages to serial console */
  97. static void
  98. -puts(const char *s)
  99. +putstr(const char *s)
  100. {
  101. #ifndef CONFIG_ETRAX_DEBUG_PORT_NULL
  102. while (*s) {
  103. @@ -188,9 +188,9 @@
  104. static void error(char *x)
  105. {
  106. - puts("\n\n");
  107. - puts(x);
  108. - puts("\n\n -- System halted\n");
  109. + putstr("\n\n");
  110. + putstr(x);
  111. + putstr("\n\n -- System halted\n");
  112. while (1); /* Halt */
  113. }
  114. @@ -234,13 +234,7 @@
  115. makecrc();
  116. - __asm__ volatile ("move $vr,%0" : "=rm" (revision));
  117. - if (revision < 10) {
  118. - puts("You need an ETRAX 100LX to run linux 2.6\n");
  119. - while (1);
  120. - }
  121. -
  122. - puts("Uncompressing Linux...\n");
  123. + putstr("Uncompressing Linux...\n");
  124. gunzip();
  125. - puts("Done. Now booting the kernel.\n");
  126. + putstr("Done. Now booting the kernel.\n");
  127. }
  128. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/drivers/axisflashmap.c linux-2.6.29.1/arch/cris/arch-v10/drivers/axisflashmap.c
  129. --- linux-2.6.29.1.orig/arch/cris/arch-v10/drivers/axisflashmap.c 2009-04-02 22:55:27.000000000 +0200
  130. +++ linux-2.6.29.1/arch/cris/arch-v10/drivers/axisflashmap.c 2009-05-09 01:52:50.210144343 +0200
  131. @@ -122,19 +122,19 @@
  132. */
  133. static struct mtd_partition axis_default_partitions[NUM_DEFAULT_PARTITIONS] = {
  134. {
  135. - .name = "boot firmware",
  136. - .size = CONFIG_ETRAX_PTABLE_SECTOR,
  137. + .name = "kernel",
  138. + .size = 0x00,
  139. .offset = 0
  140. },
  141. {
  142. - .name = "kernel",
  143. - .size = 0x200000 - (6 * CONFIG_ETRAX_PTABLE_SECTOR),
  144. - .offset = CONFIG_ETRAX_PTABLE_SECTOR
  145. + .name = "rootfs",
  146. + .size = 0x200000 ,
  147. + .offset = 0x200000
  148. },
  149. {
  150. - .name = "filesystem",
  151. - .size = 5 * CONFIG_ETRAX_PTABLE_SECTOR,
  152. - .offset = 0x200000 - (5 * CONFIG_ETRAX_PTABLE_SECTOR)
  153. + .name = "cfgfs",
  154. + .size = 0x20000 ,
  155. + .offset = CONFIG_ETRAX_MTD_SIZE - 0x20000
  156. }
  157. };
  158. @@ -281,6 +281,11 @@
  159. struct partitiontable_entry *ptable;
  160. int use_default_ptable = 1; /* Until proven otherwise. */
  161. const char pmsg[] = " /dev/flash%d at 0x%08x, size 0x%08x\n";
  162. + unsigned int kernel_part_size = 0;
  163. + unsigned char *flash_mem = (unsigned char*)(FLASH_CACHED_ADDR);
  164. + unsigned int flash_scan_count = 0;
  165. + const char *part_magic = "ACME_PART_MAGIC";
  166. + unsigned int magic_len = strlen(part_magic);
  167. if (!(mymtd = flash_probe())) {
  168. /* There's no reason to use this module if no flash chip can
  169. @@ -292,6 +297,31 @@
  170. mymtd->name, mymtd->size);
  171. axisflash_mtd = mymtd;
  172. }
  173. + /* scan flash to findout where out partition starts */
  174. +
  175. + printk(KERN_INFO "Scanning flash for end of kernel magic\n");
  176. + for(flash_scan_count = 0; flash_scan_count < 100000; flash_scan_count++){
  177. + if(strncmp(&flash_mem[flash_scan_count], part_magic, magic_len - 1) == 0)
  178. + {
  179. + kernel_part_size = flash_mem[flash_scan_count + magic_len ];
  180. + kernel_part_size <<= 8;
  181. + kernel_part_size += flash_mem[flash_scan_count + magic_len + 2];
  182. + kernel_part_size <<= 8;
  183. + kernel_part_size += flash_mem[flash_scan_count + magic_len + 1];
  184. + kernel_part_size <<= 8;
  185. + kernel_part_size += flash_mem[flash_scan_count + magic_len + 3];
  186. + printk(KERN_INFO "Kernel ends at 0x%.08X\n", kernel_part_size);
  187. + flash_scan_count = 1100000;
  188. + }
  189. + }
  190. +
  191. +
  192. + if(kernel_part_size){
  193. + kernel_part_size = (kernel_part_size & 0xffff0000);
  194. + axis_default_partitions[0].size = kernel_part_size;
  195. + axis_default_partitions[1].size = mymtd->size - axis_default_partitions[0].size - axis_default_partitions[2].size;
  196. + axis_default_partitions[1].offset = axis_default_partitions[0].size;
  197. + }
  198. if (mymtd) {
  199. mymtd->owner = THIS_MODULE;
  200. @@ -360,21 +390,6 @@
  201. use_default_ptable = !ptable_ok;
  202. }
  203. - if (romfs_in_flash) {
  204. - /* Add an overlapping device for the root partition (romfs). */
  205. -
  206. - axis_partitions[pidx].name = "romfs";
  207. - axis_partitions[pidx].size = romfs_length;
  208. - axis_partitions[pidx].offset = romfs_start - FLASH_CACHED_ADDR;
  209. - axis_partitions[pidx].mask_flags |= MTD_WRITEABLE;
  210. -
  211. - printk(KERN_INFO
  212. - " Adding readonly flash partition for romfs image:\n");
  213. - printk(pmsg, pidx, axis_partitions[pidx].offset,
  214. - axis_partitions[pidx].size);
  215. - pidx++;
  216. - }
  217. -
  218. #ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
  219. if (mymtd) {
  220. main_partition.size = mymtd->size;
  221. @@ -397,36 +412,6 @@
  222. if (err)
  223. panic("axisflashmap could not add MTD partitions!\n");
  224. }
  225. -
  226. - if (!romfs_in_flash) {
  227. - /* Create an RAM device for the root partition (romfs). */
  228. -
  229. -#if !defined(CONFIG_MTD_MTDRAM) || (CONFIG_MTDRAM_TOTAL_SIZE != 0) || (CONFIG_MTDRAM_ABS_POS != 0)
  230. - /* No use trying to boot this kernel from RAM. Panic! */
  231. - printk(KERN_EMERG "axisflashmap: Cannot create an MTD RAM "
  232. - "device due to kernel (mis)configuration!\n");
  233. - panic("This kernel cannot boot from RAM!\n");
  234. -#else
  235. - struct mtd_info *mtd_ram;
  236. -
  237. - mtd_ram = kmalloc(sizeof(struct mtd_info), GFP_KERNEL);
  238. - if (!mtd_ram)
  239. - panic("axisflashmap couldn't allocate memory for "
  240. - "mtd_info!\n");
  241. -
  242. - printk(KERN_INFO " Adding RAM partition for romfs image:\n");
  243. - printk(pmsg, pidx, (unsigned)romfs_start,
  244. - (unsigned)romfs_length);
  245. -
  246. - err = mtdram_init_device(mtd_ram,
  247. - (void *)romfs_start,
  248. - romfs_length,
  249. - "romfs");
  250. - if (err)
  251. - panic("axisflashmap could not initialize MTD RAM "
  252. - "device!\n");
  253. -#endif
  254. - }
  255. return err;
  256. }
  257. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/drivers/ds1302.c linux-2.6.29.1/arch/cris/arch-v10/drivers/ds1302.c
  258. --- linux-2.6.29.1.orig/arch/cris/arch-v10/drivers/ds1302.c 2009-04-02 22:55:27.000000000 +0200
  259. +++ linux-2.6.29.1/arch/cris/arch-v10/drivers/ds1302.c 2009-05-09 01:52:50.538166563 +0200
  260. @@ -21,6 +21,7 @@
  261. #include <linux/delay.h>
  262. #include <linux/bcd.h>
  263. #include <linux/capability.h>
  264. +#include <linux/device.h>
  265. #include <asm/uaccess.h>
  266. #include <asm/system.h>
  267. @@ -489,6 +490,10 @@
  268. return 0;
  269. }
  270. +#ifdef CONFIG_SYSFS
  271. +static struct class *rtc_class;
  272. +#endif
  273. +
  274. static int __init ds1302_register(void)
  275. {
  276. ds1302_init();
  277. @@ -497,6 +502,12 @@
  278. ds1302_name, RTC_MAJOR_NR);
  279. return -1;
  280. }
  281. + #ifdef CONFIG_SYSFS
  282. + rtc_class = class_create(THIS_MODULE, "rtc");
  283. + class_device_create(rtc_class, NULL, MKDEV(RTC_MAJOR_NR, 0),
  284. + NULL, "rtc");
  285. + #endif
  286. +
  287. return 0;
  288. }
  289. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/drivers/gpio.c linux-2.6.29.1/arch/cris/arch-v10/drivers/gpio.c
  290. --- linux-2.6.29.1.orig/arch/cris/arch-v10/drivers/gpio.c 2009-04-02 22:55:27.000000000 +0200
  291. +++ linux-2.6.29.1/arch/cris/arch-v10/drivers/gpio.c 2009-05-09 01:52:50.586168771 +0200
  292. @@ -21,6 +21,7 @@
  293. #include <linux/poll.h>
  294. #include <linux/init.h>
  295. #include <linux/interrupt.h>
  296. +#include <linux/device.h>
  297. #include <asm/etraxgpio.h>
  298. #include <arch/svinto.h>
  299. @@ -771,6 +772,10 @@
  300. /* main driver initialization routine, called from mem.c */
  301. +#ifdef CONFIG_SYSFS
  302. +static struct class *gpio_class;
  303. +#endif
  304. +
  305. static int __init gpio_init(void)
  306. {
  307. int res;
  308. @@ -784,6 +789,13 @@
  309. return res;
  310. }
  311. +#ifdef CONFIG_SYSFS
  312. + gpio_class = class_create(THIS_MODULE, "gpio");
  313. + device_create(gpio_class, NULL, MKDEV(GPIO_MAJOR, 0), NULL, "gpioa");
  314. + device_create(gpio_class, NULL, MKDEV(GPIO_MAJOR, 1), NULL, "gpiob");
  315. + device_create(gpio_class, NULL, MKDEV(GPIO_MAJOR, 2), NULL, "leds");
  316. + device_create(gpio_class, NULL, MKDEV(GPIO_MAJOR, 3), NULL, "gpiog");
  317. +#endif
  318. /* Clear all leds */
  319. #if defined (CONFIG_ETRAX_CSP0_LEDS) || defined (CONFIG_ETRAX_PA_LEDS) || defined (CONFIG_ETRAX_PB_LEDS)
  320. CRIS_LED_NETWORK_SET(0);
  321. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/lib/hw_settings.S linux-2.6.29.1/arch/cris/arch-v10/lib/hw_settings.S
  322. --- linux-2.6.29.1.orig/arch/cris/arch-v10/lib/hw_settings.S 2009-04-02 22:55:27.000000000 +0200
  323. +++ linux-2.6.29.1/arch/cris/arch-v10/lib/hw_settings.S 2009-05-09 01:52:50.690174762 +0200
  324. @@ -60,3 +60,5 @@
  325. .dword R_PORT_PB_SET
  326. .dword PB_SET_VALUE
  327. .dword 0 ; No more register values
  328. + .ascii "ACME_PART_MAGIC"
  329. + .dword 0xdeadc0de
  330. diff -Nur linux-2.6.29.1.orig/arch/cris/arch-v10/mm/init.c linux-2.6.29.1/arch/cris/arch-v10/mm/init.c
  331. --- linux-2.6.29.1.orig/arch/cris/arch-v10/mm/init.c 2009-04-02 22:55:27.000000000 +0200
  332. +++ linux-2.6.29.1/arch/cris/arch-v10/mm/init.c 2009-05-09 01:52:50.754179285 +0200
  333. @@ -184,6 +184,9 @@
  334. free_area_init_node(0, zones_size, PAGE_OFFSET >> PAGE_SHIFT, 0);
  335. }
  336. +void free_initrd_mem(unsigned long start, unsigned long end)
  337. +{
  338. +}
  339. /* Initialize remaps of some I/O-ports. It is important that this
  340. * is called before any driver is initialized.
  341. diff -Nur linux-2.6.29.1.orig/drivers/net/cris/eth_v10.c linux-2.6.29.1/drivers/net/cris/eth_v10.c
  342. --- linux-2.6.29.1.orig/drivers/net/cris/eth_v10.c 2009-04-02 22:55:27.000000000 +0200
  343. +++ linux-2.6.29.1/drivers/net/cris/eth_v10.c 2009-05-09 01:52:50.754179285 +0200
  344. @@ -1705,7 +1705,7 @@
  345. static void
  346. e100_netpoll(struct net_device* netdev)
  347. {
  348. - e100rxtx_interrupt(NETWORK_DMA_TX_IRQ_NBR, netdev, NULL);
  349. + e100rxtx_interrupt(NETWORK_DMA_TX_IRQ_NBR, netdev);
  350. }
  351. #endif
  352. diff -Nur linux-2.6.29.1.orig/drivers/serial/crisv10.c linux-2.6.29.1/drivers/serial/crisv10.c
  353. --- linux-2.6.29.1.orig/drivers/serial/crisv10.c 2009-04-02 22:55:27.000000000 +0200
  354. +++ linux-2.6.29.1/drivers/serial/crisv10.c 2009-05-09 01:52:50.758178956 +0200
  355. @@ -27,6 +27,7 @@
  356. #include <linux/kernel.h>
  357. #include <linux/mutex.h>
  358. #include <linux/bitops.h>
  359. +#include <linux/device.h>
  360. #include <asm/io.h>
  361. #include <asm/irq.h>
  362. @@ -4393,6 +4394,7 @@
  363. .tiocmset = rs_tiocmset
  364. };
  365. +static struct class *rs_class;
  366. static int __init
  367. rs_init(void)
  368. {
  369. @@ -4527,6 +4529,24 @@
  370. #endif
  371. #endif /* CONFIG_SVINTO_SIM */
  372. + rs_class = class_create(THIS_MODULE, "rs_tty");
  373. +#ifdef CONFIG_ETRAX_SERIAL_PORT0
  374. + device_create(rs_class, NULL,
  375. + MKDEV(TTY_MAJOR, 64), NULL, "ttyS0");
  376. +#endif
  377. +#ifdef CONFIG_ETRAX_SERIAL_PORT1
  378. + device_create(rs_class, NULL,
  379. + MKDEV(TTY_MAJOR, 65), NULL, "ttyS1");
  380. +#endif
  381. +#ifdef CONFIG_ETRAX_SERIAL_PORT2
  382. + device_create(rs_class, NULL,
  383. + MKDEV(TTY_MAJOR, 66), NULL, "ttyS2");
  384. +#endif
  385. +#ifdef CONFIG_ETRAX_SERIAL_PORT3
  386. + device_create(rs_class, NULL,
  387. + MKDEV(TTY_MAJOR, 67), NULL, "ttyS3");
  388. +#endif
  389. +
  390. return 0;
  391. }
  392. diff -Nur linux-2.6.29.1.orig/drivers/usb/Makefile linux-2.6.29.1/drivers/usb/Makefile
  393. --- linux-2.6.29.1.orig/drivers/usb/Makefile 2009-04-02 22:55:27.000000000 +0200
  394. +++ linux-2.6.29.1/drivers/usb/Makefile 2009-05-09 01:52:50.758178956 +0200
  395. @@ -19,6 +19,7 @@
  396. obj-$(CONFIG_USB_U132_HCD) += host/
  397. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  398. obj-$(CONFIG_USB_HWA_HCD) += host/
  399. +obj-$(CONFIG_ETRAX_USB_HOST) += host/
  400. obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
  401. diff -Nur linux-2.6.29.1.orig/drivers/usb/host/Makefile linux-2.6.29.1/drivers/usb/host/Makefile
  402. --- linux-2.6.29.1.orig/drivers/usb/host/Makefile 2009-04-02 22:55:27.000000000 +0200
  403. +++ linux-2.6.29.1/drivers/usb/host/Makefile 2009-05-09 01:52:50.758178956 +0200
  404. @@ -29,3 +29,4 @@
  405. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  406. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  407. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  408. +obj-$(CONFIG_ETRAX_USB_HOST) += hc-crisv10.o
  409. diff -Nur linux-2.6.29.1.orig/drivers/usb/host/hc-cris-dbg.h linux-2.6.29.1/drivers/usb/host/hc-cris-dbg.h
  410. --- linux-2.6.29.1.orig/drivers/usb/host/hc-cris-dbg.h 1970-01-01 01:00:00.000000000 +0100
  411. +++ linux-2.6.29.1/drivers/usb/host/hc-cris-dbg.h 2009-05-09 01:52:50.762178907 +0200
  412. @@ -0,0 +1,146 @@
  413. +
  414. +/* macros for debug output */
  415. +
  416. +#define warn(fmt, args...) \
  417. + printk(KERN_INFO "crisv10 warn: ");printk(fmt, ## args)
  418. +
  419. +#define hcd_dbg(hcd, fmt, args...) \
  420. + dev_info(hcd->self.controller, fmt, ## args)
  421. +#define hcd_err(hcd, fmt, args...) \
  422. + dev_err(hcd->self.controller, fmt, ## args)
  423. +#define hcd_info(hcd, fmt, args...) \
  424. + dev_info(hcd->self.controller, fmt, ## args)
  425. +#define hcd_warn(hcd, fmt, args...) \
  426. + dev_warn(hcd->self.controller, fmt, ## args)
  427. +
  428. +/*
  429. +#define devdrv_dbg(fmt, args...) \
  430. + printk(KERN_INFO "usb_devdrv dbg: ");printk(fmt, ## args)
  431. +*/
  432. +#define devdrv_dbg(fmt, args...) {}
  433. +
  434. +#define devdrv_err(fmt, args...) \
  435. + printk(KERN_ERR "usb_devdrv error: ");printk(fmt, ## args)
  436. +#define devdrv_info(fmt, args...) \
  437. + printk(KERN_INFO "usb_devdrv: ");printk(fmt, ## args)
  438. +
  439. +#define irq_dbg(fmt, args...) \
  440. + printk(KERN_INFO "crisv10_irq dbg: ");printk(fmt, ## args)
  441. +#define irq_err(fmt, args...) \
  442. + printk(KERN_ERR "crisv10_irq error: ");printk(fmt, ## args)
  443. +#define irq_warn(fmt, args...) \
  444. + printk(KERN_INFO "crisv10_irq warn: ");printk(fmt, ## args)
  445. +#define irq_info(fmt, args...) \
  446. + printk(KERN_INFO "crisv10_hcd: ");printk(fmt, ## args)
  447. +
  448. +/*
  449. +#define rh_dbg(fmt, args...) \
  450. + printk(KERN_DEBUG "crisv10_rh dbg: ");printk(fmt, ## args)
  451. +*/
  452. +#define rh_dbg(fmt, args...) {}
  453. +
  454. +#define rh_err(fmt, args...) \
  455. + printk(KERN_ERR "crisv10_rh error: ");printk(fmt, ## args)
  456. +#define rh_warn(fmt, args...) \
  457. + printk(KERN_INFO "crisv10_rh warning: ");printk(fmt, ## args)
  458. +#define rh_info(fmt, args...) \
  459. + printk(KERN_INFO "crisv10_rh: ");printk(fmt, ## args)
  460. +
  461. +/*
  462. +#define tc_dbg(fmt, args...) \
  463. + printk(KERN_INFO "crisv10_tc dbg: ");printk(fmt, ## args)
  464. +*/
  465. +#define tc_dbg(fmt, args...) {while(0){}}
  466. +
  467. +#define tc_err(fmt, args...) \
  468. + printk(KERN_ERR "crisv10_tc error: ");printk(fmt, ## args)
  469. +/*
  470. +#define tc_warn(fmt, args...) \
  471. + printk(KERN_INFO "crisv10_tc warning: ");printk(fmt, ## args)
  472. +*/
  473. +#define tc_warn(fmt, args...) {while(0){}}
  474. +
  475. +#define tc_info(fmt, args...) \
  476. + printk(KERN_INFO "crisv10_tc: ");printk(fmt, ## args)
  477. +
  478. +
  479. +/* Debug print-outs for various traffic types */
  480. +
  481. +#define intr_warn(fmt, args...) \
  482. + printk(KERN_INFO "crisv10_intr warning: ");printk(fmt, ## args)
  483. +
  484. +#define intr_dbg(fmt, args...) \
  485. + printk(KERN_DEBUG "crisv10_intr dbg: ");printk(fmt, ## args)
  486. +/*
  487. +#define intr_dbg(fmt, args...) {while(0){}}
  488. +*/
  489. +
  490. +
  491. +#define isoc_err(fmt, args...) \
  492. + printk(KERN_ERR "crisv10_isoc error: ");printk(fmt, ## args)
  493. +/*
  494. +#define isoc_warn(fmt, args...) \
  495. + printk(KERN_INFO "crisv10_isoc warning: ");printk(fmt, ## args)
  496. +*/
  497. +#define isoc_warn(fmt, args...) {while(0){}}
  498. +
  499. +/*
  500. +#define isoc_dbg(fmt, args...) \
  501. + printk(KERN_INFO "crisv10_isoc dbg: ");printk(fmt, ## args)
  502. +*/
  503. +#define isoc_dbg(fmt, args...) {while(0){}}
  504. +
  505. +/*
  506. +#define timer_warn(fmt, args...) \
  507. + printk(KERN_INFO "crisv10_timer warning: ");printk(fmt, ## args)
  508. +*/
  509. +#define timer_warn(fmt, args...) {while(0){}}
  510. +
  511. +/*
  512. +#define timer_dbg(fmt, args...) \
  513. + printk(KERN_INFO "crisv10_timer dbg: ");printk(fmt, ## args)
  514. +*/
  515. +#define timer_dbg(fmt, args...) {while(0){}}
  516. +
  517. +
  518. +/* Debug printouts for events related to late finishing of URBs */
  519. +
  520. +#define late_dbg(fmt, args...) \
  521. + printk(KERN_INFO "crisv10_late dbg: ");printk(fmt, ## args)
  522. +/*
  523. +#define late_dbg(fmt, args...) {while(0){}}
  524. +*/
  525. +
  526. +#define late_warn(fmt, args...) \
  527. + printk(KERN_INFO "crisv10_late warning: ");printk(fmt, ## args)
  528. +/*
  529. +#define errno_dbg(fmt, args...) \
  530. + printk(KERN_INFO "crisv10_errno dbg: ");printk(fmt, ## args)
  531. +*/
  532. +#define errno_dbg(fmt, args...) {while(0){}}
  533. +
  534. +
  535. +#define dma_dbg(fmt, args...) \
  536. + printk(KERN_INFO "crisv10_dma dbg: ");printk(fmt, ## args)
  537. +#define dma_err(fmt, args...) \
  538. + printk(KERN_ERR "crisv10_dma error: ");printk(fmt, ## args)
  539. +#define dma_warn(fmt, args...) \
  540. + printk(KERN_INFO "crisv10_dma warning: ");printk(fmt, ## args)
  541. +#define dma_info(fmt, args...) \
  542. + printk(KERN_INFO "crisv10_dma: ");printk(fmt, ## args)
  543. +
  544. +
  545. +
  546. +#define str_dir(pipe) \
  547. + (usb_pipeout(pipe) ? "out" : "in")
  548. +#define str_type(pipe) \
  549. + ({ \
  550. + char *s = "?"; \
  551. + switch (usb_pipetype(pipe)) { \
  552. + case PIPE_ISOCHRONOUS: s = "iso"; break; \
  553. + case PIPE_INTERRUPT: s = "intr"; break; \
  554. + case PIPE_CONTROL: s = "ctrl"; break; \
  555. + case PIPE_BULK: s = "bulk"; break; \
  556. + }; \
  557. + s; \
  558. + })
  559. diff -Nur linux-2.6.29.1.orig/drivers/usb/host/hc-crisv10.c linux-2.6.29.1/drivers/usb/host/hc-crisv10.c
  560. --- linux-2.6.29.1.orig/drivers/usb/host/hc-crisv10.c 1970-01-01 01:00:00.000000000 +0100
  561. +++ linux-2.6.29.1/drivers/usb/host/hc-crisv10.c 2009-05-09 01:52:50.834182770 +0200
  562. @@ -0,0 +1,4800 @@
  563. +/*
  564. + *
  565. + * ETRAX 100LX USB Host Controller Driver
  566. + *
  567. + * Copyright (C) 2005, 2006 Axis Communications AB
  568. + *
  569. + * Author: Konrad Eriksson <konrad.eriksson@axis.se>
  570. + *
  571. + */
  572. +
  573. +#include <linux/module.h>
  574. +#include <linux/kernel.h>
  575. +#include <linux/init.h>
  576. +#include <linux/moduleparam.h>
  577. +#include <linux/spinlock.h>
  578. +#include <linux/usb.h>
  579. +#include <linux/platform_device.h>
  580. +
  581. +#include <asm/io.h>
  582. +#include <asm/irq.h>
  583. +#include <arch/dma.h>
  584. +#include <arch/io_interface_mux.h>
  585. +
  586. +#include "../core/hcd.h"
  587. +#include "../core/hub.h"
  588. +#include "hc-crisv10.h"
  589. +#include "hc-cris-dbg.h"
  590. +
  591. +
  592. +/***************************************************************************/
  593. +/***************************************************************************/
  594. +/* Host Controller settings */
  595. +/***************************************************************************/
  596. +/***************************************************************************/
  597. +
  598. +#define VERSION "1.00 hinko.4"
  599. +#define COPYRIGHT "(c) 2005, 2006 Axis Communications AB"
  600. +#define DESCRIPTION "ETRAX 100LX USB Host Controller (2.6.25-rc9 port)"
  601. +
  602. +#define ETRAX_USB_HC_IRQ USB_HC_IRQ_NBR
  603. +#define ETRAX_USB_RX_IRQ USB_DMA_RX_IRQ_NBR
  604. +#define ETRAX_USB_TX_IRQ USB_DMA_TX_IRQ_NBR
  605. +
  606. +/* Number of physical ports in Etrax 100LX */
  607. +#define USB_ROOT_HUB_PORTS 2
  608. +
  609. +const char hc_name[] = "hc-crisv10";
  610. +const char product_desc[] = DESCRIPTION;
  611. +
  612. +/* The number of epids is, among other things, used for pre-allocating
  613. + ctrl, bulk and isoc EP descriptors (one for each epid).
  614. + Assumed to be > 1 when initiating the DMA lists. */
  615. +#define NBR_OF_EPIDS 32
  616. +
  617. +/* Support interrupt traffic intervals up to 128 ms. */
  618. +#define MAX_INTR_INTERVAL 128
  619. +
  620. +/* If periodic traffic (intr or isoc) is to be used, then one entry in the EP
  621. + table must be "invalid". By this we mean that we shouldn't care about epid
  622. + attentions for this epid, or at least handle them differently from epid
  623. + attentions for "valid" epids. This define determines which one to use
  624. + (don't change it). */
  625. +#define INVALID_EPID 31
  626. +/* A special epid for the bulk dummys. */
  627. +#define DUMMY_EPID 30
  628. +
  629. +/* Module settings */
  630. +
  631. +MODULE_DESCRIPTION(DESCRIPTION);
  632. +MODULE_LICENSE("GPL");
  633. +MODULE_AUTHOR("Konrad Eriksson <konrad.eriksson@axis.se>");
  634. +
  635. +
  636. +/* Module parameters */
  637. +
  638. +/* 0 = No ports enabled
  639. + 1 = Only port 1 enabled (on board ethernet on devboard)
  640. + 2 = Only port 2 enabled (external connector on devboard)
  641. + 3 = Both ports enabled
  642. +*/
  643. +static unsigned int ports = 3;
  644. +module_param(ports, uint, S_IRUGO);
  645. +MODULE_PARM_DESC(ports, "Bitmask indicating USB ports to use");
  646. +
  647. +
  648. +/***************************************************************************/
  649. +/***************************************************************************/
  650. +/* Shared global variables for this module */
  651. +/***************************************************************************/
  652. +/***************************************************************************/
  653. +
  654. +/* EP descriptor lists for non period transfers. Must be 32-bit aligned. */
  655. +static volatile struct USB_EP_Desc TxBulkEPList[NBR_OF_EPIDS] __attribute__ ((aligned (4)));
  656. +
  657. +static volatile struct USB_EP_Desc TxCtrlEPList[NBR_OF_EPIDS] __attribute__ ((aligned (4)));
  658. +
  659. +/* EP descriptor lists for period transfers. Must be 32-bit aligned. */
  660. +static volatile struct USB_EP_Desc TxIntrEPList[MAX_INTR_INTERVAL] __attribute__ ((aligned (4)));
  661. +static volatile struct USB_SB_Desc TxIntrSB_zout __attribute__ ((aligned (4)));
  662. +
  663. +static volatile struct USB_EP_Desc TxIsocEPList[NBR_OF_EPIDS] __attribute__ ((aligned (4)));
  664. +static volatile struct USB_SB_Desc TxIsocSB_zout __attribute__ ((aligned (4)));
  665. +
  666. +//static volatile struct USB_SB_Desc TxIsocSBList[NBR_OF_EPIDS] __attribute__ ((aligned (4)));
  667. +
  668. +/* After each enabled bulk EP IN we put two disabled EP descriptors with the eol flag set,
  669. + causing the DMA to stop the DMA channel. The first of these two has the intr flag set, which
  670. + gives us a dma8_sub0_descr interrupt. When we receive this, we advance the DMA one step in the
  671. + EP list and then restart the bulk channel, thus forcing a switch between bulk EP descriptors
  672. + in each frame. */
  673. +static volatile struct USB_EP_Desc TxBulkDummyEPList[NBR_OF_EPIDS][2] __attribute__ ((aligned (4)));
  674. +
  675. +/* List of URB pointers, where each points to the active URB for a epid.
  676. + For Bulk, Ctrl and Intr this means which URB that currently is added to
  677. + DMA lists (Isoc URBs are all directly added to DMA lists). As soon as
  678. + URB has completed is the queue examined and the first URB in queue is
  679. + removed and moved to the activeUrbList while its state change to STARTED and
  680. + its transfer(s) gets added to DMA list (exception Isoc where URBs enter
  681. + state STARTED directly and added transfers added to DMA lists). */
  682. +static struct urb *activeUrbList[NBR_OF_EPIDS];
  683. +
  684. +/* Additional software state info for each epid */
  685. +static struct etrax_epid epid_state[NBR_OF_EPIDS];
  686. +
  687. +/* Timer handles for bulk traffic timer used to avoid DMA bug where DMA stops
  688. + even if there is new data waiting to be processed */
  689. +static struct timer_list bulk_start_timer = TIMER_INITIALIZER(NULL, 0, 0);
  690. +static struct timer_list bulk_eot_timer = TIMER_INITIALIZER(NULL, 0, 0);
  691. +
  692. +/* We want the start timer to expire before the eot timer, because the former
  693. + might start traffic, thus making it unnecessary for the latter to time
  694. + out. */
  695. +#define BULK_START_TIMER_INTERVAL (HZ/50) /* 20 ms */
  696. +#define BULK_EOT_TIMER_INTERVAL (HZ/16) /* 60 ms */
  697. +
  698. +/* Delay before a URB completion happen when it's scheduled to be delayed */
  699. +#define LATER_TIMER_DELAY (HZ/50) /* 20 ms */
  700. +
  701. +/* Simplifying macros for checking software state info of a epid */
  702. +/* ----------------------------------------------------------------------- */
  703. +#define epid_inuse(epid) epid_state[epid].inuse
  704. +#define epid_out_traffic(epid) epid_state[epid].out_traffic
  705. +#define epid_isoc(epid) (epid_state[epid].type == PIPE_ISOCHRONOUS ? 1 : 0)
  706. +#define epid_intr(epid) (epid_state[epid].type == PIPE_INTERRUPT ? 1 : 0)
  707. +
  708. +
  709. +/***************************************************************************/
  710. +/***************************************************************************/
  711. +/* DEBUG FUNCTIONS */
  712. +/***************************************************************************/
  713. +/***************************************************************************/
  714. +/* Note that these functions are always available in their "__" variants,
  715. + for use in error situations. The "__" missing variants are controlled by
  716. + the USB_DEBUG_DESC/USB_DEBUG_URB macros. */
  717. +static void __dump_urb(struct urb* purb)
  718. +{
  719. + struct crisv10_urb_priv *urb_priv = purb->hcpriv;
  720. + int urb_num = -1;
  721. + if(urb_priv) {
  722. + urb_num = urb_priv->urb_num;
  723. + }
  724. + printk("\nURB:0x%x[%d]\n", (unsigned int)purb, urb_num);
  725. + printk("dev :0x%08lx\n", (unsigned long)purb->dev);
  726. + printk("pipe :0x%08x\n", purb->pipe);
  727. + printk("status :%d\n", purb->status);
  728. + printk("transfer_flags :0x%08x\n", purb->transfer_flags);
  729. + printk("transfer_buffer :0x%08lx\n", (unsigned long)purb->transfer_buffer);
  730. + printk("transfer_buffer_length:%d\n", purb->transfer_buffer_length);
  731. + printk("actual_length :%d\n", purb->actual_length);
  732. + printk("setup_packet :0x%08lx\n", (unsigned long)purb->setup_packet);
  733. + printk("start_frame :%d\n", purb->start_frame);
  734. + printk("number_of_packets :%d\n", purb->number_of_packets);
  735. + printk("interval :%d\n", purb->interval);
  736. + printk("error_count :%d\n", purb->error_count);
  737. + printk("context :0x%08lx\n", (unsigned long)purb->context);
  738. + printk("complete :0x%08lx\n\n", (unsigned long)purb->complete);
  739. +}
  740. +
  741. +static void __dump_in_desc(volatile struct USB_IN_Desc *in)
  742. +{
  743. + printk("\nUSB_IN_Desc at 0x%08lx\n", (unsigned long)in);
  744. + printk(" sw_len : 0x%04x (%d)\n", in->sw_len, in->sw_len);
  745. + printk(" command : 0x%04x\n", in->command);
  746. + printk(" next : 0x%08lx\n", in->next);
  747. + printk(" buf : 0x%08lx\n", in->buf);
  748. + printk(" hw_len : 0x%04x (%d)\n", in->hw_len, in->hw_len);
  749. + printk(" status : 0x%04x\n\n", in->status);
  750. +}
  751. +
  752. +static void __dump_sb_desc(volatile struct USB_SB_Desc *sb)
  753. +{
  754. + char tt = (sb->command & 0x30) >> 4;
  755. + char *tt_string;
  756. +
  757. + switch (tt) {
  758. + case 0:
  759. + tt_string = "zout";
  760. + break;
  761. + case 1:
  762. + tt_string = "in";
  763. + break;
  764. + case 2:
  765. + tt_string = "out";
  766. + break;
  767. + case 3:
  768. + tt_string = "setup";
  769. + break;
  770. + default:
  771. + tt_string = "unknown (weird)";
  772. + }
  773. +
  774. + printk(" USB_SB_Desc at 0x%08lx ", (unsigned long)sb);
  775. + printk(" command:0x%04x (", sb->command);
  776. + printk("rem:%d ", (sb->command & 0x3f00) >> 8);
  777. + printk("full:%d ", (sb->command & 0x40) >> 6);
  778. + printk("tt:%d(%s) ", tt, tt_string);
  779. + printk("intr:%d ", (sb->command & 0x8) >> 3);
  780. + printk("eot:%d ", (sb->command & 0x2) >> 1);
  781. + printk("eol:%d)", sb->command & 0x1);
  782. + printk(" sw_len:0x%04x(%d)", sb->sw_len, sb->sw_len);
  783. + printk(" next:0x%08lx", sb->next);
  784. + printk(" buf:0x%08lx\n", sb->buf);
  785. +}
  786. +
  787. +
  788. +static void __dump_ep_desc(volatile struct USB_EP_Desc *ep)
  789. +{
  790. + printk("USB_EP_Desc at 0x%08lx ", (unsigned long)ep);
  791. + printk(" command:0x%04x (", ep->command);
  792. + printk("ep_id:%d ", (ep->command & 0x1f00) >> 8);
  793. + printk("enable:%d ", (ep->command & 0x10) >> 4);
  794. + printk("intr:%d ", (ep->command & 0x8) >> 3);
  795. + printk("eof:%d ", (ep->command & 0x2) >> 1);
  796. + printk("eol:%d)", ep->command & 0x1);
  797. + printk(" hw_len:0x%04x(%d)", ep->hw_len, ep->hw_len);
  798. + printk(" next:0x%08lx", ep->next);
  799. + printk(" sub:0x%08lx\n", ep->sub);
  800. +}
  801. +
  802. +static inline void __dump_ep_list(int pipe_type)
  803. +{
  804. + volatile struct USB_EP_Desc *ep;
  805. + volatile struct USB_EP_Desc *first_ep;
  806. + volatile struct USB_SB_Desc *sb;
  807. +
  808. + switch (pipe_type)
  809. + {
  810. + case PIPE_BULK:
  811. + first_ep = &TxBulkEPList[0];
  812. + break;
  813. + case PIPE_CONTROL:
  814. + first_ep = &TxCtrlEPList[0];
  815. + break;
  816. + case PIPE_INTERRUPT:
  817. + first_ep = &TxIntrEPList[0];
  818. + break;
  819. + case PIPE_ISOCHRONOUS:
  820. + first_ep = &TxIsocEPList[0];
  821. + break;
  822. + default:
  823. + warn("Cannot dump unknown traffic type");
  824. + return;
  825. + }
  826. + ep = first_ep;
  827. +
  828. + printk("\n\nDumping EP list...\n\n");
  829. +
  830. + do {
  831. + __dump_ep_desc(ep);
  832. + /* Cannot phys_to_virt on 0 as it turns into 80000000, which is != 0. */
  833. + sb = ep->sub ? phys_to_virt(ep->sub) : 0;
  834. + while (sb) {
  835. + __dump_sb_desc(sb);
  836. + sb = sb->next ? phys_to_virt(sb->next) : 0;
  837. + }
  838. + ep = (volatile struct USB_EP_Desc *)(phys_to_virt(ep->next));
  839. +
  840. + } while (ep != first_ep);
  841. +}
  842. +
  843. +static inline void __dump_ept_data(int epid)
  844. +{
  845. + unsigned long flags;
  846. + __u32 r_usb_ept_data;
  847. +
  848. + if (epid < 0 || epid > 31) {
  849. + printk("Cannot dump ept data for invalid epid %d\n", epid);
  850. + return;
  851. + }
  852. +
  853. + local_irq_save(flags);
  854. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid);
  855. + nop();
  856. + r_usb_ept_data = *R_USB_EPT_DATA;
  857. + local_irq_restore(flags);
  858. +
  859. + printk(" R_USB_EPT_DATA = 0x%x for epid %d :\n", r_usb_ept_data, epid);
  860. + if (r_usb_ept_data == 0) {
  861. + /* No need for more detailed printing. */
  862. + return;
  863. + }
  864. + printk(" valid : %d\n", (r_usb_ept_data & 0x80000000) >> 31);
  865. + printk(" hold : %d\n", (r_usb_ept_data & 0x40000000) >> 30);
  866. + printk(" error_count_in : %d\n", (r_usb_ept_data & 0x30000000) >> 28);
  867. + printk(" t_in : %d\n", (r_usb_ept_data & 0x08000000) >> 27);
  868. + printk(" low_speed : %d\n", (r_usb_ept_data & 0x04000000) >> 26);
  869. + printk(" port : %d\n", (r_usb_ept_data & 0x03000000) >> 24);
  870. + printk(" error_code : %d\n", (r_usb_ept_data & 0x00c00000) >> 22);
  871. + printk(" t_out : %d\n", (r_usb_ept_data & 0x00200000) >> 21);
  872. + printk(" error_count_out : %d\n", (r_usb_ept_data & 0x00180000) >> 19);
  873. + printk(" max_len : %d\n", (r_usb_ept_data & 0x0003f800) >> 11);
  874. + printk(" ep : %d\n", (r_usb_ept_data & 0x00000780) >> 7);
  875. + printk(" dev : %d\n", (r_usb_ept_data & 0x0000003f));
  876. +}
  877. +
  878. +static inline void __dump_ept_data_iso(int epid)
  879. +{
  880. + unsigned long flags;
  881. + __u32 ept_data;
  882. +
  883. + if (epid < 0 || epid > 31) {
  884. + printk("Cannot dump ept data for invalid epid %d\n", epid);
  885. + return;
  886. + }
  887. +
  888. + local_irq_save(flags);
  889. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid);
  890. + nop();
  891. + ept_data = *R_USB_EPT_DATA_ISO;
  892. + local_irq_restore(flags);
  893. +
  894. + printk(" R_USB_EPT_DATA = 0x%x for epid %d :\n", ept_data, epid);
  895. + if (ept_data == 0) {
  896. + /* No need for more detailed printing. */
  897. + return;
  898. + }
  899. + printk(" valid : %d\n", IO_EXTRACT(R_USB_EPT_DATA_ISO, valid,
  900. + ept_data));
  901. + printk(" port : %d\n", IO_EXTRACT(R_USB_EPT_DATA_ISO, port,
  902. + ept_data));
  903. + printk(" error_code : %d\n", IO_EXTRACT(R_USB_EPT_DATA_ISO, error_code,
  904. + ept_data));
  905. + printk(" max_len : %d\n", IO_EXTRACT(R_USB_EPT_DATA_ISO, max_len,
  906. + ept_data));
  907. + printk(" ep : %d\n", IO_EXTRACT(R_USB_EPT_DATA_ISO, ep,
  908. + ept_data));
  909. + printk(" dev : %d\n", IO_EXTRACT(R_USB_EPT_DATA_ISO, dev,
  910. + ept_data));
  911. +}
  912. +
  913. +static inline void __dump_ept_data_list(void)
  914. +{
  915. + int i;
  916. +
  917. + printk("Dumping the whole R_USB_EPT_DATA list\n");
  918. +
  919. + for (i = 0; i < 32; i++) {
  920. + __dump_ept_data(i);
  921. + }
  922. +}
  923. +
  924. +static void debug_epid(int epid) {
  925. + int i;
  926. +
  927. + if(epid_isoc(epid)) {
  928. + __dump_ept_data_iso(epid);
  929. + } else {
  930. + __dump_ept_data(epid);
  931. + }
  932. +
  933. + printk("Bulk:\n");
  934. + for(i = 0; i < 32; i++) {
  935. + if(IO_EXTRACT(USB_EP_command, epid, TxBulkEPList[i].command) ==
  936. + epid) {
  937. + printk("%d: ", i); __dump_ep_desc(&(TxBulkEPList[i]));
  938. + }
  939. + }
  940. +
  941. + printk("Ctrl:\n");
  942. + for(i = 0; i < 32; i++) {
  943. + if(IO_EXTRACT(USB_EP_command, epid, TxCtrlEPList[i].command) ==
  944. + epid) {
  945. + printk("%d: ", i); __dump_ep_desc(&(TxCtrlEPList[i]));
  946. + }
  947. + }
  948. +
  949. + printk("Intr:\n");
  950. + for(i = 0; i < MAX_INTR_INTERVAL; i++) {
  951. + if(IO_EXTRACT(USB_EP_command, epid, TxIntrEPList[i].command) ==
  952. + epid) {
  953. + printk("%d: ", i); __dump_ep_desc(&(TxIntrEPList[i]));
  954. + }
  955. + }
  956. +
  957. + printk("Isoc:\n");
  958. + for(i = 0; i < 32; i++) {
  959. + if(IO_EXTRACT(USB_EP_command, epid, TxIsocEPList[i].command) ==
  960. + epid) {
  961. + printk("%d: ", i); __dump_ep_desc(&(TxIsocEPList[i]));
  962. + }
  963. + }
  964. +
  965. + __dump_ept_data_list();
  966. + __dump_ep_list(PIPE_INTERRUPT);
  967. + printk("\n\n");
  968. +}
  969. +
  970. +
  971. +
  972. +char* hcd_status_to_str(__u8 bUsbStatus) {
  973. + static char hcd_status_str[128];
  974. + hcd_status_str[0] = '\0';
  975. + if(bUsbStatus & IO_STATE(R_USB_STATUS, ourun, yes)) {
  976. + strcat(hcd_status_str, "ourun ");
  977. + }
  978. + if(bUsbStatus & IO_STATE(R_USB_STATUS, perror, yes)) {
  979. + strcat(hcd_status_str, "perror ");
  980. + }
  981. + if(bUsbStatus & IO_STATE(R_USB_STATUS, device_mode, yes)) {
  982. + strcat(hcd_status_str, "device_mode ");
  983. + }
  984. + if(bUsbStatus & IO_STATE(R_USB_STATUS, host_mode, yes)) {
  985. + strcat(hcd_status_str, "host_mode ");
  986. + }
  987. + if(bUsbStatus & IO_STATE(R_USB_STATUS, started, yes)) {
  988. + strcat(hcd_status_str, "started ");
  989. + }
  990. + if(bUsbStatus & IO_STATE(R_USB_STATUS, running, yes)) {
  991. + strcat(hcd_status_str, "running ");
  992. + }
  993. + return hcd_status_str;
  994. +}
  995. +
  996. +
  997. +char* sblist_to_str(struct USB_SB_Desc* sb_desc) {
  998. + static char sblist_to_str_buff[128];
  999. + char tmp[32], tmp2[32];
  1000. + sblist_to_str_buff[0] = '\0';
  1001. + while(sb_desc != NULL) {
  1002. + switch(IO_EXTRACT(USB_SB_command, tt, sb_desc->command)) {
  1003. + case 0: sprintf(tmp, "zout"); break;
  1004. + case 1: sprintf(tmp, "in"); break;
  1005. + case 2: sprintf(tmp, "out"); break;
  1006. + case 3: sprintf(tmp, "setup"); break;
  1007. + }
  1008. + sprintf(tmp2, "(%s %d)", tmp, sb_desc->sw_len);
  1009. + strcat(sblist_to_str_buff, tmp2);
  1010. + if(sb_desc->next != 0) {
  1011. + sb_desc = phys_to_virt(sb_desc->next);
  1012. + } else {
  1013. + sb_desc = NULL;
  1014. + }
  1015. + }
  1016. + return sblist_to_str_buff;
  1017. +}
  1018. +
  1019. +char* port_status_to_str(__u16 wPortStatus) {
  1020. + static char port_status_str[128];
  1021. + port_status_str[0] = '\0';
  1022. + if(wPortStatus & IO_STATE(R_USB_RH_PORT_STATUS_1, connected, yes)) {
  1023. + strcat(port_status_str, "connected ");
  1024. + }
  1025. + if(wPortStatus & IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, yes)) {
  1026. + strcat(port_status_str, "enabled ");
  1027. + }
  1028. + if(wPortStatus & IO_STATE(R_USB_RH_PORT_STATUS_1, suspended, yes)) {
  1029. + strcat(port_status_str, "suspended ");
  1030. + }
  1031. + if(wPortStatus & IO_STATE(R_USB_RH_PORT_STATUS_1, reset, yes)) {
  1032. + strcat(port_status_str, "reset ");
  1033. + }
  1034. + if(wPortStatus & IO_STATE(R_USB_RH_PORT_STATUS_1, speed, full)) {
  1035. + strcat(port_status_str, "full-speed ");
  1036. + } else {
  1037. + strcat(port_status_str, "low-speed ");
  1038. + }
  1039. + return port_status_str;
  1040. +}
  1041. +
  1042. +
  1043. +char* endpoint_to_str(struct usb_endpoint_descriptor *ed) {
  1044. + static char endpoint_to_str_buff[128];
  1045. + char tmp[32];
  1046. + int epnum = ed->bEndpointAddress & 0x0F;
  1047. + int dir = ed->bEndpointAddress & 0x80;
  1048. + int type = ed->bmAttributes & 0x03;
  1049. + endpoint_to_str_buff[0] = '\0';
  1050. + sprintf(endpoint_to_str_buff, "ep:%d ", epnum);
  1051. + switch(type) {
  1052. + case 0:
  1053. + sprintf(tmp, " ctrl");
  1054. + break;
  1055. + case 1:
  1056. + sprintf(tmp, " isoc");
  1057. + break;
  1058. + case 2:
  1059. + sprintf(tmp, " bulk");
  1060. + break;
  1061. + case 3:
  1062. + sprintf(tmp, " intr");
  1063. + break;
  1064. + }
  1065. + strcat(endpoint_to_str_buff, tmp);
  1066. + if(dir) {
  1067. + sprintf(tmp, " in");
  1068. + } else {
  1069. + sprintf(tmp, " out");
  1070. + }
  1071. + strcat(endpoint_to_str_buff, tmp);
  1072. +
  1073. + return endpoint_to_str_buff;
  1074. +}
  1075. +
  1076. +/* Debug helper functions for Transfer Controller */
  1077. +char* pipe_to_str(unsigned int pipe) {
  1078. + static char pipe_to_str_buff[128];
  1079. + char tmp[64];
  1080. + sprintf(pipe_to_str_buff, "dir:%s", str_dir(pipe));
  1081. + sprintf(tmp, " type:%s", str_type(pipe));
  1082. + strcat(pipe_to_str_buff, tmp);
  1083. +
  1084. + sprintf(tmp, " dev:%d", usb_pipedevice(pipe));
  1085. + strcat(pipe_to_str_buff, tmp);
  1086. + sprintf(tmp, " ep:%d", usb_pipeendpoint(pipe));
  1087. + strcat(pipe_to_str_buff, tmp);
  1088. + return pipe_to_str_buff;
  1089. +}
  1090. +
  1091. +
  1092. +#define USB_DEBUG_DESC 1
  1093. +
  1094. +#ifdef USB_DEBUG_DESC
  1095. +#define dump_in_desc(x) __dump_in_desc(x)
  1096. +#define dump_sb_desc(...) __dump_sb_desc(...)
  1097. +#define dump_ep_desc(x) __dump_ep_desc(x)
  1098. +#define dump_ept_data(x) __dump_ept_data(x)
  1099. +#else
  1100. +#define dump_in_desc(...) do {} while (0)
  1101. +#define dump_sb_desc(...) do {} while (0)
  1102. +#define dump_ep_desc(...) do {} while (0)
  1103. +#endif
  1104. +
  1105. +
  1106. +/* Uncomment this to enable massive function call trace
  1107. + #define USB_DEBUG_TRACE */
  1108. +//#define USB_DEBUG_TRACE 1
  1109. +
  1110. +#ifdef USB_DEBUG_TRACE
  1111. +#define DBFENTER (printk(": Entering: %s\n", __FUNCTION__))
  1112. +#define DBFEXIT (printk(": Exiting: %s\n", __FUNCTION__))
  1113. +#else
  1114. +#define DBFENTER do {} while (0)
  1115. +#define DBFEXIT do {} while (0)
  1116. +#endif
  1117. +
  1118. +#define CHECK_ALIGN(x) if (((__u32)(x)) & 0x00000003) \
  1119. +{panic("Alignment check (DWORD) failed at %s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__);}
  1120. +
  1121. +/* Most helpful debugging aid */
  1122. +#define ASSERT(expr) ((void) ((expr) ? 0 : (err("assert failed at: %s %d",__FUNCTION__, __LINE__))))
  1123. +
  1124. +
  1125. +/***************************************************************************/
  1126. +/***************************************************************************/
  1127. +/* Forward declarations */
  1128. +/***************************************************************************/
  1129. +/***************************************************************************/
  1130. +void crisv10_hcd_epid_attn_irq(struct crisv10_irq_reg *reg);
  1131. +void crisv10_hcd_port_status_irq(struct crisv10_irq_reg *reg);
  1132. +void crisv10_hcd_ctl_status_irq(struct crisv10_irq_reg *reg);
  1133. +void crisv10_hcd_isoc_eof_irq(struct crisv10_irq_reg *reg);
  1134. +
  1135. +void rh_port_status_change(__u16[]);
  1136. +int rh_clear_port_feature(__u8, __u16);
  1137. +int rh_set_port_feature(__u8, __u16);
  1138. +static void rh_disable_port(unsigned int port);
  1139. +
  1140. +static void check_finished_bulk_tx_epids(struct usb_hcd *hcd,
  1141. + int timer);
  1142. +
  1143. +//static int tc_setup_epid(struct usb_host_endpoint *ep, struct urb *urb,
  1144. +// int mem_flags);
  1145. +static int tc_setup_epid(struct urb *urb, int mem_flags);
  1146. +static void tc_free_epid(struct usb_host_endpoint *ep);
  1147. +static int tc_allocate_epid(void);
  1148. +static void tc_finish_urb(struct usb_hcd *hcd, struct urb *urb, int status);
  1149. +static void tc_finish_urb_later(struct usb_hcd *hcd, struct urb *urb,
  1150. + int status);
  1151. +
  1152. +static int urb_priv_create(struct usb_hcd *hcd, struct urb *urb, int epid,
  1153. + int mem_flags);
  1154. +static void urb_priv_free(struct usb_hcd *hcd, struct urb *urb);
  1155. +
  1156. +static inline struct urb *urb_list_first(int epid);
  1157. +static inline void urb_list_add(struct urb *urb, int epid,
  1158. + int mem_flags);
  1159. +static inline urb_entry_t *urb_list_entry(struct urb *urb, int epid);
  1160. +static inline void urb_list_del(struct urb *urb, int epid);
  1161. +static inline void urb_list_move_last(struct urb *urb, int epid);
  1162. +static inline struct urb *urb_list_next(struct urb *urb, int epid);
  1163. +
  1164. +int create_sb_for_urb(struct urb *urb, int mem_flags);
  1165. +int init_intr_urb(struct urb *urb, int mem_flags);
  1166. +
  1167. +static inline void etrax_epid_set(__u8 index, __u32 data);
  1168. +static inline void etrax_epid_clear_error(__u8 index);
  1169. +static inline void etrax_epid_set_toggle(__u8 index, __u8 dirout,
  1170. + __u8 toggle);
  1171. +static inline __u8 etrax_epid_get_toggle(__u8 index, __u8 dirout);
  1172. +static inline __u32 etrax_epid_get(__u8 index);
  1173. +
  1174. +/* We're accessing the same register position in Etrax so
  1175. + when we do full access the internal difference doesn't matter */
  1176. +#define etrax_epid_iso_set(index, data) etrax_epid_set(index, data)
  1177. +#define etrax_epid_iso_get(index) etrax_epid_get(index)
  1178. +
  1179. +
  1180. +//static void tc_dma_process_isoc_urb(struct urb *urb);
  1181. +static void tc_dma_process_queue(int epid);
  1182. +static void tc_dma_unlink_intr_urb(struct urb *urb);
  1183. +static irqreturn_t tc_dma_tx_interrupt(int irq, void *vhc);
  1184. +static irqreturn_t tc_dma_rx_interrupt(int irq, void *vhc);
  1185. +
  1186. +static void tc_bulk_start_timer_func(unsigned long dummy);
  1187. +static void tc_bulk_eot_timer_func(unsigned long dummy);
  1188. +
  1189. +
  1190. +/*************************************************************/
  1191. +/*************************************************************/
  1192. +/* Host Controler Driver block */
  1193. +/*************************************************************/
  1194. +/*************************************************************/
  1195. +
  1196. +/* HCD operations */
  1197. +static irqreturn_t crisv10_hcd_top_irq(int irq, void*);
  1198. +static int crisv10_hcd_reset(struct usb_hcd *);
  1199. +static int crisv10_hcd_start(struct usb_hcd *);
  1200. +static void crisv10_hcd_stop(struct usb_hcd *);
  1201. +#ifdef CONFIG_PM
  1202. +static int crisv10_hcd_suspend(struct device *, u32, u32);
  1203. +static int crisv10_hcd_resume(struct device *, u32);
  1204. +#endif /* CONFIG_PM */
  1205. +static int crisv10_hcd_get_frame(struct usb_hcd *);
  1206. +
  1207. +//static int tc_urb_enqueue(struct usb_hcd *, struct usb_host_endpoint *ep, struct urb *, gfp_t mem_flags);
  1208. +static int tc_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
  1209. +//static int tc_urb_dequeue(struct usb_hcd *, struct urb *);
  1210. +static int tc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
  1211. +static void tc_endpoint_disable(struct usb_hcd *, struct usb_host_endpoint *ep);
  1212. +
  1213. +static int rh_status_data_request(struct usb_hcd *, char *);
  1214. +static int rh_control_request(struct usb_hcd *, u16, u16, u16, char*, u16);
  1215. +
  1216. +#ifdef CONFIG_PM
  1217. +static int crisv10_hcd_hub_suspend(struct usb_hcd *);
  1218. +static int crisv10_hcd_hub_resume(struct usb_hcd *);
  1219. +#endif /* CONFIG_PM */
  1220. +#ifdef CONFIG_USB_OTG
  1221. +static int crisv10_hcd_start_port_reset(struct usb_hcd *, unsigned);
  1222. +#endif /* CONFIG_USB_OTG */
  1223. +
  1224. +/* host controller driver interface */
  1225. +static const struct hc_driver crisv10_hc_driver =
  1226. + {
  1227. + .description = hc_name,
  1228. + .product_desc = product_desc,
  1229. + .hcd_priv_size = sizeof(struct crisv10_hcd),
  1230. +
  1231. + /* Attaching IRQ handler manualy in probe() */
  1232. + /* .irq = crisv10_hcd_irq, */
  1233. +
  1234. + .flags = HCD_USB11,
  1235. +
  1236. + /* called to init HCD and root hub */
  1237. + .reset = crisv10_hcd_reset,
  1238. + .start = crisv10_hcd_start,
  1239. +
  1240. + /* cleanly make HCD stop writing memory and doing I/O */
  1241. + .stop = crisv10_hcd_stop,
  1242. +
  1243. + /* return current frame number */
  1244. + .get_frame_number = crisv10_hcd_get_frame,
  1245. +
  1246. +
  1247. + /* Manage i/o requests via the Transfer Controller */
  1248. + .urb_enqueue = tc_urb_enqueue,
  1249. + .urb_dequeue = tc_urb_dequeue,
  1250. +
  1251. + /* hw synch, freeing endpoint resources that urb_dequeue can't */
  1252. + .endpoint_disable = tc_endpoint_disable,
  1253. +
  1254. +
  1255. + /* Root Hub support */
  1256. + .hub_status_data = rh_status_data_request,
  1257. + .hub_control = rh_control_request,
  1258. +#ifdef CONFIG_PM
  1259. + .hub_suspend = rh_suspend_request,
  1260. + .hub_resume = rh_resume_request,
  1261. +#endif /* CONFIG_PM */
  1262. +#ifdef CONFIG_USB_OTG
  1263. + .start_port_reset = crisv10_hcd_start_port_reset,
  1264. +#endif /* CONFIG_USB_OTG */
  1265. + };
  1266. +
  1267. +
  1268. +/*
  1269. + * conversion between pointers to a hcd and the corresponding
  1270. + * crisv10_hcd
  1271. + */
  1272. +
  1273. +static inline struct crisv10_hcd *hcd_to_crisv10_hcd(struct usb_hcd *hcd)
  1274. +{
  1275. + return (struct crisv10_hcd *) hcd->hcd_priv;
  1276. +}
  1277. +
  1278. +static inline struct usb_hcd *crisv10_hcd_to_hcd(struct crisv10_hcd *hcd)
  1279. +{
  1280. + return container_of((void *) hcd, struct usb_hcd, hcd_priv);
  1281. +}
  1282. +
  1283. +/* check if specified port is in use */
  1284. +static inline int port_in_use(unsigned int port)
  1285. +{
  1286. + return ports & (1 << port);
  1287. +}
  1288. +
  1289. +/* number of ports in use */
  1290. +static inline unsigned int num_ports(void)
  1291. +{
  1292. + unsigned int i, num = 0;
  1293. + for (i = 0; i < USB_ROOT_HUB_PORTS; i++)
  1294. + if (port_in_use(i))
  1295. + num++;
  1296. + return num;
  1297. +}
  1298. +
  1299. +/* map hub port number to the port number used internally by the HC */
  1300. +static inline unsigned int map_port(unsigned int port)
  1301. +{
  1302. + unsigned int i, num = 0;
  1303. + for (i = 0; i < USB_ROOT_HUB_PORTS; i++)
  1304. + if (port_in_use(i))
  1305. + if (++num == port)
  1306. + return i;
  1307. + return -1;
  1308. +}
  1309. +
  1310. +/* size of descriptors in slab cache */
  1311. +#ifndef MAX
  1312. +#define MAX(x, y) ((x) > (y) ? (x) : (y))
  1313. +#endif
  1314. +
  1315. +
  1316. +/******************************************************************/
  1317. +/* Hardware Interrupt functions */
  1318. +/******************************************************************/
  1319. +
  1320. +/* Fast interrupt handler for HC */
  1321. +static irqreturn_t crisv10_hcd_top_irq(int irq, void *vcd)
  1322. +{
  1323. + struct usb_hcd *hcd = vcd;
  1324. + struct crisv10_irq_reg reg;
  1325. + __u32 irq_mask;
  1326. + unsigned long flags;
  1327. +
  1328. + DBFENTER;
  1329. +
  1330. + ASSERT(hcd != NULL);
  1331. + reg.hcd = hcd;
  1332. +
  1333. + /* Turn of other interrupts while handling these sensitive cases */
  1334. + local_irq_save(flags);
  1335. +
  1336. + /* Read out which interrupts that are flaged */
  1337. + irq_mask = *R_USB_IRQ_MASK_READ;
  1338. + reg.r_usb_irq_mask_read = irq_mask;
  1339. +
  1340. + /* Reading R_USB_STATUS clears the ctl_status interrupt. Note that
  1341. + R_USB_STATUS must be read before R_USB_EPID_ATTN since reading the latter
  1342. + clears the ourun and perror fields of R_USB_STATUS. */
  1343. + reg.r_usb_status = *R_USB_STATUS;
  1344. +
  1345. + /* Reading R_USB_EPID_ATTN clears the iso_eof, bulk_eot and epid_attn
  1346. + interrupts. */
  1347. + reg.r_usb_epid_attn = *R_USB_EPID_ATTN;
  1348. +
  1349. + /* Reading R_USB_RH_PORT_STATUS_1 and R_USB_RH_PORT_STATUS_2 clears the
  1350. + port_status interrupt. */
  1351. + reg.r_usb_rh_port_status_1 = *R_USB_RH_PORT_STATUS_1;
  1352. + reg.r_usb_rh_port_status_2 = *R_USB_RH_PORT_STATUS_2;
  1353. +
  1354. + /* Reading R_USB_FM_NUMBER clears the sof interrupt. */
  1355. + /* Note: the lower 11 bits contain the actual frame number, sent with each
  1356. + sof. */
  1357. + reg.r_usb_fm_number = *R_USB_FM_NUMBER;
  1358. +
  1359. + /* Interrupts are handled in order of priority. */
  1360. + if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, port_status)) {
  1361. + crisv10_hcd_port_status_irq(&reg);
  1362. + }
  1363. + if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, epid_attn)) {
  1364. + crisv10_hcd_epid_attn_irq(&reg);
  1365. + }
  1366. + if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, ctl_status)) {
  1367. + crisv10_hcd_ctl_status_irq(&reg);
  1368. + }
  1369. + if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, iso_eof)) {
  1370. + crisv10_hcd_isoc_eof_irq(&reg);
  1371. + }
  1372. + if (irq_mask & IO_MASK(R_USB_IRQ_MASK_READ, bulk_eot)) {
  1373. + /* Update/restart the bulk start timer since obviously the channel is
  1374. + running. */
  1375. + mod_timer(&bulk_start_timer, jiffies + BULK_START_TIMER_INTERVAL);
  1376. + /* Update/restart the bulk eot timer since we just received an bulk eot
  1377. + interrupt. */
  1378. + mod_timer(&bulk_eot_timer, jiffies + BULK_EOT_TIMER_INTERVAL);
  1379. +
  1380. + /* Check for finished bulk transfers on epids */
  1381. + check_finished_bulk_tx_epids(hcd, 0);
  1382. + }
  1383. + local_irq_restore(flags);
  1384. +
  1385. + DBFEXIT;
  1386. + return IRQ_HANDLED;
  1387. +}
  1388. +
  1389. +
  1390. +void crisv10_hcd_epid_attn_irq(struct crisv10_irq_reg *reg) {
  1391. + struct usb_hcd *hcd = reg->hcd;
  1392. + struct crisv10_urb_priv *urb_priv;
  1393. + int epid;
  1394. + DBFENTER;
  1395. +
  1396. + for (epid = 0; epid < NBR_OF_EPIDS; epid++) {
  1397. + if (test_bit(epid, (void *)&reg->r_usb_epid_attn)) {
  1398. + struct urb *urb;
  1399. + __u32 ept_data;
  1400. + int error_code;
  1401. +
  1402. + if (epid == DUMMY_EPID || epid == INVALID_EPID) {
  1403. + /* We definitely don't care about these ones. Besides, they are
  1404. + always disabled, so any possible disabling caused by the
  1405. + epid attention interrupt is irrelevant. */
  1406. + warn("Got epid_attn for INVALID_EPID or DUMMY_EPID (%d).", epid);
  1407. + continue;
  1408. + }
  1409. +
  1410. + if(!epid_inuse(epid)) {
  1411. + irq_err("Epid attention on epid:%d that isn't in use\n", epid);
  1412. + printk("R_USB_STATUS: 0x%x\n", reg->r_usb_status);
  1413. + debug_epid(epid);
  1414. + continue;
  1415. + }
  1416. +
  1417. + /* Note that although there are separate R_USB_EPT_DATA and
  1418. + R_USB_EPT_DATA_ISO registers, they are located at the same address and
  1419. + are of the same size. In other words, this read should be ok for isoc
  1420. + also. */
  1421. + ept_data = etrax_epid_get(epid);
  1422. + error_code = IO_EXTRACT(R_USB_EPT_DATA, error_code, ept_data);
  1423. +
  1424. + /* Get the active URB for this epid. We blatantly assume
  1425. + that only this URB could have caused the epid attention. */
  1426. + urb = activeUrbList[epid];
  1427. + if (urb == NULL) {
  1428. + irq_err("Attention on epid:%d error:%d with no active URB.\n",
  1429. + epid, error_code);
  1430. + printk("R_USB_STATUS: 0x%x\n", reg->r_usb_status);
  1431. + debug_epid(epid);
  1432. + continue;
  1433. + }
  1434. +
  1435. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  1436. + ASSERT(urb_priv);
  1437. +
  1438. + /* Using IO_STATE_VALUE on R_USB_EPT_DATA should be ok for isoc also. */
  1439. + if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code, no_error)) {
  1440. +
  1441. + /* Isoc traffic doesn't have error_count_in/error_count_out. */
  1442. + if ((usb_pipetype(urb->pipe) != PIPE_ISOCHRONOUS) &&
  1443. + (IO_EXTRACT(R_USB_EPT_DATA, error_count_in, ept_data) == 3 ||
  1444. + IO_EXTRACT(R_USB_EPT_DATA, error_count_out, ept_data) == 3)) {
  1445. + /* Check if URB allready is marked for late-finish, we can get
  1446. + several 3rd error for Intr traffic when a device is unplugged */
  1447. + if(urb_priv->later_data == NULL) {
  1448. + /* 3rd error. */
  1449. + irq_warn("3rd error for epid:%d (%s %s) URB:0x%x[%d]\n", epid,
  1450. + str_dir(urb->pipe), str_type(urb->pipe),
  1451. + (unsigned int)urb, urb_priv->urb_num);
  1452. +
  1453. + tc_finish_urb_later(hcd, urb, -EPROTO);
  1454. + }
  1455. +
  1456. + } else if (reg->r_usb_status & IO_MASK(R_USB_STATUS, perror)) {
  1457. + irq_warn("Perror for epid:%d\n", epid);
  1458. + printk("FM_NUMBER: %d\n", reg->r_usb_fm_number & 0x7ff);
  1459. + printk("R_USB_STATUS: 0x%x\n", reg->r_usb_status);
  1460. + __dump_urb(urb);
  1461. + debug_epid(epid);
  1462. +
  1463. + if (!(ept_data & IO_MASK(R_USB_EPT_DATA, valid))) {
  1464. + /* invalid ep_id */
  1465. + panic("Perror because of invalid epid."
  1466. + " Deconfigured too early?");
  1467. + } else {
  1468. + /* past eof1, near eof, zout transfer, setup transfer */
  1469. + /* Dump the urb and the relevant EP descriptor. */
  1470. + panic("Something wrong with DMA descriptor contents."
  1471. + " Too much traffic inserted?");
  1472. + }
  1473. + } else if (reg->r_usb_status & IO_MASK(R_USB_STATUS, ourun)) {
  1474. + /* buffer ourun */
  1475. + printk("FM_NUMBER: %d\n", reg->r_usb_fm_number & 0x7ff);
  1476. + printk("R_USB_STATUS: 0x%x\n", reg->r_usb_status);
  1477. + __dump_urb(urb);
  1478. + debug_epid(epid);
  1479. +
  1480. + panic("Buffer overrun/underrun for epid:%d. DMA too busy?", epid);
  1481. + } else {
  1482. + irq_warn("Attention on epid:%d (%s %s) with no error code\n", epid,
  1483. + str_dir(urb->pipe), str_type(urb->pipe));
  1484. + printk("R_USB_STATUS: 0x%x\n", reg->r_usb_status);
  1485. + __dump_urb(urb);
  1486. + debug_epid(epid);
  1487. + }
  1488. +
  1489. + } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code,
  1490. + stall)) {
  1491. + /* Not really a protocol error, just says that the endpoint gave
  1492. + a stall response. Note that error_code cannot be stall for isoc. */
  1493. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  1494. + panic("Isoc traffic cannot stall");
  1495. + }
  1496. +
  1497. + tc_dbg("Stall for epid:%d (%s %s) URB:0x%x\n", epid,
  1498. + str_dir(urb->pipe), str_type(urb->pipe), (unsigned int)urb);
  1499. + tc_finish_urb(hcd, urb, -EPIPE);
  1500. +
  1501. + } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code,
  1502. + bus_error)) {
  1503. + /* Two devices responded to a transaction request. Must be resolved
  1504. + by software. FIXME: Reset ports? */
  1505. + panic("Bus error for epid %d."
  1506. + " Two devices responded to transaction request\n",
  1507. + epid);
  1508. +
  1509. + } else if (error_code == IO_STATE_VALUE(R_USB_EPT_DATA, error_code,
  1510. + buffer_error)) {
  1511. + /* DMA overrun or underrun. */
  1512. + irq_warn("Buffer overrun/underrun for epid:%d (%s %s)\n", epid,
  1513. + str_dir(urb->pipe), str_type(urb->pipe));
  1514. +
  1515. + /* It seems that error_code = buffer_error in
  1516. + R_USB_EPT_DATA/R_USB_EPT_DATA_ISO and ourun = yes in R_USB_STATUS
  1517. + are the same error. */
  1518. + tc_finish_urb(hcd, urb, -EPROTO);
  1519. + } else {
  1520. + irq_warn("Unknown attention on epid:%d (%s %s)\n", epid,
  1521. + str_dir(urb->pipe), str_type(urb->pipe));
  1522. + dump_ept_data(epid);
  1523. + }
  1524. + }
  1525. + }
  1526. + DBFEXIT;
  1527. +}
  1528. +
  1529. +void crisv10_hcd_port_status_irq(struct crisv10_irq_reg *reg)
  1530. +{
  1531. + __u16 port_reg[USB_ROOT_HUB_PORTS];
  1532. + DBFENTER;
  1533. + port_reg[0] = reg->r_usb_rh_port_status_1;
  1534. + port_reg[1] = reg->r_usb_rh_port_status_2;
  1535. + rh_port_status_change(port_reg);
  1536. + DBFEXIT;
  1537. +}
  1538. +
  1539. +void crisv10_hcd_isoc_eof_irq(struct crisv10_irq_reg *reg)
  1540. +{
  1541. + int epid;
  1542. + struct urb *urb;
  1543. + struct crisv10_urb_priv *urb_priv;
  1544. +
  1545. + DBFENTER;
  1546. +
  1547. + for (epid = 0; epid < NBR_OF_EPIDS - 1; epid++) {
  1548. +
  1549. + /* Only check epids that are in use, is valid and has SB list */
  1550. + if (!epid_inuse(epid) || epid == INVALID_EPID ||
  1551. + TxIsocEPList[epid].sub == 0 || epid == DUMMY_EPID) {
  1552. + /* Nothing here to see. */
  1553. + continue;
  1554. + }
  1555. + ASSERT(epid_isoc(epid));
  1556. +
  1557. + /* Get the active URB for this epid (if any). */
  1558. + urb = activeUrbList[epid];
  1559. + if (urb == 0) {
  1560. + isoc_warn("Ignoring NULL urb for epid:%d\n", epid);
  1561. + continue;
  1562. + }
  1563. + if(!epid_out_traffic(epid)) {
  1564. + /* Sanity check. */
  1565. + ASSERT(usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS);
  1566. +
  1567. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  1568. + ASSERT(urb_priv);
  1569. +
  1570. + if (urb_priv->urb_state == NOT_STARTED) {
  1571. + /* If ASAP is not set and urb->start_frame is the current frame,
  1572. + start the transfer. */
  1573. + if (!(urb->transfer_flags & URB_ISO_ASAP) &&
  1574. + (urb->start_frame == (*R_USB_FM_NUMBER & 0x7ff))) {
  1575. + /* EP should not be enabled if we're waiting for start_frame */
  1576. + ASSERT((TxIsocEPList[epid].command &
  1577. + IO_STATE(USB_EP_command, enable, yes)) == 0);
  1578. +
  1579. + isoc_warn("Enabling isoc IN EP descr for epid %d\n", epid);
  1580. + TxIsocEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes);
  1581. +
  1582. + /* This urb is now active. */
  1583. + urb_priv->urb_state = STARTED;
  1584. + continue;
  1585. + }
  1586. + }
  1587. + }
  1588. + }
  1589. +
  1590. + DBFEXIT;
  1591. +}
  1592. +
  1593. +void crisv10_hcd_ctl_status_irq(struct crisv10_irq_reg *reg)
  1594. +{
  1595. + struct crisv10_hcd* crisv10_hcd = hcd_to_crisv10_hcd(reg->hcd);
  1596. +
  1597. + DBFENTER;
  1598. + ASSERT(crisv10_hcd);
  1599. +
  1600. + irq_dbg("ctr_status_irq, controller status: %s\n",
  1601. + hcd_status_to_str(reg->r_usb_status));
  1602. +
  1603. + /* FIXME: What should we do if we get ourun or perror? Dump the EP and SB
  1604. + list for the corresponding epid? */
  1605. + if (reg->r_usb_status & IO_MASK(R_USB_STATUS, ourun)) {
  1606. + panic("USB controller got ourun.");
  1607. + }
  1608. + if (reg->r_usb_status & IO_MASK(R_USB_STATUS, perror)) {
  1609. +
  1610. + /* Before, etrax_usb_do_intr_recover was called on this epid if it was
  1611. + an interrupt pipe. I don't see how re-enabling all EP descriptors
  1612. + will help if there was a programming error. */
  1613. + panic("USB controller got perror.");
  1614. + }
  1615. +
  1616. + /* Keep track of USB Controller, if it's running or not */
  1617. + if(reg->r_usb_status & IO_STATE(R_USB_STATUS, running, yes)) {
  1618. + crisv10_hcd->running = 1;
  1619. + } else {
  1620. + crisv10_hcd->running = 0;
  1621. + }
  1622. +
  1623. + if (reg->r_usb_status & IO_MASK(R_USB_STATUS, device_mode)) {
  1624. + /* We should never operate in device mode. */
  1625. + panic("USB controller in device mode.");
  1626. + }
  1627. +
  1628. + /* Set the flag to avoid getting "Unlink after no-IRQ? Controller is probably
  1629. + using the wrong IRQ" from hcd_unlink_urb() in drivers/usb/core/hcd.c */
  1630. + set_bit(HCD_FLAG_SAW_IRQ, &reg->hcd->flags);
  1631. +
  1632. + DBFEXIT;
  1633. +}
  1634. +
  1635. +
  1636. +/******************************************************************/
  1637. +/* Host Controller interface functions */
  1638. +/******************************************************************/
  1639. +
  1640. +static inline void crisv10_ready_wait(void) {
  1641. + volatile int timeout = 10000;
  1642. + /* Check the busy bit of USB controller in Etrax */
  1643. + while((*R_USB_COMMAND & IO_MASK(R_USB_COMMAND, busy)) &&
  1644. + (timeout-- > 0));
  1645. + if(timeout == 0) {
  1646. + warn("Timeout while waiting for USB controller to be idle\n");
  1647. + }
  1648. +}
  1649. +
  1650. +/* reset host controller */
  1651. +static int crisv10_hcd_reset(struct usb_hcd *hcd)
  1652. +{
  1653. + DBFENTER;
  1654. + hcd_dbg(hcd, "reset\n");
  1655. +
  1656. +
  1657. + /* Reset the USB interface. */
  1658. + /*
  1659. + *R_USB_COMMAND =
  1660. + IO_STATE(R_USB_COMMAND, port_sel, nop) |
  1661. + IO_STATE(R_USB_COMMAND, port_cmd, reset) |
  1662. + IO_STATE(R_USB_COMMAND, ctrl_cmd, reset);
  1663. + nop();
  1664. + */
  1665. + DBFEXIT;
  1666. + return 0;
  1667. +}
  1668. +
  1669. +/* start host controller */
  1670. +static int crisv10_hcd_start(struct usb_hcd *hcd)
  1671. +{
  1672. + DBFENTER;
  1673. + hcd_dbg(hcd, "start\n");
  1674. +
  1675. + crisv10_ready_wait();
  1676. +
  1677. + /* Start processing of USB traffic. */
  1678. + *R_USB_COMMAND =
  1679. + IO_STATE(R_USB_COMMAND, port_sel, nop) |
  1680. + IO_STATE(R_USB_COMMAND, port_cmd, reset) |
  1681. + IO_STATE(R_USB_COMMAND, ctrl_cmd, host_run);
  1682. +
  1683. + nop();
  1684. +
  1685. + hcd->state = HC_STATE_RUNNING;
  1686. +
  1687. + DBFEXIT;
  1688. + return 0;
  1689. +}
  1690. +
  1691. +/* stop host controller */
  1692. +static void crisv10_hcd_stop(struct usb_hcd *hcd)
  1693. +{
  1694. + DBFENTER;
  1695. + hcd_dbg(hcd, "stop\n");
  1696. + crisv10_hcd_reset(hcd);
  1697. + DBFEXIT;
  1698. +}
  1699. +
  1700. +/* return the current frame number */
  1701. +static int crisv10_hcd_get_frame(struct usb_hcd *hcd)
  1702. +{
  1703. + DBFENTER;
  1704. + DBFEXIT;
  1705. + return (*R_USB_FM_NUMBER & 0x7ff);
  1706. +}
  1707. +
  1708. +#ifdef CONFIG_USB_OTG
  1709. +
  1710. +static int crisv10_hcd_start_port_reset(struct usb_hcd *hcd, unsigned port)
  1711. +{
  1712. + return 0; /* no-op for now */
  1713. +}
  1714. +
  1715. +#endif /* CONFIG_USB_OTG */
  1716. +
  1717. +
  1718. +/******************************************************************/
  1719. +/* Root Hub functions */
  1720. +/******************************************************************/
  1721. +
  1722. +/* root hub status */
  1723. +static const struct usb_hub_status rh_hub_status =
  1724. + {
  1725. + .wHubStatus = 0,
  1726. + .wHubChange = 0,
  1727. + };
  1728. +
  1729. +/* root hub descriptor */
  1730. +static const u8 rh_hub_descr[] =
  1731. + {
  1732. + 0x09, /* bDescLength */
  1733. + 0x29, /* bDescriptorType */
  1734. + USB_ROOT_HUB_PORTS, /* bNbrPorts */
  1735. + 0x00, /* wHubCharacteristics */
  1736. + 0x00,
  1737. + 0x01, /* bPwrOn2pwrGood */
  1738. + 0x00, /* bHubContrCurrent */
  1739. + 0x00, /* DeviceRemovable */
  1740. + 0xff /* PortPwrCtrlMask */
  1741. + };
  1742. +
  1743. +/* Actual holder of root hub status*/
  1744. +struct crisv10_rh rh;
  1745. +
  1746. +/* Initialize root hub data structures (called from dvdrv_hcd_probe()) */
  1747. +int rh_init(void) {
  1748. + int i;
  1749. + /* Reset port status flags */
  1750. + for (i = 0; i < USB_ROOT_HUB_PORTS; i++) {
  1751. + rh.wPortChange[i] = 0;
  1752. + rh.wPortStatusPrev[i] = 0;
  1753. + }
  1754. + return 0;
  1755. +}
  1756. +
  1757. +#define RH_FEAT_MASK ((1<<USB_PORT_FEAT_CONNECTION)|\
  1758. + (1<<USB_PORT_FEAT_ENABLE)|\
  1759. + (1<<USB_PORT_FEAT_SUSPEND)|\
  1760. + (1<<USB_PORT_FEAT_RESET))
  1761. +
  1762. +/* Handle port status change interrupt (called from bottom part interrupt) */
  1763. +void rh_port_status_change(__u16 port_reg[]) {
  1764. + int i;
  1765. + __u16 wChange;
  1766. +
  1767. + for(i = 0; i < USB_ROOT_HUB_PORTS; i++) {
  1768. + /* Xor out changes since last read, masked for important flags */
  1769. + wChange = (port_reg[i] & RH_FEAT_MASK) ^ rh.wPortStatusPrev[i];
  1770. + /* Or changes together with (if any) saved changes */
  1771. + rh.wPortChange[i] |= wChange;
  1772. + /* Save new status */
  1773. + rh.wPortStatusPrev[i] = port_reg[i];
  1774. +
  1775. + if(wChange) {
  1776. + rh_dbg("Interrupt port_status change port%d: %s Current-status:%s\n", i+1,
  1777. + port_status_to_str(wChange),
  1778. + port_status_to_str(port_reg[i]));
  1779. + }
  1780. + }
  1781. +}
  1782. +
  1783. +/* Construct port status change bitmap for the root hub */
  1784. +static int rh_status_data_request(struct usb_hcd *hcd, char *buf)
  1785. +{
  1786. + struct crisv10_hcd* crisv10_hcd = hcd_to_crisv10_hcd(hcd);
  1787. + unsigned int i;
  1788. +
  1789. +// DBFENTER;
  1790. +
  1791. + /*
  1792. + * corresponds to hub status change EP (USB 2.0 spec section 11.13.4)
  1793. + * return bitmap indicating ports with status change
  1794. + */
  1795. + *buf = 0;
  1796. + spin_lock(&crisv10_hcd->lock);
  1797. + for (i = 1; i <= crisv10_hcd->num_ports; i++) {
  1798. + if (rh.wPortChange[map_port(i)]) {
  1799. + *buf |= (1 << i);
  1800. + rh_dbg("rh_status_data_request, change on port %d: %s Current Status: %s\n", i,
  1801. + port_status_to_str(rh.wPortChange[map_port(i)]),
  1802. + port_status_to_str(rh.wPortStatusPrev[map_port(i)]));
  1803. + }
  1804. + }
  1805. + spin_unlock(&crisv10_hcd->lock);
  1806. +
  1807. +// DBFEXIT;
  1808. +
  1809. + return *buf == 0 ? 0 : 1;
  1810. +}
  1811. +
  1812. +/* Handle a control request for the root hub (called from hcd_driver) */
  1813. +static int rh_control_request(struct usb_hcd *hcd,
  1814. + u16 typeReq,
  1815. + u16 wValue,
  1816. + u16 wIndex,
  1817. + char *buf,
  1818. + u16 wLength) {
  1819. +
  1820. + struct crisv10_hcd *crisv10_hcd = hcd_to_crisv10_hcd(hcd);
  1821. + int retval = 0;
  1822. + int len;
  1823. + DBFENTER;
  1824. +
  1825. + switch (typeReq) {
  1826. + case GetHubDescriptor:
  1827. + rh_dbg("GetHubDescriptor\n");
  1828. + len = min_t(unsigned int, sizeof rh_hub_descr, wLength);
  1829. + memcpy(buf, rh_hub_descr, len);
  1830. + buf[2] = crisv10_hcd->num_ports;
  1831. + break;
  1832. + case GetHubStatus:
  1833. + rh_dbg("GetHubStatus\n");
  1834. + len = min_t(unsigned int, sizeof rh_hub_status, wLength);
  1835. + memcpy(buf, &rh_hub_status, len);
  1836. + break;
  1837. + case GetPortStatus:
  1838. + if (!wIndex || wIndex > crisv10_hcd->num_ports)
  1839. + goto error;
  1840. + rh_dbg("GetportStatus, port:%d change:%s status:%s\n", wIndex,
  1841. + port_status_to_str(rh.wPortChange[map_port(wIndex)]),
  1842. + port_status_to_str(rh.wPortStatusPrev[map_port(wIndex)]));
  1843. + *(u16 *) buf = cpu_to_le16(rh.wPortStatusPrev[map_port(wIndex)]);
  1844. + *(u16 *) (buf + 2) = cpu_to_le16(rh.wPortChange[map_port(wIndex)]);
  1845. + break;
  1846. + case SetHubFeature:
  1847. + rh_dbg("SetHubFeature\n");
  1848. + case ClearHubFeature:
  1849. + rh_dbg("ClearHubFeature\n");
  1850. + switch (wValue) {
  1851. + case C_HUB_OVER_CURRENT:
  1852. + case C_HUB_LOCAL_POWER:
  1853. + rh_warn("Not implemented hub request:%d \n", typeReq);
  1854. + /* not implemented */
  1855. + break;
  1856. + default:
  1857. + goto error;
  1858. + }
  1859. + break;
  1860. + case SetPortFeature:
  1861. + if (!wIndex || wIndex > crisv10_hcd->num_ports)
  1862. + goto error;
  1863. + if(rh_set_port_feature(map_port(wIndex), wValue))
  1864. + goto error;
  1865. + break;
  1866. + case ClearPortFeature:
  1867. + if (!wIndex || wIndex > crisv10_hcd->num_ports)
  1868. + goto error;
  1869. + if(rh_clear_port_feature(map_port(wIndex), wValue))
  1870. + goto error;
  1871. + break;
  1872. + default:
  1873. + rh_warn("Unknown hub request: %d\n", typeReq);
  1874. + error:
  1875. + retval = -EPIPE;
  1876. + }
  1877. + DBFEXIT;
  1878. + return retval;
  1879. +}
  1880. +
  1881. +int rh_set_port_feature(__u8 bPort, __u16 wFeature) {
  1882. + __u8 bUsbCommand = 0;
  1883. + switch(wFeature) {
  1884. + case USB_PORT_FEAT_RESET:
  1885. + rh_dbg("SetPortFeature: reset\n");
  1886. + bUsbCommand |= IO_STATE(R_USB_COMMAND, port_cmd, reset);
  1887. + goto set;
  1888. + break;
  1889. + case USB_PORT_FEAT_SUSPEND:
  1890. + rh_dbg("SetPortFeature: suspend\n");
  1891. + bUsbCommand |= IO_STATE(R_USB_COMMAND, port_cmd, suspend);
  1892. + goto set;
  1893. + break;
  1894. + case USB_PORT_FEAT_POWER:
  1895. + rh_dbg("SetPortFeature: power\n");
  1896. + break;
  1897. + case USB_PORT_FEAT_C_CONNECTION:
  1898. + rh_dbg("SetPortFeature: c_connection\n");
  1899. + break;
  1900. + case USB_PORT_FEAT_C_RESET:
  1901. + rh_dbg("SetPortFeature: c_reset\n");
  1902. + break;
  1903. + case USB_PORT_FEAT_C_OVER_CURRENT:
  1904. + rh_dbg("SetPortFeature: c_over_current\n");
  1905. + break;
  1906. +
  1907. + set:
  1908. + /* Select which port via the port_sel field */
  1909. + bUsbCommand |= IO_FIELD(R_USB_COMMAND, port_sel, bPort+1);
  1910. +
  1911. + /* Make sure the controller isn't busy. */
  1912. + crisv10_ready_wait();
  1913. + /* Send out the actual command to the USB controller */
  1914. + *R_USB_COMMAND = bUsbCommand;
  1915. +
  1916. + /* If port reset then also bring USB controller into running state */
  1917. + if(wFeature == USB_PORT_FEAT_RESET) {
  1918. + /* Wait a while for controller to first become started after port reset */
  1919. + udelay(12000); /* 12ms blocking wait */
  1920. +
  1921. + /* Make sure the controller isn't busy. */
  1922. + crisv10_ready_wait();
  1923. +
  1924. + /* If all enabled ports were disabled the host controller goes down into
  1925. + started mode, so we need to bring it back into the running state.
  1926. + (This is safe even if it's already in the running state.) */
  1927. + *R_USB_COMMAND =
  1928. + IO_STATE(R_USB_COMMAND, port_sel, nop) |
  1929. + IO_STATE(R_USB_COMMAND, port_cmd, reset) |
  1930. + IO_STATE(R_USB_COMMAND, ctrl_cmd, host_run);
  1931. + }
  1932. +
  1933. + break;
  1934. + default:
  1935. + rh_dbg("SetPortFeature: unknown feature\n");
  1936. + return -1;
  1937. + }
  1938. + return 0;
  1939. +}
  1940. +
  1941. +int rh_clear_port_feature(__u8 bPort, __u16 wFeature) {
  1942. + switch(wFeature) {
  1943. + case USB_PORT_FEAT_ENABLE:
  1944. + rh_dbg("ClearPortFeature: enable\n");
  1945. + rh_disable_port(bPort);
  1946. + break;
  1947. + case USB_PORT_FEAT_SUSPEND:
  1948. + rh_dbg("ClearPortFeature: suspend\n");
  1949. + break;
  1950. + case USB_PORT_FEAT_POWER:
  1951. + rh_dbg("ClearPortFeature: power\n");
  1952. + break;
  1953. +
  1954. + case USB_PORT_FEAT_C_ENABLE:
  1955. + rh_dbg("ClearPortFeature: c_enable\n");
  1956. + goto clear;
  1957. + case USB_PORT_FEAT_C_SUSPEND:
  1958. + rh_dbg("ClearPortFeature: c_suspend\n");
  1959. + goto clear;
  1960. + case USB_PORT_FEAT_C_CONNECTION:
  1961. + rh_dbg("ClearPortFeature: c_connection\n");
  1962. + goto clear;
  1963. + case USB_PORT_FEAT_C_OVER_CURRENT:
  1964. + rh_dbg("ClearPortFeature: c_over_current\n");
  1965. + goto clear;
  1966. + case USB_PORT_FEAT_C_RESET:
  1967. + rh_dbg("ClearPortFeature: c_reset\n");
  1968. + goto clear;
  1969. + clear:
  1970. + rh.wPortChange[bPort] &= ~(1 << (wFeature - 16));
  1971. + break;
  1972. + default:
  1973. + rh_dbg("ClearPortFeature: unknown feature\n");
  1974. + return -1;
  1975. + }
  1976. + return 0;
  1977. +}
  1978. +
  1979. +
  1980. +#ifdef CONFIG_PM
  1981. +/* Handle a suspend request for the root hub (called from hcd_driver) */
  1982. +static int rh_suspend_request(struct usb_hcd *hcd)
  1983. +{
  1984. + return 0; /* no-op for now */
  1985. +}
  1986. +
  1987. +/* Handle a resume request for the root hub (called from hcd_driver) */
  1988. +static int rh_resume_request(struct usb_hcd *hcd)
  1989. +{
  1990. + return 0; /* no-op for now */
  1991. +}
  1992. +#endif /* CONFIG_PM */
  1993. +
  1994. +
  1995. +
  1996. +/* Wrapper function for workaround port disable registers in USB controller */
  1997. +static void rh_disable_port(unsigned int port) {
  1998. + volatile int timeout = 10000;
  1999. + volatile char* usb_portx_disable;
  2000. + switch(port) {
  2001. + case 0:
  2002. + usb_portx_disable = R_USB_PORT1_DISABLE;
  2003. + break;
  2004. + case 1:
  2005. + usb_portx_disable = R_USB_PORT2_DISABLE;
  2006. + break;
  2007. + default:
  2008. + /* Invalid port index */
  2009. + return;
  2010. + }
  2011. + /* Set disable flag in special register */
  2012. + *usb_portx_disable = IO_STATE(R_USB_PORT1_DISABLE, disable, yes);
  2013. + /* Wait until not enabled anymore */
  2014. + while((rh.wPortStatusPrev[port] &
  2015. + IO_STATE(R_USB_RH_PORT_STATUS_1, enabled, yes)) &&
  2016. + (timeout-- > 0));
  2017. + if(timeout == 0) {
  2018. + warn("Timeout while waiting for port %d to become disabled\n", port);
  2019. + }
  2020. + /* clear disable flag in special register */
  2021. + *usb_portx_disable = IO_STATE(R_USB_PORT1_DISABLE, disable, no);
  2022. + rh_info("Physical port %d disabled\n", port+1);
  2023. +}
  2024. +
  2025. +
  2026. +/******************************************************************/
  2027. +/* Transfer Controller (TC) functions */
  2028. +/******************************************************************/
  2029. +
  2030. +/* FIXME: Should RX_BUF_SIZE be a config option, or maybe we should adjust it
  2031. + dynamically?
  2032. + To adjust it dynamically we would have to get an interrupt when we reach
  2033. + the end of the rx descriptor list, or when we get close to the end, and
  2034. + then allocate more descriptors. */
  2035. +#define NBR_OF_RX_DESC 512
  2036. +#define RX_DESC_BUF_SIZE 1024
  2037. +#define RX_BUF_SIZE (NBR_OF_RX_DESC * RX_DESC_BUF_SIZE)
  2038. +
  2039. +
  2040. +/* Local variables for Transfer Controller */
  2041. +/* --------------------------------------- */
  2042. +
  2043. +/* This is a circular (double-linked) list of the active urbs for each epid.
  2044. + The head is never removed, and new urbs are linked onto the list as
  2045. + urb_entry_t elements. Don't reference urb_list directly; use the wrapper
  2046. + functions instead (which includes spin_locks) */
  2047. +static struct list_head urb_list[NBR_OF_EPIDS];
  2048. +
  2049. +/* Read about the need and usage of this lock in submit_ctrl_urb. */
  2050. +/* Lock for URB lists for each EPID */
  2051. +static spinlock_t urb_list_lock;
  2052. +
  2053. +/* Lock for EPID array register (R_USB_EPT_x) in Etrax */
  2054. +static spinlock_t etrax_epid_lock;
  2055. +
  2056. +/* Lock for dma8 sub0 handling */
  2057. +static spinlock_t etrax_dma8_sub0_lock;
  2058. +
  2059. +/* DMA IN cache bug. Align the DMA IN buffers to 32 bytes, i.e. a cache line.
  2060. + Since RX_DESC_BUF_SIZE is 1024 is a multiple of 32, all rx buffers will be
  2061. + cache aligned. */
  2062. +static volatile unsigned char RxBuf[RX_BUF_SIZE] __attribute__ ((aligned (32)));
  2063. +static volatile struct USB_IN_Desc RxDescList[NBR_OF_RX_DESC] __attribute__ ((aligned (4)));
  2064. +
  2065. +/* Pointers into RxDescList. */
  2066. +static volatile struct USB_IN_Desc *myNextRxDesc;
  2067. +static volatile struct USB_IN_Desc *myLastRxDesc;
  2068. +
  2069. +/* A zout transfer makes a memory access at the address of its buf pointer,
  2070. + which means that setting this buf pointer to 0 will cause an access to the
  2071. + flash. In addition to this, setting sw_len to 0 results in a 16/32 bytes
  2072. + (depending on DMA burst size) transfer.
  2073. + Instead, we set it to 1, and point it to this buffer. */
  2074. +static int zout_buffer[4] __attribute__ ((aligned (4)));
  2075. +
  2076. +/* Cache for allocating new EP and SB descriptors. */
  2077. +//static kmem_cache_t *usb_desc_cache;
  2078. +static struct kmem_cache *usb_desc_cache;
  2079. +
  2080. +/* Cache for the data allocated in the isoc descr top half. */
  2081. +//static kmem_cache_t *isoc_compl_cache;
  2082. +static struct kmem_cache *isoc_compl_cache;
  2083. +
  2084. +/* Cache for the data allocated when delayed finishing of URBs */
  2085. +//static kmem_cache_t *later_data_cache;
  2086. +static struct kmem_cache *later_data_cache;
  2087. +
  2088. +/* Counter to keep track of how many Isoc EP we have sat up. Used to enable
  2089. + and disable iso_eof interrupt. We only need these interrupts when we have
  2090. + Isoc data endpoints (consumes CPU cycles).
  2091. + FIXME: This could be more fine granular, so this interrupt is only enabled
  2092. + when we have a In Isoc URB not URB_ISO_ASAP flaged queued. */
  2093. +static int isoc_epid_counter;
  2094. +
  2095. +/* Protecting wrapper functions for R_USB_EPT_x */
  2096. +/* -------------------------------------------- */
  2097. +static inline void etrax_epid_set(__u8 index, __u32 data) {
  2098. + unsigned long flags;
  2099. + spin_lock_irqsave(&etrax_epid_lock, flags);
  2100. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, index);
  2101. + nop();
  2102. + *R_USB_EPT_DATA = data;
  2103. + spin_unlock_irqrestore(&etrax_epid_lock, flags);
  2104. +}
  2105. +
  2106. +static inline void etrax_epid_clear_error(__u8 index) {
  2107. + unsigned long flags;
  2108. + spin_lock_irqsave(&etrax_epid_lock, flags);
  2109. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, index);
  2110. + nop();
  2111. + *R_USB_EPT_DATA &=
  2112. + ~(IO_MASK(R_USB_EPT_DATA, error_count_in) |
  2113. + IO_MASK(R_USB_EPT_DATA, error_count_out) |
  2114. + IO_MASK(R_USB_EPT_DATA, error_code));
  2115. + spin_unlock_irqrestore(&etrax_epid_lock, flags);
  2116. +}
  2117. +
  2118. +static inline void etrax_epid_set_toggle(__u8 index, __u8 dirout,
  2119. + __u8 toggle) {
  2120. + unsigned long flags;
  2121. + spin_lock_irqsave(&etrax_epid_lock, flags);
  2122. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, index);
  2123. + nop();
  2124. + if(dirout) {
  2125. + *R_USB_EPT_DATA &= ~IO_MASK(R_USB_EPT_DATA, t_out);
  2126. + *R_USB_EPT_DATA |= IO_FIELD(R_USB_EPT_DATA, t_out, toggle);
  2127. + } else {
  2128. + *R_USB_EPT_DATA &= ~IO_MASK(R_USB_EPT_DATA, t_in);
  2129. + *R_USB_EPT_DATA |= IO_FIELD(R_USB_EPT_DATA, t_in, toggle);
  2130. + }
  2131. + spin_unlock_irqrestore(&etrax_epid_lock, flags);
  2132. +}
  2133. +
  2134. +static inline __u8 etrax_epid_get_toggle(__u8 index, __u8 dirout) {
  2135. + unsigned long flags;
  2136. + __u8 toggle;
  2137. + spin_lock_irqsave(&etrax_epid_lock, flags);
  2138. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, index);
  2139. + nop();
  2140. + if (dirout) {
  2141. + toggle = IO_EXTRACT(R_USB_EPT_DATA, t_out, *R_USB_EPT_DATA);
  2142. + } else {
  2143. + toggle = IO_EXTRACT(R_USB_EPT_DATA, t_in, *R_USB_EPT_DATA);
  2144. + }
  2145. + spin_unlock_irqrestore(&etrax_epid_lock, flags);
  2146. + return toggle;
  2147. +}
  2148. +
  2149. +
  2150. +static inline __u32 etrax_epid_get(__u8 index) {
  2151. + unsigned long flags;
  2152. + __u32 data;
  2153. + spin_lock_irqsave(&etrax_epid_lock, flags);
  2154. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, index);
  2155. + nop();
  2156. + data = *R_USB_EPT_DATA;
  2157. + spin_unlock_irqrestore(&etrax_epid_lock, flags);
  2158. + return data;
  2159. +}
  2160. +
  2161. +
  2162. +
  2163. +
  2164. +/* Main functions for Transfer Controller */
  2165. +/* -------------------------------------- */
  2166. +
  2167. +/* Init structs, memories and lists used by Transfer Controller */
  2168. +int tc_init(struct usb_hcd *hcd) {
  2169. + int i;
  2170. + /* Clear software state info for all epids */
  2171. + memset(epid_state, 0, sizeof(struct etrax_epid) * NBR_OF_EPIDS);
  2172. +
  2173. + /* Set Invalid and Dummy as being in use and disabled */
  2174. + epid_state[INVALID_EPID].inuse = 1;
  2175. + epid_state[DUMMY_EPID].inuse = 1;
  2176. + epid_state[INVALID_EPID].disabled = 1;
  2177. + epid_state[DUMMY_EPID].disabled = 1;
  2178. +
  2179. + /* Clear counter for how many Isoc epids we have sat up */
  2180. + isoc_epid_counter = 0;
  2181. +
  2182. + /* Initialize the urb list by initiating a head for each list.
  2183. + Also reset list hodling active URB for each epid */
  2184. + for (i = 0; i < NBR_OF_EPIDS; i++) {
  2185. + INIT_LIST_HEAD(&urb_list[i]);
  2186. + activeUrbList[i] = NULL;
  2187. + }
  2188. +
  2189. + /* Init lock for URB lists */
  2190. + spin_lock_init(&urb_list_lock);
  2191. + /* Init lock for Etrax R_USB_EPT register */
  2192. + spin_lock_init(&etrax_epid_lock);
  2193. + /* Init lock for Etrax dma8 sub0 handling */
  2194. + spin_lock_init(&etrax_dma8_sub0_lock);
  2195. +
  2196. + /* We use kmem_cache_* to make sure that all DMA desc. are dword aligned */
  2197. +
  2198. + /* Note that we specify sizeof(struct USB_EP_Desc) as the size, but also
  2199. + allocate SB descriptors from this cache. This is ok since
  2200. + sizeof(struct USB_EP_Desc) == sizeof(struct USB_SB_Desc). */
  2201. +// usb_desc_cache = kmem_cache_create("usb_desc_cache",
  2202. +// sizeof(struct USB_EP_Desc), 0,
  2203. +// SLAB_HWCACHE_ALIGN, 0, 0);
  2204. + usb_desc_cache = kmem_cache_create(
  2205. + "usb_desc_cache",
  2206. + sizeof(struct USB_EP_Desc),
  2207. + 0,
  2208. + SLAB_HWCACHE_ALIGN,
  2209. + NULL);
  2210. + if(usb_desc_cache == NULL) {
  2211. + return -ENOMEM;
  2212. + }
  2213. +
  2214. + /* Create slab cache for speedy allocation of memory for isoc bottom-half
  2215. + interrupt handling */
  2216. +// isoc_compl_cache =
  2217. +// kmem_cache_create("isoc_compl_cache",
  2218. +// sizeof(struct crisv10_isoc_complete_data),
  2219. +// 0, SLAB_HWCACHE_ALIGN, 0, 0);
  2220. + isoc_compl_cache = kmem_cache_create(
  2221. + "isoc_compl_cache",
  2222. + sizeof(struct crisv10_isoc_complete_data),
  2223. + 0,
  2224. + SLAB_HWCACHE_ALIGN,
  2225. + NULL
  2226. + );
  2227. +
  2228. + if(isoc_compl_cache == NULL) {
  2229. + return -ENOMEM;
  2230. + }
  2231. +
  2232. + /* Create slab cache for speedy allocation of memory for later URB finish
  2233. + struct */
  2234. +// later_data_cache =
  2235. +// kmem_cache_create("later_data_cache",
  2236. +// sizeof(struct urb_later_data),
  2237. +// 0, SLAB_HWCACHE_ALIGN, 0, 0);
  2238. +
  2239. + later_data_cache = kmem_cache_create(
  2240. + "later_data_cache",
  2241. + sizeof(struct urb_later_data),
  2242. + 0,
  2243. + SLAB_HWCACHE_ALIGN,
  2244. + NULL
  2245. + );
  2246. +
  2247. + if(later_data_cache == NULL) {
  2248. + return -ENOMEM;
  2249. + }
  2250. +
  2251. +
  2252. + /* Initiate the bulk start timer. */
  2253. + init_timer(&bulk_start_timer);
  2254. + bulk_start_timer.expires = jiffies + BULK_START_TIMER_INTERVAL;
  2255. + bulk_start_timer.function = tc_bulk_start_timer_func;
  2256. + add_timer(&bulk_start_timer);
  2257. +
  2258. +
  2259. + /* Initiate the bulk eot timer. */
  2260. + init_timer(&bulk_eot_timer);
  2261. + bulk_eot_timer.expires = jiffies + BULK_EOT_TIMER_INTERVAL;
  2262. + bulk_eot_timer.function = tc_bulk_eot_timer_func;
  2263. + bulk_eot_timer.data = (unsigned long)hcd;
  2264. + add_timer(&bulk_eot_timer);
  2265. +
  2266. + return 0;
  2267. +}
  2268. +
  2269. +/* Uninitialize all resources used by Transfer Controller */
  2270. +void tc_destroy(void) {
  2271. +
  2272. + /* Destroy all slab cache */
  2273. + kmem_cache_destroy(usb_desc_cache);
  2274. + kmem_cache_destroy(isoc_compl_cache);
  2275. + kmem_cache_destroy(later_data_cache);
  2276. +
  2277. + /* Remove timers */
  2278. + del_timer(&bulk_start_timer);
  2279. + del_timer(&bulk_eot_timer);
  2280. +}
  2281. +
  2282. +static void restart_dma8_sub0(void) {
  2283. + unsigned long flags;
  2284. + spin_lock_irqsave(&etrax_dma8_sub0_lock, flags);
  2285. + /* Verify that the dma is not running */
  2286. + if ((*R_DMA_CH8_SUB0_CMD & IO_MASK(R_DMA_CH8_SUB0_CMD, cmd)) == 0) {
  2287. + struct USB_EP_Desc *ep = (struct USB_EP_Desc *)phys_to_virt(*R_DMA_CH8_SUB0_EP);
  2288. + while (DUMMY_EPID == IO_EXTRACT(USB_EP_command, epid, ep->command)) {
  2289. + ep = (struct USB_EP_Desc *)phys_to_virt(ep->next);
  2290. + }
  2291. + /* Advance the DMA to the next EP descriptor that is not a DUMMY_EPID.
  2292. + * ep->next is already a physical address. virt_to_phys is needed, see
  2293. + * http://mhonarc.axis.se/dev-etrax/msg08630.html
  2294. + */
  2295. + //*R_DMA_CH8_SUB0_EP = ep->next;
  2296. + *R_DMA_CH8_SUB0_EP = virt_to_phys(ep);
  2297. + /* Restart the DMA */
  2298. + *R_DMA_CH8_SUB0_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start);
  2299. + }
  2300. + spin_unlock_irqrestore(&etrax_dma8_sub0_lock, flags);
  2301. +}
  2302. +
  2303. +/* queue an URB with the transfer controller (called from hcd_driver) */
  2304. +//static int tc_urb_enqueue(struct usb_hcd *hcd,
  2305. +// struct usb_host_endpoint *ep,
  2306. +// struct urb *urb,
  2307. +// gfp_t mem_flags) {
  2308. +static int tc_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags)
  2309. +{
  2310. + int epid;
  2311. + int retval;
  2312. +// int bustime = 0;
  2313. + int maxpacket;
  2314. + unsigned long flags;
  2315. + struct crisv10_urb_priv *urb_priv;
  2316. + struct crisv10_hcd* crisv10_hcd = hcd_to_crisv10_hcd(hcd);
  2317. + DBFENTER;
  2318. +
  2319. + if(!(crisv10_hcd->running)) {
  2320. + /* The USB Controller is not running, probably because no device is
  2321. + attached. No idea to enqueue URBs then */
  2322. + tc_warn("Rejected enqueueing of URB:0x%x because no dev attached\n",
  2323. + (unsigned int)urb);
  2324. + return -ENOENT;
  2325. + }
  2326. +
  2327. + maxpacket = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
  2328. +
  2329. + /* hinko ignore usb_pipeisoc */
  2330. +#if 0
  2331. + /* Special case check for In Isoc transfers. Specification states that each
  2332. + In Isoc transfer consists of one packet and therefore it should fit into
  2333. + the transfer-buffer of an URB.
  2334. + We do the check here to be sure (an invalid scenario can be produced with
  2335. + parameters to the usbtest suite) */
  2336. + if(usb_pipeisoc(urb->pipe) && usb_pipein(urb->pipe) &&
  2337. + (urb->transfer_buffer_length < maxpacket)) {
  2338. + tc_err("Submit In Isoc URB with buffer length:%d to pipe with maxpacketlen: %d\n", urb->transfer_buffer_length, maxpacket);
  2339. + return -EMSGSIZE;
  2340. + }
  2341. +
  2342. + /* Check if there is enough bandwidth for periodic transfer */
  2343. + if(usb_pipeint(urb->pipe) || usb_pipeisoc(urb->pipe)) {
  2344. + /* only check (and later claim) if not already claimed */
  2345. + if (urb->bandwidth == 0) {
  2346. + bustime = usb_check_bandwidth(urb->dev, urb);
  2347. + if (bustime < 0) {
  2348. + tc_err("Not enough periodic bandwidth\n");
  2349. + return -ENOSPC;
  2350. + }
  2351. + }
  2352. + }
  2353. +#endif
  2354. +
  2355. + /* Check if there is a epid for URBs destination, if not this function
  2356. + set up one. */
  2357. + //epid = tc_setup_epid(ep, urb, mem_flags);
  2358. + epid = tc_setup_epid(urb, mem_flags);
  2359. + if (epid < 0) {
  2360. + tc_err("Failed setup epid:%d for URB:0x%x\n", epid, (unsigned int)urb);
  2361. + DBFEXIT;
  2362. + return -ENOMEM;
  2363. + }
  2364. +
  2365. + if(urb == activeUrbList[epid]) {
  2366. + tc_err("Resubmition of allready active URB:0x%x\n", (unsigned int)urb);
  2367. + return -ENXIO;
  2368. + }
  2369. +
  2370. + if(urb_list_entry(urb, epid)) {
  2371. + tc_err("Resubmition of allready queued URB:0x%x\n", (unsigned int)urb);
  2372. + return -ENXIO;
  2373. + }
  2374. +
  2375. + /* If we actively have flaged endpoint as disabled then refuse submition */
  2376. + if(epid_state[epid].disabled) {
  2377. + return -ENOENT;
  2378. + }
  2379. +
  2380. + /* Allocate and init HC-private data for URB */
  2381. + if(urb_priv_create(hcd, urb, epid, mem_flags) != 0) {
  2382. + DBFEXIT;
  2383. + return -ENOMEM;
  2384. + }
  2385. + urb_priv = urb->hcpriv;
  2386. +
  2387. + tc_dbg("Enqueue URB:0x%x[%d] epid:%d (%s) bufflen:%d\n",
  2388. + (unsigned int)urb, urb_priv->urb_num, epid,
  2389. + pipe_to_str(urb->pipe), urb->transfer_buffer_length);
  2390. +
  2391. + /* Create and link SBs required for this URB */
  2392. + retval = create_sb_for_urb(urb, mem_flags);
  2393. + if(retval != 0) {
  2394. + tc_err("Failed to create SBs for URB:0x%x[%d]\n", (unsigned int)urb,
  2395. + urb_priv->urb_num);
  2396. + urb_priv_free(hcd, urb);
  2397. + DBFEXIT;
  2398. + return retval;
  2399. + }
  2400. +
  2401. + /* Init intr EP pool if this URB is a INTR transfer. This pool is later
  2402. + used when inserting EPs in the TxIntrEPList. We do the alloc here
  2403. + so we can't run out of memory later */
  2404. + if(usb_pipeint(urb->pipe)) {
  2405. + retval = init_intr_urb(urb, mem_flags);
  2406. + if(retval != 0) {
  2407. + tc_warn("Failed to init Intr URB\n");
  2408. + urb_priv_free(hcd, urb);
  2409. + DBFEXIT;
  2410. + return retval;
  2411. + }
  2412. + }
  2413. +
  2414. + /* Disable other access when inserting USB */
  2415. +
  2416. + /* BUG on sleeping inside int disabled if using local_irq_save/local_irq_restore
  2417. + * her - because urb_list_add() and tc_dma_process_queue() save irqs again !??!
  2418. + */
  2419. +// local_irq_save(flags);
  2420. +
  2421. + /* hinko ignore usb_pipeisoc */
  2422. +#if 0
  2423. + /* Claim bandwidth, if needed */
  2424. + if(bustime) {
  2425. + usb_claim_bandwidth(urb->dev, urb, bustime, 0);
  2426. + }
  2427. +
  2428. + /* Add URB to EP queue */
  2429. + urb_list_add(urb, epid, mem_flags);
  2430. +
  2431. + if(usb_pipeisoc(urb->pipe)) {
  2432. + /* Special processing of Isoc URBs. */
  2433. + tc_dma_process_isoc_urb(urb);
  2434. + } else {
  2435. + /* Process EP queue for rest of the URB types (Bulk, Ctrl, Intr) */
  2436. + tc_dma_process_queue(epid);
  2437. + }
  2438. +#endif
  2439. + /* Add URB to EP queue */
  2440. + urb_list_add(urb, epid, mem_flags);
  2441. +
  2442. + /*hinko link/unlink urb -> ep */
  2443. + spin_lock_irqsave(&crisv10_hcd->lock, flags);
  2444. + //spin_lock(&crisv10_hcd->lock);
  2445. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  2446. + if (retval) {
  2447. + spin_unlock_irqrestore(&crisv10_hcd->lock, flags);
  2448. + tc_warn("Failed to link urb to ep\n");
  2449. + urb_priv_free(hcd, urb);
  2450. + DBFEXIT;
  2451. + return retval;
  2452. + }
  2453. + spin_unlock_irqrestore(&crisv10_hcd->lock, flags);
  2454. + //spin_unlock(&crisv10_hcd->lock);
  2455. +
  2456. + /* Process EP queue for rest of the URB types (Bulk, Ctrl, Intr) */
  2457. + tc_dma_process_queue(epid);
  2458. +
  2459. +// local_irq_restore(flags);
  2460. +
  2461. + DBFEXIT;
  2462. + return 0;
  2463. +}
  2464. +
  2465. +/* remove an URB from the transfer controller queues (called from hcd_driver)*/
  2466. +//static int tc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  2467. +static int tc_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  2468. +{
  2469. + struct crisv10_urb_priv *urb_priv;
  2470. + unsigned long flags;
  2471. + int epid;
  2472. +
  2473. + DBFENTER;
  2474. + /* Disable interrupts here since a descriptor interrupt for the isoc epid
  2475. + will modify the sb list. This could possibly be done more granular, but
  2476. + urb_dequeue should not be used frequently anyway.
  2477. + */
  2478. + local_irq_save(flags);
  2479. +
  2480. + urb_priv = urb->hcpriv;
  2481. +
  2482. + if (!urb_priv) {
  2483. + /* This happens if a device driver calls unlink on an urb that
  2484. + was never submitted (lazy driver) or if the urb was completed
  2485. + while dequeue was being called. */
  2486. + tc_warn("Dequeing of not enqueued URB:0x%x\n", (unsigned int)urb);
  2487. + local_irq_restore(flags);
  2488. + return 0;
  2489. + }
  2490. + epid = urb_priv->epid;
  2491. +
  2492. + tc_warn("Dequeing %s URB:0x%x[%d] (%s %s epid:%d) status:%d %s\n",
  2493. + (urb == activeUrbList[epid]) ? "active" : "queued",
  2494. + (unsigned int)urb, urb_priv->urb_num, str_dir(urb->pipe),
  2495. + str_type(urb->pipe), epid, urb->status,
  2496. + (urb_priv->later_data) ? "later-sched" : "");
  2497. +
  2498. + /* For Bulk, Ctrl and Intr are only one URB active at a time. So any URB
  2499. + that isn't active can be dequeued by just removing it from the queue */
  2500. + if(usb_pipebulk(urb->pipe) || usb_pipecontrol(urb->pipe) ||
  2501. + usb_pipeint(urb->pipe)) {
  2502. +
  2503. + /* Check if URB haven't gone further than the queue */
  2504. + if(urb != activeUrbList[epid]) {
  2505. + ASSERT(urb_priv->later_data == NULL);
  2506. + tc_warn("Dequeing URB:0x%x[%d] (%s %s epid:%d) from queue"
  2507. + " (not active)\n", (unsigned int)urb, urb_priv->urb_num,
  2508. + str_dir(urb->pipe), str_type(urb->pipe), epid);
  2509. +
  2510. + /* Finish the URB with error status from USB core */
  2511. + tc_finish_urb(hcd, urb, urb->status);
  2512. + local_irq_restore(flags);
  2513. + return 0;
  2514. + }
  2515. + }
  2516. +
  2517. + /* Set URB status to Unlink for handling when interrupt comes. */
  2518. + urb_priv->urb_state = UNLINK;
  2519. +
  2520. + /* Differentiate dequeing of Bulk and Ctrl from Isoc and Intr */
  2521. + switch(usb_pipetype(urb->pipe)) {
  2522. + case PIPE_BULK:
  2523. + /* Check if EP still is enabled */
  2524. + if (TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  2525. + /* The EP was enabled, disable it. */
  2526. + TxBulkEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  2527. + }
  2528. + /* Kicking dummy list out of the party. */
  2529. + TxBulkEPList[epid].next = virt_to_phys(&TxBulkEPList[(epid + 1) % NBR_OF_EPIDS]);
  2530. + break;
  2531. + case PIPE_CONTROL:
  2532. + /* Check if EP still is enabled */
  2533. + if (TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  2534. + /* The EP was enabled, disable it. */
  2535. + TxCtrlEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  2536. + }
  2537. + break;
  2538. + case PIPE_ISOCHRONOUS:
  2539. + /* Disabling, busy-wait and unlinking of Isoc SBs will be done in
  2540. + finish_isoc_urb(). Because there might the case when URB is dequeued
  2541. + but there are other valid URBs waiting */
  2542. +
  2543. + /* Check if In Isoc EP still is enabled */
  2544. + if (TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  2545. + /* The EP was enabled, disable it. */
  2546. + TxIsocEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  2547. + }
  2548. + break;
  2549. + case PIPE_INTERRUPT:
  2550. + /* Special care is taken for interrupt URBs. EPs are unlinked in
  2551. + tc_finish_urb */
  2552. + break;
  2553. + default:
  2554. + break;
  2555. + }
  2556. +
  2557. + /* Asynchronous unlink, finish the URB later from scheduled or other
  2558. + event (data finished, error) */
  2559. + tc_finish_urb_later(hcd, urb, urb->status);
  2560. +
  2561. + local_irq_restore(flags);
  2562. + DBFEXIT;
  2563. + return 0;
  2564. +}
  2565. +
  2566. +
  2567. +static void tc_sync_finish_epid(struct usb_hcd *hcd, int epid) {
  2568. + volatile int timeout = 10000;
  2569. + struct urb* urb;
  2570. + struct crisv10_urb_priv* urb_priv;
  2571. + unsigned long flags;
  2572. +
  2573. + volatile struct USB_EP_Desc *first_ep; /* First EP in the list. */
  2574. + volatile struct USB_EP_Desc *curr_ep; /* Current EP, the iterator. */
  2575. + volatile struct USB_EP_Desc *next_ep; /* The EP after current. */
  2576. +
  2577. + int type = epid_state[epid].type;
  2578. +
  2579. + /* Setting this flag will cause enqueue() to return -ENOENT for new
  2580. + submitions on this endpoint and finish_urb() wont process queue further */
  2581. + epid_state[epid].disabled = 1;
  2582. +
  2583. + switch(type) {
  2584. + case PIPE_BULK:
  2585. + /* Check if EP still is enabled */
  2586. + if (TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  2587. + /* The EP was enabled, disable it. */
  2588. + TxBulkEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  2589. + tc_warn("sync_finish: Disabling EP for epid:%d\n", epid);
  2590. +
  2591. + /* Do busy-wait until DMA not using this EP descriptor anymore */
  2592. + while((*R_DMA_CH8_SUB0_EP ==
  2593. + virt_to_phys(&TxBulkEPList[epid])) &&
  2594. + (timeout-- > 0));
  2595. + if(timeout == 0) {
  2596. + warn("Timeout while waiting for DMA-TX-Bulk to leave EP for"
  2597. + " epid:%d\n", epid);
  2598. + }
  2599. + }
  2600. + break;
  2601. +
  2602. + case PIPE_CONTROL:
  2603. + /* Check if EP still is enabled */
  2604. + if (TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  2605. + /* The EP was enabled, disable it. */
  2606. + TxCtrlEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  2607. + tc_warn("sync_finish: Disabling EP for epid:%d\n", epid);
  2608. +
  2609. + /* Do busy-wait until DMA not using this EP descriptor anymore */
  2610. + while((*R_DMA_CH8_SUB1_EP ==
  2611. + virt_to_phys(&TxCtrlEPList[epid])) &&
  2612. + (timeout-- > 0));
  2613. + if(timeout == 0) {
  2614. + warn("Timeout while waiting for DMA-TX-Ctrl to leave EP for"
  2615. + " epid:%d\n", epid);
  2616. + }
  2617. + }
  2618. + break;
  2619. +
  2620. + case PIPE_INTERRUPT:
  2621. + local_irq_save(flags);
  2622. + /* Disable all Intr EPs belonging to epid */
  2623. + first_ep = &TxIntrEPList[0];
  2624. + curr_ep = first_ep;
  2625. + do {
  2626. + next_ep = (struct USB_EP_Desc *)phys_to_virt(curr_ep->next);
  2627. + if (IO_EXTRACT(USB_EP_command, epid, next_ep->command) == epid) {
  2628. + /* Disable EP */
  2629. + next_ep->command &= ~IO_MASK(USB_EP_command, enable);
  2630. + }
  2631. + curr_ep = phys_to_virt(curr_ep->next);
  2632. + } while (curr_ep != first_ep);
  2633. +
  2634. + local_irq_restore(flags);
  2635. + break;
  2636. +
  2637. + case PIPE_ISOCHRONOUS:
  2638. + /* Check if EP still is enabled */
  2639. + if (TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  2640. + tc_warn("sync_finish: Disabling Isoc EP for epid:%d\n", epid);
  2641. + /* The EP was enabled, disable it. */
  2642. + TxIsocEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  2643. +
  2644. + while((*R_DMA_CH8_SUB3_EP == virt_to_phys(&TxIsocEPList[epid])) &&
  2645. + (timeout-- > 0));
  2646. + if(timeout == 0) {
  2647. + warn("Timeout while waiting for DMA-TX-Isoc to leave EP for"
  2648. + " epid:%d\n", epid);
  2649. + }
  2650. + }
  2651. + break;
  2652. + }
  2653. +
  2654. + local_irq_save(flags);
  2655. +
  2656. + /* Finish if there is active URB for this endpoint */
  2657. + if(activeUrbList[epid] != NULL) {
  2658. + urb = activeUrbList[epid];
  2659. + urb_priv = urb->hcpriv;
  2660. + ASSERT(urb_priv);
  2661. + tc_warn("Sync finish %s URB:0x%x[%d] (%s %s epid:%d) status:%d %s\n",
  2662. + (urb == activeUrbList[epid]) ? "active" : "queued",
  2663. + (unsigned int)urb, urb_priv->urb_num, str_dir(urb->pipe),
  2664. + str_type(urb->pipe), epid, urb->status,
  2665. + (urb_priv->later_data) ? "later-sched" : "");
  2666. +
  2667. + tc_finish_urb(hcd, activeUrbList[epid], -ENOENT);
  2668. + ASSERT(activeUrbList[epid] == NULL);
  2669. + }
  2670. +
  2671. + /* Finish any queued URBs for this endpoint. There won't be any resubmitions
  2672. + because epid_disabled causes enqueue() to fail for this endpoint */
  2673. + while((urb = urb_list_first(epid)) != NULL) {
  2674. + urb_priv = urb->hcpriv;
  2675. + ASSERT(urb_priv);
  2676. +
  2677. + tc_warn("Sync finish %s URB:0x%x[%d] (%s %s epid:%d) status:%d %s\n",
  2678. + (urb == activeUrbList[epid]) ? "active" : "queued",
  2679. + (unsigned int)urb, urb_priv->urb_num, str_dir(urb->pipe),
  2680. + str_type(urb->pipe), epid, urb->status,
  2681. + (urb_priv->later_data) ? "later-sched" : "");
  2682. +
  2683. + tc_finish_urb(hcd, urb, -ENOENT);
  2684. + }
  2685. + epid_state[epid].disabled = 0;
  2686. + local_irq_restore(flags);
  2687. +}
  2688. +
  2689. +/* free resources associated with an endpoint (called from hcd_driver) */
  2690. +static void tc_endpoint_disable(struct usb_hcd *hcd,
  2691. + struct usb_host_endpoint *ep) {
  2692. + DBFENTER;
  2693. + /* Only free epid if it has been allocated. We get two endpoint_disable
  2694. + requests for ctrl endpoints so ignore the second one */
  2695. + if(ep->hcpriv != NULL) {
  2696. + struct crisv10_ep_priv *ep_priv = ep->hcpriv;
  2697. + int epid = ep_priv->epid;
  2698. + tc_warn("endpoint_disable ep:0x%x ep-priv:0x%x (%s) (epid:%d freed)\n",
  2699. + (unsigned int)ep, (unsigned int)ep->hcpriv,
  2700. + endpoint_to_str(&(ep->desc)), epid);
  2701. +
  2702. + tc_sync_finish_epid(hcd, epid);
  2703. +
  2704. + ASSERT(activeUrbList[epid] == NULL);
  2705. + ASSERT(list_empty(&urb_list[epid]));
  2706. +
  2707. + tc_free_epid(ep);
  2708. + } else {
  2709. + tc_dbg("endpoint_disable ep:0x%x ep-priv:0x%x (%s)\n", (unsigned int)ep,
  2710. + (unsigned int)ep->hcpriv, endpoint_to_str(&(ep->desc)));
  2711. + }
  2712. + DBFEXIT;
  2713. +}
  2714. +
  2715. +//static void tc_finish_urb_later_proc(void *data) {
  2716. +static void tc_finish_urb_later_proc(struct work_struct *work) {
  2717. + unsigned long flags;
  2718. + //struct urb_later_data* uld = (struct urb_later_data*)data;
  2719. + struct urb_later_data* uld = container_of(work, struct urb_later_data, ws.work);
  2720. + local_irq_save(flags);
  2721. + if(uld->urb == NULL) {
  2722. + late_dbg("Later finish of URB = NULL (allready finished)\n");
  2723. + } else {
  2724. + struct crisv10_urb_priv* urb_priv = uld->urb->hcpriv;
  2725. + ASSERT(urb_priv);
  2726. + if(urb_priv->urb_num == uld->urb_num) {
  2727. + late_dbg("Later finish of URB:0x%x[%d]\n", (unsigned int)(uld->urb),
  2728. + urb_priv->urb_num);
  2729. + if(uld->status != uld->urb->status) {
  2730. + errno_dbg("Later-finish URB with status:%d, later-status:%d\n",
  2731. + uld->urb->status, uld->status);
  2732. + }
  2733. + if(uld != urb_priv->later_data) {
  2734. + panic("Scheduled uld not same as URBs uld\n");
  2735. + }
  2736. + tc_finish_urb(uld->hcd, uld->urb, uld->status);
  2737. + } else {
  2738. + late_warn("Ignoring later finish of URB:0x%x[%d]"
  2739. + ", urb_num doesn't match current URB:0x%x[%d]",
  2740. + (unsigned int)(uld->urb), uld->urb_num,
  2741. + (unsigned int)(uld->urb), urb_priv->urb_num);
  2742. + }
  2743. + }
  2744. + local_irq_restore(flags);
  2745. + kmem_cache_free(later_data_cache, uld);
  2746. +}
  2747. +
  2748. +static void tc_finish_urb_later(struct usb_hcd *hcd, struct urb *urb,
  2749. + int status) {
  2750. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  2751. + struct urb_later_data* uld;
  2752. +
  2753. + ASSERT(urb_priv);
  2754. +
  2755. + if(urb_priv->later_data != NULL) {
  2756. + /* Later-finish allready scheduled for this URB, just update status to
  2757. + return when finishing later */
  2758. + errno_dbg("Later-finish schedule change URB status:%d with new"
  2759. + " status:%d\n", urb_priv->later_data->status, status);
  2760. +
  2761. + urb_priv->later_data->status = status;
  2762. + return;
  2763. + }
  2764. +
  2765. + uld = kmem_cache_alloc(later_data_cache, GFP_ATOMIC);
  2766. + ASSERT(uld);
  2767. +
  2768. + uld->hcd = hcd;
  2769. + uld->urb = urb;
  2770. + uld->urb_num = urb_priv->urb_num;
  2771. + uld->status = status;
  2772. +
  2773. + //INIT_WORK(&uld->ws, tc_finish_urb_later_proc, uld);
  2774. + INIT_DELAYED_WORK(&uld->ws, tc_finish_urb_later_proc);
  2775. + urb_priv->later_data = uld;
  2776. +
  2777. + /* Schedule the finishing of the URB to happen later */
  2778. + schedule_delayed_work(&uld->ws, LATER_TIMER_DELAY);
  2779. +}
  2780. +
  2781. + /* hinko ignore usb_pipeisoc */
  2782. +#if 0
  2783. +static void tc_finish_isoc_urb(struct usb_hcd *hcd, struct urb *urb,
  2784. + int status);
  2785. +#endif
  2786. +
  2787. +static void tc_finish_urb(struct usb_hcd *hcd, struct urb *urb, int status) {
  2788. + struct crisv10_hcd* crisv10_hcd = hcd_to_crisv10_hcd(hcd);
  2789. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  2790. + int epid;
  2791. + char toggle;
  2792. + int urb_num;
  2793. +
  2794. + DBFENTER;
  2795. + ASSERT(urb_priv != NULL);
  2796. + epid = urb_priv->epid;
  2797. + urb_num = urb_priv->urb_num;
  2798. +
  2799. + if(urb != activeUrbList[epid]) {
  2800. + if(urb_list_entry(urb, epid)) {
  2801. + /* Remove this URB from the list. Only happens when URB are finished
  2802. + before having been processed (dequeing) */
  2803. + urb_list_del(urb, epid);
  2804. + } else {
  2805. + tc_warn("Finishing of URB:0x%x[%d] neither active or in queue for"
  2806. + " epid:%d\n", (unsigned int)urb, urb_num, epid);
  2807. + }
  2808. + }
  2809. +
  2810. + /* Cancel any pending later-finish of this URB */
  2811. + if(urb_priv->later_data) {
  2812. + urb_priv->later_data->urb = NULL;
  2813. + }
  2814. +
  2815. + /* For an IN pipe, we always set the actual length, regardless of whether
  2816. + there was an error or not (which means the device driver can use the data
  2817. + if it wants to). */
  2818. + if(usb_pipein(urb->pipe)) {
  2819. + urb->actual_length = urb_priv->rx_offset;
  2820. + } else {
  2821. + /* Set actual_length for OUT urbs also; the USB mass storage driver seems
  2822. + to want that. */
  2823. + if (status == 0 && urb->status == -EINPROGRESS) {
  2824. + urb->actual_length = urb->transfer_buffer_length;
  2825. + } else {
  2826. + /* We wouldn't know of any partial writes if there was an error. */
  2827. + urb->actual_length = 0;
  2828. + }
  2829. + }
  2830. +
  2831. +
  2832. + /* URB status mangling */
  2833. + if(urb->status == -EINPROGRESS) {
  2834. + /* The USB core hasn't changed the status, let's set our finish status */
  2835. + urb->status = status;
  2836. +
  2837. + if ((status == 0) && (urb->transfer_flags & URB_SHORT_NOT_OK) &&
  2838. + usb_pipein(urb->pipe) &&
  2839. + (urb->actual_length != urb->transfer_buffer_length)) {
  2840. + /* URB_SHORT_NOT_OK means that short reads (shorter than the endpoint's
  2841. + max length) is to be treated as an error. */
  2842. + errno_dbg("Finishing URB:0x%x[%d] with SHORT_NOT_OK flag and short"
  2843. + " data:%d\n", (unsigned int)urb, urb_num,
  2844. + urb->actual_length);
  2845. + urb->status = -EREMOTEIO;
  2846. + }
  2847. +
  2848. + if(urb_priv->urb_state == UNLINK) {
  2849. + /* URB has been requested to be unlinked asynchronously */
  2850. + urb->status = -ECONNRESET;
  2851. + errno_dbg("Fixing unlink status of URB:0x%x[%d] to:%d\n",
  2852. + (unsigned int)urb, urb_num, urb->status);
  2853. + }
  2854. + } else {
  2855. + /* The USB Core wants to signal some error via the URB, pass it through */
  2856. + }
  2857. +
  2858. + /* hinko ignore usb_pipeisoc */
  2859. +#if 0
  2860. + /* use completely different finish function for Isoc URBs */
  2861. + if(usb_pipeisoc(urb->pipe)) {
  2862. + tc_finish_isoc_urb(hcd, urb, status);
  2863. + return;
  2864. + }
  2865. +#endif
  2866. +
  2867. + /* Do special unlinking of EPs for Intr traffic */
  2868. + if(usb_pipeint(urb->pipe)) {
  2869. + tc_dma_unlink_intr_urb(urb);
  2870. + }
  2871. +
  2872. + /* hinko ignore usb_pipeisoc */
  2873. +#if 0
  2874. + /* Release allocated bandwidth for periodic transfers */
  2875. + if(usb_pipeint(urb->pipe) || usb_pipeisoc(urb->pipe))
  2876. + usb_release_bandwidth(urb->dev, urb, 0);
  2877. +#endif
  2878. +
  2879. + /* This URB is active on EP */
  2880. + if(urb == activeUrbList[epid]) {
  2881. + /* We need to fiddle with the toggle bits because the hardware doesn't do
  2882. + it for us. */
  2883. + toggle = etrax_epid_get_toggle(epid, usb_pipeout(urb->pipe));
  2884. + usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  2885. + usb_pipeout(urb->pipe), toggle);
  2886. +
  2887. + /* Checks for Ctrl and Bulk EPs */
  2888. + switch(usb_pipetype(urb->pipe)) {
  2889. + case PIPE_BULK:
  2890. + /* Check so Bulk EP realy is disabled before finishing active URB */
  2891. + ASSERT((TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) ==
  2892. + IO_STATE(USB_EP_command, enable, no));
  2893. + /* Disable sub-pointer for EP to avoid next tx_interrupt() to
  2894. + process Bulk EP. */
  2895. + TxBulkEPList[epid].sub = 0;
  2896. + /* No need to wait for the DMA before changing the next pointer.
  2897. + The modulo NBR_OF_EPIDS isn't actually necessary, since we will never use
  2898. + the last one (INVALID_EPID) for actual traffic. */
  2899. + TxBulkEPList[epid].next =
  2900. + virt_to_phys(&TxBulkEPList[(epid + 1) % NBR_OF_EPIDS]);
  2901. + break;
  2902. + case PIPE_CONTROL:
  2903. + /* Check so Ctrl EP realy is disabled before finishing active URB */
  2904. + ASSERT((TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable)) ==
  2905. + IO_STATE(USB_EP_command, enable, no));
  2906. + /* Disable sub-pointer for EP to avoid next tx_interrupt() to
  2907. + process Ctrl EP. */
  2908. + TxCtrlEPList[epid].sub = 0;
  2909. + break;
  2910. + }
  2911. + }
  2912. +
  2913. + /* Free HC-private URB data*/
  2914. + urb_priv_free(hcd, urb);
  2915. +
  2916. + if(urb->status) {
  2917. + errno_dbg("finish_urb (URB:0x%x[%d] %s %s) (data:%d) status:%d\n",
  2918. + (unsigned int)urb, urb_num, str_dir(urb->pipe),
  2919. + str_type(urb->pipe), urb->actual_length, urb->status);
  2920. + } else {
  2921. + tc_dbg("finish_urb (URB:0x%x[%d] %s %s) (data:%d) status:%d\n",
  2922. + (unsigned int)urb, urb_num, str_dir(urb->pipe),
  2923. + str_type(urb->pipe), urb->actual_length, urb->status);
  2924. + }
  2925. +
  2926. + /* If we just finished an active URB, clear active pointer. */
  2927. + if (urb == activeUrbList[epid]) {
  2928. + /* Make URB not active on EP anymore */
  2929. + activeUrbList[epid] = NULL;
  2930. +
  2931. + if(urb->status == 0) {
  2932. + /* URB finished sucessfully, process queue to see if there are any more
  2933. + URBs waiting before we call completion function.*/
  2934. + if(crisv10_hcd->running) {
  2935. + /* Only process queue if USB controller is running */
  2936. + tc_dma_process_queue(epid);
  2937. + } else {
  2938. + tc_warn("No processing of queue for epid:%d, USB Controller not"
  2939. + " running\n", epid);
  2940. + }
  2941. + }
  2942. + }
  2943. +
  2944. + /* Hand the URB from HCD to its USB device driver, using its completion
  2945. + functions */
  2946. +// usb_hcd_giveback_urb (hcd, urb);
  2947. + /**
  2948. + * usb_hcd_unlink_urb_from_ep - remove an URB from its endpoint queue
  2949. + * @hcd: host controller to which @urb was submitted
  2950. + * @urb: URB being unlinked
  2951. + *
  2952. + * Host controller drivers should call this routine before calling
  2953. + * usb_hcd_giveback_urb(). The HCD's private spinlock must be held and
  2954. + * interrupts must be disabled. The actions carried out here are required
  2955. + * for URB completion.
  2956. + */
  2957. +
  2958. + /*hinko link/unlink urb -> ep */
  2959. + //spin_lock(&crisv10_hcd->lock);
  2960. + unsigned long flags;
  2961. + spin_lock_irqsave(&crisv10_hcd->lock, flags);
  2962. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  2963. + usb_hcd_giveback_urb(hcd, urb, status);
  2964. + //spin_unlock(&crisv10_hcd->lock);
  2965. + spin_unlock_irqrestore(&crisv10_hcd->lock, flags);
  2966. +
  2967. + /* Check the queue once more if the URB returned with error, because we
  2968. + didn't do it before the completion function because the specification
  2969. + states that the queue should not restart until all it's unlinked
  2970. + URBs have been fully retired, with the completion functions run */
  2971. + if(crisv10_hcd->running) {
  2972. + /* Only process queue if USB controller is running */
  2973. + tc_dma_process_queue(epid);
  2974. + } else {
  2975. + tc_warn("No processing of queue for epid:%d, USB Controller not running\n",
  2976. + epid);
  2977. + }
  2978. +
  2979. + DBFEXIT;
  2980. +}
  2981. +
  2982. + /* hinko ignore usb_pipeisoc */
  2983. +#if 0
  2984. +static void tc_finish_isoc_urb(struct usb_hcd *hcd, struct urb *urb,
  2985. + int status) {
  2986. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  2987. + int epid, i;
  2988. + volatile int timeout = 10000;
  2989. +
  2990. + ASSERT(urb_priv);
  2991. + epid = urb_priv->epid;
  2992. +
  2993. + ASSERT(usb_pipeisoc(urb->pipe));
  2994. +
  2995. + /* Set that all isoc packets have status and length set before
  2996. + completing the urb. */
  2997. + for (i = urb_priv->isoc_packet_counter; i < urb->number_of_packets; i++){
  2998. + urb->iso_frame_desc[i].actual_length = 0;
  2999. + urb->iso_frame_desc[i].status = -EPROTO;
  3000. + }
  3001. +
  3002. + /* Check if the URB is currently active (done or error) */
  3003. + if(urb == activeUrbList[epid]) {
  3004. + /* Check if there are another In Isoc URB queued for this epid */
  3005. + if (!list_empty(&urb_list[epid])&& !epid_state[epid].disabled) {
  3006. + /* Move it from queue to active and mark it started so Isoc transfers
  3007. + won't be interrupted.
  3008. + All Isoc URBs data transfers are already added to DMA lists so we
  3009. + don't have to insert anything in DMA lists here. */
  3010. + activeUrbList[epid] = urb_list_first(epid);
  3011. + ((struct crisv10_urb_priv *)(activeUrbList[epid]->hcpriv))->urb_state =
  3012. + STARTED;
  3013. + urb_list_del(activeUrbList[epid], epid);
  3014. +
  3015. + if(urb->status) {
  3016. + errno_dbg("finish_isoc_urb (URB:0x%x[%d] %s %s) (%d of %d packets)"
  3017. + " status:%d, new waiting URB:0x%x[%d]\n",
  3018. + (unsigned int)urb, urb_priv->urb_num, str_dir(urb->pipe),
  3019. + str_type(urb->pipe), urb_priv->isoc_packet_counter,
  3020. + urb->number_of_packets, urb->status,
  3021. + (unsigned int)activeUrbList[epid],
  3022. + ((struct crisv10_urb_priv *)(activeUrbList[epid]->hcpriv))->urb_num);
  3023. + }
  3024. +
  3025. + } else { /* No other URB queued for this epid */
  3026. + if(urb->status) {
  3027. + errno_dbg("finish_isoc_urb (URB:0x%x[%d] %s %s) (%d of %d packets)"
  3028. + " status:%d, no new URB waiting\n",
  3029. + (unsigned int)urb, urb_priv->urb_num, str_dir(urb->pipe),
  3030. + str_type(urb->pipe), urb_priv->isoc_packet_counter,
  3031. + urb->number_of_packets, urb->status);
  3032. + }
  3033. +
  3034. + /* Check if EP is still enabled, then shut it down. */
  3035. + if (TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  3036. + isoc_dbg("Isoc EP enabled for epid:%d, disabling it\n", epid);
  3037. +
  3038. + /* Should only occur for In Isoc EPs where SB isn't consumed. */
  3039. + ASSERT(usb_pipein(urb->pipe));
  3040. +
  3041. + /* Disable it and wait for it to stop */
  3042. + TxIsocEPList[epid].command &= ~IO_MASK(USB_EP_command, enable);
  3043. +
  3044. + /* Ah, the luxury of busy-wait. */
  3045. + while((*R_DMA_CH8_SUB3_EP == virt_to_phys(&TxIsocEPList[epid])) &&
  3046. + (timeout-- > 0));
  3047. + if(timeout == 0) {
  3048. + warn("Timeout while waiting for DMA-TX-Isoc to leave EP for epid:%d\n", epid);
  3049. + }
  3050. + }
  3051. +
  3052. + /* Unlink SB to say that epid is finished. */
  3053. + TxIsocEPList[epid].sub = 0;
  3054. + TxIsocEPList[epid].hw_len = 0;
  3055. +
  3056. + /* No URB active for EP anymore */
  3057. + activeUrbList[epid] = NULL;
  3058. + }
  3059. + } else { /* Finishing of not active URB (queued up with SBs thought) */
  3060. + isoc_warn("finish_isoc_urb (URB:0x%x %s) (%d of %d packets) status:%d,"
  3061. + " SB queued but not active\n",
  3062. + (unsigned int)urb, str_dir(urb->pipe),
  3063. + urb_priv->isoc_packet_counter, urb->number_of_packets,
  3064. + urb->status);
  3065. + if(usb_pipeout(urb->pipe)) {
  3066. + /* Finishing of not yet active Out Isoc URB needs unlinking of SBs. */
  3067. + struct USB_SB_Desc *iter_sb, *prev_sb, *next_sb;
  3068. +
  3069. + iter_sb = TxIsocEPList[epid].sub ?
  3070. + phys_to_virt(TxIsocEPList[epid].sub) : 0;
  3071. + prev_sb = 0;
  3072. +
  3073. + /* SB that is linked before this URBs first SB */
  3074. + while (iter_sb && (iter_sb != urb_priv->first_sb)) {
  3075. + prev_sb = iter_sb;
  3076. + iter_sb = iter_sb->next ? phys_to_virt(iter_sb->next) : 0;
  3077. + }
  3078. +
  3079. + if (iter_sb == 0) {
  3080. + /* Unlink of the URB currently being transmitted. */
  3081. + prev_sb = 0;
  3082. + iter_sb = TxIsocEPList[epid].sub ? phys_to_virt(TxIsocEPList[epid].sub) : 0;
  3083. + }
  3084. +
  3085. + while (iter_sb && (iter_sb != urb_priv->last_sb)) {
  3086. + iter_sb = iter_sb->next ? phys_to_virt(iter_sb->next) : 0;
  3087. + }
  3088. +
  3089. + if (iter_sb) {
  3090. + next_sb = iter_sb->next ? phys_to_virt(iter_sb->next) : 0;
  3091. + } else {
  3092. + /* This should only happen if the DMA has completed
  3093. + processing the SB list for this EP while interrupts
  3094. + are disabled. */
  3095. + isoc_dbg("Isoc urb not found, already sent?\n");
  3096. + next_sb = 0;
  3097. + }
  3098. + if (prev_sb) {
  3099. + prev_sb->next = next_sb ? virt_to_phys(next_sb) : 0;
  3100. + } else {
  3101. + TxIsocEPList[epid].sub = next_sb ? virt_to_phys(next_sb) : 0;
  3102. + }
  3103. + }
  3104. + }
  3105. +
  3106. + /* Free HC-private URB data*/
  3107. + urb_priv_free(hcd, urb);
  3108. +
  3109. + usb_release_bandwidth(urb->dev, urb, 0);
  3110. +
  3111. + /* Hand the URB from HCD to its USB device driver, using its completion
  3112. + functions */
  3113. + usb_hcd_giveback_urb (hcd, urb);
  3114. +}
  3115. +#endif
  3116. +
  3117. +static __u32 urb_num = 0;
  3118. +
  3119. +/* allocate and initialize URB private data */
  3120. +static int urb_priv_create(struct usb_hcd *hcd, struct urb *urb, int epid,
  3121. + int mem_flags) {
  3122. + struct crisv10_urb_priv *urb_priv;
  3123. +
  3124. + urb_priv = kmalloc(sizeof *urb_priv, mem_flags);
  3125. + if (!urb_priv)
  3126. + return -ENOMEM;
  3127. + memset(urb_priv, 0, sizeof *urb_priv);
  3128. +
  3129. + urb_priv->epid = epid;
  3130. + urb_priv->urb_state = NOT_STARTED;
  3131. +
  3132. + urb->hcpriv = urb_priv;
  3133. + /* Assign URB a sequence number, and increment counter */
  3134. + urb_priv->urb_num = urb_num;
  3135. + urb_num++;
  3136. + return 0;
  3137. +}
  3138. +
  3139. +/* free URB private data */
  3140. +static void urb_priv_free(struct usb_hcd *hcd, struct urb *urb) {
  3141. + int i;
  3142. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  3143. + ASSERT(urb_priv != 0);
  3144. +
  3145. + /* Check it has any SBs linked that needs to be freed*/
  3146. + if(urb_priv->first_sb != NULL) {
  3147. + struct USB_SB_Desc *next_sb, *first_sb, *last_sb;
  3148. + int i = 0;
  3149. + first_sb = urb_priv->first_sb;
  3150. + last_sb = urb_priv->last_sb;
  3151. + ASSERT(last_sb);
  3152. + while(first_sb != last_sb) {
  3153. + next_sb = (struct USB_SB_Desc *)phys_to_virt(first_sb->next);
  3154. + kmem_cache_free(usb_desc_cache, first_sb);
  3155. + first_sb = next_sb;
  3156. + i++;
  3157. + }
  3158. + kmem_cache_free(usb_desc_cache, last_sb);
  3159. + i++;
  3160. + }
  3161. +
  3162. + /* Check if it has any EPs in its Intr pool that also needs to be freed */
  3163. + if(urb_priv->intr_ep_pool_length > 0) {
  3164. + for(i = 0; i < urb_priv->intr_ep_pool_length; i++) {
  3165. + kfree(urb_priv->intr_ep_pool[i]);
  3166. + }
  3167. + /*
  3168. + tc_dbg("Freed %d EPs from URB:0x%x EP pool\n",
  3169. + urb_priv->intr_ep_pool_length, (unsigned int)urb);
  3170. + */
  3171. + }
  3172. +
  3173. + kfree(urb_priv);
  3174. + urb->hcpriv = NULL;
  3175. +}
  3176. +
  3177. +static int ep_priv_create(struct usb_host_endpoint *ep, int mem_flags) {
  3178. + struct crisv10_ep_priv *ep_priv;
  3179. +
  3180. + ep_priv = kmalloc(sizeof *ep_priv, mem_flags);
  3181. + if (!ep_priv)
  3182. + return -ENOMEM;
  3183. + memset(ep_priv, 0, sizeof *ep_priv);
  3184. +
  3185. + ep->hcpriv = ep_priv;
  3186. + return 0;
  3187. +}
  3188. +
  3189. +static void ep_priv_free(struct usb_host_endpoint *ep) {
  3190. + struct crisv10_ep_priv *ep_priv = ep->hcpriv;
  3191. + ASSERT(ep_priv);
  3192. + kfree(ep_priv);
  3193. + ep->hcpriv = NULL;
  3194. +}
  3195. +
  3196. +/* EPID handling functions, managing EP-list in Etrax through wrappers */
  3197. +/* ------------------------------------------------------------------- */
  3198. +
  3199. +/* Sets up a new EPID for an endpoint or returns existing if found */
  3200. +//static int tc_setup_epid(struct usb_host_endpoint *ep, struct urb *urb,
  3201. +// int mem_flags) {
  3202. +static int tc_setup_epid(struct urb *urb, int mem_flags)
  3203. +{
  3204. + int epid;
  3205. + char devnum, endpoint, out_traffic, slow;
  3206. + int maxlen;
  3207. + __u32 epid_data;
  3208. + struct usb_host_endpoint *ep = urb->ep;
  3209. + struct crisv10_ep_priv *ep_priv = ep->hcpriv;
  3210. +
  3211. + DBFENTER;
  3212. +
  3213. + /* Check if a valid epid already is setup for this endpoint */
  3214. + if(ep_priv != NULL) {
  3215. + return ep_priv->epid;
  3216. + }
  3217. +
  3218. + /* We must find and initiate a new epid for this urb. */
  3219. + epid = tc_allocate_epid();
  3220. +
  3221. + if (epid == -1) {
  3222. + /* Failed to allocate a new epid. */
  3223. + DBFEXIT;
  3224. + return epid;
  3225. + }
  3226. +
  3227. + /* We now have a new epid to use. Claim it. */
  3228. + epid_state[epid].inuse = 1;
  3229. +
  3230. + /* Init private data for new endpoint */
  3231. + if(ep_priv_create(ep, mem_flags) != 0) {
  3232. + return -ENOMEM;
  3233. + }
  3234. + ep_priv = ep->hcpriv;
  3235. + ep_priv->epid = epid;
  3236. +
  3237. + devnum = usb_pipedevice(urb->pipe);
  3238. + endpoint = usb_pipeendpoint(urb->pipe);
  3239. + slow = (urb->dev->speed == USB_SPEED_LOW);
  3240. + maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
  3241. +
  3242. + if (usb_pipetype(urb->pipe) == PIPE_CONTROL) {
  3243. + /* We want both IN and OUT control traffic to be put on the same
  3244. + EP/SB list. */
  3245. + out_traffic = 1;
  3246. + } else {
  3247. + out_traffic = usb_pipeout(urb->pipe);
  3248. + }
  3249. +
  3250. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  3251. + epid_data = IO_STATE(R_USB_EPT_DATA_ISO, valid, yes) |
  3252. + /* FIXME: Change any to the actual port? */
  3253. + IO_STATE(R_USB_EPT_DATA_ISO, port, any) |
  3254. + IO_FIELD(R_USB_EPT_DATA_ISO, max_len, maxlen) |
  3255. + IO_FIELD(R_USB_EPT_DATA_ISO, ep, endpoint) |
  3256. + IO_FIELD(R_USB_EPT_DATA_ISO, dev, devnum);
  3257. + etrax_epid_iso_set(epid, epid_data);
  3258. + } else {
  3259. + epid_data = IO_STATE(R_USB_EPT_DATA, valid, yes) |
  3260. + IO_FIELD(R_USB_EPT_DATA, low_speed, slow) |
  3261. + /* FIXME: Change any to the actual port? */
  3262. + IO_STATE(R_USB_EPT_DATA, port, any) |
  3263. + IO_FIELD(R_USB_EPT_DATA, max_len, maxlen) |
  3264. + IO_FIELD(R_USB_EPT_DATA, ep, endpoint) |
  3265. + IO_FIELD(R_USB_EPT_DATA, dev, devnum);
  3266. + etrax_epid_set(epid, epid_data);
  3267. + }
  3268. +
  3269. + epid_state[epid].out_traffic = out_traffic;
  3270. + epid_state[epid].type = usb_pipetype(urb->pipe);
  3271. +
  3272. + tc_warn("Setting up ep:0x%x epid:%d (addr:%d endp:%d max_len:%d %s %s %s)\n",
  3273. + (unsigned int)ep, epid, devnum, endpoint, maxlen,
  3274. + str_type(urb->pipe), out_traffic ? "out" : "in",
  3275. + slow ? "low" : "full");
  3276. +
  3277. + /* Enable Isoc eof interrupt if we set up the first Isoc epid */
  3278. + if(usb_pipeisoc(urb->pipe)) {
  3279. + isoc_epid_counter++;
  3280. + if(isoc_epid_counter == 1) {
  3281. + isoc_warn("Enabled Isoc eof interrupt\n");
  3282. + *R_USB_IRQ_MASK_SET |= IO_STATE(R_USB_IRQ_MASK_SET, iso_eof, set);
  3283. + }
  3284. + }
  3285. +
  3286. + DBFEXIT;
  3287. + return epid;
  3288. +}
  3289. +
  3290. +static void tc_free_epid(struct usb_host_endpoint *ep) {
  3291. + unsigned long flags;
  3292. + struct crisv10_ep_priv *ep_priv = ep->hcpriv;
  3293. + int epid;
  3294. + volatile int timeout = 10000;
  3295. +
  3296. + DBFENTER;
  3297. +
  3298. + if (ep_priv == NULL) {
  3299. + tc_warn("Trying to free unused epid on ep:0x%x\n", (unsigned int)ep);
  3300. + DBFEXIT;
  3301. + return;
  3302. + }
  3303. +
  3304. + epid = ep_priv->epid;
  3305. +
  3306. + /* Disable Isoc eof interrupt if we free the last Isoc epid */
  3307. + if(epid_isoc(epid)) {
  3308. + ASSERT(isoc_epid_counter > 0);
  3309. + isoc_epid_counter--;
  3310. + if(isoc_epid_counter == 0) {
  3311. + *R_USB_IRQ_MASK_SET &= ~IO_STATE(R_USB_IRQ_MASK_SET, iso_eof, set);
  3312. + isoc_warn("Disabled Isoc eof interrupt\n");
  3313. + }
  3314. + }
  3315. +
  3316. + /* Take lock manualy instead of in epid_x_x wrappers,
  3317. + because we need to be polling here */
  3318. + spin_lock_irqsave(&etrax_epid_lock, flags);
  3319. +
  3320. + *R_USB_EPT_INDEX = IO_FIELD(R_USB_EPT_INDEX, value, epid);
  3321. + nop();
  3322. + while((*R_USB_EPT_DATA & IO_MASK(R_USB_EPT_DATA, hold)) &&
  3323. + (timeout-- > 0));
  3324. + if(timeout == 0) {
  3325. + warn("Timeout while waiting for epid:%d to drop hold\n", epid);
  3326. + }
  3327. + /* This will, among other things, set the valid field to 0. */
  3328. + *R_USB_EPT_DATA = 0;
  3329. + spin_unlock_irqrestore(&etrax_epid_lock, flags);
  3330. +
  3331. + /* Free resource in software state info list */
  3332. + epid_state[epid].inuse = 0;
  3333. +
  3334. + /* Free private endpoint data */
  3335. + ep_priv_free(ep);
  3336. +
  3337. + DBFEXIT;
  3338. +}
  3339. +
  3340. +static int tc_allocate_epid(void) {
  3341. + int i;
  3342. + DBFENTER;
  3343. + for (i = 0; i < NBR_OF_EPIDS; i++) {
  3344. + if (!epid_inuse(i)) {
  3345. + DBFEXIT;
  3346. + return i;
  3347. + }
  3348. + }
  3349. +
  3350. + tc_warn("Found no free epids\n");
  3351. + DBFEXIT;
  3352. + return -1;
  3353. +}
  3354. +
  3355. +
  3356. +/* Wrappers around the list functions (include/linux/list.h). */
  3357. +/* ---------------------------------------------------------- */
  3358. +static inline int __urb_list_empty(int epid) {
  3359. + int retval;
  3360. + retval = list_empty(&urb_list[epid]);
  3361. + return retval;
  3362. +}
  3363. +
  3364. +/* Returns first urb for this epid, or NULL if list is empty. */
  3365. +static inline struct urb *urb_list_first(int epid) {
  3366. + unsigned long flags;
  3367. + struct urb *first_urb = 0;
  3368. + spin_lock_irqsave(&urb_list_lock, flags);
  3369. + if (!__urb_list_empty(epid)) {
  3370. + /* Get the first urb (i.e. head->next). */
  3371. + urb_entry_t *urb_entry = list_entry((&urb_list[epid])->next, urb_entry_t, list);
  3372. + first_urb = urb_entry->urb;
  3373. + }
  3374. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3375. + return first_urb;
  3376. +}
  3377. +
  3378. +/* Adds an urb_entry last in the list for this epid. */
  3379. +static inline void urb_list_add(struct urb *urb, int epid, int mem_flags) {
  3380. + unsigned long flags;
  3381. + urb_entry_t *urb_entry = (urb_entry_t *)kmalloc(sizeof(urb_entry_t), mem_flags);
  3382. + ASSERT(urb_entry);
  3383. +
  3384. + urb_entry->urb = urb;
  3385. + spin_lock_irqsave(&urb_list_lock, flags);
  3386. + list_add_tail(&urb_entry->list, &urb_list[epid]);
  3387. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3388. +}
  3389. +
  3390. +/* Search through the list for an element that contains this urb. (The list
  3391. + is expected to be short and the one we are about to delete will often be
  3392. + the first in the list.)
  3393. + Should be protected by spin_locks in calling function */
  3394. +static inline urb_entry_t *__urb_list_entry(struct urb *urb, int epid) {
  3395. + struct list_head *entry;
  3396. + struct list_head *tmp;
  3397. + urb_entry_t *urb_entry;
  3398. +
  3399. + list_for_each_safe(entry, tmp, &urb_list[epid]) {
  3400. + urb_entry = list_entry(entry, urb_entry_t, list);
  3401. + ASSERT(urb_entry);
  3402. + ASSERT(urb_entry->urb);
  3403. +
  3404. + if (urb_entry->urb == urb) {
  3405. + return urb_entry;
  3406. + }
  3407. + }
  3408. + return 0;
  3409. +}
  3410. +
  3411. +/* Same function as above but for global use. Protects list by spinlock */
  3412. +static inline urb_entry_t *urb_list_entry(struct urb *urb, int epid) {
  3413. + unsigned long flags;
  3414. + urb_entry_t *urb_entry;
  3415. + spin_lock_irqsave(&urb_list_lock, flags);
  3416. + urb_entry = __urb_list_entry(urb, epid);
  3417. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3418. + return (urb_entry);
  3419. +}
  3420. +
  3421. +/* Delete an urb from the list. */
  3422. +static inline void urb_list_del(struct urb *urb, int epid) {
  3423. + unsigned long flags;
  3424. + urb_entry_t *urb_entry;
  3425. +
  3426. + /* Delete entry and free. */
  3427. + spin_lock_irqsave(&urb_list_lock, flags);
  3428. + urb_entry = __urb_list_entry(urb, epid);
  3429. + ASSERT(urb_entry);
  3430. +
  3431. + list_del(&urb_entry->list);
  3432. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3433. + kfree(urb_entry);
  3434. +}
  3435. +
  3436. +/* Move an urb to the end of the list. */
  3437. +static inline void urb_list_move_last(struct urb *urb, int epid) {
  3438. + unsigned long flags;
  3439. + urb_entry_t *urb_entry;
  3440. +
  3441. + spin_lock_irqsave(&urb_list_lock, flags);
  3442. + urb_entry = __urb_list_entry(urb, epid);
  3443. + ASSERT(urb_entry);
  3444. +
  3445. + list_del(&urb_entry->list);
  3446. + list_add_tail(&urb_entry->list, &urb_list[epid]);
  3447. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3448. +}
  3449. +
  3450. +/* Get the next urb in the list. */
  3451. +static inline struct urb *urb_list_next(struct urb *urb, int epid) {
  3452. + unsigned long flags;
  3453. + urb_entry_t *urb_entry;
  3454. +
  3455. + spin_lock_irqsave(&urb_list_lock, flags);
  3456. + urb_entry = __urb_list_entry(urb, epid);
  3457. + ASSERT(urb_entry);
  3458. +
  3459. + if (urb_entry->list.next != &urb_list[epid]) {
  3460. + struct list_head *elem = urb_entry->list.next;
  3461. + urb_entry = list_entry(elem, urb_entry_t, list);
  3462. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3463. + return urb_entry->urb;
  3464. + } else {
  3465. + spin_unlock_irqrestore(&urb_list_lock, flags);
  3466. + return NULL;
  3467. + }
  3468. +}
  3469. +
  3470. +struct USB_EP_Desc* create_ep(int epid, struct USB_SB_Desc* sb_desc,
  3471. + int mem_flags) {
  3472. + struct USB_EP_Desc *ep_desc;
  3473. + ep_desc = (struct USB_EP_Desc *) kmem_cache_alloc(usb_desc_cache, mem_flags);
  3474. + if(ep_desc == NULL)
  3475. + return NULL;
  3476. + memset(ep_desc, 0, sizeof(struct USB_EP_Desc));
  3477. +
  3478. + ep_desc->hw_len = 0;
  3479. + ep_desc->command = (IO_FIELD(USB_EP_command, epid, epid) |
  3480. + IO_STATE(USB_EP_command, enable, yes));
  3481. + if(sb_desc == NULL) {
  3482. + ep_desc->sub = 0;
  3483. + } else {
  3484. + ep_desc->sub = virt_to_phys(sb_desc);
  3485. + }
  3486. + return ep_desc;
  3487. +}
  3488. +
  3489. +#define TT_ZOUT 0
  3490. +#define TT_IN 1
  3491. +#define TT_OUT 2
  3492. +#define TT_SETUP 3
  3493. +
  3494. +#define CMD_EOL IO_STATE(USB_SB_command, eol, yes)
  3495. +#define CMD_INTR IO_STATE(USB_SB_command, intr, yes)
  3496. +#define CMD_FULL IO_STATE(USB_SB_command, full, yes)
  3497. +
  3498. +/* Allocation and setup of a generic SB. Used to create SETUP, OUT and ZOUT
  3499. + SBs. Also used by create_sb_in() to avoid same allocation procedure at two
  3500. + places */
  3501. +struct USB_SB_Desc* create_sb(struct USB_SB_Desc* sb_prev, int tt, void* data,
  3502. + int datalen, int mem_flags) {
  3503. + struct USB_SB_Desc *sb_desc;
  3504. + sb_desc = (struct USB_SB_Desc*)kmem_cache_alloc(usb_desc_cache, mem_flags);
  3505. + if(sb_desc == NULL)
  3506. + return NULL;
  3507. + memset(sb_desc, 0, sizeof(struct USB_SB_Desc));
  3508. +
  3509. + sb_desc->command = IO_FIELD(USB_SB_command, tt, tt) |
  3510. + IO_STATE(USB_SB_command, eot, yes);
  3511. +
  3512. + sb_desc->sw_len = datalen;
  3513. + if(data != NULL) {
  3514. + sb_desc->buf = virt_to_phys(data);
  3515. + } else {
  3516. + sb_desc->buf = 0;
  3517. + }
  3518. + if(sb_prev != NULL) {
  3519. + sb_prev->next = virt_to_phys(sb_desc);
  3520. + }
  3521. + return sb_desc;
  3522. +}
  3523. +
  3524. +/* Creates a copy of an existing SB by allocation space for it and copy
  3525. + settings */
  3526. +struct USB_SB_Desc* create_sb_copy(struct USB_SB_Desc* sb_orig, int mem_flags) {
  3527. + struct USB_SB_Desc *sb_desc;
  3528. + sb_desc = (struct USB_SB_Desc*)kmem_cache_alloc(usb_desc_cache, mem_flags);
  3529. + if(sb_desc == NULL)
  3530. + return NULL;
  3531. +
  3532. + memcpy(sb_desc, sb_orig, sizeof(struct USB_SB_Desc));
  3533. + return sb_desc;
  3534. +}
  3535. +
  3536. +/* A specific create_sb function for creation of in SBs. This is due to
  3537. + that datalen in In SBs shows how many packets we are expecting. It also
  3538. + sets up the rem field to show if how many bytes we expect in last packet
  3539. + if it's not a full one */
  3540. +struct USB_SB_Desc* create_sb_in(struct USB_SB_Desc* sb_prev, int datalen,
  3541. + int maxlen, int mem_flags) {
  3542. + struct USB_SB_Desc *sb_desc;
  3543. + sb_desc = create_sb(sb_prev, TT_IN, NULL,
  3544. + datalen ? (datalen - 1) / maxlen + 1 : 0, mem_flags);
  3545. + if(sb_desc == NULL)
  3546. + return NULL;
  3547. + sb_desc->command |= IO_FIELD(USB_SB_command, rem, datalen % maxlen);
  3548. + return sb_desc;
  3549. +}
  3550. +
  3551. +void set_sb_cmds(struct USB_SB_Desc *sb_desc, __u16 flags) {
  3552. + sb_desc->command |= flags;
  3553. +}
  3554. +
  3555. +int create_sb_for_urb(struct urb *urb, int mem_flags) {
  3556. + int is_out = !usb_pipein(urb->pipe);
  3557. + int type = usb_pipetype(urb->pipe);
  3558. + int maxlen = usb_maxpacket(urb->dev, urb->pipe, is_out);
  3559. + int buf_len = urb->transfer_buffer_length;
  3560. + void *buf = buf_len > 0 ? urb->transfer_buffer : NULL;
  3561. + struct USB_SB_Desc *sb_desc = NULL;
  3562. +
  3563. + struct crisv10_urb_priv *urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  3564. + ASSERT(urb_priv != NULL);
  3565. +
  3566. + switch(type) {
  3567. + case PIPE_CONTROL:
  3568. + /* Setup stage */
  3569. + sb_desc = create_sb(NULL, TT_SETUP, urb->setup_packet, 8, mem_flags);
  3570. + if(sb_desc == NULL)
  3571. + return -ENOMEM;
  3572. + set_sb_cmds(sb_desc, CMD_FULL);
  3573. +
  3574. + /* Attach first SB to URB */
  3575. + urb_priv->first_sb = sb_desc;
  3576. +
  3577. + if (is_out) { /* Out Control URB */
  3578. + /* If this Control OUT transfer has an optional data stage we add
  3579. + an OUT token before the mandatory IN (status) token */
  3580. + if ((buf_len > 0) && buf) {
  3581. + sb_desc = create_sb(sb_desc, TT_OUT, buf, buf_len, mem_flags);
  3582. + if(sb_desc == NULL)
  3583. + return -ENOMEM;
  3584. + set_sb_cmds(sb_desc, CMD_FULL);
  3585. + }
  3586. +
  3587. + /* Status stage */
  3588. + /* The data length has to be exactly 1. This is due to a requirement
  3589. + of the USB specification that a host must be prepared to receive
  3590. + data in the status phase */
  3591. + sb_desc = create_sb(sb_desc, TT_IN, NULL, 1, mem_flags);
  3592. + if(sb_desc == NULL)
  3593. + return -ENOMEM;
  3594. + } else { /* In control URB */
  3595. + /* Data stage */
  3596. + sb_desc = create_sb_in(sb_desc, buf_len, maxlen, mem_flags);
  3597. + if(sb_desc == NULL)
  3598. + return -ENOMEM;
  3599. +
  3600. + /* Status stage */
  3601. + /* Read comment at zout_buffer declaration for an explanation to this. */
  3602. + sb_desc = create_sb(sb_desc, TT_ZOUT, &zout_buffer[0], 1, mem_flags);
  3603. + if(sb_desc == NULL)
  3604. + return -ENOMEM;
  3605. + /* Set descriptor interrupt flag for in URBs so we can finish URB after
  3606. + zout-packet has been sent */
  3607. + set_sb_cmds(sb_desc, CMD_INTR | CMD_FULL);
  3608. + }
  3609. + /* Set end-of-list flag in last SB */
  3610. + set_sb_cmds(sb_desc, CMD_EOL);
  3611. + /* Attach last SB to URB */
  3612. + urb_priv->last_sb = sb_desc;
  3613. + break;
  3614. +
  3615. + case PIPE_BULK:
  3616. + if (is_out) { /* Out Bulk URB */
  3617. + sb_desc = create_sb(NULL, TT_OUT, buf, buf_len, mem_flags);
  3618. + if(sb_desc == NULL)
  3619. + return -ENOMEM;
  3620. + /* The full field is set to yes, even if we don't actually check that
  3621. + this is a full-length transfer (i.e., that transfer_buffer_length %
  3622. + maxlen = 0).
  3623. + Setting full prevents the USB controller from sending an empty packet
  3624. + in that case. However, if URB_ZERO_PACKET was set we want that. */
  3625. + if (!(urb->transfer_flags & URB_ZERO_PACKET)) {
  3626. + set_sb_cmds(sb_desc, CMD_FULL);
  3627. + }
  3628. + } else { /* In Bulk URB */
  3629. + sb_desc = create_sb_in(NULL, buf_len, maxlen, mem_flags);
  3630. + if(sb_desc == NULL)
  3631. + return -ENOMEM;
  3632. + }
  3633. + /* Set end-of-list flag for last SB */
  3634. + set_sb_cmds(sb_desc, CMD_EOL);
  3635. +
  3636. + /* Attach SB to URB */
  3637. + urb_priv->first_sb = sb_desc;
  3638. + urb_priv->last_sb = sb_desc;
  3639. + break;
  3640. +
  3641. + case PIPE_INTERRUPT:
  3642. + if(is_out) { /* Out Intr URB */
  3643. + sb_desc = create_sb(NULL, TT_OUT, buf, buf_len, mem_flags);
  3644. + if(sb_desc == NULL)
  3645. + return -ENOMEM;
  3646. +
  3647. + /* The full field is set to yes, even if we don't actually check that
  3648. + this is a full-length transfer (i.e., that transfer_buffer_length %
  3649. + maxlen = 0).
  3650. + Setting full prevents the USB controller from sending an empty packet
  3651. + in that case. However, if URB_ZERO_PACKET was set we want that. */
  3652. + if (!(urb->transfer_flags & URB_ZERO_PACKET)) {
  3653. + set_sb_cmds(sb_desc, CMD_FULL);
  3654. + }
  3655. + /* Only generate TX interrupt if it's a Out URB*/
  3656. + set_sb_cmds(sb_desc, CMD_INTR);
  3657. +
  3658. + } else { /* In Intr URB */
  3659. + sb_desc = create_sb_in(NULL, buf_len, maxlen, mem_flags);
  3660. + if(sb_desc == NULL)
  3661. + return -ENOMEM;
  3662. + }
  3663. + /* Set end-of-list flag for last SB */
  3664. + set_sb_cmds(sb_desc, CMD_EOL);
  3665. +
  3666. + /* Attach SB to URB */
  3667. + urb_priv->first_sb = sb_desc;
  3668. + urb_priv->last_sb = sb_desc;
  3669. +
  3670. + break;
  3671. + case PIPE_ISOCHRONOUS:
  3672. + if(is_out) { /* Out Isoc URB */
  3673. + int i;
  3674. + if(urb->number_of_packets == 0) {
  3675. + tc_err("Can't create SBs for Isoc URB with zero packets\n");
  3676. + return -EPIPE;
  3677. + }
  3678. + /* Create one SB descriptor for each packet and link them together. */
  3679. + for(i = 0; i < urb->number_of_packets; i++) {
  3680. + if (urb->iso_frame_desc[i].length > 0) {
  3681. +
  3682. + sb_desc = create_sb(sb_desc, TT_OUT, urb->transfer_buffer +
  3683. + urb->iso_frame_desc[i].offset,
  3684. + urb->iso_frame_desc[i].length, mem_flags);
  3685. + if(sb_desc == NULL)
  3686. + return -ENOMEM;
  3687. +
  3688. + /* Check if it's a full length packet */
  3689. + if (urb->iso_frame_desc[i].length ==
  3690. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe))) {
  3691. + set_sb_cmds(sb_desc, CMD_FULL);
  3692. + }
  3693. +
  3694. + } else { /* zero length packet */
  3695. + sb_desc = create_sb(sb_desc, TT_ZOUT, &zout_buffer[0], 1, mem_flags);
  3696. + if(sb_desc == NULL)
  3697. + return -ENOMEM;
  3698. + set_sb_cmds(sb_desc, CMD_FULL);
  3699. + }
  3700. + /* Attach first SB descriptor to URB */
  3701. + if (i == 0) {
  3702. + urb_priv->first_sb = sb_desc;
  3703. + }
  3704. + }
  3705. + /* Set interrupt and end-of-list flags in last SB */
  3706. + set_sb_cmds(sb_desc, CMD_INTR | CMD_EOL);
  3707. + /* Attach last SB descriptor to URB */
  3708. + urb_priv->last_sb = sb_desc;
  3709. + tc_dbg("Created %d out SBs for Isoc URB:0x%x\n",
  3710. + urb->number_of_packets, (unsigned int)urb);
  3711. + } else { /* In Isoc URB */
  3712. + /* Actual number of packets is not relevant for periodic in traffic as
  3713. + long as it is more than zero. Set to 1 always. */
  3714. + sb_desc = create_sb(sb_desc, TT_IN, NULL, 1, mem_flags);
  3715. + if(sb_desc == NULL)
  3716. + return -ENOMEM;
  3717. + /* Set end-of-list flags for SB */
  3718. + set_sb_cmds(sb_desc, CMD_EOL);
  3719. +
  3720. + /* Attach SB to URB */
  3721. + urb_priv->first_sb = sb_desc;
  3722. + urb_priv->last_sb = sb_desc;
  3723. + }
  3724. + break;
  3725. + default:
  3726. + tc_err("Unknown pipe-type\n");
  3727. + return -EPIPE;
  3728. + break;
  3729. + }
  3730. + return 0;
  3731. +}
  3732. +
  3733. +int init_intr_urb(struct urb *urb, int mem_flags) {
  3734. + struct crisv10_urb_priv *urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  3735. + struct USB_EP_Desc* ep_desc;
  3736. + int interval;
  3737. + int i;
  3738. + int ep_count;
  3739. +
  3740. + ASSERT(urb_priv != NULL);
  3741. + ASSERT(usb_pipeint(urb->pipe));
  3742. + /* We can't support interval longer than amount of eof descriptors in
  3743. + TxIntrEPList */
  3744. + if(urb->interval > MAX_INTR_INTERVAL) {
  3745. + tc_err("Interrupt interval %dms too big (max: %dms)\n", urb->interval,
  3746. + MAX_INTR_INTERVAL);
  3747. + return -EINVAL;
  3748. + }
  3749. +
  3750. + /* We assume that the SB descriptors already have been setup */
  3751. + ASSERT(urb_priv->first_sb != NULL);
  3752. +
  3753. + /* Round of the interval to 2^n, it is obvious that this code favours
  3754. + smaller numbers, but that is actually a good thing */
  3755. + /* FIXME: The "rounding error" for larger intervals will be quite
  3756. + large. For in traffic this shouldn't be a problem since it will only
  3757. + mean that we "poll" more often. */
  3758. + interval = urb->interval;
  3759. + for (i = 0; interval; i++) {
  3760. + interval = interval >> 1;
  3761. + }
  3762. + urb_priv->interval = 1 << (i - 1);
  3763. +
  3764. + /* We can only have max interval for Out Interrupt due to that we can only
  3765. + handle one linked in EP for a certain epid in the Intr descr array at the
  3766. + time. The USB Controller in the Etrax 100LX continues to process Intr EPs
  3767. + so we have no way of knowing which one that caused the actual transfer if
  3768. + we have several linked in. */
  3769. + if(usb_pipeout(urb->pipe)) {
  3770. + urb_priv->interval = MAX_INTR_INTERVAL;
  3771. + }
  3772. +
  3773. + /* Calculate amount of EPs needed */
  3774. + ep_count = MAX_INTR_INTERVAL / urb_priv->interval;
  3775. +
  3776. + for(i = 0; i < ep_count; i++) {
  3777. + ep_desc = create_ep(urb_priv->epid, urb_priv->first_sb, mem_flags);
  3778. + if(ep_desc == NULL) {
  3779. + /* Free any descriptors that we may have allocated before failure */
  3780. + while(i > 0) {
  3781. + i--;
  3782. + kfree(urb_priv->intr_ep_pool[i]);
  3783. + }
  3784. + return -ENOMEM;
  3785. + }
  3786. + urb_priv->intr_ep_pool[i] = ep_desc;
  3787. + }
  3788. + urb_priv->intr_ep_pool_length = ep_count;
  3789. + return 0;
  3790. +}
  3791. +
  3792. +/* DMA RX/TX functions */
  3793. +/* ----------------------- */
  3794. +
  3795. +static void tc_dma_init_rx_list(void) {
  3796. + int i;
  3797. +
  3798. + /* Setup descriptor list except last one */
  3799. + for (i = 0; i < (NBR_OF_RX_DESC - 1); i++) {
  3800. + RxDescList[i].sw_len = RX_DESC_BUF_SIZE;
  3801. + RxDescList[i].command = 0;
  3802. + RxDescList[i].next = virt_to_phys(&RxDescList[i + 1]);
  3803. + RxDescList[i].buf = virt_to_phys(RxBuf + (i * RX_DESC_BUF_SIZE));
  3804. + RxDescList[i].hw_len = 0;
  3805. + RxDescList[i].status = 0;
  3806. +
  3807. + /* DMA IN cache bug. (struct etrax_dma_descr has the same layout as
  3808. + USB_IN_Desc for the relevant fields.) */
  3809. + prepare_rx_descriptor((struct etrax_dma_descr*)&RxDescList[i]);
  3810. +
  3811. + }
  3812. + /* Special handling of last descriptor */
  3813. + RxDescList[i].sw_len = RX_DESC_BUF_SIZE;
  3814. + RxDescList[i].command = IO_STATE(USB_IN_command, eol, yes);
  3815. + RxDescList[i].next = virt_to_phys(&RxDescList[0]);
  3816. + RxDescList[i].buf = virt_to_phys(RxBuf + (i * RX_DESC_BUF_SIZE));
  3817. + RxDescList[i].hw_len = 0;
  3818. + RxDescList[i].status = 0;
  3819. +
  3820. + /* Setup list pointers that show progress in list */
  3821. + myNextRxDesc = &RxDescList[0];
  3822. + myLastRxDesc = &RxDescList[NBR_OF_RX_DESC - 1];
  3823. +
  3824. + flush_etrax_cache();
  3825. + /* Point DMA to first descriptor in list and start it */
  3826. + *R_DMA_CH9_FIRST = virt_to_phys(myNextRxDesc);
  3827. + *R_DMA_CH9_CMD = IO_STATE(R_DMA_CH9_CMD, cmd, start);
  3828. +}
  3829. +
  3830. +
  3831. +static void tc_dma_init_tx_bulk_list(void) {
  3832. + int i;
  3833. + volatile struct USB_EP_Desc *epDescr;
  3834. +
  3835. + for (i = 0; i < (NBR_OF_EPIDS - 1); i++) {
  3836. + epDescr = &(TxBulkEPList[i]);
  3837. + CHECK_ALIGN(epDescr);
  3838. + epDescr->hw_len = 0;
  3839. + epDescr->command = IO_FIELD(USB_EP_command, epid, i);
  3840. + epDescr->sub = 0;
  3841. + epDescr->next = virt_to_phys(&TxBulkEPList[i + 1]);
  3842. +
  3843. + /* Initiate two EPs, disabled and with the eol flag set. No need for any
  3844. + preserved epid. */
  3845. +
  3846. + /* The first one has the intr flag set so we get an interrupt when the DMA
  3847. + channel is about to become disabled. */
  3848. + CHECK_ALIGN(&TxBulkDummyEPList[i][0]);
  3849. + TxBulkDummyEPList[i][0].hw_len = 0;
  3850. + TxBulkDummyEPList[i][0].command = (IO_FIELD(USB_EP_command, epid, DUMMY_EPID) |
  3851. + IO_STATE(USB_EP_command, eol, yes) |
  3852. + IO_STATE(USB_EP_command, intr, yes));
  3853. + TxBulkDummyEPList[i][0].sub = 0;
  3854. + TxBulkDummyEPList[i][0].next = virt_to_phys(&TxBulkDummyEPList[i][1]);
  3855. +
  3856. + /* The second one. */
  3857. + CHECK_ALIGN(&TxBulkDummyEPList[i][1]);
  3858. + TxBulkDummyEPList[i][1].hw_len = 0;
  3859. + TxBulkDummyEPList[i][1].command = (IO_FIELD(USB_EP_command, epid, DUMMY_EPID) |
  3860. + IO_STATE(USB_EP_command, eol, yes));
  3861. + TxBulkDummyEPList[i][1].sub = 0;
  3862. + /* The last dummy's next pointer is the same as the current EP's next pointer. */
  3863. + TxBulkDummyEPList[i][1].next = virt_to_phys(&TxBulkEPList[i + 1]);
  3864. + }
  3865. +
  3866. + /* Special handling of last descr in list, make list circular */
  3867. + epDescr = &TxBulkEPList[i];
  3868. + CHECK_ALIGN(epDescr);
  3869. + epDescr->hw_len = 0;
  3870. + epDescr->command = IO_STATE(USB_EP_command, eol, yes) |
  3871. + IO_FIELD(USB_EP_command, epid, i);
  3872. + epDescr->sub = 0;
  3873. + epDescr->next = virt_to_phys(&TxBulkEPList[0]);
  3874. +
  3875. + /* Init DMA sub-channel pointers to last item in each list */
  3876. + *R_DMA_CH8_SUB0_EP = virt_to_phys(&TxBulkEPList[i]);
  3877. + /* No point in starting the bulk channel yet.
  3878. + *R_DMA_CH8_SUB0_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start); */
  3879. +}
  3880. +
  3881. +static void tc_dma_init_tx_ctrl_list(void) {
  3882. + int i;
  3883. + volatile struct USB_EP_Desc *epDescr;
  3884. +
  3885. + for (i = 0; i < (NBR_OF_EPIDS - 1); i++) {
  3886. + epDescr = &(TxCtrlEPList[i]);
  3887. + CHECK_ALIGN(epDescr);
  3888. + epDescr->hw_len = 0;
  3889. + epDescr->command = IO_FIELD(USB_EP_command, epid, i);
  3890. + epDescr->sub = 0;
  3891. + epDescr->next = virt_to_phys(&TxCtrlEPList[i + 1]);
  3892. + }
  3893. + /* Special handling of last descr in list, make list circular */
  3894. + epDescr = &TxCtrlEPList[i];
  3895. + CHECK_ALIGN(epDescr);
  3896. + epDescr->hw_len = 0;
  3897. + epDescr->command = IO_STATE(USB_EP_command, eol, yes) |
  3898. + IO_FIELD(USB_EP_command, epid, i);
  3899. + epDescr->sub = 0;
  3900. + epDescr->next = virt_to_phys(&TxCtrlEPList[0]);
  3901. +
  3902. + /* Init DMA sub-channel pointers to last item in each list */
  3903. + *R_DMA_CH8_SUB1_EP = virt_to_phys(&TxCtrlEPList[i]);
  3904. + /* No point in starting the ctrl channel yet.
  3905. + *R_DMA_CH8_SUB1_CMD = IO_STATE(R_DMA_CH8_SUB0_CMD, cmd, start); */
  3906. +}
  3907. +
  3908. +
  3909. +static void tc_dma_init_tx_intr_list(void) {
  3910. + int i;
  3911. +
  3912. + TxIntrSB_zout.sw_len = 1;
  3913. + TxIntrSB_zout.next = 0;
  3914. + TxIntrSB_zout.buf = virt_to_phys(&zout_buffer[0]);
  3915. + TxIntrSB_zout.command = (IO_FIELD(USB_SB_command, rem, 0) |
  3916. + IO_STATE(USB_SB_command, tt, zout) |
  3917. + IO_STATE(USB_SB_command, full, yes) |
  3918. + IO_STATE(USB_SB_command, eot, yes) |
  3919. + IO_STATE(USB_SB_command, eol, yes));
  3920. +
  3921. + for (i = 0; i < (MAX_INTR_INTERVAL - 1); i++) {
  3922. + CHECK_ALIGN(&TxIntrEPList[i]);
  3923. + TxIntrEPList[i].hw_len = 0;
  3924. + TxIntrEPList[i].command =
  3925. + (IO_STATE(USB_EP_command, eof, yes) |
  3926. + IO_STATE(USB_EP_command, enable, yes) |
  3927. + IO_FIELD(USB_EP_command, epid, INVALID_EPID));
  3928. + TxIntrEPList[i].sub = virt_to_phys(&TxIntrSB_zout);
  3929. + TxIntrEPList[i].next = virt_to_phys(&TxIntrEPList[i + 1]);
  3930. + }
  3931. +
  3932. + /* Special handling of last descr in list, make list circular */
  3933. + CHECK_ALIGN(&TxIntrEPList[i]);
  3934. + TxIntrEPList[i].hw_len = 0;
  3935. + TxIntrEPList[i].command =
  3936. + (IO_STATE(USB_EP_command, eof, yes) |
  3937. + IO_STATE(USB_EP_command, eol, yes) |
  3938. + IO_STATE(USB_EP_command, enable, yes) |
  3939. + IO_FIELD(USB_EP_command, epid, INVALID_EPID));
  3940. + TxIntrEPList[i].sub = virt_to_phys(&TxIntrSB_zout);
  3941. + TxIntrEPList[i].next = virt_to_phys(&TxIntrEPList[0]);
  3942. +
  3943. + intr_dbg("Initiated Intr EP descriptor list\n");
  3944. +
  3945. +
  3946. + /* Connect DMA 8 sub-channel 2 to first in list */
  3947. + *R_DMA_CH8_SUB2_EP = virt_to_phys(&TxIntrEPList[0]);
  3948. +}
  3949. +
  3950. +static void tc_dma_init_tx_isoc_list(void) {
  3951. + int i;
  3952. +
  3953. + DBFENTER;
  3954. +
  3955. + /* Read comment at zout_buffer declaration for an explanation to this. */
  3956. + TxIsocSB_zout.sw_len = 1;
  3957. + TxIsocSB_zout.next = 0;
  3958. + TxIsocSB_zout.buf = virt_to_phys(&zout_buffer[0]);
  3959. + TxIsocSB_zout.command = (IO_FIELD(USB_SB_command, rem, 0) |
  3960. + IO_STATE(USB_SB_command, tt, zout) |
  3961. + IO_STATE(USB_SB_command, full, yes) |
  3962. + IO_STATE(USB_SB_command, eot, yes) |
  3963. + IO_STATE(USB_SB_command, eol, yes));
  3964. +
  3965. + /* The last isochronous EP descriptor is a dummy. */
  3966. + for (i = 0; i < (NBR_OF_EPIDS - 1); i++) {
  3967. + CHECK_ALIGN(&TxIsocEPList[i]);
  3968. + TxIsocEPList[i].hw_len = 0;
  3969. + TxIsocEPList[i].command = IO_FIELD(USB_EP_command, epid, i);
  3970. + TxIsocEPList[i].sub = 0;
  3971. + TxIsocEPList[i].next = virt_to_phys(&TxIsocEPList[i + 1]);
  3972. + }
  3973. +
  3974. + CHECK_ALIGN(&TxIsocEPList[i]);
  3975. + TxIsocEPList[i].hw_len = 0;
  3976. +
  3977. + /* Must enable the last EP descr to get eof interrupt. */
  3978. + TxIsocEPList[i].command = (IO_STATE(USB_EP_command, enable, yes) |
  3979. + IO_STATE(USB_EP_command, eof, yes) |
  3980. + IO_STATE(USB_EP_command, eol, yes) |
  3981. + IO_FIELD(USB_EP_command, epid, INVALID_EPID));
  3982. + TxIsocEPList[i].sub = virt_to_phys(&TxIsocSB_zout);
  3983. + TxIsocEPList[i].next = virt_to_phys(&TxIsocEPList[0]);
  3984. +
  3985. + *R_DMA_CH8_SUB3_EP = virt_to_phys(&TxIsocEPList[0]);
  3986. + *R_DMA_CH8_SUB3_CMD = IO_STATE(R_DMA_CH8_SUB3_CMD, cmd, start);
  3987. +}
  3988. +
  3989. +static int tc_dma_init(struct usb_hcd *hcd) {
  3990. + tc_dma_init_rx_list();
  3991. + tc_dma_init_tx_bulk_list();
  3992. + tc_dma_init_tx_ctrl_list();
  3993. + tc_dma_init_tx_intr_list();
  3994. + tc_dma_init_tx_isoc_list();
  3995. +
  3996. + if (cris_request_dma(USB_TX_DMA_NBR,
  3997. + "ETRAX 100LX built-in USB (Tx)",
  3998. + DMA_VERBOSE_ON_ERROR,
  3999. + dma_usb)) {
  4000. + err("Could not allocate DMA ch 8 for USB");
  4001. + return -EBUSY;
  4002. + }
  4003. +
  4004. + if (cris_request_dma(USB_RX_DMA_NBR,
  4005. + "ETRAX 100LX built-in USB (Rx)",
  4006. + DMA_VERBOSE_ON_ERROR,
  4007. + dma_usb)) {
  4008. + err("Could not allocate DMA ch 9 for USB");
  4009. + return -EBUSY;
  4010. + }
  4011. +
  4012. + *R_IRQ_MASK2_SET =
  4013. + /* Note that these interrupts are not used. */
  4014. + IO_STATE(R_IRQ_MASK2_SET, dma8_sub0_descr, set) |
  4015. + /* Sub channel 1 (ctrl) descr. interrupts are used. */
  4016. + IO_STATE(R_IRQ_MASK2_SET, dma8_sub1_descr, set) |
  4017. + IO_STATE(R_IRQ_MASK2_SET, dma8_sub2_descr, set) |
  4018. + /* Sub channel 3 (isoc) descr. interrupts are used. */
  4019. + IO_STATE(R_IRQ_MASK2_SET, dma8_sub3_descr, set);
  4020. +
  4021. + /* Note that the dma9_descr interrupt is not used. */
  4022. + *R_IRQ_MASK2_SET =
  4023. + IO_STATE(R_IRQ_MASK2_SET, dma9_eop, set) |
  4024. + IO_STATE(R_IRQ_MASK2_SET, dma9_descr, set);
  4025. +
  4026. + if (request_irq(ETRAX_USB_RX_IRQ, tc_dma_rx_interrupt, 0,
  4027. + "ETRAX 100LX built-in USB (Rx)", hcd)) {
  4028. + err("Could not allocate IRQ %d for USB", ETRAX_USB_RX_IRQ);
  4029. + return -EBUSY;
  4030. + }
  4031. +
  4032. + if (request_irq(ETRAX_USB_TX_IRQ, tc_dma_tx_interrupt, 0,
  4033. + "ETRAX 100LX built-in USB (Tx)", hcd)) {
  4034. + err("Could not allocate IRQ %d for USB", ETRAX_USB_TX_IRQ);
  4035. + return -EBUSY;
  4036. + }
  4037. +
  4038. + return 0;
  4039. +}
  4040. +
  4041. +static void tc_dma_destroy(void) {
  4042. + free_irq(ETRAX_USB_RX_IRQ, NULL);
  4043. + free_irq(ETRAX_USB_TX_IRQ, NULL);
  4044. +
  4045. + cris_free_dma(USB_TX_DMA_NBR, "ETRAX 100LX built-in USB (Tx)");
  4046. + cris_free_dma(USB_RX_DMA_NBR, "ETRAX 100LX built-in USB (Rx)");
  4047. +
  4048. +}
  4049. +
  4050. +static void tc_dma_link_intr_urb(struct urb *urb);
  4051. +
  4052. +/* Handle processing of Bulk, Ctrl and Intr queues */
  4053. +static void tc_dma_process_queue(int epid) {
  4054. + struct urb *urb;
  4055. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  4056. + unsigned long flags;
  4057. + char toggle;
  4058. +
  4059. + if(epid_state[epid].disabled) {
  4060. + /* Don't process any URBs on a disabled endpoint */
  4061. + return;
  4062. + }
  4063. +
  4064. + /* Do not disturb us while fiddling with EPs and epids */
  4065. + local_irq_save(flags);
  4066. +
  4067. + /* For bulk, Ctrl and Intr can we only have one URB active at a time for
  4068. + a specific EP. */
  4069. + if(activeUrbList[epid] != NULL) {
  4070. + /* An URB is already active on EP, skip checking queue */
  4071. + local_irq_restore(flags);
  4072. + return;
  4073. + }
  4074. +
  4075. + urb = urb_list_first(epid);
  4076. + if(urb == NULL) {
  4077. + /* No URB waiting in EP queue. Nothing do to */
  4078. + local_irq_restore(flags);
  4079. + return;
  4080. + }
  4081. +
  4082. + urb_priv = urb->hcpriv;
  4083. + ASSERT(urb_priv != NULL);
  4084. + ASSERT(urb_priv->urb_state == NOT_STARTED);
  4085. + ASSERT(!usb_pipeisoc(urb->pipe));
  4086. +
  4087. + /* Remove this URB from the queue and move it to active */
  4088. + activeUrbList[epid] = urb;
  4089. + urb_list_del(urb, epid);
  4090. +
  4091. + urb_priv->urb_state = STARTED;
  4092. +
  4093. + /* Reset error counters (regardless of which direction this traffic is). */
  4094. + etrax_epid_clear_error(epid);
  4095. +
  4096. + /* Special handling of Intr EP lists */
  4097. + if(usb_pipeint(urb->pipe)) {
  4098. + tc_dma_link_intr_urb(urb);
  4099. + local_irq_restore(flags);
  4100. + return;
  4101. + }
  4102. +
  4103. + /* Software must preset the toggle bits for Bulk and Ctrl */
  4104. + if(usb_pipecontrol(urb->pipe)) {
  4105. + /* Toggle bits are initialized only during setup transaction in a
  4106. + CTRL transfer */
  4107. + etrax_epid_set_toggle(epid, 0, 0);
  4108. + etrax_epid_set_toggle(epid, 1, 0);
  4109. + } else {
  4110. + toggle = usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  4111. + usb_pipeout(urb->pipe));
  4112. + etrax_epid_set_toggle(epid, usb_pipeout(urb->pipe), toggle);
  4113. + }
  4114. +
  4115. + tc_dbg("Added SBs from (URB:0x%x %s %s) to epid %d: %s\n",
  4116. + (unsigned int)urb, str_dir(urb->pipe), str_type(urb->pipe), epid,
  4117. + sblist_to_str(urb_priv->first_sb));
  4118. +
  4119. + /* We start the DMA sub channel without checking if it's running or not,
  4120. + because:
  4121. + 1) If it's already running, issuing the start command is a nop.
  4122. + 2) We avoid a test-and-set race condition. */
  4123. + switch(usb_pipetype(urb->pipe)) {
  4124. + case PIPE_BULK:
  4125. + /* Assert that the EP descriptor is disabled. */
  4126. + ASSERT(!(TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)));
  4127. +
  4128. + /* Set up and enable the EP descriptor. */
  4129. + TxBulkEPList[epid].sub = virt_to_phys(urb_priv->first_sb);
  4130. + TxBulkEPList[epid].hw_len = 0;
  4131. + TxBulkEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes);
  4132. +
  4133. + /* Check if the dummy list is already with us (if several urbs were queued). */
  4134. + if (usb_pipein(urb->pipe) && (TxBulkEPList[epid].next != virt_to_phys(&TxBulkDummyEPList[epid][0]))) {
  4135. + tc_dbg("Inviting dummy list to the party for urb 0x%lx, epid %d",
  4136. + (unsigned long)urb, epid);
  4137. +
  4138. + /* We don't need to check if the DMA is at this EP or not before changing the
  4139. + next pointer, since we will do it in one 32-bit write (EP descriptors are
  4140. + 32-bit aligned). */
  4141. + TxBulkEPList[epid].next = virt_to_phys(&TxBulkDummyEPList[epid][0]);
  4142. + }
  4143. +
  4144. + restart_dma8_sub0();
  4145. +
  4146. + /* Update/restart the bulk start timer since we just started the channel.*/
  4147. + mod_timer(&bulk_start_timer, jiffies + BULK_START_TIMER_INTERVAL);
  4148. + /* Update/restart the bulk eot timer since we just inserted traffic. */
  4149. + mod_timer(&bulk_eot_timer, jiffies + BULK_EOT_TIMER_INTERVAL);
  4150. + break;
  4151. + case PIPE_CONTROL:
  4152. + /* Assert that the EP descriptor is disabled. */
  4153. + ASSERT(!(TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable)));
  4154. +
  4155. + /* Set up and enable the EP descriptor. */
  4156. + TxCtrlEPList[epid].sub = virt_to_phys(urb_priv->first_sb);
  4157. + TxCtrlEPList[epid].hw_len = 0;
  4158. + TxCtrlEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes);
  4159. +
  4160. + *R_DMA_CH8_SUB1_CMD = IO_STATE(R_DMA_CH8_SUB1_CMD, cmd, start);
  4161. + break;
  4162. + }
  4163. + local_irq_restore(flags);
  4164. +}
  4165. +
  4166. +static void tc_dma_link_intr_urb(struct urb *urb) {
  4167. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  4168. + volatile struct USB_EP_Desc *tmp_ep;
  4169. + struct USB_EP_Desc *ep_desc;
  4170. + int i = 0, epid;
  4171. + int pool_idx = 0;
  4172. +
  4173. + ASSERT(urb_priv != NULL);
  4174. + epid = urb_priv->epid;
  4175. + ASSERT(urb_priv->interval > 0);
  4176. + ASSERT(urb_priv->intr_ep_pool_length > 0);
  4177. +
  4178. + tmp_ep = &TxIntrEPList[0];
  4179. +
  4180. + /* Only insert one EP descriptor in list for Out Intr URBs.
  4181. + We can only handle Out Intr with interval of 128ms because
  4182. + it's not possible to insert several Out Intr EPs because they
  4183. + are not consumed by the DMA. */
  4184. + if(usb_pipeout(urb->pipe)) {
  4185. + ep_desc = urb_priv->intr_ep_pool[0];
  4186. + ASSERT(ep_desc);
  4187. + ep_desc->next = tmp_ep->next;
  4188. + tmp_ep->next = virt_to_phys(ep_desc);
  4189. + i++;
  4190. + } else {
  4191. + /* Loop through Intr EP descriptor list and insert EP for URB at
  4192. + specified interval */
  4193. + do {
  4194. + /* Each EP descriptor with eof flag sat signals a new frame */
  4195. + if (tmp_ep->command & IO_MASK(USB_EP_command, eof)) {
  4196. + /* Insert a EP from URBs EP pool at correct interval */
  4197. + if ((i % urb_priv->interval) == 0) {
  4198. + ep_desc = urb_priv->intr_ep_pool[pool_idx];
  4199. + ASSERT(ep_desc);
  4200. + ep_desc->next = tmp_ep->next;
  4201. + tmp_ep->next = virt_to_phys(ep_desc);
  4202. + pool_idx++;
  4203. + ASSERT(pool_idx <= urb_priv->intr_ep_pool_length);
  4204. + }
  4205. + i++;
  4206. + }
  4207. + tmp_ep = (struct USB_EP_Desc *)phys_to_virt(tmp_ep->next);
  4208. + } while(tmp_ep != &TxIntrEPList[0]);
  4209. + }
  4210. +
  4211. + intr_dbg("Added SBs to intr epid %d: %s interval:%d (%d EP)\n", epid,
  4212. + sblist_to_str(urb_priv->first_sb), urb_priv->interval, pool_idx);
  4213. +
  4214. + /* We start the DMA sub channel without checking if it's running or not,
  4215. + because:
  4216. + 1) If it's already running, issuing the start command is a nop.
  4217. + 2) We avoid a test-and-set race condition. */
  4218. + *R_DMA_CH8_SUB2_CMD = IO_STATE(R_DMA_CH8_SUB2_CMD, cmd, start);
  4219. +}
  4220. +
  4221. + /* hinko ignore usb_pipeisoc */
  4222. +#if 0
  4223. +static void tc_dma_process_isoc_urb(struct urb *urb) {
  4224. + unsigned long flags;
  4225. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  4226. + int epid;
  4227. +
  4228. + /* Do not disturb us while fiddling with EPs and epids */
  4229. + local_irq_save(flags);
  4230. +
  4231. + ASSERT(urb_priv);
  4232. + ASSERT(urb_priv->first_sb);
  4233. + epid = urb_priv->epid;
  4234. +
  4235. + if(activeUrbList[epid] == NULL) {
  4236. + /* EP is idle, so make this URB active */
  4237. + activeUrbList[epid] = urb;
  4238. + urb_list_del(urb, epid);
  4239. + ASSERT(TxIsocEPList[epid].sub == 0);
  4240. + ASSERT(!(TxIsocEPList[epid].command &
  4241. + IO_STATE(USB_EP_command, enable, yes)));
  4242. +
  4243. + /* Differentiate between In and Out Isoc. Because In SBs are not consumed*/
  4244. + if(usb_pipein(urb->pipe)) {
  4245. + /* Each EP for In Isoc will have only one SB descriptor, setup when
  4246. + submitting the first active urb. We do it here by copying from URBs
  4247. + pre-allocated SB. */
  4248. + memcpy((void *)&(TxIsocSBList[epid]), urb_priv->first_sb,
  4249. + sizeof(TxIsocSBList[epid]));
  4250. + TxIsocEPList[epid].hw_len = 0;
  4251. + TxIsocEPList[epid].sub = virt_to_phys(&(TxIsocSBList[epid]));
  4252. + } else {
  4253. + /* For Out Isoc we attach the pre-allocated list of SBs for the URB */
  4254. + TxIsocEPList[epid].hw_len = 0;
  4255. + TxIsocEPList[epid].sub = virt_to_phys(urb_priv->first_sb);
  4256. +
  4257. + isoc_dbg("Attached first URB:0x%x[%d] to epid:%d first_sb:0x%x"
  4258. + " last_sb::0x%x\n",
  4259. + (unsigned int)urb, urb_priv->urb_num, epid,
  4260. + (unsigned int)(urb_priv->first_sb),
  4261. + (unsigned int)(urb_priv->last_sb));
  4262. + }
  4263. +
  4264. + if (urb->transfer_flags & URB_ISO_ASAP) {
  4265. + /* The isoc transfer should be started as soon as possible. The
  4266. + start_frame field is a return value if URB_ISO_ASAP was set. Comparing
  4267. + R_USB_FM_NUMBER with a USB Chief trace shows that the first isoc IN
  4268. + token is sent 2 frames later. I'm not sure how this affects usage of
  4269. + the start_frame field by the device driver, or how it affects things
  4270. + when USB_ISO_ASAP is not set, so therefore there's no compensation for
  4271. + the 2 frame "lag" here. */
  4272. + urb->start_frame = (*R_USB_FM_NUMBER & 0x7ff);
  4273. + TxIsocEPList[epid].command |= IO_STATE(USB_EP_command, enable, yes);
  4274. + urb_priv->urb_state = STARTED;
  4275. + isoc_dbg("URB_ISO_ASAP set, urb->start_frame set to %d\n",
  4276. + urb->start_frame);
  4277. + } else {
  4278. + /* Not started yet. */
  4279. + urb_priv->urb_state = NOT_STARTED;
  4280. + isoc_warn("urb_priv->urb_state set to NOT_STARTED for URB:0x%x\n",
  4281. + (unsigned int)urb);
  4282. + }
  4283. +
  4284. + } else {
  4285. + /* An URB is already active on the EP. Leave URB in queue and let
  4286. + finish_isoc_urb process it after current active URB */
  4287. + ASSERT(TxIsocEPList[epid].sub != 0);
  4288. +
  4289. + if(usb_pipein(urb->pipe)) {
  4290. + /* Because there already is a active In URB on this epid we do nothing
  4291. + and the finish_isoc_urb() function will handle switching to next URB*/
  4292. +
  4293. + } else { /* For Out Isoc, insert new URBs traffic last in SB-list. */
  4294. + struct USB_SB_Desc *temp_sb_desc;
  4295. +
  4296. + /* Set state STARTED to all Out Isoc URBs added to SB list because we
  4297. + don't know how many of them that are finished before descr interrupt*/
  4298. + urb_priv->urb_state = STARTED;
  4299. +
  4300. + /* Find end of current SB list by looking for SB with eol flag sat */
  4301. + temp_sb_desc = phys_to_virt(TxIsocEPList[epid].sub);
  4302. + while ((temp_sb_desc->command & IO_MASK(USB_SB_command, eol)) !=
  4303. + IO_STATE(USB_SB_command, eol, yes)) {
  4304. + ASSERT(temp_sb_desc->next);
  4305. + temp_sb_desc = phys_to_virt(temp_sb_desc->next);
  4306. + }
  4307. +
  4308. + isoc_dbg("Appended URB:0x%x[%d] (first:0x%x last:0x%x) to epid:%d"
  4309. + " sub:0x%x eol:0x%x\n",
  4310. + (unsigned int)urb, urb_priv->urb_num,
  4311. + (unsigned int)(urb_priv->first_sb),
  4312. + (unsigned int)(urb_priv->last_sb), epid,
  4313. + (unsigned int)phys_to_virt(TxIsocEPList[epid].sub),
  4314. + (unsigned int)temp_sb_desc);
  4315. +
  4316. + /* Next pointer must be set before eol is removed. */
  4317. + temp_sb_desc->next = virt_to_phys(urb_priv->first_sb);
  4318. + /* Clear the previous end of list flag since there is a new in the
  4319. + added SB descriptor list. */
  4320. + temp_sb_desc->command &= ~IO_MASK(USB_SB_command, eol);
  4321. +
  4322. + if (!(TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable))) {
  4323. + __u32 epid_data;
  4324. + /* 8.8.5 in Designer's Reference says we should check for and correct
  4325. + any errors in the EP here. That should not be necessary if
  4326. + epid_attn is handled correctly, so we assume all is ok. */
  4327. + epid_data = etrax_epid_iso_get(epid);
  4328. + if (IO_EXTRACT(R_USB_EPT_DATA, error_code, epid_data) !=
  4329. + IO_STATE_VALUE(R_USB_EPT_DATA, error_code, no_error)) {
  4330. + isoc_err("Disabled Isoc EP with error:%d on epid:%d when appending"
  4331. + " URB:0x%x[%d]\n",
  4332. + IO_EXTRACT(R_USB_EPT_DATA, error_code, epid_data), epid,
  4333. + (unsigned int)urb, urb_priv->urb_num);
  4334. + }
  4335. +
  4336. + /* The SB list was exhausted. */
  4337. + if (virt_to_phys(urb_priv->last_sb) != TxIsocEPList[epid].sub) {
  4338. + /* The new sublist did not get processed before the EP was
  4339. + disabled. Setup the EP again. */
  4340. +
  4341. + if(virt_to_phys(temp_sb_desc) == TxIsocEPList[epid].sub) {
  4342. + isoc_dbg("EP for epid:%d stoped at SB:0x%x before newly inserted"
  4343. + ", restarting from this URBs SB:0x%x\n",
  4344. + epid, (unsigned int)temp_sb_desc,
  4345. + (unsigned int)(urb_priv->first_sb));
  4346. + TxIsocEPList[epid].hw_len = 0;
  4347. + TxIsocEPList[epid].sub = virt_to_phys(urb_priv->first_sb);
  4348. + urb->start_frame = (*R_USB_FM_NUMBER & 0x7ff);
  4349. + /* Enable the EP again so data gets processed this time */
  4350. + TxIsocEPList[epid].command |=
  4351. + IO_STATE(USB_EP_command, enable, yes);
  4352. +
  4353. + } else {
  4354. + /* The EP has been disabled but not at end this URB (god knows
  4355. + where). This should generate an epid_attn so we should not be
  4356. + here */
  4357. + isoc_warn("EP was disabled on sb:0x%x before SB list for"
  4358. + " URB:0x%x[%d] got processed\n",
  4359. + (unsigned int)phys_to_virt(TxIsocEPList[epid].sub),
  4360. + (unsigned int)urb, urb_priv->urb_num);
  4361. + }
  4362. + } else {
  4363. + /* This might happend if we are slow on this function and isn't
  4364. + an error. */
  4365. + isoc_dbg("EP was disabled and finished with SBs from appended"
  4366. + " URB:0x%x[%d]\n", (unsigned int)urb, urb_priv->urb_num);
  4367. + }
  4368. + }
  4369. + }
  4370. + }
  4371. +
  4372. + /* Start the DMA sub channel */
  4373. + *R_DMA_CH8_SUB3_CMD = IO_STATE(R_DMA_CH8_SUB3_CMD, cmd, start);
  4374. +
  4375. + local_irq_restore(flags);
  4376. +}
  4377. +#endif
  4378. +
  4379. +static void tc_dma_unlink_intr_urb(struct urb *urb) {
  4380. + struct crisv10_urb_priv *urb_priv = urb->hcpriv;
  4381. + volatile struct USB_EP_Desc *first_ep; /* First EP in the list. */
  4382. + volatile struct USB_EP_Desc *curr_ep; /* Current EP, the iterator. */
  4383. + volatile struct USB_EP_Desc *next_ep; /* The EP after current. */
  4384. + volatile struct USB_EP_Desc *unlink_ep; /* The one we should remove from
  4385. + the list. */
  4386. + int count = 0;
  4387. + volatile int timeout = 10000;
  4388. + int epid;
  4389. +
  4390. + /* Read 8.8.4 in Designer's Reference, "Removing an EP Descriptor from the
  4391. + List". */
  4392. + ASSERT(urb_priv);
  4393. + ASSERT(urb_priv->intr_ep_pool_length > 0);
  4394. + epid = urb_priv->epid;
  4395. +
  4396. + /* First disable all Intr EPs belonging to epid for this URB */
  4397. + first_ep = &TxIntrEPList[0];
  4398. + curr_ep = first_ep;
  4399. + do {
  4400. + next_ep = (struct USB_EP_Desc *)phys_to_virt(curr_ep->next);
  4401. + if (IO_EXTRACT(USB_EP_command, epid, next_ep->command) == epid) {
  4402. + /* Disable EP */
  4403. + next_ep->command &= ~IO_MASK(USB_EP_command, enable);
  4404. + }
  4405. + curr_ep = phys_to_virt(curr_ep->next);
  4406. + } while (curr_ep != first_ep);
  4407. +
  4408. +
  4409. + /* Now unlink all EPs belonging to this epid from Descr list */
  4410. + first_ep = &TxIntrEPList[0];
  4411. + curr_ep = first_ep;
  4412. + do {
  4413. + next_ep = (struct USB_EP_Desc *)phys_to_virt(curr_ep->next);
  4414. + if (IO_EXTRACT(USB_EP_command, epid, next_ep->command) == epid) {
  4415. + /* This is the one we should unlink. */
  4416. + unlink_ep = next_ep;
  4417. +
  4418. + /* Actually unlink the EP from the DMA list. */
  4419. + curr_ep->next = unlink_ep->next;
  4420. +
  4421. + /* Wait until the DMA is no longer at this descriptor. */
  4422. + while((*R_DMA_CH8_SUB2_EP == virt_to_phys(unlink_ep)) &&
  4423. + (timeout-- > 0));
  4424. + if(timeout == 0) {
  4425. + warn("Timeout while waiting for DMA-TX-Intr to leave unlink EP\n");
  4426. + }
  4427. +
  4428. + count++;
  4429. + }
  4430. + curr_ep = phys_to_virt(curr_ep->next);
  4431. + } while (curr_ep != first_ep);
  4432. +
  4433. + if(count != urb_priv->intr_ep_pool_length) {
  4434. + intr_warn("Unlinked %d of %d Intr EPs for URB:0x%x[%d]\n", count,
  4435. + urb_priv->intr_ep_pool_length, (unsigned int)urb,
  4436. + urb_priv->urb_num);
  4437. + } else {
  4438. + intr_dbg("Unlinked %d of %d interrupt EPs for URB:0x%x\n", count,
  4439. + urb_priv->intr_ep_pool_length, (unsigned int)urb);
  4440. + }
  4441. +}
  4442. +
  4443. +static void check_finished_bulk_tx_epids(struct usb_hcd *hcd,
  4444. + int timer) {
  4445. + unsigned long flags;
  4446. + int epid;
  4447. + struct urb *urb;
  4448. + struct crisv10_urb_priv * urb_priv;
  4449. + __u32 epid_data;
  4450. +
  4451. + /* Protect TxEPList */
  4452. + local_irq_save(flags);
  4453. +
  4454. + for (epid = 0; epid < NBR_OF_EPIDS; epid++) {
  4455. + /* A finished EP descriptor is disabled and has a valid sub pointer */
  4456. + if (!(TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) &&
  4457. + (TxBulkEPList[epid].sub != 0)) {
  4458. +
  4459. + /* Get the active URB for this epid */
  4460. + urb = activeUrbList[epid];
  4461. + /* Sanity checks */
  4462. + ASSERT(urb);
  4463. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  4464. + ASSERT(urb_priv);
  4465. +
  4466. + /* Only handle finished out Bulk EPs here,
  4467. + and let RX interrupt take care of the rest */
  4468. + if(!epid_out_traffic(epid)) {
  4469. + continue;
  4470. + }
  4471. +
  4472. + if(timer) {
  4473. + tc_warn("Found finished %s Bulk epid:%d URB:0x%x[%d] from timeout\n",
  4474. + epid_out_traffic(epid) ? "Out" : "In", epid, (unsigned int)urb,
  4475. + urb_priv->urb_num);
  4476. + } else {
  4477. + tc_dbg("Found finished %s Bulk epid:%d URB:0x%x[%d] from interrupt\n",
  4478. + epid_out_traffic(epid) ? "Out" : "In", epid, (unsigned int)urb,
  4479. + urb_priv->urb_num);
  4480. + }
  4481. +
  4482. + if(urb_priv->urb_state == UNLINK) {
  4483. + /* This Bulk URB is requested to be unlinked, that means that the EP
  4484. + has been disabled and we might not have sent all data */
  4485. + tc_finish_urb(hcd, urb, urb->status);
  4486. + continue;
  4487. + }
  4488. +
  4489. + ASSERT(urb_priv->urb_state == STARTED);
  4490. + if (phys_to_virt(TxBulkEPList[epid].sub) != urb_priv->last_sb) {
  4491. + tc_err("Endpoint got disabled before reaching last sb\n");
  4492. + }
  4493. +
  4494. + epid_data = etrax_epid_get(epid);
  4495. + if (IO_EXTRACT(R_USB_EPT_DATA, error_code, epid_data) ==
  4496. + IO_STATE_VALUE(R_USB_EPT_DATA, error_code, no_error)) {
  4497. + /* This means that the endpoint has no error, is disabled
  4498. + and had inserted traffic, i.e. transfer successfully completed. */
  4499. + tc_finish_urb(hcd, urb, 0);
  4500. + } else {
  4501. + /* Shouldn't happen. We expect errors to be caught by epid
  4502. + attention. */
  4503. + tc_err("Found disabled bulk EP desc (epid:%d error:%d)\n",
  4504. + epid, IO_EXTRACT(R_USB_EPT_DATA, error_code, epid_data));
  4505. + }
  4506. + } else {
  4507. + tc_dbg("Ignoring In Bulk epid:%d, let RX interrupt handle it\n", epid);
  4508. + }
  4509. + }
  4510. +
  4511. + local_irq_restore(flags);
  4512. +}
  4513. +
  4514. +static void check_finished_ctrl_tx_epids(struct usb_hcd *hcd) {
  4515. + unsigned long flags;
  4516. + int epid;
  4517. + struct urb *urb;
  4518. + struct crisv10_urb_priv * urb_priv;
  4519. + __u32 epid_data;
  4520. +
  4521. + /* Protect TxEPList */
  4522. + local_irq_save(flags);
  4523. +
  4524. + for (epid = 0; epid < NBR_OF_EPIDS; epid++) {
  4525. + if(epid == DUMMY_EPID)
  4526. + continue;
  4527. +
  4528. + /* A finished EP descriptor is disabled and has a valid sub pointer */
  4529. + if (!(TxCtrlEPList[epid].command & IO_MASK(USB_EP_command, enable)) &&
  4530. + (TxCtrlEPList[epid].sub != 0)) {
  4531. +
  4532. + /* Get the active URB for this epid */
  4533. + urb = activeUrbList[epid];
  4534. +
  4535. + if(urb == NULL) {
  4536. + tc_warn("Found finished Ctrl epid:%d with no active URB\n", epid);
  4537. + continue;
  4538. + }
  4539. +
  4540. + /* Sanity checks */
  4541. + ASSERT(usb_pipein(urb->pipe));
  4542. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  4543. + ASSERT(urb_priv);
  4544. + if (phys_to_virt(TxCtrlEPList[epid].sub) != urb_priv->last_sb) {
  4545. + tc_err("Endpoint got disabled before reaching last sb\n");
  4546. + }
  4547. +
  4548. + epid_data = etrax_epid_get(epid);
  4549. + if (IO_EXTRACT(R_USB_EPT_DATA, error_code, epid_data) ==
  4550. + IO_STATE_VALUE(R_USB_EPT_DATA, error_code, no_error)) {
  4551. + /* This means that the endpoint has no error, is disabled
  4552. + and had inserted traffic, i.e. transfer successfully completed. */
  4553. +
  4554. + /* Check if RX-interrupt for In Ctrl has been processed before
  4555. + finishing the URB */
  4556. + if(urb_priv->ctrl_rx_done) {
  4557. + tc_dbg("Finishing In Ctrl URB:0x%x[%d] in tx_interrupt\n",
  4558. + (unsigned int)urb, urb_priv->urb_num);
  4559. + tc_finish_urb(hcd, urb, 0);
  4560. + } else {
  4561. + /* If we get zout descriptor interrupt before RX was done for a
  4562. + In Ctrl transfer, then we flag that and it will be finished
  4563. + in the RX-Interrupt */
  4564. + urb_priv->ctrl_zout_done = 1;
  4565. + tc_dbg("Got zout descr interrupt before RX interrupt\n");
  4566. + }
  4567. + } else {
  4568. + /* Shouldn't happen. We expect errors to be caught by epid
  4569. + attention. */
  4570. + tc_err("Found disabled Ctrl EP desc (epid:%d URB:0x%x[%d]) error_code:%d\n", epid, (unsigned int)urb, urb_priv->urb_num, IO_EXTRACT(R_USB_EPT_DATA, error_code, epid_data));
  4571. + __dump_ep_desc(&(TxCtrlEPList[epid]));
  4572. + __dump_ept_data(epid);
  4573. + }
  4574. + }
  4575. + }
  4576. + local_irq_restore(flags);
  4577. +}
  4578. +
  4579. + /* hinko ignore usb_pipeisoc */
  4580. +#if 0
  4581. +/* This function goes through all epids that are setup for Out Isoc transfers
  4582. + and marks (isoc_out_done) all queued URBs that the DMA has finished
  4583. + transfer for.
  4584. + No URB completetion is done here to make interrupt routine return quickly.
  4585. + URBs are completed later with help of complete_isoc_bottom_half() that
  4586. + becomes schedules when this functions is finished. */
  4587. +static void check_finished_isoc_tx_epids(void) {
  4588. + unsigned long flags;
  4589. + int epid;
  4590. + struct urb *urb;
  4591. + struct crisv10_urb_priv * urb_priv;
  4592. + struct USB_SB_Desc* sb_desc;
  4593. + int epid_done;
  4594. +
  4595. + /* Protect TxIsocEPList */
  4596. + local_irq_save(flags);
  4597. +
  4598. + for (epid = 0; epid < NBR_OF_EPIDS; epid++) {
  4599. + if (TxIsocEPList[epid].sub == 0 || epid == INVALID_EPID ||
  4600. + !epid_out_traffic(epid)) {
  4601. + /* Nothing here to see. */
  4602. + continue;
  4603. + }
  4604. + ASSERT(epid_inuse(epid));
  4605. + ASSERT(epid_isoc(epid));
  4606. +
  4607. + sb_desc = phys_to_virt(TxIsocEPList[epid].sub);
  4608. + /* Find the last descriptor of the currently active URB for this ep.
  4609. + This is the first descriptor in the sub list marked for a descriptor
  4610. + interrupt. */
  4611. + while (sb_desc && !IO_EXTRACT(USB_SB_command, intr, sb_desc->command)) {
  4612. + sb_desc = sb_desc->next ? phys_to_virt(sb_desc->next) : 0;
  4613. + }
  4614. + ASSERT(sb_desc);
  4615. +
  4616. + isoc_dbg("Descr IRQ checking epid:%d sub:0x%x intr:0x%x\n",
  4617. + epid, (unsigned int)phys_to_virt(TxIsocEPList[epid].sub),
  4618. + (unsigned int)sb_desc);
  4619. +
  4620. + urb = activeUrbList[epid];
  4621. + if(urb == NULL) {
  4622. + isoc_err("Isoc Descr irq on epid:%d with no active URB\n", epid);
  4623. + continue;
  4624. + }
  4625. +
  4626. + epid_done = 0;
  4627. + while(urb && !epid_done) {
  4628. + /* Sanity check. */
  4629. + ASSERT(usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS);
  4630. + ASSERT(usb_pipeout(urb->pipe));
  4631. +
  4632. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  4633. + ASSERT(urb_priv);
  4634. + ASSERT(urb_priv->urb_state == STARTED ||
  4635. + urb_priv->urb_state == UNLINK);
  4636. +
  4637. + if (sb_desc != urb_priv->last_sb) {
  4638. + /* This urb has been sent. */
  4639. + urb_priv->isoc_out_done = 1;
  4640. +
  4641. + } else { /* Found URB that has last_sb as the interrupt reason */
  4642. +
  4643. + /* Check if EP has been disabled, meaning that all transfers are done*/
  4644. + if(!(TxIsocEPList[epid].command & IO_MASK(USB_EP_command, enable))) {
  4645. + ASSERT((sb_desc->command & IO_MASK(USB_SB_command, eol)) ==
  4646. + IO_STATE(USB_SB_command, eol, yes));
  4647. + ASSERT(sb_desc->next == 0);
  4648. + urb_priv->isoc_out_done = 1;
  4649. + } else {
  4650. + isoc_dbg("Skipping URB:0x%x[%d] because EP not disabled yet\n",
  4651. + (unsigned int)urb, urb_priv->urb_num);
  4652. + }
  4653. + /* Stop looking any further in queue */
  4654. + epid_done = 1;
  4655. + }
  4656. +
  4657. + if (!epid_done) {
  4658. + if(urb == activeUrbList[epid]) {
  4659. + urb = urb_list_first(epid);
  4660. + } else {
  4661. + urb = urb_list_next(urb, epid);
  4662. + }
  4663. + }
  4664. + } /* END: while(urb && !epid_done) */
  4665. + }
  4666. +
  4667. + local_irq_restore(flags);
  4668. +}
  4669. +
  4670. +
  4671. +/* This is where the Out Isoc URBs are realy completed. This function is
  4672. + scheduled from tc_dma_tx_interrupt() when one or more Out Isoc transfers
  4673. + are done. This functions completes all URBs earlier marked with
  4674. + isoc_out_done by fast interrupt routine check_finished_isoc_tx_epids() */
  4675. +
  4676. +static void complete_isoc_bottom_half(void *data) {
  4677. + struct crisv10_isoc_complete_data *comp_data;
  4678. + struct usb_iso_packet_descriptor *packet;
  4679. + struct crisv10_urb_priv * urb_priv;
  4680. + unsigned long flags;
  4681. + struct urb* urb;
  4682. + int epid_done;
  4683. + int epid;
  4684. + int i;
  4685. +
  4686. + comp_data = (struct crisv10_isoc_complete_data*)data;
  4687. +
  4688. + local_irq_save(flags);
  4689. +
  4690. + for (epid = 0; epid < NBR_OF_EPIDS - 1; epid++) {
  4691. + if(!epid_inuse(epid) || !epid_isoc(epid) || !epid_out_traffic(epid) || epid == DUMMY_EPID) {
  4692. + /* Only check valid Out Isoc epids */
  4693. + continue;
  4694. + }
  4695. +
  4696. + isoc_dbg("Isoc bottom-half checking epid:%d, sub:0x%x\n", epid,
  4697. + (unsigned int)phys_to_virt(TxIsocEPList[epid].sub));
  4698. +
  4699. + /* The descriptor interrupt handler has marked all transmitted Out Isoc
  4700. + URBs with isoc_out_done. Now we traverse all epids and for all that
  4701. + have out Isoc traffic we traverse its URB list and complete the
  4702. + transmitted URBs. */
  4703. + epid_done = 0;
  4704. + while (!epid_done) {
  4705. +
  4706. + /* Get the active urb (if any) */
  4707. + urb = activeUrbList[epid];
  4708. + if (urb == 0) {
  4709. + isoc_dbg("No active URB on epid:%d anymore\n", epid);
  4710. + epid_done = 1;
  4711. + continue;
  4712. + }
  4713. +
  4714. + /* Sanity check. */
  4715. + ASSERT(usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS);
  4716. + ASSERT(usb_pipeout(urb->pipe));
  4717. +
  4718. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  4719. + ASSERT(urb_priv);
  4720. +
  4721. + if (!(urb_priv->isoc_out_done)) {
  4722. + /* We have reached URB that isn't flaged done yet, stop traversing. */
  4723. + isoc_dbg("Stoped traversing Out Isoc URBs on epid:%d"
  4724. + " before not yet flaged URB:0x%x[%d]\n",
  4725. + epid, (unsigned int)urb, urb_priv->urb_num);
  4726. + epid_done = 1;
  4727. + continue;
  4728. + }
  4729. +
  4730. + /* This urb has been sent. */
  4731. + isoc_dbg("Found URB:0x%x[%d] that is flaged isoc_out_done\n",
  4732. + (unsigned int)urb, urb_priv->urb_num);
  4733. +
  4734. + /* Set ok on transfered packets for this URB and finish it */
  4735. + for (i = 0; i < urb->number_of_packets; i++) {
  4736. + packet = &urb->iso_frame_desc[i];
  4737. + packet->status = 0;
  4738. + packet->actual_length = packet->length;
  4739. + }
  4740. + urb_priv->isoc_packet_counter = urb->number_of_packets;
  4741. + tc_finish_urb(comp_data->hcd, urb, 0);
  4742. +
  4743. + } /* END: while(!epid_done) */
  4744. + } /* END: for(epid...) */
  4745. +
  4746. + local_irq_restore(flags);
  4747. + kmem_cache_free(isoc_compl_cache, comp_data);
  4748. +}
  4749. +#endif
  4750. +
  4751. +static void check_finished_intr_tx_epids(struct usb_hcd *hcd) {
  4752. + unsigned long flags;
  4753. + int epid;
  4754. + struct urb *urb;
  4755. + struct crisv10_urb_priv * urb_priv;
  4756. + volatile struct USB_EP_Desc *curr_ep; /* Current EP, the iterator. */
  4757. + volatile struct USB_EP_Desc *next_ep; /* The EP after current. */
  4758. +
  4759. + /* Protect TxintrEPList */
  4760. + local_irq_save(flags);
  4761. +
  4762. + for (epid = 0; epid < NBR_OF_EPIDS; epid++) {
  4763. + if(!epid_inuse(epid) || !epid_intr(epid) || !epid_out_traffic(epid)) {
  4764. + /* Nothing to see on this epid. Only check valid Out Intr epids */
  4765. + continue;
  4766. + }
  4767. +
  4768. + urb = activeUrbList[epid];
  4769. + if(urb == 0) {
  4770. + intr_warn("Found Out Intr epid:%d with no active URB\n", epid);
  4771. + continue;
  4772. + }
  4773. +
  4774. + /* Sanity check. */
  4775. + ASSERT(usb_pipetype(urb->pipe) == PIPE_INTERRUPT);
  4776. + ASSERT(usb_pipeout(urb->pipe));
  4777. +
  4778. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  4779. + ASSERT(urb_priv);
  4780. +
  4781. + /* Go through EPs between first and second sof-EP. It's here Out Intr EPs
  4782. + are inserted.*/
  4783. + curr_ep = &TxIntrEPList[0];
  4784. + do {
  4785. + next_ep = (struct USB_EP_Desc *)phys_to_virt(curr_ep->next);
  4786. + if(next_ep == urb_priv->intr_ep_pool[0]) {
  4787. + /* We found the Out Intr EP for this epid */
  4788. +
  4789. + /* Disable it so it doesn't get processed again */
  4790. + next_ep->command &= ~IO_MASK(USB_EP_command, enable);
  4791. +
  4792. + /* Finish the active Out Intr URB with status OK */
  4793. + tc_finish_urb(hcd, urb, 0);
  4794. + }
  4795. + curr_ep = phys_to_virt(curr_ep->next);
  4796. + } while (curr_ep != &TxIntrEPList[1]);
  4797. +
  4798. + }
  4799. + local_irq_restore(flags);
  4800. +}
  4801. +
  4802. +/* Interrupt handler for DMA8/IRQ24 with subchannels (called from hardware intr) */
  4803. +static irqreturn_t tc_dma_tx_interrupt(int irq, void *vhc) {
  4804. + struct usb_hcd *hcd = (struct usb_hcd*)vhc;
  4805. + ASSERT(hcd);
  4806. +
  4807. + if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub0_descr)) {
  4808. + /* Clear this interrupt */
  4809. + *R_DMA_CH8_SUB0_CLR_INTR = IO_STATE(R_DMA_CH8_SUB0_CLR_INTR, clr_descr, do);
  4810. + restart_dma8_sub0();
  4811. + }
  4812. +
  4813. + if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub1_descr)) {
  4814. + /* Clear this interrupt */
  4815. + *R_DMA_CH8_SUB1_CLR_INTR = IO_STATE(R_DMA_CH8_SUB1_CLR_INTR, clr_descr, do);
  4816. + check_finished_ctrl_tx_epids(hcd);
  4817. + }
  4818. +
  4819. + if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub2_descr)) {
  4820. + /* Clear this interrupt */
  4821. + *R_DMA_CH8_SUB2_CLR_INTR = IO_STATE(R_DMA_CH8_SUB2_CLR_INTR, clr_descr, do);
  4822. + check_finished_intr_tx_epids(hcd);
  4823. + }
  4824. +
  4825. + /* hinko ignore usb_pipeisoc */
  4826. +#if 0
  4827. + if (*R_IRQ_READ2 & IO_MASK(R_IRQ_READ2, dma8_sub3_descr)) {
  4828. + struct crisv10_isoc_complete_data* comp_data;
  4829. +
  4830. + /* Flag done Out Isoc for later completion */
  4831. + check_finished_isoc_tx_epids();
  4832. +
  4833. + /* Clear this interrupt */
  4834. + *R_DMA_CH8_SUB3_CLR_INTR = IO_STATE(R_DMA_CH8_SUB3_CLR_INTR, clr_descr, do);
  4835. + /* Schedule bottom half of Out Isoc completion function. This function
  4836. + finishes the URBs marked with isoc_out_done */
  4837. + comp_data = (struct crisv10_isoc_complete_data*)
  4838. + kmem_cache_alloc(isoc_compl_cache, GFP_ATOMIC);
  4839. + ASSERT(comp_data != NULL);
  4840. + comp_data ->hcd = hcd;
  4841. +
  4842. + //INIT_WORK(&comp_data->usb_bh, complete_isoc_bottom_half, comp_data);
  4843. + INIT_WORK(&comp_data->usb_bh, complete_isoc_bottom_half);
  4844. + schedule_work(&comp_data->usb_bh);
  4845. + }
  4846. +#endif
  4847. +
  4848. + return IRQ_HANDLED;
  4849. +}
  4850. +
  4851. +/* Interrupt handler for DMA9/IRQ25 (called from hardware intr) */
  4852. +static irqreturn_t tc_dma_rx_interrupt(int irq, void *vhc) {
  4853. + unsigned long flags;
  4854. + struct urb *urb;
  4855. + struct usb_hcd *hcd = (struct usb_hcd*)vhc;
  4856. + struct crisv10_urb_priv *urb_priv;
  4857. + int epid = 0;
  4858. + int real_error;
  4859. +
  4860. + ASSERT(hcd);
  4861. +
  4862. + /* Clear this interrupt. */
  4863. + *R_DMA_CH9_CLR_INTR = IO_STATE(R_DMA_CH9_CLR_INTR, clr_eop, do);
  4864. +
  4865. + /* Custom clear interrupt for this interrupt */
  4866. + /* The reason we cli here is that we call the driver's callback functions. */
  4867. + local_irq_save(flags);
  4868. +
  4869. + /* Note that this while loop assumes that all packets span only
  4870. + one rx descriptor. */
  4871. + while(myNextRxDesc->status & IO_MASK(USB_IN_status, eop)) {
  4872. + epid = IO_EXTRACT(USB_IN_status, epid, myNextRxDesc->status);
  4873. + /* Get the active URB for this epid */
  4874. + urb = activeUrbList[epid];
  4875. +
  4876. + ASSERT(epid_inuse(epid));
  4877. + if (!urb) {
  4878. + dma_err("No urb for epid %d in rx interrupt\n", epid);
  4879. + goto skip_out;
  4880. + }
  4881. +
  4882. + /* Check if any errors on epid */
  4883. + real_error = 0;
  4884. + if (myNextRxDesc->status & IO_MASK(USB_IN_status, error)) {
  4885. + __u32 r_usb_ept_data;
  4886. +
  4887. + if (usb_pipeisoc(urb->pipe)) {
  4888. + r_usb_ept_data = etrax_epid_iso_get(epid);
  4889. + if((r_usb_ept_data & IO_MASK(R_USB_EPT_DATA_ISO, valid)) &&
  4890. + (IO_EXTRACT(R_USB_EPT_DATA_ISO, error_code, r_usb_ept_data) == 0) &&
  4891. + (myNextRxDesc->status & IO_MASK(USB_IN_status, nodata))) {
  4892. + /* Not an error, just a failure to receive an expected iso
  4893. + in packet in this frame. This is not documented
  4894. + in the designers reference. Continue processing.
  4895. + */
  4896. + } else real_error = 1;
  4897. + } else real_error = 1;
  4898. + }
  4899. +
  4900. + if(real_error) {
  4901. + dma_err("Error in RX descr on epid:%d for URB 0x%x",
  4902. + epid, (unsigned int)urb);
  4903. + dump_ept_data(epid);
  4904. + dump_in_desc(myNextRxDesc);
  4905. + goto skip_out;
  4906. + }
  4907. +
  4908. + urb_priv = (struct crisv10_urb_priv *)urb->hcpriv;
  4909. + ASSERT(urb_priv);
  4910. + ASSERT(urb_priv->urb_state == STARTED ||
  4911. + urb_priv->urb_state == UNLINK);
  4912. +
  4913. + if ((usb_pipetype(urb->pipe) == PIPE_BULK) ||
  4914. + (usb_pipetype(urb->pipe) == PIPE_CONTROL) ||
  4915. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  4916. +
  4917. + /* We get nodata for empty data transactions, and the rx descriptor's
  4918. + hw_len field is not valid in that case. No data to copy in other
  4919. + words. */
  4920. + if (myNextRxDesc->status & IO_MASK(USB_IN_status, nodata)) {
  4921. + /* No data to copy */
  4922. + } else {
  4923. + /*
  4924. + dma_dbg("Processing RX for URB:0x%x epid:%d (data:%d ofs:%d)\n",
  4925. + (unsigned int)urb, epid, myNextRxDesc->hw_len,
  4926. + urb_priv->rx_offset);
  4927. + */
  4928. + /* Only copy data if URB isn't flaged to be unlinked*/
  4929. + if(urb_priv->urb_state != UNLINK) {
  4930. + /* Make sure the data fits in the buffer. */
  4931. + if(urb_priv->rx_offset + myNextRxDesc->hw_len
  4932. + <= urb->transfer_buffer_length) {
  4933. +
  4934. + /* Copy the data to URBs buffer */
  4935. + memcpy(urb->transfer_buffer + urb_priv->rx_offset,
  4936. + phys_to_virt(myNextRxDesc->buf), myNextRxDesc->hw_len);
  4937. + urb_priv->rx_offset += myNextRxDesc->hw_len;
  4938. + } else {
  4939. + /* Signal overflow when returning URB */
  4940. + urb->status = -EOVERFLOW;
  4941. + tc_finish_urb_later(hcd, urb, urb->status);
  4942. + }
  4943. + }
  4944. + }
  4945. +
  4946. + /* Check if it was the last packet in the transfer */
  4947. + if (myNextRxDesc->status & IO_MASK(USB_IN_status, eot)) {
  4948. + /* Special handling for In Ctrl URBs. */
  4949. + if(usb_pipecontrol(urb->pipe) && usb_pipein(urb->pipe) &&
  4950. + !(urb_priv->ctrl_zout_done)) {
  4951. + /* Flag that RX part of Ctrl transfer is done. Because zout descr
  4952. + interrupt hasn't happend yet will the URB be finished in the
  4953. + TX-Interrupt. */
  4954. + urb_priv->ctrl_rx_done = 1;
  4955. + tc_dbg("Not finishing In Ctrl URB:0x%x from rx_interrupt, waiting"
  4956. + " for zout\n", (unsigned int)urb);
  4957. + } else {
  4958. + tc_finish_urb(hcd, urb, 0);
  4959. + }
  4960. + }
  4961. + } else { /* ISOC RX */
  4962. + /*
  4963. + isoc_dbg("Processing RX for epid:%d (URB:0x%x) ISOC pipe\n",
  4964. + epid, (unsigned int)urb);
  4965. + */
  4966. +
  4967. + struct usb_iso_packet_descriptor *packet;
  4968. +
  4969. + if (urb_priv->urb_state == UNLINK) {
  4970. + isoc_warn("Ignoring Isoc Rx data for urb being unlinked.\n");
  4971. + goto skip_out;
  4972. + } else if (urb_priv->urb_state == NOT_STARTED) {
  4973. + isoc_err("What? Got Rx data for Isoc urb that isn't started?\n");
  4974. + goto skip_out;
  4975. + }
  4976. +
  4977. + packet = &urb->iso_frame_desc[urb_priv->isoc_packet_counter];
  4978. + ASSERT(packet);
  4979. + packet->status = 0;
  4980. +
  4981. + if (myNextRxDesc->status & IO_MASK(USB_IN_status, nodata)) {
  4982. + /* We get nodata for empty data transactions, and the rx descriptor's
  4983. + hw_len field is not valid in that case. We copy 0 bytes however to
  4984. + stay in synch. */
  4985. + packet->actual_length = 0;
  4986. + } else {
  4987. + packet->actual_length = myNextRxDesc->hw_len;
  4988. + /* Make sure the data fits in the buffer. */
  4989. + ASSERT(packet->actual_length <= packet->length);
  4990. + memcpy(urb->transfer_buffer + packet->offset,
  4991. + phys_to_virt(myNextRxDesc->buf), packet->actual_length);
  4992. + if(packet->actual_length > 0)
  4993. + isoc_dbg("Copied %d bytes, packet %d for URB:0x%x[%d]\n",
  4994. + packet->actual_length, urb_priv->isoc_packet_counter,
  4995. + (unsigned int)urb, urb_priv->urb_num);
  4996. + }
  4997. +
  4998. + /* Increment the packet counter. */
  4999. + urb_priv->isoc_packet_counter++;
  5000. +
  5001. + /* Note that we don't care about the eot field in the rx descriptor's
  5002. + status. It will always be set for isoc traffic. */
  5003. + if (urb->number_of_packets == urb_priv->isoc_packet_counter) {
  5004. + /* Complete the urb with status OK. */
  5005. + tc_finish_urb(hcd, urb, 0);
  5006. + }
  5007. + }
  5008. +
  5009. + skip_out:
  5010. + myNextRxDesc->status = 0;
  5011. + myNextRxDesc->command |= IO_MASK(USB_IN_command, eol);
  5012. + myLastRxDesc->command &= ~IO_MASK(USB_IN_command, eol);
  5013. + myLastRxDesc = myNextRxDesc;
  5014. + myNextRxDesc = phys_to_virt(myNextRxDesc->next);
  5015. + flush_etrax_cache();
  5016. + *R_DMA_CH9_CMD = IO_STATE(R_DMA_CH9_CMD, cmd, restart);
  5017. + }
  5018. +
  5019. + local_irq_restore(flags);
  5020. +
  5021. + return IRQ_HANDLED;
  5022. +}
  5023. +
  5024. +static void tc_bulk_start_timer_func(unsigned long dummy) {
  5025. + /* We might enable an EP descriptor behind the current DMA position when
  5026. + it's about to decide that there are no more bulk traffic and it should
  5027. + stop the bulk channel.
  5028. + Therefore we periodically check if the bulk channel is stopped and there
  5029. + is an enabled bulk EP descriptor, in which case we start the bulk
  5030. + channel. */
  5031. +
  5032. + if (!(*R_DMA_CH8_SUB0_CMD & IO_MASK(R_DMA_CH8_SUB0_CMD, cmd))) {
  5033. + int epid;
  5034. +
  5035. + timer_dbg("bulk_start_timer: Bulk DMA channel not running.\n");
  5036. +
  5037. + for (epid = 0; epid < NBR_OF_EPIDS; epid++) {
  5038. + if (TxBulkEPList[epid].command & IO_MASK(USB_EP_command, enable)) {
  5039. + timer_warn("Found enabled EP for epid %d, starting bulk channel.\n",
  5040. + epid);
  5041. + restart_dma8_sub0();
  5042. +
  5043. + /* Restart the bulk eot timer since we just started the bulk channel.*/
  5044. + mod_timer(&bulk_eot_timer, jiffies + BULK_EOT_TIMER_INTERVAL);
  5045. +
  5046. + /* No need to search any further. */
  5047. + break;
  5048. + }
  5049. + }
  5050. + } else {
  5051. + timer_dbg("bulk_start_timer: Bulk DMA channel running.\n");
  5052. + }
  5053. +}
  5054. +
  5055. +static void tc_bulk_eot_timer_func(unsigned long dummy) {
  5056. + struct usb_hcd *hcd = (struct usb_hcd*)dummy;
  5057. + ASSERT(hcd);
  5058. + /* Because of a race condition in the top half, we might miss a bulk eot.
  5059. + This timer "simulates" a bulk eot if we don't get one for a while,
  5060. + hopefully correcting the situation. */
  5061. + timer_dbg("bulk_eot_timer timed out.\n");
  5062. + check_finished_bulk_tx_epids(hcd, 1);
  5063. +}
  5064. +
  5065. +
  5066. +/*************************************************************/
  5067. +/*************************************************************/
  5068. +/* Device driver block */
  5069. +/*************************************************************/
  5070. +/*************************************************************/
  5071. +
  5072. +/* Forward declarations for device driver functions */
  5073. +static int devdrv_hcd_probe(struct device *);
  5074. +static int devdrv_hcd_remove(struct device *);
  5075. +#ifdef CONFIG_PM
  5076. +static int devdrv_hcd_suspend(struct device *, u32, u32);
  5077. +static int devdrv_hcd_resume(struct device *, u32);
  5078. +#endif /* CONFIG_PM */
  5079. +
  5080. +/* the device */
  5081. +static struct platform_device *devdrv_hc_platform_device;
  5082. +
  5083. +/* device driver interface */
  5084. +static struct device_driver devdrv_hc_device_driver = {
  5085. + .name = (char *) hc_name,
  5086. + .bus = &platform_bus_type,
  5087. +
  5088. + .probe = devdrv_hcd_probe,
  5089. + .remove = devdrv_hcd_remove,
  5090. +
  5091. +#ifdef CONFIG_PM
  5092. + .suspend = devdrv_hcd_suspend,
  5093. + .resume = devdrv_hcd_resume,
  5094. +#endif /* CONFIG_PM */
  5095. +};
  5096. +
  5097. +/* initialize the host controller and driver */
  5098. +static int __init_or_module devdrv_hcd_probe(struct device *dev)
  5099. +{
  5100. + struct usb_hcd *hcd;
  5101. + struct crisv10_hcd *crisv10_hcd;
  5102. + int retval;
  5103. +
  5104. + /* Check DMA burst length */
  5105. + if(IO_EXTRACT(R_BUS_CONFIG, dma_burst, *R_BUS_CONFIG) !=
  5106. + IO_STATE(R_BUS_CONFIG, dma_burst, burst32)) {
  5107. + devdrv_err("Invalid DMA burst length in Etrax 100LX,"
  5108. + " needs to be 32\n");
  5109. + return -EPERM;
  5110. + }
  5111. +
  5112. + hcd = usb_create_hcd(&crisv10_hc_driver, dev, dev->bus_id);
  5113. + if (!hcd)
  5114. + return -ENOMEM;
  5115. +
  5116. + crisv10_hcd = hcd_to_crisv10_hcd(hcd);
  5117. + spin_lock_init(&crisv10_hcd->lock);
  5118. + crisv10_hcd->num_ports = num_ports();
  5119. + crisv10_hcd->running = 0;
  5120. +
  5121. + dev_set_drvdata(dev, crisv10_hcd);
  5122. +
  5123. + devdrv_dbg("ETRAX USB IRQs HC:%d RX:%d TX:%d\n", ETRAX_USB_HC_IRQ,
  5124. + ETRAX_USB_RX_IRQ, ETRAX_USB_TX_IRQ);
  5125. +
  5126. + /* Print out chip version read from registers */
  5127. + int rev_maj = *R_USB_REVISION & IO_MASK(R_USB_REVISION, major);
  5128. + int rev_min = *R_USB_REVISION & IO_MASK(R_USB_REVISION, minor);
  5129. + if(rev_min == 0) {
  5130. + devdrv_info("Etrax 100LX USB Revision %d v1,2\n", rev_maj);
  5131. + } else {
  5132. + devdrv_info("Etrax 100LX USB Revision %d v%d\n", rev_maj, rev_min);
  5133. + }
  5134. +
  5135. + devdrv_info("Bulk timer interval, start:%d eot:%d\n",
  5136. + BULK_START_TIMER_INTERVAL,
  5137. + BULK_EOT_TIMER_INTERVAL);
  5138. +
  5139. +
  5140. + /* Init root hub data structures */
  5141. + if(rh_init()) {
  5142. + devdrv_err("Failed init data for Root Hub\n");
  5143. + retval = -ENOMEM;
  5144. + }
  5145. +
  5146. + if(port_in_use(0)) {
  5147. + if (cris_request_io_interface(if_usb_1, "ETRAX100LX USB-HCD")) {
  5148. + printk(KERN_CRIT "usb-host: request IO interface usb1 failed");
  5149. + retval = -EBUSY;
  5150. + goto out;
  5151. + }
  5152. + devdrv_info("Claimed interface for USB physical port 1\n");
  5153. + }
  5154. + if(port_in_use(1)) {
  5155. + if (cris_request_io_interface(if_usb_2, "ETRAX100LX USB-HCD")) {
  5156. + /* Free first interface if second failed to be claimed */
  5157. + if(port_in_use(0)) {
  5158. + cris_free_io_interface(if_usb_1);
  5159. + }
  5160. + printk(KERN_CRIT "usb-host: request IO interface usb2 failed");
  5161. + retval = -EBUSY;
  5162. + goto out;
  5163. + }
  5164. + devdrv_info("Claimed interface for USB physical port 2\n");
  5165. + }
  5166. +
  5167. + /* Init transfer controller structs and locks */
  5168. + if((retval = tc_init(hcd)) != 0) {
  5169. + goto out;
  5170. + }
  5171. +
  5172. + /* Attach interrupt functions for DMA and init DMA controller */
  5173. + if((retval = tc_dma_init(hcd)) != 0) {
  5174. + goto out;
  5175. + }
  5176. +
  5177. + /* Attach the top IRQ handler for USB controller interrupts */
  5178. + if (request_irq(ETRAX_USB_HC_IRQ, crisv10_hcd_top_irq, 0,
  5179. + "ETRAX 100LX built-in USB (HC)", hcd)) {
  5180. + err("Could not allocate IRQ %d for USB", ETRAX_USB_HC_IRQ);
  5181. + retval = -EBUSY;
  5182. + goto out;
  5183. + }
  5184. +
  5185. + /* iso_eof is only enabled when isoc traffic is running. */
  5186. + *R_USB_IRQ_MASK_SET =
  5187. + /* IO_STATE(R_USB_IRQ_MASK_SET, iso_eof, set) | */
  5188. + IO_STATE(R_USB_IRQ_MASK_SET, bulk_eot, set) |
  5189. + IO_STATE(R_USB_IRQ_MASK_SET, epid_attn, set) |
  5190. + IO_STATE(R_USB_IRQ_MASK_SET, port_status, set) |
  5191. + IO_STATE(R_USB_IRQ_MASK_SET, ctl_status, set);
  5192. +
  5193. +
  5194. + crisv10_ready_wait();
  5195. + /* Reset the USB interface. */
  5196. + *R_USB_COMMAND =
  5197. + IO_STATE(R_USB_COMMAND, port_sel, nop) |
  5198. + IO_STATE(R_USB_COMMAND, port_cmd, reset) |
  5199. + IO_STATE(R_USB_COMMAND, ctrl_cmd, reset);
  5200. +
  5201. + /* Designer's Reference, p. 8 - 10 says we should Initate R_USB_FM_PSTART to
  5202. + 0x2A30 (10800), to guarantee that control traffic gets 10% of the
  5203. + bandwidth, and periodic transfer may allocate the rest (90%).
  5204. + This doesn't work though.
  5205. + The value 11960 is chosen to be just after the SOF token, with a couple
  5206. + of bit times extra for possible bit stuffing. */
  5207. + *R_USB_FM_PSTART = IO_FIELD(R_USB_FM_PSTART, value, 11960);
  5208. +
  5209. + crisv10_ready_wait();
  5210. + /* Configure the USB interface as a host controller. */
  5211. + *R_USB_COMMAND =
  5212. + IO_STATE(R_USB_COMMAND, port_sel, nop) |
  5213. + IO_STATE(R_USB_COMMAND, port_cmd, reset) |
  5214. + IO_STATE(R_USB_COMMAND, ctrl_cmd, host_config);
  5215. +
  5216. +
  5217. + /* Check so controller not busy before enabling ports */
  5218. + crisv10_ready_wait();
  5219. +
  5220. + /* Enable selected USB ports */
  5221. + if(port_in_use(0)) {
  5222. + *R_USB_PORT1_DISABLE = IO_STATE(R_USB_PORT1_DISABLE, disable, no);
  5223. + } else {
  5224. + *R_USB_PORT1_DISABLE = IO_STATE(R_USB_PORT1_DISABLE, disable, yes);
  5225. + }
  5226. + if(port_in_use(1)) {
  5227. + *R_USB_PORT2_DISABLE = IO_STATE(R_USB_PORT2_DISABLE, disable, no);
  5228. + } else {
  5229. + *R_USB_PORT2_DISABLE = IO_STATE(R_USB_PORT2_DISABLE, disable, yes);
  5230. + }
  5231. +
  5232. + crisv10_ready_wait();
  5233. + /* Start processing of USB traffic. */
  5234. + *R_USB_COMMAND =
  5235. + IO_STATE(R_USB_COMMAND, port_sel, nop) |
  5236. + IO_STATE(R_USB_COMMAND, port_cmd, reset) |
  5237. + IO_STATE(R_USB_COMMAND, ctrl_cmd, host_run);
  5238. +
  5239. + /* Do not continue probing initialization before USB interface is done */
  5240. + crisv10_ready_wait();
  5241. +
  5242. + /* Register our Host Controller to USB Core
  5243. + * Finish the remaining parts of generic HCD initialization: allocate the
  5244. + * buffers of consistent memory, register the bus
  5245. + * and call the driver's reset() and start() routines. */
  5246. + retval = usb_add_hcd(hcd, ETRAX_USB_HC_IRQ, IRQF_DISABLED);
  5247. + if (retval != 0) {
  5248. + devdrv_err("Failed registering HCD driver\n");
  5249. + goto out;
  5250. + }
  5251. +
  5252. + return 0;
  5253. +
  5254. + out:
  5255. + devdrv_hcd_remove(dev);
  5256. + return retval;
  5257. +}
  5258. +
  5259. +
  5260. +/* cleanup after the host controller and driver */
  5261. +static int __init_or_module devdrv_hcd_remove(struct device *dev)
  5262. +{
  5263. + struct crisv10_hcd *crisv10_hcd = dev_get_drvdata(dev);
  5264. + struct usb_hcd *hcd;
  5265. +
  5266. + if (!crisv10_hcd)
  5267. + return 0;
  5268. + hcd = crisv10_hcd_to_hcd(crisv10_hcd);
  5269. +
  5270. +
  5271. + /* Stop USB Controller in Etrax 100LX */
  5272. + crisv10_hcd_reset(hcd);
  5273. +
  5274. + usb_remove_hcd(hcd);
  5275. + devdrv_dbg("Removed HCD from USB Core\n");
  5276. +
  5277. + /* Free USB Controller IRQ */
  5278. + free_irq(ETRAX_USB_HC_IRQ, NULL);
  5279. +
  5280. + /* Free resources */
  5281. + tc_dma_destroy();
  5282. + tc_destroy();
  5283. +
  5284. +
  5285. + if(port_in_use(0)) {
  5286. + cris_free_io_interface(if_usb_1);
  5287. + }
  5288. + if(port_in_use(1)) {
  5289. + cris_free_io_interface(if_usb_2);
  5290. + }
  5291. +
  5292. + devdrv_dbg("Freed all claimed resources\n");
  5293. +
  5294. + return 0;
  5295. +}
  5296. +
  5297. +
  5298. +#ifdef CONFIG_PM
  5299. +
  5300. +static int devdrv_hcd_suspend(struct usb_hcd *hcd, u32 state, u32 level)
  5301. +{
  5302. + return 0; /* no-op for now */
  5303. +}
  5304. +
  5305. +static int devdrv_hcd_resume(struct usb_hcd *hcd, u32 level)
  5306. +{
  5307. + return 0; /* no-op for now */
  5308. +}
  5309. +
  5310. +#endif /* CONFIG_PM */
  5311. +
  5312. +
  5313. +
  5314. +/*************************************************************/
  5315. +/*************************************************************/
  5316. +/* Module block */
  5317. +/*************************************************************/
  5318. +/*************************************************************/
  5319. +
  5320. +/* register driver */
  5321. +static int __init module_hcd_init(void)
  5322. +{
  5323. +
  5324. + if (usb_disabled())
  5325. + return -ENODEV;
  5326. +
  5327. + /* Here we select enabled ports by following defines created from
  5328. + menuconfig */
  5329. +#ifndef CONFIG_ETRAX_USB_HOST_PORT1
  5330. + ports &= ~(1<<0);
  5331. +#endif
  5332. +#ifndef CONFIG_ETRAX_USB_HOST_PORT2
  5333. + ports &= ~(1<<1);
  5334. +#endif
  5335. +
  5336. + printk(KERN_INFO "%s version "VERSION" "COPYRIGHT"\n", product_desc);
  5337. +
  5338. + devdrv_hc_platform_device =
  5339. + platform_device_register_simple((char *) hc_name, 0, NULL, 0);
  5340. +
  5341. + if (IS_ERR(devdrv_hc_platform_device))
  5342. + return PTR_ERR(devdrv_hc_platform_device);
  5343. + return driver_register(&devdrv_hc_device_driver);
  5344. + /*
  5345. + * Note that we do not set the DMA mask for the device,
  5346. + * i.e. we pretend that we will use PIO, since no specific
  5347. + * allocation routines are needed for DMA buffers. This will
  5348. + * cause the HCD buffer allocation routines to fall back to
  5349. + * kmalloc().
  5350. + */
  5351. +}
  5352. +
  5353. +/* unregister driver */
  5354. +static void __exit module_hcd_exit(void)
  5355. +{
  5356. + driver_unregister(&devdrv_hc_device_driver);
  5357. +}
  5358. +
  5359. +
  5360. +/* Module hooks */
  5361. +module_init(module_hcd_init);
  5362. +module_exit(module_hcd_exit);
  5363. diff -Nur linux-2.6.29.1.orig/drivers/usb/host/hc-crisv10.h linux-2.6.29.1/drivers/usb/host/hc-crisv10.h
  5364. --- linux-2.6.29.1.orig/drivers/usb/host/hc-crisv10.h 1970-01-01 01:00:00.000000000 +0100
  5365. +++ linux-2.6.29.1/drivers/usb/host/hc-crisv10.h 2009-05-09 01:52:50.842184906 +0200
  5366. @@ -0,0 +1,331 @@
  5367. +#ifndef __LINUX_ETRAX_USB_H
  5368. +#define __LINUX_ETRAX_USB_H
  5369. +
  5370. +#include <linux/types.h>
  5371. +#include <linux/list.h>
  5372. +
  5373. +struct USB_IN_Desc {
  5374. + volatile __u16 sw_len;
  5375. + volatile __u16 command;
  5376. + volatile unsigned long next;
  5377. + volatile unsigned long buf;
  5378. + volatile __u16 hw_len;
  5379. + volatile __u16 status;
  5380. +};
  5381. +
  5382. +struct USB_SB_Desc {
  5383. + volatile __u16 sw_len;
  5384. + volatile __u16 command;
  5385. + volatile unsigned long next;
  5386. + volatile unsigned long buf;
  5387. +};
  5388. +
  5389. +struct USB_EP_Desc {
  5390. + volatile __u16 hw_len;
  5391. + volatile __u16 command;
  5392. + volatile unsigned long sub;
  5393. + volatile unsigned long next;
  5394. +};
  5395. +
  5396. +
  5397. +/* Root Hub port status struct */
  5398. +struct crisv10_rh {
  5399. + volatile __u16 wPortChange[2];
  5400. + volatile __u16 wPortStatusPrev[2];
  5401. +};
  5402. +
  5403. +/* HCD description */
  5404. +struct crisv10_hcd {
  5405. + spinlock_t lock;
  5406. + __u8 num_ports;
  5407. + __u8 running;
  5408. +};
  5409. +
  5410. +
  5411. +/* Endpoint HC private data description */
  5412. +struct crisv10_ep_priv {
  5413. + int epid;
  5414. +};
  5415. +
  5416. +/* Additional software state info for a USB Controller epid */
  5417. +struct etrax_epid {
  5418. + __u8 inuse; /* !0 = setup in Etrax and used for a endpoint */
  5419. + __u8 disabled; /* !0 = Temporarly disabled to avoid resubmission */
  5420. + __u8 type; /* Setup as: PIPE_BULK, PIPE_CONTROL ... */
  5421. + __u8 out_traffic; /* !0 = This epid is for out traffic */
  5422. +};
  5423. +
  5424. +/* Struct to hold information of scheduled later URB completion */
  5425. +struct urb_later_data {
  5426. +// struct work_struct ws;
  5427. + struct delayed_work ws;
  5428. + struct usb_hcd *hcd;
  5429. + struct urb *urb;
  5430. + int urb_num;
  5431. + int status;
  5432. +};
  5433. +
  5434. +
  5435. +typedef enum {
  5436. + STARTED,
  5437. + NOT_STARTED,
  5438. + UNLINK,
  5439. +} crisv10_urb_state_t;
  5440. +
  5441. +
  5442. +struct crisv10_urb_priv {
  5443. + /* Sequence number for this URB. Every new submited URB gets this from
  5444. + a incrementing counter. Used when a URB is scheduled for later finish to
  5445. + be sure that the intended URB hasn't already been completed (device
  5446. + drivers has a tendency to reuse URBs once they are completed, causing us
  5447. + to not be able to single old ones out only based on the URB pointer.) */
  5448. + __u32 urb_num;
  5449. +
  5450. + /* The first_sb field is used for freeing all SB descriptors belonging
  5451. + to an urb. The corresponding ep descriptor's sub pointer cannot be
  5452. + used for this since the DMA advances the sub pointer as it processes
  5453. + the sb list. */
  5454. + struct USB_SB_Desc *first_sb;
  5455. +
  5456. + /* The last_sb field referes to the last SB descriptor that belongs to
  5457. + this urb. This is important to know so we can free the SB descriptors
  5458. + that ranges between first_sb and last_sb. */
  5459. + struct USB_SB_Desc *last_sb;
  5460. +
  5461. + /* The rx_offset field is used in ctrl and bulk traffic to keep track
  5462. + of the offset in the urb's transfer_buffer where incoming data should be
  5463. + copied to. */
  5464. + __u32 rx_offset;
  5465. +
  5466. + /* Counter used in isochronous transfers to keep track of the
  5467. + number of packets received/transmitted. */
  5468. + __u32 isoc_packet_counter;
  5469. +
  5470. + /* Flag that marks if this Isoc Out URB has finished it's transfer. Used
  5471. + because several URBs can be finished before list is processed */
  5472. + __u8 isoc_out_done;
  5473. +
  5474. + /* This field is used to pass information about the urb's current state
  5475. + between the various interrupt handlers (thus marked volatile). */
  5476. + volatile crisv10_urb_state_t urb_state;
  5477. +
  5478. + /* In Ctrl transfers consist of (at least) 3 packets: SETUP, IN and ZOUT.
  5479. + When DMA8 sub-channel 2 has processed the SB list for this sequence we
  5480. + get a interrupt. We also get a interrupt for In transfers and which
  5481. + one of these interrupts that comes first depends of data size and device.
  5482. + To be sure that we have got both interrupts before we complete the URB
  5483. + we have these to flags that shows which part that has completed.
  5484. + We can then check when we get one of the interrupts that if the other has
  5485. + occured it's safe for us to complete the URB, otherwise we set appropriate
  5486. + flag and do the completion when we get the other interrupt. */
  5487. + volatile unsigned char ctrl_zout_done;
  5488. + volatile unsigned char ctrl_rx_done;
  5489. +
  5490. + /* Connection between the submitted urb and ETRAX epid number */
  5491. + __u8 epid;
  5492. +
  5493. + /* The rx_data_list field is used for periodic traffic, to hold
  5494. + received data for later processing in the the complete_urb functions,
  5495. + where the data us copied to the urb's transfer_buffer. Basically, we
  5496. + use this intermediate storage because we don't know when it's safe to
  5497. + reuse the transfer_buffer (FIXME?). */
  5498. + struct list_head rx_data_list;
  5499. +
  5500. +
  5501. + /* The interval time rounded up to closest 2^N */
  5502. + int interval;
  5503. +
  5504. + /* Pool of EP descriptors needed if it's a INTR transfer.
  5505. + Amount of EPs in pool correspons to how many INTR that should
  5506. + be inserted in TxIntrEPList (max 128, defined by MAX_INTR_INTERVAL) */
  5507. + struct USB_EP_Desc* intr_ep_pool[128];
  5508. +
  5509. + /* The mount of EPs allocated for this INTR URB */
  5510. + int intr_ep_pool_length;
  5511. +
  5512. + /* Pointer to info struct if URB is scheduled to be finished later */
  5513. + struct urb_later_data* later_data;
  5514. +};
  5515. +
  5516. +
  5517. +/* This struct is for passing data from the top half to the bottom half irq
  5518. + handlers */
  5519. +struct crisv10_irq_reg {
  5520. + struct usb_hcd* hcd;
  5521. + __u32 r_usb_epid_attn;
  5522. + __u8 r_usb_status;
  5523. + __u16 r_usb_rh_port_status_1;
  5524. + __u16 r_usb_rh_port_status_2;
  5525. + __u32 r_usb_irq_mask_read;
  5526. + __u32 r_usb_fm_number;
  5527. + struct work_struct usb_bh;
  5528. +};
  5529. +
  5530. +
  5531. +/* This struct is for passing data from the isoc top half to the isoc bottom
  5532. + half. */
  5533. +struct crisv10_isoc_complete_data {
  5534. + struct usb_hcd *hcd;
  5535. + struct urb *urb;
  5536. + struct work_struct usb_bh;
  5537. +};
  5538. +
  5539. +/* Entry item for URB lists for each endpint */
  5540. +typedef struct urb_entry
  5541. +{
  5542. + struct urb *urb;
  5543. + struct list_head list;
  5544. +} urb_entry_t;
  5545. +
  5546. +/* ---------------------------------------------------------------------------
  5547. + Virtual Root HUB
  5548. + ------------------------------------------------------------------------- */
  5549. +/* destination of request */
  5550. +#define RH_INTERFACE 0x01
  5551. +#define RH_ENDPOINT 0x02
  5552. +#define RH_OTHER 0x03
  5553. +
  5554. +#define RH_CLASS 0x20
  5555. +#define RH_VENDOR 0x40
  5556. +
  5557. +/* Requests: bRequest << 8 | bmRequestType */
  5558. +#define RH_GET_STATUS 0x0080
  5559. +#define RH_CLEAR_FEATURE 0x0100
  5560. +#define RH_SET_FEATURE 0x0300
  5561. +#define RH_SET_ADDRESS 0x0500
  5562. +#define RH_GET_DESCRIPTOR 0x0680
  5563. +#define RH_SET_DESCRIPTOR 0x0700
  5564. +#define RH_GET_CONFIGURATION 0x0880
  5565. +#define RH_SET_CONFIGURATION 0x0900
  5566. +#define RH_GET_STATE 0x0280
  5567. +#define RH_GET_INTERFACE 0x0A80
  5568. +#define RH_SET_INTERFACE 0x0B00
  5569. +#define RH_SYNC_FRAME 0x0C80
  5570. +/* Our Vendor Specific Request */
  5571. +#define RH_SET_EP 0x2000
  5572. +
  5573. +
  5574. +/* Hub port features */
  5575. +#define RH_PORT_CONNECTION 0x00
  5576. +#define RH_PORT_ENABLE 0x01
  5577. +#define RH_PORT_SUSPEND 0x02
  5578. +#define RH_PORT_OVER_CURRENT 0x03
  5579. +#define RH_PORT_RESET 0x04
  5580. +#define RH_PORT_POWER 0x08
  5581. +#define RH_PORT_LOW_SPEED 0x09
  5582. +#define RH_C_PORT_CONNECTION 0x10
  5583. +#define RH_C_PORT_ENABLE 0x11
  5584. +#define RH_C_PORT_SUSPEND 0x12
  5585. +#define RH_C_PORT_OVER_CURRENT 0x13
  5586. +#define RH_C_PORT_RESET 0x14
  5587. +
  5588. +/* Hub features */
  5589. +#define RH_C_HUB_LOCAL_POWER 0x00
  5590. +#define RH_C_HUB_OVER_CURRENT 0x01
  5591. +
  5592. +#define RH_DEVICE_REMOTE_WAKEUP 0x00
  5593. +#define RH_ENDPOINT_STALL 0x01
  5594. +
  5595. +/* Our Vendor Specific feature */
  5596. +#define RH_REMOVE_EP 0x00
  5597. +
  5598. +
  5599. +#define RH_ACK 0x01
  5600. +#define RH_REQ_ERR -1
  5601. +#define RH_NACK 0x00
  5602. +
  5603. +/* Field definitions for */
  5604. +
  5605. +#define USB_IN_command__eol__BITNR 0 /* command macros */
  5606. +#define USB_IN_command__eol__WIDTH 1
  5607. +#define USB_IN_command__eol__no 0
  5608. +#define USB_IN_command__eol__yes 1
  5609. +
  5610. +#define USB_IN_command__intr__BITNR 3
  5611. +#define USB_IN_command__intr__WIDTH 1
  5612. +#define USB_IN_command__intr__no 0
  5613. +#define USB_IN_command__intr__yes 1
  5614. +
  5615. +#define USB_IN_status__eop__BITNR 1 /* status macros. */
  5616. +#define USB_IN_status__eop__WIDTH 1
  5617. +#define USB_IN_status__eop__no 0
  5618. +#define USB_IN_status__eop__yes 1
  5619. +
  5620. +#define USB_IN_status__eot__BITNR 5
  5621. +#define USB_IN_status__eot__WIDTH 1
  5622. +#define USB_IN_status__eot__no 0
  5623. +#define USB_IN_status__eot__yes 1
  5624. +
  5625. +#define USB_IN_status__error__BITNR 6
  5626. +#define USB_IN_status__error__WIDTH 1
  5627. +#define USB_IN_status__error__no 0
  5628. +#define USB_IN_status__error__yes 1
  5629. +
  5630. +#define USB_IN_status__nodata__BITNR 7
  5631. +#define USB_IN_status__nodata__WIDTH 1
  5632. +#define USB_IN_status__nodata__no 0
  5633. +#define USB_IN_status__nodata__yes 1
  5634. +
  5635. +#define USB_IN_status__epid__BITNR 8
  5636. +#define USB_IN_status__epid__WIDTH 5
  5637. +
  5638. +#define USB_EP_command__eol__BITNR 0
  5639. +#define USB_EP_command__eol__WIDTH 1
  5640. +#define USB_EP_command__eol__no 0
  5641. +#define USB_EP_command__eol__yes 1
  5642. +
  5643. +#define USB_EP_command__eof__BITNR 1
  5644. +#define USB_EP_command__eof__WIDTH 1
  5645. +#define USB_EP_command__eof__no 0
  5646. +#define USB_EP_command__eof__yes 1
  5647. +
  5648. +#define USB_EP_command__intr__BITNR 3
  5649. +#define USB_EP_command__intr__WIDTH 1
  5650. +#define USB_EP_command__intr__no 0
  5651. +#define USB_EP_command__intr__yes 1
  5652. +
  5653. +#define USB_EP_command__enable__BITNR 4
  5654. +#define USB_EP_command__enable__WIDTH 1
  5655. +#define USB_EP_command__enable__no 0
  5656. +#define USB_EP_command__enable__yes 1
  5657. +
  5658. +#define USB_EP_command__hw_valid__BITNR 5
  5659. +#define USB_EP_command__hw_valid__WIDTH 1
  5660. +#define USB_EP_command__hw_valid__no 0
  5661. +#define USB_EP_command__hw_valid__yes 1
  5662. +
  5663. +#define USB_EP_command__epid__BITNR 8
  5664. +#define USB_EP_command__epid__WIDTH 5
  5665. +
  5666. +#define USB_SB_command__eol__BITNR 0 /* command macros. */
  5667. +#define USB_SB_command__eol__WIDTH 1
  5668. +#define USB_SB_command__eol__no 0
  5669. +#define USB_SB_command__eol__yes 1
  5670. +
  5671. +#define USB_SB_command__eot__BITNR 1
  5672. +#define USB_SB_command__eot__WIDTH 1
  5673. +#define USB_SB_command__eot__no 0
  5674. +#define USB_SB_command__eot__yes 1
  5675. +
  5676. +#define USB_SB_command__intr__BITNR 3
  5677. +#define USB_SB_command__intr__WIDTH 1
  5678. +#define USB_SB_command__intr__no 0
  5679. +#define USB_SB_command__intr__yes 1
  5680. +
  5681. +#define USB_SB_command__tt__BITNR 4
  5682. +#define USB_SB_command__tt__WIDTH 2
  5683. +#define USB_SB_command__tt__zout 0
  5684. +#define USB_SB_command__tt__in 1
  5685. +#define USB_SB_command__tt__out 2
  5686. +#define USB_SB_command__tt__setup 3
  5687. +
  5688. +
  5689. +#define USB_SB_command__rem__BITNR 8
  5690. +#define USB_SB_command__rem__WIDTH 6
  5691. +
  5692. +#define USB_SB_command__full__BITNR 6
  5693. +#define USB_SB_command__full__WIDTH 1
  5694. +#define USB_SB_command__full__no 0
  5695. +#define USB_SB_command__full__yes 1
  5696. +
  5697. +#endif
  5698. diff -Nur linux-2.6.29.1.orig/lib/klist.c linux-2.6.29.1/lib/klist.c
  5699. --- linux-2.6.29.1.orig/lib/klist.c 2009-04-02 22:55:27.000000000 +0200
  5700. +++ linux-2.6.29.1/lib/klist.c 2009-05-09 01:52:50.846185695 +0200
  5701. @@ -60,7 +60,7 @@
  5702. {
  5703. knode->n_klist = klist;
  5704. /* no knode deserves to start its life dead */
  5705. - WARN_ON(knode_dead(knode));
  5706. + //WARN_ON(knode_dead(knode));
  5707. }
  5708. static void knode_kill(struct klist_node *knode)