cris.patch 189 KB

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