1
0

cris.patch 189 KB

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