cris.patch 186 KB

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