cris.patch 189 KB

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