cris.patch 188 KB

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