cris.patch 189 KB

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