cris.patch 189 KB

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