cris.patch 189 KB

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