1
0

cris.patch 189 KB

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