704-fsl-mc-layerscape-support.patch 345 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297
  1. From 667f0792b6f6d000c10f21c29c397c84cbe77f4a Mon Sep 17 00:00:00 2001
  2. From: Yangbo Lu <[email protected]>
  3. Date: Wed, 17 Jan 2018 15:11:45 +0800
  4. Subject: [PATCH 10/30] fsl-mc: layerscape support
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This is an integrated patch for layerscape mc-bus support.
  9. Signed-off-by: Stuart Yoder <[email protected]>
  10. Signed-off-by: Bharat Bhushan <[email protected]>
  11. Signed-off-by: Arnd Bergmann <[email protected]>
  12. Signed-off-by: Laurentiu Tudor <[email protected]>
  13. Signed-off-by: Roy Pledge <[email protected]>
  14. Signed-off-by: Shiva Kerdel <[email protected]>
  15. Signed-off-by: Nipun Gupta <[email protected]>
  16. Signed-off-by: Ioana Ciornei <[email protected]>
  17. Signed-off-by: Horia Geantă <[email protected]>
  18. Signed-off-by: Yangbo Lu <[email protected]>
  19. ---
  20. drivers/staging/fsl-mc/bus/Kconfig | 41 +-
  21. drivers/staging/fsl-mc/bus/Makefile | 10 +-
  22. drivers/staging/fsl-mc/bus/dpbp-cmd.h | 80 ++
  23. drivers/staging/fsl-mc/bus/dpbp.c | 450 +--------
  24. drivers/staging/fsl-mc/bus/dpcon-cmd.h | 85 ++
  25. drivers/staging/fsl-mc/bus/dpcon.c | 317 ++++++
  26. drivers/staging/fsl-mc/bus/dpio/Makefile | 11 +
  27. .../{include/dpcon-cmd.h => bus/dpio/dpio-cmd.h} | 73 +-
  28. drivers/staging/fsl-mc/bus/dpio/dpio-driver.c | 296 ++++++
  29. drivers/staging/fsl-mc/bus/dpio/dpio-service.c | 693 +++++++++++++
  30. drivers/staging/fsl-mc/bus/dpio/dpio.c | 224 +++++
  31. drivers/staging/fsl-mc/bus/dpio/dpio.h | 109 ++
  32. drivers/staging/fsl-mc/bus/dpio/qbman-portal.c | 1049 ++++++++++++++++++++
  33. drivers/staging/fsl-mc/bus/dpio/qbman-portal.h | 662 ++++++++++++
  34. drivers/staging/fsl-mc/bus/dpio/qbman_debug.c | 853 ++++++++++++++++
  35. drivers/staging/fsl-mc/bus/dpio/qbman_debug.h | 136 +++
  36. drivers/staging/fsl-mc/bus/dpio/qbman_private.h | 171 ++++
  37. drivers/staging/fsl-mc/bus/dpmcp-cmd.h | 112 +--
  38. drivers/staging/fsl-mc/bus/dpmcp.c | 374 +------
  39. drivers/staging/fsl-mc/bus/dpmcp.h | 127 +--
  40. drivers/staging/fsl-mc/bus/dpmng-cmd.h | 14 +-
  41. drivers/staging/fsl-mc/bus/dpmng.c | 37 +-
  42. drivers/staging/fsl-mc/bus/dprc-cmd.h | 82 +-
  43. drivers/staging/fsl-mc/bus/dprc-driver.c | 38 +-
  44. drivers/staging/fsl-mc/bus/dprc.c | 629 +-----------
  45. drivers/staging/fsl-mc/bus/fsl-mc-allocator.c | 78 +-
  46. drivers/staging/fsl-mc/bus/fsl-mc-bus.c | 318 +++---
  47. drivers/staging/fsl-mc/bus/fsl-mc-iommu.c | 104 ++
  48. drivers/staging/fsl-mc/bus/fsl-mc-msi.c | 2 +-
  49. drivers/staging/fsl-mc/bus/fsl-mc-private.h | 6 +-
  50. .../staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c | 10 +-
  51. drivers/staging/fsl-mc/bus/mc-io.c | 4 +-
  52. drivers/staging/fsl-mc/bus/mc-ioctl.h | 22 +
  53. drivers/staging/fsl-mc/bus/mc-restool.c | 405 ++++++++
  54. drivers/staging/fsl-mc/bus/mc-sys.c | 14 +-
  55. drivers/staging/fsl-mc/include/dpaa2-fd.h | 706 +++++++++++++
  56. drivers/staging/fsl-mc/include/dpaa2-global.h | 202 ++++
  57. drivers/staging/fsl-mc/include/dpaa2-io.h | 190 ++++
  58. drivers/staging/fsl-mc/include/dpbp-cmd.h | 185 ----
  59. drivers/staging/fsl-mc/include/dpbp.h | 158 +--
  60. drivers/staging/fsl-mc/include/dpcon.h | 115 +++
  61. drivers/staging/fsl-mc/include/dpmng.h | 16 +-
  62. drivers/staging/fsl-mc/include/dpopr.h | 110 ++
  63. drivers/staging/fsl-mc/include/dprc.h | 470 +++------
  64. drivers/staging/fsl-mc/include/mc-bus.h | 7 +-
  65. drivers/staging/fsl-mc/include/mc-cmd.h | 44 +-
  66. drivers/staging/fsl-mc/include/mc-sys.h | 3 +-
  67. drivers/staging/fsl-mc/include/mc.h | 17 +-
  68. 48 files changed, 7247 insertions(+), 2612 deletions(-)
  69. create mode 100644 drivers/staging/fsl-mc/bus/dpbp-cmd.h
  70. create mode 100644 drivers/staging/fsl-mc/bus/dpcon-cmd.h
  71. create mode 100644 drivers/staging/fsl-mc/bus/dpcon.c
  72. create mode 100644 drivers/staging/fsl-mc/bus/dpio/Makefile
  73. rename drivers/staging/fsl-mc/{include/dpcon-cmd.h => bus/dpio/dpio-cmd.h} (64%)
  74. create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
  75. create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio-service.c
  76. create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio.c
  77. create mode 100644 drivers/staging/fsl-mc/bus/dpio/dpio.h
  78. create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
  79. create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
  80. create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman_debug.c
  81. create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman_debug.h
  82. create mode 100644 drivers/staging/fsl-mc/bus/dpio/qbman_private.h
  83. create mode 100644 drivers/staging/fsl-mc/bus/fsl-mc-iommu.c
  84. create mode 100644 drivers/staging/fsl-mc/bus/mc-ioctl.h
  85. create mode 100644 drivers/staging/fsl-mc/bus/mc-restool.c
  86. create mode 100644 drivers/staging/fsl-mc/include/dpaa2-fd.h
  87. create mode 100644 drivers/staging/fsl-mc/include/dpaa2-global.h
  88. create mode 100644 drivers/staging/fsl-mc/include/dpaa2-io.h
  89. delete mode 100644 drivers/staging/fsl-mc/include/dpbp-cmd.h
  90. create mode 100644 drivers/staging/fsl-mc/include/dpcon.h
  91. create mode 100644 drivers/staging/fsl-mc/include/dpopr.h
  92. --- a/drivers/staging/fsl-mc/bus/Kconfig
  93. +++ b/drivers/staging/fsl-mc/bus/Kconfig
  94. @@ -1,25 +1,40 @@
  95. #
  96. -# Freescale Management Complex (MC) bus drivers
  97. +# DPAA2 fsl-mc bus
  98. #
  99. -# Copyright (C) 2014 Freescale Semiconductor, Inc.
  100. +# Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  101. #
  102. # This file is released under the GPLv2
  103. #
  104. config FSL_MC_BUS
  105. - bool "Freescale Management Complex (MC) bus driver"
  106. - depends on OF && ARM64
  107. + bool "QorIQ DPAA2 fsl-mc bus driver"
  108. + depends on OF && ARCH_LAYERSCAPE
  109. select GENERIC_MSI_IRQ_DOMAIN
  110. help
  111. - Driver to enable the bus infrastructure for the Freescale
  112. - QorIQ Management Complex (fsl-mc). The fsl-mc is a hardware
  113. - module of the QorIQ LS2 SoCs, that does resource management
  114. - for hardware building-blocks in the SoC that can be used
  115. - to dynamically create networking hardware objects such as
  116. - network interfaces (NICs), crypto accelerator instances,
  117. - or L2 switches.
  118. + Driver to enable the bus infrastructure for the QorIQ DPAA2
  119. + architecture. The fsl-mc bus driver handles discovery of
  120. + DPAA2 objects (which are represented as Linux devices) and
  121. + binding objects to drivers.
  122. - Only enable this option when building the kernel for
  123. - Freescale QorQIQ LS2xxxx SoCs.
  124. +config FSL_MC_DPIO
  125. + tristate "QorIQ DPAA2 DPIO driver"
  126. + depends on FSL_MC_BUS
  127. + help
  128. + Driver for the DPAA2 DPIO object. A DPIO provides queue and
  129. + buffer management facilities for software to interact with
  130. + other DPAA2 objects. This driver does not expose the DPIO
  131. + objects individually, but groups them under a service layer
  132. + API.
  133. +config FSL_QBMAN_DEBUG
  134. + tristate "Freescale QBMAN Debug APIs"
  135. + depends on FSL_MC_DPIO
  136. + help
  137. + QBMan debug assistant APIs.
  138. +config FSL_MC_RESTOOL
  139. + tristate "Freescale Management Complex (MC) restool driver"
  140. + depends on FSL_MC_BUS
  141. + help
  142. + Driver that provides kernel support for the Freescale Management
  143. + Complex resource manager user-space tool.
  144. --- a/drivers/staging/fsl-mc/bus/Makefile
  145. +++ b/drivers/staging/fsl-mc/bus/Makefile
  146. @@ -17,4 +17,12 @@ mc-bus-driver-objs := fsl-mc-bus.o \
  147. fsl-mc-msi.o \
  148. irq-gic-v3-its-fsl-mc-msi.o \
  149. dpmcp.o \
  150. - dpbp.o
  151. + dpbp.o \
  152. + dpcon.o \
  153. + fsl-mc-iommu.o
  154. +
  155. +# MC DPIO driver
  156. +obj-$(CONFIG_FSL_MC_DPIO) += dpio/
  157. +
  158. +# MC restool kernel support
  159. +obj-$(CONFIG_FSL_MC_RESTOOL) += mc-restool.o
  160. --- /dev/null
  161. +++ b/drivers/staging/fsl-mc/bus/dpbp-cmd.h
  162. @@ -0,0 +1,80 @@
  163. +/*
  164. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  165. + *
  166. + * Redistribution and use in source and binary forms, with or without
  167. + * modification, are permitted provided that the following conditions are met:
  168. + * * Redistributions of source code must retain the above copyright
  169. + * notice, this list of conditions and the following disclaimer.
  170. + * * Redistributions in binary form must reproduce the above copyright
  171. + * notice, this list of conditions and the following disclaimer in the
  172. + * documentation and/or other materials provided with the distribution.
  173. + * * Neither the name of the above-listed copyright holders nor the
  174. + * names of any contributors may be used to endorse or promote products
  175. + * derived from this software without specific prior written permission.
  176. + *
  177. + * ALTERNATIVELY, this software may be distributed under the terms of the
  178. + * GNU General Public License ("GPL") as published by the Free Software
  179. + * Foundation, either version 2 of that License or (at your option) any
  180. + * later version.
  181. + *
  182. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  183. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  184. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  185. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  186. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  187. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  188. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  189. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  190. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  191. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  192. + * POSSIBILITY OF SUCH DAMAGE.
  193. + */
  194. +#ifndef _FSL_DPBP_CMD_H
  195. +#define _FSL_DPBP_CMD_H
  196. +
  197. +/* DPBP Version */
  198. +#define DPBP_VER_MAJOR 3
  199. +#define DPBP_VER_MINOR 2
  200. +
  201. +/* Command versioning */
  202. +#define DPBP_CMD_BASE_VERSION 1
  203. +#define DPBP_CMD_ID_OFFSET 4
  204. +
  205. +#define DPBP_CMD(id) ((id << DPBP_CMD_ID_OFFSET) | DPBP_CMD_BASE_VERSION)
  206. +
  207. +/* Command IDs */
  208. +#define DPBP_CMDID_CLOSE DPBP_CMD(0x800)
  209. +#define DPBP_CMDID_OPEN DPBP_CMD(0x804)
  210. +#define DPBP_CMDID_GET_API_VERSION DPBP_CMD(0xa04)
  211. +
  212. +#define DPBP_CMDID_ENABLE DPBP_CMD(0x002)
  213. +#define DPBP_CMDID_DISABLE DPBP_CMD(0x003)
  214. +#define DPBP_CMDID_GET_ATTR DPBP_CMD(0x004)
  215. +#define DPBP_CMDID_RESET DPBP_CMD(0x005)
  216. +#define DPBP_CMDID_IS_ENABLED DPBP_CMD(0x006)
  217. +
  218. +struct dpbp_cmd_open {
  219. + __le32 dpbp_id;
  220. +};
  221. +
  222. +struct dpbp_cmd_destroy {
  223. + __le32 object_id;
  224. +};
  225. +
  226. +#define DPBP_ENABLE 0x1
  227. +
  228. +struct dpbp_rsp_is_enabled {
  229. + u8 enabled;
  230. +};
  231. +
  232. +struct dpbp_rsp_get_attributes {
  233. + /* response word 0 */
  234. + __le16 pad;
  235. + __le16 bpid;
  236. + __le32 id;
  237. + /* response word 1 */
  238. + __le16 version_major;
  239. + __le16 version_minor;
  240. +};
  241. +
  242. +#endif /* _FSL_DPBP_CMD_H */
  243. --- a/drivers/staging/fsl-mc/bus/dpbp.c
  244. +++ b/drivers/staging/fsl-mc/bus/dpbp.c
  245. @@ -1,4 +1,5 @@
  246. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  247. +/*
  248. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  249. *
  250. * Redistribution and use in source and binary forms, with or without
  251. * modification, are permitted provided that the following conditions are met:
  252. @@ -11,7 +12,6 @@
  253. * names of any contributors may be used to endorse or promote products
  254. * derived from this software without specific prior written permission.
  255. *
  256. - *
  257. * ALTERNATIVELY, this software may be distributed under the terms of the
  258. * GNU General Public License ("GPL") as published by the Free Software
  259. * Foundation, either version 2 of that License or (at your option) any
  260. @@ -32,7 +32,8 @@
  261. #include "../include/mc-sys.h"
  262. #include "../include/mc-cmd.h"
  263. #include "../include/dpbp.h"
  264. -#include "../include/dpbp-cmd.h"
  265. +
  266. +#include "dpbp-cmd.h"
  267. /**
  268. * dpbp_open() - Open a control session for the specified object.
  269. @@ -105,74 +106,6 @@ int dpbp_close(struct fsl_mc_io *mc_io,
  270. EXPORT_SYMBOL(dpbp_close);
  271. /**
  272. - * dpbp_create() - Create the DPBP object.
  273. - * @mc_io: Pointer to MC portal's I/O object
  274. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  275. - * @cfg: Configuration structure
  276. - * @token: Returned token; use in subsequent API calls
  277. - *
  278. - * Create the DPBP object, allocate required resources and
  279. - * perform required initialization.
  280. - *
  281. - * The object can be created either by declaring it in the
  282. - * DPL file, or by calling this function.
  283. - * This function returns a unique authentication token,
  284. - * associated with the specific object ID and the specific MC
  285. - * portal; this token must be used in all subsequent calls to
  286. - * this specific object. For objects that are created using the
  287. - * DPL file, call dpbp_open function to get an authentication
  288. - * token first.
  289. - *
  290. - * Return: '0' on Success; Error code otherwise.
  291. - */
  292. -int dpbp_create(struct fsl_mc_io *mc_io,
  293. - u32 cmd_flags,
  294. - const struct dpbp_cfg *cfg,
  295. - u16 *token)
  296. -{
  297. - struct mc_command cmd = { 0 };
  298. - int err;
  299. -
  300. - (void)(cfg); /* unused */
  301. -
  302. - /* prepare command */
  303. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_CREATE,
  304. - cmd_flags, 0);
  305. -
  306. - /* send command to mc*/
  307. - err = mc_send_command(mc_io, &cmd);
  308. - if (err)
  309. - return err;
  310. -
  311. - /* retrieve response parameters */
  312. - *token = mc_cmd_hdr_read_token(&cmd);
  313. -
  314. - return 0;
  315. -}
  316. -
  317. -/**
  318. - * dpbp_destroy() - Destroy the DPBP object and release all its resources.
  319. - * @mc_io: Pointer to MC portal's I/O object
  320. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  321. - * @token: Token of DPBP object
  322. - *
  323. - * Return: '0' on Success; error code otherwise.
  324. - */
  325. -int dpbp_destroy(struct fsl_mc_io *mc_io,
  326. - u32 cmd_flags,
  327. - u16 token)
  328. -{
  329. - struct mc_command cmd = { 0 };
  330. -
  331. - /* prepare command */
  332. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_DESTROY,
  333. - cmd_flags, token);
  334. -
  335. - /* send command to mc*/
  336. - return mc_send_command(mc_io, &cmd);
  337. -}
  338. -
  339. -/**
  340. * dpbp_enable() - Enable the DPBP.
  341. * @mc_io: Pointer to MC portal's I/O object
  342. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  343. @@ -250,6 +183,7 @@ int dpbp_is_enabled(struct fsl_mc_io *mc
  344. return 0;
  345. }
  346. +EXPORT_SYMBOL(dpbp_is_enabled);
  347. /**
  348. * dpbp_reset() - Reset the DPBP, returns the object to initial state.
  349. @@ -272,310 +206,7 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
  350. /* send command to mc*/
  351. return mc_send_command(mc_io, &cmd);
  352. }
  353. -
  354. -/**
  355. - * dpbp_set_irq() - Set IRQ information for the DPBP to trigger an interrupt.
  356. - * @mc_io: Pointer to MC portal's I/O object
  357. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  358. - * @token: Token of DPBP object
  359. - * @irq_index: Identifies the interrupt index to configure
  360. - * @irq_cfg: IRQ configuration
  361. - *
  362. - * Return: '0' on Success; Error code otherwise.
  363. - */
  364. -int dpbp_set_irq(struct fsl_mc_io *mc_io,
  365. - u32 cmd_flags,
  366. - u16 token,
  367. - u8 irq_index,
  368. - struct dpbp_irq_cfg *irq_cfg)
  369. -{
  370. - struct mc_command cmd = { 0 };
  371. - struct dpbp_cmd_set_irq *cmd_params;
  372. -
  373. - /* prepare command */
  374. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ,
  375. - cmd_flags, token);
  376. - cmd_params = (struct dpbp_cmd_set_irq *)cmd.params;
  377. - cmd_params->irq_index = irq_index;
  378. - cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
  379. - cmd_params->irq_addr = cpu_to_le64(irq_cfg->addr);
  380. - cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
  381. -
  382. - /* send command to mc*/
  383. - return mc_send_command(mc_io, &cmd);
  384. -}
  385. -
  386. -/**
  387. - * dpbp_get_irq() - Get IRQ information from the DPBP.
  388. - * @mc_io: Pointer to MC portal's I/O object
  389. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  390. - * @token: Token of DPBP object
  391. - * @irq_index: The interrupt index to configure
  392. - * @type: Interrupt type: 0 represents message interrupt
  393. - * type (both irq_addr and irq_val are valid)
  394. - * @irq_cfg: IRQ attributes
  395. - *
  396. - * Return: '0' on Success; Error code otherwise.
  397. - */
  398. -int dpbp_get_irq(struct fsl_mc_io *mc_io,
  399. - u32 cmd_flags,
  400. - u16 token,
  401. - u8 irq_index,
  402. - int *type,
  403. - struct dpbp_irq_cfg *irq_cfg)
  404. -{
  405. - struct mc_command cmd = { 0 };
  406. - struct dpbp_cmd_get_irq *cmd_params;
  407. - struct dpbp_rsp_get_irq *rsp_params;
  408. - int err;
  409. -
  410. - /* prepare command */
  411. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ,
  412. - cmd_flags, token);
  413. - cmd_params = (struct dpbp_cmd_get_irq *)cmd.params;
  414. - cmd_params->irq_index = irq_index;
  415. -
  416. - /* send command to mc*/
  417. - err = mc_send_command(mc_io, &cmd);
  418. - if (err)
  419. - return err;
  420. -
  421. - /* retrieve response parameters */
  422. - rsp_params = (struct dpbp_rsp_get_irq *)cmd.params;
  423. - irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
  424. - irq_cfg->addr = le64_to_cpu(rsp_params->irq_addr);
  425. - irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
  426. - *type = le32_to_cpu(rsp_params->type);
  427. -
  428. - return 0;
  429. -}
  430. -
  431. -/**
  432. - * dpbp_set_irq_enable() - Set overall interrupt state.
  433. - * @mc_io: Pointer to MC portal's I/O object
  434. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  435. - * @token: Token of DPBP object
  436. - * @irq_index: The interrupt index to configure
  437. - * @en: Interrupt state - enable = 1, disable = 0
  438. - *
  439. - * Allows GPP software to control when interrupts are generated.
  440. - * Each interrupt can have up to 32 causes. The enable/disable control's the
  441. - * overall interrupt state. if the interrupt is disabled no causes will cause
  442. - * an interrupt.
  443. - *
  444. - * Return: '0' on Success; Error code otherwise.
  445. - */
  446. -int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
  447. - u32 cmd_flags,
  448. - u16 token,
  449. - u8 irq_index,
  450. - u8 en)
  451. -{
  452. - struct mc_command cmd = { 0 };
  453. - struct dpbp_cmd_set_irq_enable *cmd_params;
  454. -
  455. - /* prepare command */
  456. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_ENABLE,
  457. - cmd_flags, token);
  458. - cmd_params = (struct dpbp_cmd_set_irq_enable *)cmd.params;
  459. - cmd_params->enable = en & DPBP_ENABLE;
  460. - cmd_params->irq_index = irq_index;
  461. -
  462. - /* send command to mc*/
  463. - return mc_send_command(mc_io, &cmd);
  464. -}
  465. -
  466. -/**
  467. - * dpbp_get_irq_enable() - Get overall interrupt state
  468. - * @mc_io: Pointer to MC portal's I/O object
  469. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  470. - * @token: Token of DPBP object
  471. - * @irq_index: The interrupt index to configure
  472. - * @en: Returned interrupt state - enable = 1, disable = 0
  473. - *
  474. - * Return: '0' on Success; Error code otherwise.
  475. - */
  476. -int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
  477. - u32 cmd_flags,
  478. - u16 token,
  479. - u8 irq_index,
  480. - u8 *en)
  481. -{
  482. - struct mc_command cmd = { 0 };
  483. - struct dpbp_cmd_get_irq_enable *cmd_params;
  484. - struct dpbp_rsp_get_irq_enable *rsp_params;
  485. - int err;
  486. -
  487. - /* prepare command */
  488. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_ENABLE,
  489. - cmd_flags, token);
  490. - cmd_params = (struct dpbp_cmd_get_irq_enable *)cmd.params;
  491. - cmd_params->irq_index = irq_index;
  492. -
  493. - /* send command to mc*/
  494. - err = mc_send_command(mc_io, &cmd);
  495. - if (err)
  496. - return err;
  497. -
  498. - /* retrieve response parameters */
  499. - rsp_params = (struct dpbp_rsp_get_irq_enable *)cmd.params;
  500. - *en = rsp_params->enabled & DPBP_ENABLE;
  501. - return 0;
  502. -}
  503. -
  504. -/**
  505. - * dpbp_set_irq_mask() - Set interrupt mask.
  506. - * @mc_io: Pointer to MC portal's I/O object
  507. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  508. - * @token: Token of DPBP object
  509. - * @irq_index: The interrupt index to configure
  510. - * @mask: Event mask to trigger interrupt;
  511. - * each bit:
  512. - * 0 = ignore event
  513. - * 1 = consider event for asserting IRQ
  514. - *
  515. - * Every interrupt can have up to 32 causes and the interrupt model supports
  516. - * masking/unmasking each cause independently
  517. - *
  518. - * Return: '0' on Success; Error code otherwise.
  519. - */
  520. -int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
  521. - u32 cmd_flags,
  522. - u16 token,
  523. - u8 irq_index,
  524. - u32 mask)
  525. -{
  526. - struct mc_command cmd = { 0 };
  527. - struct dpbp_cmd_set_irq_mask *cmd_params;
  528. -
  529. - /* prepare command */
  530. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_IRQ_MASK,
  531. - cmd_flags, token);
  532. - cmd_params = (struct dpbp_cmd_set_irq_mask *)cmd.params;
  533. - cmd_params->mask = cpu_to_le32(mask);
  534. - cmd_params->irq_index = irq_index;
  535. -
  536. - /* send command to mc*/
  537. - return mc_send_command(mc_io, &cmd);
  538. -}
  539. -
  540. -/**
  541. - * dpbp_get_irq_mask() - Get interrupt mask.
  542. - * @mc_io: Pointer to MC portal's I/O object
  543. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  544. - * @token: Token of DPBP object
  545. - * @irq_index: The interrupt index to configure
  546. - * @mask: Returned event mask to trigger interrupt
  547. - *
  548. - * Every interrupt can have up to 32 causes and the interrupt model supports
  549. - * masking/unmasking each cause independently
  550. - *
  551. - * Return: '0' on Success; Error code otherwise.
  552. - */
  553. -int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
  554. - u32 cmd_flags,
  555. - u16 token,
  556. - u8 irq_index,
  557. - u32 *mask)
  558. -{
  559. - struct mc_command cmd = { 0 };
  560. - struct dpbp_cmd_get_irq_mask *cmd_params;
  561. - struct dpbp_rsp_get_irq_mask *rsp_params;
  562. - int err;
  563. -
  564. - /* prepare command */
  565. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_MASK,
  566. - cmd_flags, token);
  567. - cmd_params = (struct dpbp_cmd_get_irq_mask *)cmd.params;
  568. - cmd_params->irq_index = irq_index;
  569. -
  570. - /* send command to mc*/
  571. - err = mc_send_command(mc_io, &cmd);
  572. - if (err)
  573. - return err;
  574. -
  575. - /* retrieve response parameters */
  576. - rsp_params = (struct dpbp_rsp_get_irq_mask *)cmd.params;
  577. - *mask = le32_to_cpu(rsp_params->mask);
  578. -
  579. - return 0;
  580. -}
  581. -
  582. -/**
  583. - * dpbp_get_irq_status() - Get the current status of any pending interrupts.
  584. - *
  585. - * @mc_io: Pointer to MC portal's I/O object
  586. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  587. - * @token: Token of DPBP object
  588. - * @irq_index: The interrupt index to configure
  589. - * @status: Returned interrupts status - one bit per cause:
  590. - * 0 = no interrupt pending
  591. - * 1 = interrupt pending
  592. - *
  593. - * Return: '0' on Success; Error code otherwise.
  594. - */
  595. -int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
  596. - u32 cmd_flags,
  597. - u16 token,
  598. - u8 irq_index,
  599. - u32 *status)
  600. -{
  601. - struct mc_command cmd = { 0 };
  602. - struct dpbp_cmd_get_irq_status *cmd_params;
  603. - struct dpbp_rsp_get_irq_status *rsp_params;
  604. - int err;
  605. -
  606. - /* prepare command */
  607. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_IRQ_STATUS,
  608. - cmd_flags, token);
  609. - cmd_params = (struct dpbp_cmd_get_irq_status *)cmd.params;
  610. - cmd_params->status = cpu_to_le32(*status);
  611. - cmd_params->irq_index = irq_index;
  612. -
  613. - /* send command to mc*/
  614. - err = mc_send_command(mc_io, &cmd);
  615. - if (err)
  616. - return err;
  617. -
  618. - /* retrieve response parameters */
  619. - rsp_params = (struct dpbp_rsp_get_irq_status *)cmd.params;
  620. - *status = le32_to_cpu(rsp_params->status);
  621. -
  622. - return 0;
  623. -}
  624. -
  625. -/**
  626. - * dpbp_clear_irq_status() - Clear a pending interrupt's status
  627. - *
  628. - * @mc_io: Pointer to MC portal's I/O object
  629. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  630. - * @token: Token of DPBP object
  631. - * @irq_index: The interrupt index to configure
  632. - * @status: Bits to clear (W1C) - one bit per cause:
  633. - * 0 = don't change
  634. - * 1 = clear status bit
  635. - *
  636. - * Return: '0' on Success; Error code otherwise.
  637. - */
  638. -int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
  639. - u32 cmd_flags,
  640. - u16 token,
  641. - u8 irq_index,
  642. - u32 status)
  643. -{
  644. - struct mc_command cmd = { 0 };
  645. - struct dpbp_cmd_clear_irq_status *cmd_params;
  646. -
  647. - /* prepare command */
  648. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_CLEAR_IRQ_STATUS,
  649. - cmd_flags, token);
  650. - cmd_params = (struct dpbp_cmd_clear_irq_status *)cmd.params;
  651. - cmd_params->status = cpu_to_le32(status);
  652. - cmd_params->irq_index = irq_index;
  653. -
  654. - /* send command to mc*/
  655. - return mc_send_command(mc_io, &cmd);
  656. -}
  657. +EXPORT_SYMBOL(dpbp_reset);
  658. /**
  659. * dpbp_get_attributes - Retrieve DPBP attributes.
  660. @@ -609,83 +240,40 @@ int dpbp_get_attributes(struct fsl_mc_io
  661. rsp_params = (struct dpbp_rsp_get_attributes *)cmd.params;
  662. attr->bpid = le16_to_cpu(rsp_params->bpid);
  663. attr->id = le32_to_cpu(rsp_params->id);
  664. - attr->version.major = le16_to_cpu(rsp_params->version_major);
  665. - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
  666. return 0;
  667. }
  668. EXPORT_SYMBOL(dpbp_get_attributes);
  669. /**
  670. - * dpbp_set_notifications() - Set notifications towards software
  671. - * @mc_io: Pointer to MC portal's I/O object
  672. + * dpbp_get_api_version - Get Data Path Buffer Pool API version
  673. + * @mc_io: Pointer to Mc portal's I/O object
  674. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  675. - * @token: Token of DPBP object
  676. - * @cfg: notifications configuration
  677. + * @major_ver: Major version of Buffer Pool API
  678. + * @minor_ver: Minor version of Buffer Pool API
  679. *
  680. * Return: '0' on Success; Error code otherwise.
  681. */
  682. -int dpbp_set_notifications(struct fsl_mc_io *mc_io,
  683. - u32 cmd_flags,
  684. - u16 token,
  685. - struct dpbp_notification_cfg *cfg)
  686. +int dpbp_get_api_version(struct fsl_mc_io *mc_io,
  687. + u32 cmd_flags,
  688. + u16 *major_ver,
  689. + u16 *minor_ver)
  690. {
  691. struct mc_command cmd = { 0 };
  692. - struct dpbp_cmd_set_notifications *cmd_params;
  693. -
  694. - /* prepare command */
  695. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_SET_NOTIFICATIONS,
  696. - cmd_flags, token);
  697. - cmd_params = (struct dpbp_cmd_set_notifications *)cmd.params;
  698. - cmd_params->depletion_entry = cpu_to_le32(cfg->depletion_entry);
  699. - cmd_params->depletion_exit = cpu_to_le32(cfg->depletion_exit);
  700. - cmd_params->surplus_entry = cpu_to_le32(cfg->surplus_entry);
  701. - cmd_params->surplus_exit = cpu_to_le32(cfg->surplus_exit);
  702. - cmd_params->options = cpu_to_le16(cfg->options);
  703. - cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
  704. - cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
  705. -
  706. - /* send command to mc*/
  707. - return mc_send_command(mc_io, &cmd);
  708. -}
  709. -
  710. -/**
  711. - * dpbp_get_notifications() - Get the notifications configuration
  712. - * @mc_io: Pointer to MC portal's I/O object
  713. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  714. - * @token: Token of DPBP object
  715. - * @cfg: notifications configuration
  716. - *
  717. - * Return: '0' on Success; Error code otherwise.
  718. - */
  719. -int dpbp_get_notifications(struct fsl_mc_io *mc_io,
  720. - u32 cmd_flags,
  721. - u16 token,
  722. - struct dpbp_notification_cfg *cfg)
  723. -{
  724. - struct mc_command cmd = { 0 };
  725. - struct dpbp_rsp_get_notifications *rsp_params;
  726. int err;
  727. /* prepare command */
  728. - cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_NOTIFICATIONS,
  729. - cmd_flags,
  730. - token);
  731. + cmd.header = mc_encode_cmd_header(DPBP_CMDID_GET_API_VERSION,
  732. + cmd_flags, 0);
  733. - /* send command to mc*/
  734. + /* send command to mc */
  735. err = mc_send_command(mc_io, &cmd);
  736. if (err)
  737. return err;
  738. /* retrieve response parameters */
  739. - rsp_params = (struct dpbp_rsp_get_notifications *)cmd.params;
  740. - cfg->depletion_entry = le32_to_cpu(rsp_params->depletion_entry);
  741. - cfg->depletion_exit = le32_to_cpu(rsp_params->depletion_exit);
  742. - cfg->surplus_entry = le32_to_cpu(rsp_params->surplus_entry);
  743. - cfg->surplus_exit = le32_to_cpu(rsp_params->surplus_exit);
  744. - cfg->options = le16_to_cpu(rsp_params->options);
  745. - cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
  746. - cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
  747. + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  748. return 0;
  749. }
  750. +EXPORT_SYMBOL(dpbp_get_api_version);
  751. --- /dev/null
  752. +++ b/drivers/staging/fsl-mc/bus/dpcon-cmd.h
  753. @@ -0,0 +1,85 @@
  754. +/*
  755. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  756. + *
  757. + * Redistribution and use in source and binary forms, with or without
  758. + * modification, are permitted provided that the following conditions are met:
  759. + * * Redistributions of source code must retain the above copyright
  760. + * notice, this list of conditions and the following disclaimer.
  761. + * * Redistributions in binary form must reproduce the above copyright
  762. + * notice, this list of conditions and the following disclaimer in the
  763. + * documentation and/or other materials provided with the distribution.
  764. + * * Neither the name of the above-listed copyright holders nor the
  765. + * names of any contributors may be used to endorse or promote products
  766. + * derived from this software without specific prior written permission.
  767. + *
  768. + * ALTERNATIVELY, this software may be distributed under the terms of the
  769. + * GNU General Public License ("GPL") as published by the Free Software
  770. + * Foundation, either version 2 of that License or (at your option) any
  771. + * later version.
  772. + *
  773. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  774. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  775. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  776. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  777. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  778. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  779. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  780. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  781. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  782. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  783. + * POSSIBILITY OF SUCH DAMAGE.
  784. + */
  785. +#ifndef _FSL_DPCON_CMD_H
  786. +#define _FSL_DPCON_CMD_H
  787. +
  788. +/* DPCON Version */
  789. +#define DPCON_VER_MAJOR 3
  790. +#define DPCON_VER_MINOR 2
  791. +
  792. +/* Command versioning */
  793. +#define DPCON_CMD_BASE_VERSION 1
  794. +#define DPCON_CMD_ID_OFFSET 4
  795. +
  796. +#define DPCON_CMD(id) (((id) << DPCON_CMD_ID_OFFSET) | DPCON_CMD_BASE_VERSION)
  797. +
  798. +/* Command IDs */
  799. +#define DPCON_CMDID_CLOSE DPCON_CMD(0x800)
  800. +#define DPCON_CMDID_OPEN DPCON_CMD(0x808)
  801. +#define DPCON_CMDID_GET_API_VERSION DPCON_CMD(0xa08)
  802. +
  803. +#define DPCON_CMDID_ENABLE DPCON_CMD(0x002)
  804. +#define DPCON_CMDID_DISABLE DPCON_CMD(0x003)
  805. +#define DPCON_CMDID_GET_ATTR DPCON_CMD(0x004)
  806. +#define DPCON_CMDID_RESET DPCON_CMD(0x005)
  807. +#define DPCON_CMDID_IS_ENABLED DPCON_CMD(0x006)
  808. +
  809. +#define DPCON_CMDID_SET_NOTIFICATION DPCON_CMD(0x100)
  810. +
  811. +struct dpcon_cmd_open {
  812. + __le32 dpcon_id;
  813. +};
  814. +
  815. +#define DPCON_ENABLE 1
  816. +
  817. +struct dpcon_rsp_is_enabled {
  818. + u8 enabled;
  819. +};
  820. +
  821. +struct dpcon_rsp_get_attr {
  822. + /* response word 0 */
  823. + __le32 id;
  824. + __le16 qbman_ch_id;
  825. + u8 num_priorities;
  826. + u8 pad;
  827. +};
  828. +
  829. +struct dpcon_cmd_set_notification {
  830. + /* cmd word 0 */
  831. + __le32 dpio_id;
  832. + u8 priority;
  833. + u8 pad[3];
  834. + /* cmd word 1 */
  835. + __le64 user_ctx;
  836. +};
  837. +
  838. +#endif /* _FSL_DPCON_CMD_H */
  839. --- /dev/null
  840. +++ b/drivers/staging/fsl-mc/bus/dpcon.c
  841. @@ -0,0 +1,317 @@
  842. +/* Copyright 2013-2016 Freescale Semiconductor Inc.
  843. + *
  844. + * Redistribution and use in source and binary forms, with or without
  845. + * modification, are permitted provided that the following conditions are met:
  846. + * * Redistributions of source code must retain the above copyright
  847. + * notice, this list of conditions and the following disclaimer.
  848. + * * Redistributions in binary form must reproduce the above copyright
  849. + * notice, this list of conditions and the following disclaimer in the
  850. + * documentation and/or other materials provided with the distribution.
  851. + * * Neither the name of the above-listed copyright holders nor the
  852. + * names of any contributors may be used to endorse or promote products
  853. + * derived from this software without specific prior written permission.
  854. + *
  855. + *
  856. + * ALTERNATIVELY, this software may be distributed under the terms of the
  857. + * GNU General Public License ("GPL") as published by the Free Software
  858. + * Foundation, either version 2 of that License or (at your option) any
  859. + * later version.
  860. + *
  861. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  862. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  863. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  864. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  865. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  866. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  867. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  868. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  869. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  870. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  871. + * POSSIBILITY OF SUCH DAMAGE.
  872. + */
  873. +#include "../include/mc-sys.h"
  874. +#include "../include/mc-cmd.h"
  875. +#include "../include/dpcon.h"
  876. +
  877. +#include "dpcon-cmd.h"
  878. +
  879. +/**
  880. + * dpcon_open() - Open a control session for the specified object
  881. + * @mc_io: Pointer to MC portal's I/O object
  882. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  883. + * @dpcon_id: DPCON unique ID
  884. + * @token: Returned token; use in subsequent API calls
  885. + *
  886. + * This function can be used to open a control session for an
  887. + * already created object; an object may have been declared in
  888. + * the DPL or by calling the dpcon_create() function.
  889. + * This function returns a unique authentication token,
  890. + * associated with the specific object ID and the specific MC
  891. + * portal; this token must be used in all subsequent commands for
  892. + * this specific object.
  893. + *
  894. + * Return: '0' on Success; Error code otherwise.
  895. + */
  896. +int dpcon_open(struct fsl_mc_io *mc_io,
  897. + u32 cmd_flags,
  898. + int dpcon_id,
  899. + u16 *token)
  900. +{
  901. + struct mc_command cmd = { 0 };
  902. + struct dpcon_cmd_open *dpcon_cmd;
  903. + int err;
  904. +
  905. + /* prepare command */
  906. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_OPEN,
  907. + cmd_flags,
  908. + 0);
  909. + dpcon_cmd = (struct dpcon_cmd_open *)cmd.params;
  910. + dpcon_cmd->dpcon_id = cpu_to_le32(dpcon_id);
  911. +
  912. + /* send command to mc*/
  913. + err = mc_send_command(mc_io, &cmd);
  914. + if (err)
  915. + return err;
  916. +
  917. + /* retrieve response parameters */
  918. + *token = mc_cmd_hdr_read_token(&cmd);
  919. +
  920. + return 0;
  921. +}
  922. +EXPORT_SYMBOL(dpcon_open);
  923. +
  924. +/**
  925. + * dpcon_close() - Close the control session of the object
  926. + * @mc_io: Pointer to MC portal's I/O object
  927. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  928. + * @token: Token of DPCON object
  929. + *
  930. + * After this function is called, no further operations are
  931. + * allowed on the object without opening a new control session.
  932. + *
  933. + * Return: '0' on Success; Error code otherwise.
  934. + */
  935. +int dpcon_close(struct fsl_mc_io *mc_io,
  936. + u32 cmd_flags,
  937. + u16 token)
  938. +{
  939. + struct mc_command cmd = { 0 };
  940. +
  941. + /* prepare command */
  942. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_CLOSE,
  943. + cmd_flags,
  944. + token);
  945. +
  946. + /* send command to mc*/
  947. + return mc_send_command(mc_io, &cmd);
  948. +}
  949. +EXPORT_SYMBOL(dpcon_close);
  950. +
  951. +/**
  952. + * dpcon_enable() - Enable the DPCON
  953. + * @mc_io: Pointer to MC portal's I/O object
  954. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  955. + * @token: Token of DPCON object
  956. + *
  957. + * Return: '0' on Success; Error code otherwise
  958. + */
  959. +int dpcon_enable(struct fsl_mc_io *mc_io,
  960. + u32 cmd_flags,
  961. + u16 token)
  962. +{
  963. + struct mc_command cmd = { 0 };
  964. +
  965. + /* prepare command */
  966. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_ENABLE,
  967. + cmd_flags,
  968. + token);
  969. +
  970. + /* send command to mc*/
  971. + return mc_send_command(mc_io, &cmd);
  972. +}
  973. +EXPORT_SYMBOL(dpcon_enable);
  974. +
  975. +/**
  976. + * dpcon_disable() - Disable the DPCON
  977. + * @mc_io: Pointer to MC portal's I/O object
  978. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  979. + * @token: Token of DPCON object
  980. + *
  981. + * Return: '0' on Success; Error code otherwise
  982. + */
  983. +int dpcon_disable(struct fsl_mc_io *mc_io,
  984. + u32 cmd_flags,
  985. + u16 token)
  986. +{
  987. + struct mc_command cmd = { 0 };
  988. +
  989. + /* prepare command */
  990. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_DISABLE,
  991. + cmd_flags,
  992. + token);
  993. +
  994. + /* send command to mc*/
  995. + return mc_send_command(mc_io, &cmd);
  996. +}
  997. +EXPORT_SYMBOL(dpcon_disable);
  998. +
  999. +/**
  1000. + * dpcon_is_enabled() - Check if the DPCON is enabled.
  1001. + * @mc_io: Pointer to MC portal's I/O object
  1002. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1003. + * @token: Token of DPCON object
  1004. + * @en: Returns '1' if object is enabled; '0' otherwise
  1005. + *
  1006. + * Return: '0' on Success; Error code otherwise.
  1007. + */
  1008. +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
  1009. + u32 cmd_flags,
  1010. + u16 token,
  1011. + int *en)
  1012. +{
  1013. + struct mc_command cmd = { 0 };
  1014. + struct dpcon_rsp_is_enabled *dpcon_rsp;
  1015. + int err;
  1016. +
  1017. + /* prepare command */
  1018. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_IS_ENABLED,
  1019. + cmd_flags,
  1020. + token);
  1021. +
  1022. + /* send command to mc*/
  1023. + err = mc_send_command(mc_io, &cmd);
  1024. + if (err)
  1025. + return err;
  1026. +
  1027. + /* retrieve response parameters */
  1028. + dpcon_rsp = (struct dpcon_rsp_is_enabled *)cmd.params;
  1029. + *en = dpcon_rsp->enabled & DPCON_ENABLE;
  1030. +
  1031. + return 0;
  1032. +}
  1033. +EXPORT_SYMBOL(dpcon_is_enabled);
  1034. +
  1035. +/**
  1036. + * dpcon_reset() - Reset the DPCON, returns the object to initial state.
  1037. + * @mc_io: Pointer to MC portal's I/O object
  1038. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1039. + * @token: Token of DPCON object
  1040. + *
  1041. + * Return: '0' on Success; Error code otherwise.
  1042. + */
  1043. +int dpcon_reset(struct fsl_mc_io *mc_io,
  1044. + u32 cmd_flags,
  1045. + u16 token)
  1046. +{
  1047. + struct mc_command cmd = { 0 };
  1048. +
  1049. + /* prepare command */
  1050. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_RESET,
  1051. + cmd_flags, token);
  1052. +
  1053. + /* send command to mc*/
  1054. + return mc_send_command(mc_io, &cmd);
  1055. +}
  1056. +EXPORT_SYMBOL(dpcon_reset);
  1057. +
  1058. +/**
  1059. + * dpcon_get_attributes() - Retrieve DPCON attributes.
  1060. + * @mc_io: Pointer to MC portal's I/O object
  1061. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1062. + * @token: Token of DPCON object
  1063. + * @attr: Object's attributes
  1064. + *
  1065. + * Return: '0' on Success; Error code otherwise.
  1066. + */
  1067. +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
  1068. + u32 cmd_flags,
  1069. + u16 token,
  1070. + struct dpcon_attr *attr)
  1071. +{
  1072. + struct mc_command cmd = { 0 };
  1073. + struct dpcon_rsp_get_attr *dpcon_rsp;
  1074. + int err;
  1075. +
  1076. + /* prepare command */
  1077. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_ATTR,
  1078. + cmd_flags,
  1079. + token);
  1080. +
  1081. + /* send command to mc*/
  1082. + err = mc_send_command(mc_io, &cmd);
  1083. + if (err)
  1084. + return err;
  1085. +
  1086. + /* retrieve response parameters */
  1087. + dpcon_rsp = (struct dpcon_rsp_get_attr *)cmd.params;
  1088. + attr->id = le32_to_cpu(dpcon_rsp->id);
  1089. + attr->qbman_ch_id = le16_to_cpu(dpcon_rsp->qbman_ch_id);
  1090. + attr->num_priorities = dpcon_rsp->num_priorities;
  1091. +
  1092. + return 0;
  1093. +}
  1094. +EXPORT_SYMBOL(dpcon_get_attributes);
  1095. +
  1096. +/**
  1097. + * dpcon_set_notification() - Set DPCON notification destination
  1098. + * @mc_io: Pointer to MC portal's I/O object
  1099. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1100. + * @token: Token of DPCON object
  1101. + * @cfg: Notification parameters
  1102. + *
  1103. + * Return: '0' on Success; Error code otherwise
  1104. + */
  1105. +int dpcon_set_notification(struct fsl_mc_io *mc_io,
  1106. + u32 cmd_flags,
  1107. + u16 token,
  1108. + struct dpcon_notification_cfg *cfg)
  1109. +{
  1110. + struct mc_command cmd = { 0 };
  1111. + struct dpcon_cmd_set_notification *dpcon_cmd;
  1112. +
  1113. + /* prepare command */
  1114. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_SET_NOTIFICATION,
  1115. + cmd_flags,
  1116. + token);
  1117. + dpcon_cmd = (struct dpcon_cmd_set_notification *)cmd.params;
  1118. + dpcon_cmd->dpio_id = cpu_to_le32(cfg->dpio_id);
  1119. + dpcon_cmd->priority = cfg->priority;
  1120. + dpcon_cmd->user_ctx = cpu_to_le64(cfg->user_ctx);
  1121. +
  1122. + /* send command to mc*/
  1123. + return mc_send_command(mc_io, &cmd);
  1124. +}
  1125. +EXPORT_SYMBOL(dpcon_set_notification);
  1126. +
  1127. +/**
  1128. + * dpcon_get_api_version - Get Data Path Concentrator API version
  1129. + * @mc_io: Pointer to MC portal's DPCON object
  1130. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1131. + * @major_ver: Major version of DPCON API
  1132. + * @minor_ver: Minor version of DPCON API
  1133. + *
  1134. + * Return: '0' on Success; Error code otherwise
  1135. + */
  1136. +int dpcon_get_api_version(struct fsl_mc_io *mc_io,
  1137. + u32 cmd_flags,
  1138. + u16 *major_ver,
  1139. + u16 *minor_ver)
  1140. +{
  1141. + struct mc_command cmd = { 0 };
  1142. + int err;
  1143. +
  1144. + /* prepare command */
  1145. + cmd.header = mc_encode_cmd_header(DPCON_CMDID_GET_API_VERSION,
  1146. + cmd_flags, 0);
  1147. +
  1148. + /* send command to mc */
  1149. + err = mc_send_command(mc_io, &cmd);
  1150. + if (err)
  1151. + return err;
  1152. +
  1153. + /* retrieve response parameters */
  1154. + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  1155. +
  1156. + return 0;
  1157. +}
  1158. +EXPORT_SYMBOL(dpcon_get_api_version);
  1159. --- /dev/null
  1160. +++ b/drivers/staging/fsl-mc/bus/dpio/Makefile
  1161. @@ -0,0 +1,11 @@
  1162. +#
  1163. +# QorIQ DPAA2 DPIO driver
  1164. +#
  1165. +
  1166. +subdir-ccflags-y := -Werror
  1167. +
  1168. +obj-$(CONFIG_FSL_MC_DPIO) += fsl-mc-dpio.o
  1169. +
  1170. +fsl-mc-dpio-objs := dpio.o qbman-portal.o dpio-service.o dpio-driver.o
  1171. +
  1172. +obj-$(CONFIG_FSL_QBMAN_DEBUG) += qbman_debug.o
  1173. --- a/drivers/staging/fsl-mc/include/dpcon-cmd.h
  1174. +++ /dev/null
  1175. @@ -1,62 +0,0 @@
  1176. -/* Copyright 2013-2015 Freescale Semiconductor Inc.
  1177. - *
  1178. - * Redistribution and use in source and binary forms, with or without
  1179. - * modification, are permitted provided that the following conditions are met:
  1180. - * * Redistributions of source code must retain the above copyright
  1181. - * notice, this list of conditions and the following disclaimer.
  1182. - * * Redistributions in binary form must reproduce the above copyright
  1183. - * notice, this list of conditions and the following disclaimer in the
  1184. - * documentation and/or other materials provided with the distribution.
  1185. - * * Neither the name of the above-listed copyright holders nor the
  1186. - * names of any contributors may be used to endorse or promote products
  1187. - * derived from this software without specific prior written permission.
  1188. - *
  1189. - *
  1190. - * ALTERNATIVELY, this software may be distributed under the terms of the
  1191. - * GNU General Public License ("GPL") as published by the Free Software
  1192. - * Foundation, either version 2 of that License or (at your option) any
  1193. - * later version.
  1194. - *
  1195. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  1196. - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1197. - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1198. - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  1199. - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  1200. - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  1201. - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  1202. - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  1203. - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  1204. - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  1205. - * POSSIBILITY OF SUCH DAMAGE.
  1206. - */
  1207. -#ifndef _FSL_DPCON_CMD_H
  1208. -#define _FSL_DPCON_CMD_H
  1209. -
  1210. -/* DPCON Version */
  1211. -#define DPCON_VER_MAJOR 2
  1212. -#define DPCON_VER_MINOR 1
  1213. -
  1214. -/* Command IDs */
  1215. -#define DPCON_CMDID_CLOSE 0x800
  1216. -#define DPCON_CMDID_OPEN 0x808
  1217. -#define DPCON_CMDID_CREATE 0x908
  1218. -#define DPCON_CMDID_DESTROY 0x900
  1219. -
  1220. -#define DPCON_CMDID_ENABLE 0x002
  1221. -#define DPCON_CMDID_DISABLE 0x003
  1222. -#define DPCON_CMDID_GET_ATTR 0x004
  1223. -#define DPCON_CMDID_RESET 0x005
  1224. -#define DPCON_CMDID_IS_ENABLED 0x006
  1225. -
  1226. -#define DPCON_CMDID_SET_IRQ 0x010
  1227. -#define DPCON_CMDID_GET_IRQ 0x011
  1228. -#define DPCON_CMDID_SET_IRQ_ENABLE 0x012
  1229. -#define DPCON_CMDID_GET_IRQ_ENABLE 0x013
  1230. -#define DPCON_CMDID_SET_IRQ_MASK 0x014
  1231. -#define DPCON_CMDID_GET_IRQ_MASK 0x015
  1232. -#define DPCON_CMDID_GET_IRQ_STATUS 0x016
  1233. -#define DPCON_CMDID_CLEAR_IRQ_STATUS 0x017
  1234. -
  1235. -#define DPCON_CMDID_SET_NOTIFICATION 0x100
  1236. -
  1237. -#endif /* _FSL_DPCON_CMD_H */
  1238. --- /dev/null
  1239. +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-cmd.h
  1240. @@ -0,0 +1,75 @@
  1241. +/*
  1242. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  1243. + * Copyright 2016 NXP
  1244. + *
  1245. + * Redistribution and use in source and binary forms, with or without
  1246. + * modification, are permitted provided that the following conditions are met:
  1247. + * * Redistributions of source code must retain the above copyright
  1248. + * notice, this list of conditions and the following disclaimer.
  1249. + * * Redistributions in binary form must reproduce the above copyright
  1250. + * notice, this list of conditions and the following disclaimer in the
  1251. + * documentation and/or other materials provided with the distribution.
  1252. + * * Neither the name of the above-listed copyright holders nor the
  1253. + * names of any contributors may be used to endorse or promote products
  1254. + * derived from this software without specific prior written permission.
  1255. + *
  1256. + * ALTERNATIVELY, this software may be distributed under the terms of the
  1257. + * GNU General Public License ("GPL") as published by the Free Software
  1258. + * Foundation, either version 2 of that License or (at your option) any
  1259. + * later version.
  1260. + *
  1261. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  1262. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1263. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1264. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  1265. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  1266. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  1267. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  1268. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  1269. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  1270. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  1271. + * POSSIBILITY OF SUCH DAMAGE.
  1272. + */
  1273. +#ifndef _FSL_DPIO_CMD_H
  1274. +#define _FSL_DPIO_CMD_H
  1275. +
  1276. +/* DPIO Version */
  1277. +#define DPIO_VER_MAJOR 4
  1278. +#define DPIO_VER_MINOR 2
  1279. +
  1280. +/* Command Versioning */
  1281. +
  1282. +#define DPIO_CMD_ID_OFFSET 4
  1283. +#define DPIO_CMD_BASE_VERSION 1
  1284. +
  1285. +#define DPIO_CMD(id) (((id) << DPIO_CMD_ID_OFFSET) | DPIO_CMD_BASE_VERSION)
  1286. +
  1287. +/* Command IDs */
  1288. +#define DPIO_CMDID_CLOSE DPIO_CMD(0x800)
  1289. +#define DPIO_CMDID_OPEN DPIO_CMD(0x803)
  1290. +#define DPIO_CMDID_GET_API_VERSION DPIO_CMD(0xa03)
  1291. +#define DPIO_CMDID_ENABLE DPIO_CMD(0x002)
  1292. +#define DPIO_CMDID_DISABLE DPIO_CMD(0x003)
  1293. +#define DPIO_CMDID_GET_ATTR DPIO_CMD(0x004)
  1294. +
  1295. +struct dpio_cmd_open {
  1296. + __le32 dpio_id;
  1297. +};
  1298. +
  1299. +#define DPIO_CHANNEL_MODE_MASK 0x3
  1300. +
  1301. +struct dpio_rsp_get_attr {
  1302. + /* cmd word 0 */
  1303. + __le32 id;
  1304. + __le16 qbman_portal_id;
  1305. + u8 num_priorities;
  1306. + u8 channel_mode;
  1307. + /* cmd word 1 */
  1308. + __le64 qbman_portal_ce_addr;
  1309. + /* cmd word 2 */
  1310. + __le64 qbman_portal_ci_addr;
  1311. + /* cmd word 3 */
  1312. + __le32 qbman_version;
  1313. +};
  1314. +
  1315. +#endif /* _FSL_DPIO_CMD_H */
  1316. --- /dev/null
  1317. +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-driver.c
  1318. @@ -0,0 +1,296 @@
  1319. +/*
  1320. + * Copyright 2014-2016 Freescale Semiconductor Inc.
  1321. + * Copyright 2016 NXP
  1322. + *
  1323. + * Redistribution and use in source and binary forms, with or without
  1324. + * modification, are permitted provided that the following conditions are met:
  1325. + * * Redistributions of source code must retain the above copyright
  1326. + * notice, this list of conditions and the following disclaimer.
  1327. + * * Redistributions in binary form must reproduce the above copyright
  1328. + * notice, this list of conditions and the following disclaimer in the
  1329. + * documentation and/or other materials provided with the distribution.
  1330. + * * Neither the name of Freescale Semiconductor nor the
  1331. + * names of its contributors may be used to endorse or promote products
  1332. + * derived from this software without specific prior written permission.
  1333. + *
  1334. + * ALTERNATIVELY, this software may be distributed under the terms of the
  1335. + * GNU General Public License ("GPL") as published by the Free Software
  1336. + * Foundation, either version 2 of that License or (at your option) any
  1337. + * later version.
  1338. + *
  1339. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  1340. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  1341. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  1342. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  1343. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  1344. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  1345. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  1346. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  1347. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  1348. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1349. + */
  1350. +
  1351. +#include <linux/types.h>
  1352. +#include <linux/init.h>
  1353. +#include <linux/module.h>
  1354. +#include <linux/platform_device.h>
  1355. +#include <linux/interrupt.h>
  1356. +#include <linux/msi.h>
  1357. +#include <linux/dma-mapping.h>
  1358. +#include <linux/delay.h>
  1359. +
  1360. +#include "../../include/mc.h"
  1361. +#include "../../include/dpaa2-io.h"
  1362. +
  1363. +#include "qbman-portal.h"
  1364. +#include "dpio.h"
  1365. +#include "dpio-cmd.h"
  1366. +
  1367. +MODULE_LICENSE("Dual BSD/GPL");
  1368. +MODULE_AUTHOR("Freescale Semiconductor, Inc");
  1369. +MODULE_DESCRIPTION("DPIO Driver");
  1370. +
  1371. +struct dpio_priv {
  1372. + struct dpaa2_io *io;
  1373. +};
  1374. +
  1375. +static irqreturn_t dpio_irq_handler(int irq_num, void *arg)
  1376. +{
  1377. + struct device *dev = (struct device *)arg;
  1378. + struct dpio_priv *priv = dev_get_drvdata(dev);
  1379. +
  1380. + return dpaa2_io_irq(priv->io);
  1381. +}
  1382. +
  1383. +static void unregister_dpio_irq_handlers(struct fsl_mc_device *dpio_dev)
  1384. +{
  1385. + struct fsl_mc_device_irq *irq;
  1386. +
  1387. + irq = dpio_dev->irqs[0];
  1388. +
  1389. + /* clear the affinity hint */
  1390. + irq_set_affinity_hint(irq->msi_desc->irq, NULL);
  1391. +}
  1392. +
  1393. +static int register_dpio_irq_handlers(struct fsl_mc_device *dpio_dev, int cpu)
  1394. +{
  1395. + struct dpio_priv *priv;
  1396. + int error;
  1397. + struct fsl_mc_device_irq *irq;
  1398. + cpumask_t mask;
  1399. +
  1400. + priv = dev_get_drvdata(&dpio_dev->dev);
  1401. +
  1402. + irq = dpio_dev->irqs[0];
  1403. + error = devm_request_irq(&dpio_dev->dev,
  1404. + irq->msi_desc->irq,
  1405. + dpio_irq_handler,
  1406. + 0,
  1407. + dev_name(&dpio_dev->dev),
  1408. + &dpio_dev->dev);
  1409. + if (error < 0) {
  1410. + dev_err(&dpio_dev->dev,
  1411. + "devm_request_irq() failed: %d\n",
  1412. + error);
  1413. + return error;
  1414. + }
  1415. +
  1416. + /* set the affinity hint */
  1417. + cpumask_clear(&mask);
  1418. + cpumask_set_cpu(cpu, &mask);
  1419. + if (irq_set_affinity_hint(irq->msi_desc->irq, &mask))
  1420. + dev_err(&dpio_dev->dev,
  1421. + "irq_set_affinity failed irq %d cpu %d\n",
  1422. + irq->msi_desc->irq, cpu);
  1423. +
  1424. + return 0;
  1425. +}
  1426. +
  1427. +static int dpaa2_dpio_probe(struct fsl_mc_device *dpio_dev)
  1428. +{
  1429. + struct dpio_attr dpio_attrs;
  1430. + struct dpaa2_io_desc desc;
  1431. + struct dpio_priv *priv;
  1432. + int err = -ENOMEM;
  1433. + struct device *dev = &dpio_dev->dev;
  1434. + static int next_cpu = -1;
  1435. +
  1436. + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  1437. + if (!priv)
  1438. + goto err_priv_alloc;
  1439. +
  1440. + dev_set_drvdata(dev, priv);
  1441. +
  1442. + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
  1443. + if (err) {
  1444. + dev_dbg(dev, "MC portal allocation failed\n");
  1445. + err = -EPROBE_DEFER;
  1446. + goto err_mcportal;
  1447. + }
  1448. +
  1449. + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
  1450. + &dpio_dev->mc_handle);
  1451. + if (err) {
  1452. + dev_err(dev, "dpio_open() failed\n");
  1453. + goto err_open;
  1454. + }
  1455. +
  1456. + err = dpio_get_attributes(dpio_dev->mc_io, 0, dpio_dev->mc_handle,
  1457. + &dpio_attrs);
  1458. + if (err) {
  1459. + dev_err(dev, "dpio_get_attributes() failed %d\n", err);
  1460. + goto err_get_attr;
  1461. + }
  1462. + desc.qman_version = dpio_attrs.qbman_version;
  1463. +
  1464. + err = dpio_enable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
  1465. + if (err) {
  1466. + dev_err(dev, "dpio_enable() failed %d\n", err);
  1467. + goto err_get_attr;
  1468. + }
  1469. +
  1470. + /* initialize DPIO descriptor */
  1471. + desc.receives_notifications = dpio_attrs.num_priorities ? 1 : 0;
  1472. + desc.has_8prio = dpio_attrs.num_priorities == 8 ? 1 : 0;
  1473. + desc.dpio_id = dpio_dev->obj_desc.id;
  1474. +
  1475. + /* get the cpu to use for the affinity hint */
  1476. + if (next_cpu == -1)
  1477. + next_cpu = cpumask_first(cpu_online_mask);
  1478. + else
  1479. + next_cpu = cpumask_next(next_cpu, cpu_online_mask);
  1480. +
  1481. + if (!cpu_possible(next_cpu)) {
  1482. + dev_err(dev, "probe failed. Number of DPIOs exceeds NR_CPUS.\n");
  1483. + err = -ERANGE;
  1484. + goto err_allocate_irqs;
  1485. + }
  1486. + desc.cpu = next_cpu;
  1487. +
  1488. + /*
  1489. + * Set the CENA regs to be the cache enabled area of the portal to
  1490. + * achieve the best performance.
  1491. + */
  1492. + desc.regs_cena = ioremap_cache_ns(dpio_dev->regions[0].start,
  1493. + resource_size(&dpio_dev->regions[0]));
  1494. + desc.regs_cinh = ioremap(dpio_dev->regions[1].start,
  1495. + resource_size(&dpio_dev->regions[1]));
  1496. +
  1497. + err = fsl_mc_allocate_irqs(dpio_dev);
  1498. + if (err) {
  1499. + dev_err(dev, "fsl_mc_allocate_irqs failed. err=%d\n", err);
  1500. + goto err_allocate_irqs;
  1501. + }
  1502. +
  1503. + err = register_dpio_irq_handlers(dpio_dev, desc.cpu);
  1504. + if (err)
  1505. + goto err_register_dpio_irq;
  1506. +
  1507. + priv->io = dpaa2_io_create(&desc);
  1508. + if (!priv->io) {
  1509. + dev_err(dev, "dpaa2_io_create failed\n");
  1510. + goto err_dpaa2_io_create;
  1511. + }
  1512. +
  1513. + dev_info(dev, "probed\n");
  1514. + dev_dbg(dev, " receives_notifications = %d\n",
  1515. + desc.receives_notifications);
  1516. + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
  1517. + fsl_mc_portal_free(dpio_dev->mc_io);
  1518. +
  1519. + return 0;
  1520. +
  1521. +err_dpaa2_io_create:
  1522. + unregister_dpio_irq_handlers(dpio_dev);
  1523. +err_register_dpio_irq:
  1524. + fsl_mc_free_irqs(dpio_dev);
  1525. +err_allocate_irqs:
  1526. + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
  1527. +err_get_attr:
  1528. + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
  1529. +err_open:
  1530. + fsl_mc_portal_free(dpio_dev->mc_io);
  1531. +err_mcportal:
  1532. + dev_set_drvdata(dev, NULL);
  1533. +err_priv_alloc:
  1534. + return err;
  1535. +}
  1536. +
  1537. +/* Tear down interrupts for a given DPIO object */
  1538. +static void dpio_teardown_irqs(struct fsl_mc_device *dpio_dev)
  1539. +{
  1540. + unregister_dpio_irq_handlers(dpio_dev);
  1541. + fsl_mc_free_irqs(dpio_dev);
  1542. +}
  1543. +
  1544. +static int dpaa2_dpio_remove(struct fsl_mc_device *dpio_dev)
  1545. +{
  1546. + struct device *dev;
  1547. + struct dpio_priv *priv;
  1548. + int err;
  1549. +
  1550. + dev = &dpio_dev->dev;
  1551. + priv = dev_get_drvdata(dev);
  1552. +
  1553. + dpaa2_io_down(priv->io);
  1554. +
  1555. + dpio_teardown_irqs(dpio_dev);
  1556. +
  1557. + err = fsl_mc_portal_allocate(dpio_dev, 0, &dpio_dev->mc_io);
  1558. + if (err) {
  1559. + dev_err(dev, "MC portal allocation failed\n");
  1560. + goto err_mcportal;
  1561. + }
  1562. +
  1563. + err = dpio_open(dpio_dev->mc_io, 0, dpio_dev->obj_desc.id,
  1564. + &dpio_dev->mc_handle);
  1565. + if (err) {
  1566. + dev_err(dev, "dpio_open() failed\n");
  1567. + goto err_open;
  1568. + }
  1569. +
  1570. + dpio_disable(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
  1571. +
  1572. + dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
  1573. +
  1574. + fsl_mc_portal_free(dpio_dev->mc_io);
  1575. +
  1576. + dev_set_drvdata(dev, NULL);
  1577. +
  1578. + return 0;
  1579. +
  1580. +err_open:
  1581. + fsl_mc_portal_free(dpio_dev->mc_io);
  1582. +err_mcportal:
  1583. + return err;
  1584. +}
  1585. +
  1586. +static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = {
  1587. + {
  1588. + .vendor = FSL_MC_VENDOR_FREESCALE,
  1589. + .obj_type = "dpio",
  1590. + },
  1591. + { .vendor = 0x0 }
  1592. +};
  1593. +
  1594. +static struct fsl_mc_driver dpaa2_dpio_driver = {
  1595. + .driver = {
  1596. + .name = KBUILD_MODNAME,
  1597. + .owner = THIS_MODULE,
  1598. + },
  1599. + .probe = dpaa2_dpio_probe,
  1600. + .remove = dpaa2_dpio_remove,
  1601. + .match_id_table = dpaa2_dpio_match_id_table
  1602. +};
  1603. +
  1604. +static int dpio_driver_init(void)
  1605. +{
  1606. + return fsl_mc_driver_register(&dpaa2_dpio_driver);
  1607. +}
  1608. +
  1609. +static void dpio_driver_exit(void)
  1610. +{
  1611. + fsl_mc_driver_unregister(&dpaa2_dpio_driver);
  1612. +}
  1613. +module_init(dpio_driver_init);
  1614. +module_exit(dpio_driver_exit);
  1615. --- /dev/null
  1616. +++ b/drivers/staging/fsl-mc/bus/dpio/dpio-service.c
  1617. @@ -0,0 +1,693 @@
  1618. +/*
  1619. + * Copyright 2014-2016 Freescale Semiconductor Inc.
  1620. + * Copyright 2016 NXP
  1621. + *
  1622. + * Redistribution and use in source and binary forms, with or without
  1623. + * modification, are permitted provided that the following conditions are met:
  1624. + * * Redistributions of source code must retain the above copyright
  1625. + * notice, this list of conditions and the following disclaimer.
  1626. + * * Redistributions in binary form must reproduce the above copyright
  1627. + * notice, this list of conditions and the following disclaimer in the
  1628. + * documentation and/or other materials provided with the distribution.
  1629. + * * Neither the name of Freescale Semiconductor nor the
  1630. + * names of its contributors may be used to endorse or promote products
  1631. + * derived from this software without specific prior written permission.
  1632. + *
  1633. + * ALTERNATIVELY, this software may be distributed under the terms of the
  1634. + * GNU General Public License ("GPL") as published by the Free Software
  1635. + * Foundation, either version 2 of that License or (at your option) any
  1636. + * later version.
  1637. + *
  1638. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  1639. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  1640. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  1641. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  1642. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  1643. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  1644. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  1645. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  1646. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  1647. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  1648. + */
  1649. +#include <linux/types.h>
  1650. +#include "../../include/mc.h"
  1651. +#include "../../include/dpaa2-io.h"
  1652. +#include <linux/init.h>
  1653. +#include <linux/module.h>
  1654. +#include <linux/platform_device.h>
  1655. +#include <linux/interrupt.h>
  1656. +#include <linux/dma-mapping.h>
  1657. +#include <linux/slab.h>
  1658. +
  1659. +#include "dpio.h"
  1660. +#include "qbman-portal.h"
  1661. +#include "qbman_debug.h"
  1662. +
  1663. +struct dpaa2_io {
  1664. + atomic_t refs;
  1665. + struct dpaa2_io_desc dpio_desc;
  1666. + struct qbman_swp_desc swp_desc;
  1667. + struct qbman_swp *swp;
  1668. + struct list_head node;
  1669. + /* protect against multiple management commands */
  1670. + spinlock_t lock_mgmt_cmd;
  1671. + /* protect notifications list */
  1672. + spinlock_t lock_notifications;
  1673. + struct list_head notifications;
  1674. +};
  1675. +
  1676. +struct dpaa2_io_store {
  1677. + unsigned int max;
  1678. + dma_addr_t paddr;
  1679. + struct dpaa2_dq *vaddr;
  1680. + void *alloced_addr; /* unaligned value from kmalloc() */
  1681. + unsigned int idx; /* position of the next-to-be-returned entry */
  1682. + struct qbman_swp *swp; /* portal used to issue VDQCR */
  1683. + struct device *dev; /* device used for DMA mapping */
  1684. +};
  1685. +
  1686. +/* keep a per cpu array of DPIOs for fast access */
  1687. +static struct dpaa2_io *dpio_by_cpu[NR_CPUS];
  1688. +static struct list_head dpio_list = LIST_HEAD_INIT(dpio_list);
  1689. +static DEFINE_SPINLOCK(dpio_list_lock);
  1690. +
  1691. +static inline struct dpaa2_io *service_select_by_cpu(struct dpaa2_io *d,
  1692. + int cpu)
  1693. +{
  1694. + if (d)
  1695. + return d;
  1696. +
  1697. + if (unlikely(cpu >= (int)num_possible_cpus()))
  1698. + return NULL;
  1699. +
  1700. + /*
  1701. + * If cpu == -1, choose the current cpu, with no guarantees about
  1702. + * potentially being migrated away.
  1703. + */
  1704. + if (cpu < 0)
  1705. + cpu = smp_processor_id();
  1706. +
  1707. + /* If a specific cpu was requested, pick it up immediately */
  1708. + return dpio_by_cpu[cpu];
  1709. +}
  1710. +
  1711. +static inline struct dpaa2_io *service_select(struct dpaa2_io *d)
  1712. +{
  1713. + if (d)
  1714. + return d;
  1715. +
  1716. + d = service_select_by_cpu(d, -1);
  1717. + if (d)
  1718. + return d;
  1719. +
  1720. + spin_lock(&dpio_list_lock);
  1721. + d = list_entry(dpio_list.next, struct dpaa2_io, node);
  1722. + list_del(&d->node);
  1723. + list_add_tail(&d->node, &dpio_list);
  1724. + spin_unlock(&dpio_list_lock);
  1725. +
  1726. + return d;
  1727. +}
  1728. +
  1729. +/**
  1730. + * dpaa2_io_create() - create a dpaa2_io object.
  1731. + * @desc: the dpaa2_io descriptor
  1732. + *
  1733. + * Activates a "struct dpaa2_io" corresponding to the given config of an actual
  1734. + * DPIO object.
  1735. + *
  1736. + * Return a valid dpaa2_io object for success, or NULL for failure.
  1737. + */
  1738. +struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc)
  1739. +{
  1740. + struct dpaa2_io *obj = kmalloc(sizeof(*obj), GFP_KERNEL);
  1741. +
  1742. + if (!obj)
  1743. + return NULL;
  1744. +
  1745. + /* check if CPU is out of range (-1 means any cpu) */
  1746. + if (desc->cpu >= (int)num_possible_cpus()) {
  1747. + kfree(obj);
  1748. + return NULL;
  1749. + }
  1750. +
  1751. + atomic_set(&obj->refs, 1);
  1752. + obj->dpio_desc = *desc;
  1753. + obj->swp_desc.cena_bar = obj->dpio_desc.regs_cena;
  1754. + obj->swp_desc.cinh_bar = obj->dpio_desc.regs_cinh;
  1755. + obj->swp_desc.qman_version = obj->dpio_desc.qman_version;
  1756. + obj->swp = qbman_swp_init(&obj->swp_desc);
  1757. +
  1758. + if (!obj->swp) {
  1759. + kfree(obj);
  1760. + return NULL;
  1761. + }
  1762. +
  1763. + INIT_LIST_HEAD(&obj->node);
  1764. + spin_lock_init(&obj->lock_mgmt_cmd);
  1765. + spin_lock_init(&obj->lock_notifications);
  1766. + INIT_LIST_HEAD(&obj->notifications);
  1767. +
  1768. + /* For now only enable DQRR interrupts */
  1769. + qbman_swp_interrupt_set_trigger(obj->swp,
  1770. + QBMAN_SWP_INTERRUPT_DQRI);
  1771. + qbman_swp_interrupt_clear_status(obj->swp, 0xffffffff);
  1772. + if (obj->dpio_desc.receives_notifications)
  1773. + qbman_swp_push_set(obj->swp, 0, 1);
  1774. +
  1775. + spin_lock(&dpio_list_lock);
  1776. + list_add_tail(&obj->node, &dpio_list);
  1777. + if (desc->cpu >= 0 && !dpio_by_cpu[desc->cpu])
  1778. + dpio_by_cpu[desc->cpu] = obj;
  1779. + spin_unlock(&dpio_list_lock);
  1780. +
  1781. + return obj;
  1782. +}
  1783. +EXPORT_SYMBOL(dpaa2_io_create);
  1784. +
  1785. +/**
  1786. + * dpaa2_io_down() - release the dpaa2_io object.
  1787. + * @d: the dpaa2_io object to be released.
  1788. + *
  1789. + * The "struct dpaa2_io" type can represent an individual DPIO object (as
  1790. + * described by "struct dpaa2_io_desc") or an instance of a "DPIO service",
  1791. + * which can be used to group/encapsulate multiple DPIO objects. In all cases,
  1792. + * each handle obtained should be released using this function.
  1793. + */
  1794. +void dpaa2_io_down(struct dpaa2_io *d)
  1795. +{
  1796. + if (!atomic_dec_and_test(&d->refs))
  1797. + return;
  1798. + kfree(d);
  1799. +}
  1800. +EXPORT_SYMBOL(dpaa2_io_down);
  1801. +
  1802. +#define DPAA_POLL_MAX 32
  1803. +
  1804. +/**
  1805. + * dpaa2_io_irq() - ISR for DPIO interrupts
  1806. + *
  1807. + * @obj: the given DPIO object.
  1808. + *
  1809. + * Return IRQ_HANDLED for success or IRQ_NONE if there
  1810. + * were no pending interrupts.
  1811. + */
  1812. +irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj)
  1813. +{
  1814. + const struct dpaa2_dq *dq;
  1815. + int max = 0;
  1816. + struct qbman_swp *swp;
  1817. + u32 status;
  1818. +
  1819. + swp = obj->swp;
  1820. + status = qbman_swp_interrupt_read_status(swp);
  1821. + if (!status)
  1822. + return IRQ_NONE;
  1823. +
  1824. + dq = qbman_swp_dqrr_next(swp);
  1825. + while (dq) {
  1826. + if (qbman_result_is_SCN(dq)) {
  1827. + struct dpaa2_io_notification_ctx *ctx;
  1828. + u64 q64;
  1829. +
  1830. + q64 = qbman_result_SCN_ctx(dq);
  1831. + ctx = (void *)q64;
  1832. + ctx->cb(ctx);
  1833. + } else {
  1834. + pr_crit("fsl-mc-dpio: Unrecognised/ignored DQRR entry\n");
  1835. + }
  1836. + qbman_swp_dqrr_consume(swp, dq);
  1837. + ++max;
  1838. + if (max > DPAA_POLL_MAX)
  1839. + goto done;
  1840. + dq = qbman_swp_dqrr_next(swp);
  1841. + }
  1842. +done:
  1843. + qbman_swp_interrupt_clear_status(swp, status);
  1844. + qbman_swp_interrupt_set_inhibit(swp, 0);
  1845. + return IRQ_HANDLED;
  1846. +}
  1847. +EXPORT_SYMBOL(dpaa2_io_irq);
  1848. +
  1849. +/**
  1850. + * dpaa2_io_service_register() - Prepare for servicing of FQDAN or CDAN
  1851. + * notifications on the given DPIO service.
  1852. + * @d: the given DPIO service.
  1853. + * @ctx: the notification context.
  1854. + *
  1855. + * The caller should make the MC command to attach a DPAA2 object to
  1856. + * a DPIO after this function completes successfully. In that way:
  1857. + * (a) The DPIO service is "ready" to handle a notification arrival
  1858. + * (which might happen before the "attach" command to MC has
  1859. + * returned control of execution back to the caller)
  1860. + * (b) The DPIO service can provide back to the caller the 'dpio_id' and
  1861. + * 'qman64' parameters that it should pass along in the MC command
  1862. + * in order for the object to be configured to produce the right
  1863. + * notification fields to the DPIO service.
  1864. + *
  1865. + * Return 0 for success, or -ENODEV for failure.
  1866. + */
  1867. +int dpaa2_io_service_register(struct dpaa2_io *d,
  1868. + struct dpaa2_io_notification_ctx *ctx)
  1869. +{
  1870. + unsigned long irqflags;
  1871. +
  1872. + d = service_select_by_cpu(d, ctx->desired_cpu);
  1873. + if (!d)
  1874. + return -ENODEV;
  1875. +
  1876. + ctx->dpio_id = d->dpio_desc.dpio_id;
  1877. + ctx->qman64 = (u64)ctx;
  1878. + ctx->dpio_private = d;
  1879. + spin_lock_irqsave(&d->lock_notifications, irqflags);
  1880. + list_add(&ctx->node, &d->notifications);
  1881. + spin_unlock_irqrestore(&d->lock_notifications, irqflags);
  1882. +
  1883. + /* Enable the generation of CDAN notifications */
  1884. + if (ctx->is_cdan)
  1885. + qbman_swp_CDAN_set_context_enable(d->swp,
  1886. + (u16)ctx->id,
  1887. + ctx->qman64);
  1888. + return 0;
  1889. +}
  1890. +EXPORT_SYMBOL(dpaa2_io_service_register);
  1891. +
  1892. +/**
  1893. + * dpaa2_io_service_deregister - The opposite of 'register'.
  1894. + * @service: the given DPIO service.
  1895. + * @ctx: the notification context.
  1896. + *
  1897. + * This function should be called only after sending the MC command to
  1898. + * to detach the notification-producing device from the DPIO.
  1899. + */
  1900. +void dpaa2_io_service_deregister(struct dpaa2_io *service,
  1901. + struct dpaa2_io_notification_ctx *ctx)
  1902. +{
  1903. + struct dpaa2_io *d = ctx->dpio_private;
  1904. + unsigned long irqflags;
  1905. +
  1906. + if (ctx->is_cdan)
  1907. + qbman_swp_CDAN_disable(d->swp, (u16)ctx->id);
  1908. +
  1909. + spin_lock_irqsave(&d->lock_notifications, irqflags);
  1910. + list_del(&ctx->node);
  1911. + spin_unlock_irqrestore(&d->lock_notifications, irqflags);
  1912. +}
  1913. +EXPORT_SYMBOL(dpaa2_io_service_deregister);
  1914. +
  1915. +/**
  1916. + * dpaa2_io_service_rearm() - Rearm the notification for the given DPIO service.
  1917. + * @d: the given DPIO service.
  1918. + * @ctx: the notification context.
  1919. + *
  1920. + * Once a FQDAN/CDAN has been produced, the corresponding FQ/channel is
  1921. + * considered "disarmed". Ie. the user can issue pull dequeue operations on that
  1922. + * traffic source for as long as it likes. Eventually it may wish to "rearm"
  1923. + * that source to allow it to produce another FQDAN/CDAN, that's what this
  1924. + * function achieves.
  1925. + *
  1926. + * Return 0 for success.
  1927. + */
  1928. +int dpaa2_io_service_rearm(struct dpaa2_io *d,
  1929. + struct dpaa2_io_notification_ctx *ctx)
  1930. +{
  1931. + unsigned long irqflags;
  1932. + int err;
  1933. +
  1934. + d = service_select_by_cpu(d, ctx->desired_cpu);
  1935. + if (!unlikely(d))
  1936. + return -ENODEV;
  1937. +
  1938. + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
  1939. + if (ctx->is_cdan)
  1940. + err = qbman_swp_CDAN_enable(d->swp, (u16)ctx->id);
  1941. + else
  1942. + err = qbman_swp_fq_schedule(d->swp, ctx->id);
  1943. + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
  1944. +
  1945. + return err;
  1946. +}
  1947. +EXPORT_SYMBOL(dpaa2_io_service_rearm);
  1948. +
  1949. +/**
  1950. + * dpaa2_io_service_pull_fq() - pull dequeue functions from a fq.
  1951. + * @d: the given DPIO service.
  1952. + * @fqid: the given frame queue id.
  1953. + * @s: the dpaa2_io_store object for the result.
  1954. + *
  1955. + * Return 0 for success, or error code for failure.
  1956. + */
  1957. +int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
  1958. + struct dpaa2_io_store *s)
  1959. +{
  1960. + struct qbman_pull_desc pd;
  1961. + int err;
  1962. +
  1963. + qbman_pull_desc_clear(&pd);
  1964. + qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
  1965. + qbman_pull_desc_set_numframes(&pd, (u8)s->max);
  1966. + qbman_pull_desc_set_fq(&pd, fqid);
  1967. +
  1968. + d = service_select(d);
  1969. + if (!d)
  1970. + return -ENODEV;
  1971. + s->swp = d->swp;
  1972. + err = qbman_swp_pull(d->swp, &pd);
  1973. + if (err)
  1974. + s->swp = NULL;
  1975. +
  1976. + return err;
  1977. +}
  1978. +EXPORT_SYMBOL(dpaa2_io_service_pull_fq);
  1979. +
  1980. +/**
  1981. + * dpaa2_io_service_pull_channel() - pull dequeue functions from a channel.
  1982. + * @d: the given DPIO service.
  1983. + * @channelid: the given channel id.
  1984. + * @s: the dpaa2_io_store object for the result.
  1985. + *
  1986. + * Return 0 for success, or error code for failure.
  1987. + */
  1988. +int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
  1989. + struct dpaa2_io_store *s)
  1990. +{
  1991. + struct qbman_pull_desc pd;
  1992. + int err;
  1993. +
  1994. + qbman_pull_desc_clear(&pd);
  1995. + qbman_pull_desc_set_storage(&pd, s->vaddr, s->paddr, 1);
  1996. + qbman_pull_desc_set_numframes(&pd, (u8)s->max);
  1997. + qbman_pull_desc_set_channel(&pd, channelid, qbman_pull_type_prio);
  1998. +
  1999. + d = service_select(d);
  2000. + if (!d)
  2001. + return -ENODEV;
  2002. +
  2003. + s->swp = d->swp;
  2004. + err = qbman_swp_pull(d->swp, &pd);
  2005. + if (err)
  2006. + s->swp = NULL;
  2007. +
  2008. + return err;
  2009. +}
  2010. +EXPORT_SYMBOL(dpaa2_io_service_pull_channel);
  2011. +
  2012. +/**
  2013. + * dpaa2_io_service_enqueue_fq() - Enqueue a frame to a frame queue.
  2014. + * @d: the given DPIO service.
  2015. + * @fqid: the given frame queue id.
  2016. + * @fd: the frame descriptor which is enqueued.
  2017. + *
  2018. + * Return 0 for successful enqueue, -EBUSY if the enqueue ring is not ready,
  2019. + * or -ENODEV if there is no dpio service.
  2020. + */
  2021. +int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d,
  2022. + u32 fqid,
  2023. + const struct dpaa2_fd *fd)
  2024. +{
  2025. + struct qbman_eq_desc ed;
  2026. +
  2027. + d = service_select(d);
  2028. + if (!d)
  2029. + return -ENODEV;
  2030. +
  2031. + qbman_eq_desc_clear(&ed);
  2032. + qbman_eq_desc_set_no_orp(&ed, 0);
  2033. + qbman_eq_desc_set_fq(&ed, fqid);
  2034. +
  2035. + return qbman_swp_enqueue(d->swp, &ed, fd);
  2036. +}
  2037. +EXPORT_SYMBOL(dpaa2_io_service_enqueue_fq);
  2038. +
  2039. +/**
  2040. + * dpaa2_io_service_enqueue_qd() - Enqueue a frame to a QD.
  2041. + * @d: the given DPIO service.
  2042. + * @qdid: the given queuing destination id.
  2043. + * @prio: the given queuing priority.
  2044. + * @qdbin: the given queuing destination bin.
  2045. + * @fd: the frame descriptor which is enqueued.
  2046. + *
  2047. + * Return 0 for successful enqueue, or -EBUSY if the enqueue ring is not ready,
  2048. + * or -ENODEV if there is no dpio service.
  2049. + */
  2050. +int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d,
  2051. + u32 qdid, u8 prio, u16 qdbin,
  2052. + const struct dpaa2_fd *fd)
  2053. +{
  2054. + struct qbman_eq_desc ed;
  2055. +
  2056. + d = service_select(d);
  2057. + if (!d)
  2058. + return -ENODEV;
  2059. +
  2060. + qbman_eq_desc_clear(&ed);
  2061. + qbman_eq_desc_set_no_orp(&ed, 0);
  2062. + qbman_eq_desc_set_qd(&ed, qdid, qdbin, prio);
  2063. +
  2064. + return qbman_swp_enqueue(d->swp, &ed, fd);
  2065. +}
  2066. +EXPORT_SYMBOL(dpaa2_io_service_enqueue_qd);
  2067. +
  2068. +/**
  2069. + * dpaa2_io_service_release() - Release buffers to a buffer pool.
  2070. + * @d: the given DPIO object.
  2071. + * @bpid: the buffer pool id.
  2072. + * @buffers: the buffers to be released.
  2073. + * @num_buffers: the number of the buffers to be released.
  2074. + *
  2075. + * Return 0 for success, and negative error code for failure.
  2076. + */
  2077. +int dpaa2_io_service_release(struct dpaa2_io *d,
  2078. + u32 bpid,
  2079. + const u64 *buffers,
  2080. + unsigned int num_buffers)
  2081. +{
  2082. + struct qbman_release_desc rd;
  2083. +
  2084. + d = service_select(d);
  2085. + if (!d)
  2086. + return -ENODEV;
  2087. +
  2088. + qbman_release_desc_clear(&rd);
  2089. + qbman_release_desc_set_bpid(&rd, bpid);
  2090. +
  2091. + return qbman_swp_release(d->swp, &rd, buffers, num_buffers);
  2092. +}
  2093. +EXPORT_SYMBOL(dpaa2_io_service_release);
  2094. +
  2095. +/**
  2096. + * dpaa2_io_service_acquire() - Acquire buffers from a buffer pool.
  2097. + * @d: the given DPIO object.
  2098. + * @bpid: the buffer pool id.
  2099. + * @buffers: the buffer addresses for acquired buffers.
  2100. + * @num_buffers: the expected number of the buffers to acquire.
  2101. + *
  2102. + * Return a negative error code if the command failed, otherwise it returns
  2103. + * the number of buffers acquired, which may be less than the number requested.
  2104. + * Eg. if the buffer pool is empty, this will return zero.
  2105. + */
  2106. +int dpaa2_io_service_acquire(struct dpaa2_io *d,
  2107. + u32 bpid,
  2108. + u64 *buffers,
  2109. + unsigned int num_buffers)
  2110. +{
  2111. + unsigned long irqflags;
  2112. + int err;
  2113. +
  2114. + d = service_select(d);
  2115. + if (!d)
  2116. + return -ENODEV;
  2117. +
  2118. + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
  2119. + err = qbman_swp_acquire(d->swp, bpid, buffers, num_buffers);
  2120. + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
  2121. +
  2122. + return err;
  2123. +}
  2124. +EXPORT_SYMBOL(dpaa2_io_service_acquire);
  2125. +
  2126. +/*
  2127. + * 'Stores' are reusable memory blocks for holding dequeue results, and to
  2128. + * assist with parsing those results.
  2129. + */
  2130. +
  2131. +/**
  2132. + * dpaa2_io_store_create() - Create the dma memory storage for dequeue result.
  2133. + * @max_frames: the maximum number of dequeued result for frames, must be <= 16.
  2134. + * @dev: the device to allow mapping/unmapping the DMAable region.
  2135. + *
  2136. + * The size of the storage is "max_frames*sizeof(struct dpaa2_dq)".
  2137. + * The 'dpaa2_io_store' returned is a DPIO service managed object.
  2138. + *
  2139. + * Return pointer to dpaa2_io_store struct for successfuly created storage
  2140. + * memory, or NULL on error.
  2141. + */
  2142. +struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
  2143. + struct device *dev)
  2144. +{
  2145. + struct dpaa2_io_store *ret;
  2146. + size_t size;
  2147. +
  2148. + if (!max_frames || (max_frames > 16))
  2149. + return NULL;
  2150. +
  2151. + ret = kmalloc(sizeof(*ret), GFP_KERNEL);
  2152. + if (!ret)
  2153. + return NULL;
  2154. +
  2155. + ret->max = max_frames;
  2156. + size = max_frames * sizeof(struct dpaa2_dq) + 64;
  2157. + ret->alloced_addr = kzalloc(size, GFP_KERNEL);
  2158. + if (!ret->alloced_addr) {
  2159. + kfree(ret);
  2160. + return NULL;
  2161. + }
  2162. +
  2163. + ret->vaddr = PTR_ALIGN(ret->alloced_addr, 64);
  2164. + ret->paddr = dma_map_single(dev, ret->vaddr,
  2165. + sizeof(struct dpaa2_dq) * max_frames,
  2166. + DMA_FROM_DEVICE);
  2167. + if (dma_mapping_error(dev, ret->paddr)) {
  2168. + kfree(ret->alloced_addr);
  2169. + kfree(ret);
  2170. + return NULL;
  2171. + }
  2172. +
  2173. + ret->idx = 0;
  2174. + ret->dev = dev;
  2175. +
  2176. + return ret;
  2177. +}
  2178. +EXPORT_SYMBOL(dpaa2_io_store_create);
  2179. +
  2180. +/**
  2181. + * dpaa2_io_store_destroy() - Frees the dma memory storage for dequeue
  2182. + * result.
  2183. + * @s: the storage memory to be destroyed.
  2184. + */
  2185. +void dpaa2_io_store_destroy(struct dpaa2_io_store *s)
  2186. +{
  2187. + dma_unmap_single(s->dev, s->paddr, sizeof(struct dpaa2_dq) * s->max,
  2188. + DMA_FROM_DEVICE);
  2189. + kfree(s->alloced_addr);
  2190. + kfree(s);
  2191. +}
  2192. +EXPORT_SYMBOL(dpaa2_io_store_destroy);
  2193. +
  2194. +/**
  2195. + * dpaa2_io_store_next() - Determine when the next dequeue result is available.
  2196. + * @s: the dpaa2_io_store object.
  2197. + * @is_last: indicate whether this is the last frame in the pull command.
  2198. + *
  2199. + * When an object driver performs dequeues to a dpaa2_io_store, this function
  2200. + * can be used to determine when the next frame result is available. Once
  2201. + * this function returns non-NULL, a subsequent call to it will try to find
  2202. + * the next dequeue result.
  2203. + *
  2204. + * Note that if a pull-dequeue has a NULL result because the target FQ/channel
  2205. + * was empty, then this function will also return NULL (rather than expecting
  2206. + * the caller to always check for this. As such, "is_last" can be used to
  2207. + * differentiate between "end-of-empty-dequeue" and "still-waiting".
  2208. + *
  2209. + * Return dequeue result for a valid dequeue result, or NULL for empty dequeue.
  2210. + */
  2211. +struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last)
  2212. +{
  2213. + int match;
  2214. + struct dpaa2_dq *ret = &s->vaddr[s->idx];
  2215. +
  2216. + match = qbman_result_has_new_result(s->swp, ret);
  2217. + if (!match) {
  2218. + *is_last = 0;
  2219. + return NULL;
  2220. + }
  2221. +
  2222. + s->idx++;
  2223. +
  2224. + if (dpaa2_dq_is_pull_complete(ret)) {
  2225. + *is_last = 1;
  2226. + s->idx = 0;
  2227. + /*
  2228. + * If we get an empty dequeue result to terminate a zero-results
  2229. + * vdqcr, return NULL to the caller rather than expecting him to
  2230. + * check non-NULL results every time.
  2231. + */
  2232. + if (!(dpaa2_dq_flags(ret) & DPAA2_DQ_STAT_VALIDFRAME))
  2233. + ret = NULL;
  2234. + } else {
  2235. + *is_last = 0;
  2236. + }
  2237. +
  2238. + return ret;
  2239. +}
  2240. +EXPORT_SYMBOL(dpaa2_io_store_next);
  2241. +
  2242. +#ifdef CONFIG_FSL_QBMAN_DEBUG
  2243. +/**
  2244. + * dpaa2_io_query_fq_count() - Get the frame and byte count for a given fq.
  2245. + * @d: the given DPIO object.
  2246. + * @fqid: the id of frame queue to be queried.
  2247. + * @fcnt: the queried frame count.
  2248. + * @bcnt: the queried byte count.
  2249. + *
  2250. + * Knowing the FQ count at run-time can be useful in debugging situations.
  2251. + * The instantaneous frame- and byte-count are hereby returned.
  2252. + *
  2253. + * Return 0 for a successful query, and negative error code if query fails.
  2254. + */
  2255. +int dpaa2_io_query_fq_count(struct dpaa2_io *d, uint32_t fqid,
  2256. + u32 *fcnt, u32 *bcnt)
  2257. +{
  2258. + struct qbman_attr state;
  2259. + struct qbman_swp *swp;
  2260. + unsigned long irqflags;
  2261. + int ret;
  2262. +
  2263. + d = service_select(d);
  2264. + if (!d)
  2265. + return -ENODEV;
  2266. +
  2267. + swp = d->swp;
  2268. + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
  2269. + ret = qbman_fq_query_state(swp, fqid, &state);
  2270. + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
  2271. + if (ret)
  2272. + return ret;
  2273. + *fcnt = qbman_fq_state_frame_count(&state);
  2274. + *bcnt = qbman_fq_state_byte_count(&state);
  2275. +
  2276. + return 0;
  2277. +}
  2278. +EXPORT_SYMBOL(dpaa2_io_query_fq_count);
  2279. +
  2280. +/**
  2281. + * dpaa2_io_query_bp_count() - Query the number of buffers currenty in a
  2282. + * buffer pool.
  2283. + * @d: the given DPIO object.
  2284. + * @bpid: the index of buffer pool to be queried.
  2285. + * @num: the queried number of buffers in the buffer pool.
  2286. + *
  2287. + * Return 0 for a sucessful query, and negative error code if query fails.
  2288. + */
  2289. +int dpaa2_io_query_bp_count(struct dpaa2_io *d, uint32_t bpid, u32 *num)
  2290. +{
  2291. + struct qbman_attr state;
  2292. + struct qbman_swp *swp;
  2293. + unsigned long irqflags;
  2294. + int ret;
  2295. +
  2296. + d = service_select(d);
  2297. + if (!d)
  2298. + return -ENODEV;
  2299. +
  2300. + swp = d->swp;
  2301. + spin_lock_irqsave(&d->lock_mgmt_cmd, irqflags);
  2302. + ret = qbman_bp_query(swp, bpid, &state);
  2303. + spin_unlock_irqrestore(&d->lock_mgmt_cmd, irqflags);
  2304. + if (ret)
  2305. + return ret;
  2306. + *num = qbman_bp_info_num_free_bufs(&state);
  2307. + return 0;
  2308. +}
  2309. +EXPORT_SYMBOL(dpaa2_io_query_bp_count);
  2310. +#endif
  2311. --- /dev/null
  2312. +++ b/drivers/staging/fsl-mc/bus/dpio/dpio.c
  2313. @@ -0,0 +1,224 @@
  2314. +/*
  2315. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  2316. + * Copyright 2016 NXP
  2317. + *
  2318. + * Redistribution and use in source and binary forms, with or without
  2319. + * modification, are permitted provided that the following conditions are met:
  2320. + * * Redistributions of source code must retain the above copyright
  2321. + * notice, this list of conditions and the following disclaimer.
  2322. + * * Redistributions in binary form must reproduce the above copyright
  2323. + * notice, this list of conditions and the following disclaimer in the
  2324. + * documentation and/or other materials provided with the distribution.
  2325. + * * Neither the name of the above-listed copyright holders nor the
  2326. + * names of any contributors may be used to endorse or promote products
  2327. + * derived from this software without specific prior written permission.
  2328. + *
  2329. + * ALTERNATIVELY, this software may be distributed under the terms of the
  2330. + * GNU General Public License ("GPL") as published by the Free Software
  2331. + * Foundation, either version 2 of that License or (at your option) any
  2332. + * later version.
  2333. + *
  2334. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  2335. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2336. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2337. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  2338. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  2339. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  2340. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  2341. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  2342. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  2343. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  2344. + * POSSIBILITY OF SUCH DAMAGE.
  2345. + */
  2346. +#include "../../include/mc-sys.h"
  2347. +#include "../../include/mc-cmd.h"
  2348. +
  2349. +#include "dpio.h"
  2350. +#include "dpio-cmd.h"
  2351. +
  2352. +/*
  2353. + * Data Path I/O Portal API
  2354. + * Contains initialization APIs and runtime control APIs for DPIO
  2355. + */
  2356. +
  2357. +/**
  2358. + * dpio_open() - Open a control session for the specified object
  2359. + * @mc_io: Pointer to MC portal's I/O object
  2360. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  2361. + * @dpio_id: DPIO unique ID
  2362. + * @token: Returned token; use in subsequent API calls
  2363. + *
  2364. + * This function can be used to open a control session for an
  2365. + * already created object; an object may have been declared in
  2366. + * the DPL or by calling the dpio_create() function.
  2367. + * This function returns a unique authentication token,
  2368. + * associated with the specific object ID and the specific MC
  2369. + * portal; this token must be used in all subsequent commands for
  2370. + * this specific object.
  2371. + *
  2372. + * Return: '0' on Success; Error code otherwise.
  2373. + */
  2374. +int dpio_open(struct fsl_mc_io *mc_io,
  2375. + u32 cmd_flags,
  2376. + int dpio_id,
  2377. + u16 *token)
  2378. +{
  2379. + struct mc_command cmd = { 0 };
  2380. + struct dpio_cmd_open *dpio_cmd;
  2381. + int err;
  2382. +
  2383. + /* prepare command */
  2384. + cmd.header = mc_encode_cmd_header(DPIO_CMDID_OPEN,
  2385. + cmd_flags,
  2386. + 0);
  2387. + dpio_cmd = (struct dpio_cmd_open *)cmd.params;
  2388. + dpio_cmd->dpio_id = cpu_to_le32(dpio_id);
  2389. +
  2390. + err = mc_send_command(mc_io, &cmd);
  2391. + if (err)
  2392. + return err;
  2393. +
  2394. + /* retrieve response parameters */
  2395. + *token = mc_cmd_hdr_read_token(&cmd);
  2396. +
  2397. + return 0;
  2398. +}
  2399. +
  2400. +/**
  2401. + * dpio_close() - Close the control session of the object
  2402. + * @mc_io: Pointer to MC portal's I/O object
  2403. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  2404. + * @token: Token of DPIO object
  2405. + *
  2406. + * Return: '0' on Success; Error code otherwise.
  2407. + */
  2408. +int dpio_close(struct fsl_mc_io *mc_io,
  2409. + u32 cmd_flags,
  2410. + u16 token)
  2411. +{
  2412. + struct mc_command cmd = { 0 };
  2413. +
  2414. + /* prepare command */
  2415. + cmd.header = mc_encode_cmd_header(DPIO_CMDID_CLOSE,
  2416. + cmd_flags,
  2417. + token);
  2418. +
  2419. + return mc_send_command(mc_io, &cmd);
  2420. +}
  2421. +
  2422. +/**
  2423. + * dpio_enable() - Enable the DPIO, allow I/O portal operations.
  2424. + * @mc_io: Pointer to MC portal's I/O object
  2425. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  2426. + * @token: Token of DPIO object
  2427. + *
  2428. + * Return: '0' on Success; Error code otherwise
  2429. + */
  2430. +int dpio_enable(struct fsl_mc_io *mc_io,
  2431. + u32 cmd_flags,
  2432. + u16 token)
  2433. +{
  2434. + struct mc_command cmd = { 0 };
  2435. +
  2436. + /* prepare command */
  2437. + cmd.header = mc_encode_cmd_header(DPIO_CMDID_ENABLE,
  2438. + cmd_flags,
  2439. + token);
  2440. +
  2441. + return mc_send_command(mc_io, &cmd);
  2442. +}
  2443. +
  2444. +/**
  2445. + * dpio_disable() - Disable the DPIO, stop any I/O portal operation.
  2446. + * @mc_io: Pointer to MC portal's I/O object
  2447. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  2448. + * @token: Token of DPIO object
  2449. + *
  2450. + * Return: '0' on Success; Error code otherwise
  2451. + */
  2452. +int dpio_disable(struct fsl_mc_io *mc_io,
  2453. + u32 cmd_flags,
  2454. + u16 token)
  2455. +{
  2456. + struct mc_command cmd = { 0 };
  2457. +
  2458. + /* prepare command */
  2459. + cmd.header = mc_encode_cmd_header(DPIO_CMDID_DISABLE,
  2460. + cmd_flags,
  2461. + token);
  2462. +
  2463. + return mc_send_command(mc_io, &cmd);
  2464. +}
  2465. +
  2466. +/**
  2467. + * dpio_get_attributes() - Retrieve DPIO attributes
  2468. + * @mc_io: Pointer to MC portal's I/O object
  2469. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  2470. + * @token: Token of DPIO object
  2471. + * @attr: Returned object's attributes
  2472. + *
  2473. + * Return: '0' on Success; Error code otherwise
  2474. + */
  2475. +int dpio_get_attributes(struct fsl_mc_io *mc_io,
  2476. + u32 cmd_flags,
  2477. + u16 token,
  2478. + struct dpio_attr *attr)
  2479. +{
  2480. + struct mc_command cmd = { 0 };
  2481. + struct dpio_rsp_get_attr *dpio_rsp;
  2482. + int err;
  2483. +
  2484. + /* prepare command */
  2485. + cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_ATTR,
  2486. + cmd_flags,
  2487. + token);
  2488. +
  2489. + err = mc_send_command(mc_io, &cmd);
  2490. + if (err)
  2491. + return err;
  2492. +
  2493. + /* retrieve response parameters */
  2494. + dpio_rsp = (struct dpio_rsp_get_attr *)cmd.params;
  2495. + attr->id = le32_to_cpu(dpio_rsp->id);
  2496. + attr->qbman_portal_id = le16_to_cpu(dpio_rsp->qbman_portal_id);
  2497. + attr->num_priorities = dpio_rsp->num_priorities;
  2498. + attr->channel_mode = dpio_rsp->channel_mode & DPIO_CHANNEL_MODE_MASK;
  2499. + attr->qbman_portal_ce_offset =
  2500. + le64_to_cpu(dpio_rsp->qbman_portal_ce_addr);
  2501. + attr->qbman_portal_ci_offset =
  2502. + le64_to_cpu(dpio_rsp->qbman_portal_ci_addr);
  2503. + attr->qbman_version = le32_to_cpu(dpio_rsp->qbman_version);
  2504. +
  2505. + return 0;
  2506. +}
  2507. +
  2508. +/**
  2509. + * dpio_get_api_version - Get Data Path I/O API version
  2510. + * @mc_io: Pointer to MC portal's DPIO object
  2511. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  2512. + * @major_ver: Major version of DPIO API
  2513. + * @minor_ver: Minor version of DPIO API
  2514. + *
  2515. + * Return: '0' on Success; Error code otherwise
  2516. + */
  2517. +int dpio_get_api_version(struct fsl_mc_io *mc_io,
  2518. + u32 cmd_flags,
  2519. + u16 *major_ver,
  2520. + u16 *minor_ver)
  2521. +{
  2522. + struct mc_command cmd = { 0 };
  2523. + int err;
  2524. +
  2525. + /* prepare command */
  2526. + cmd.header = mc_encode_cmd_header(DPIO_CMDID_GET_API_VERSION,
  2527. + cmd_flags, 0);
  2528. +
  2529. + err = mc_send_command(mc_io, &cmd);
  2530. + if (err)
  2531. + return err;
  2532. +
  2533. + /* retrieve response parameters */
  2534. + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  2535. +
  2536. + return 0;
  2537. +}
  2538. --- /dev/null
  2539. +++ b/drivers/staging/fsl-mc/bus/dpio/dpio.h
  2540. @@ -0,0 +1,109 @@
  2541. +/*
  2542. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  2543. + * Copyright 2016 NXP
  2544. + *
  2545. + * Redistribution and use in source and binary forms, with or without
  2546. + * modification, are permitted provided that the following conditions are met:
  2547. + * * Redistributions of source code must retain the above copyright
  2548. + * notice, this list of conditions and the following disclaimer.
  2549. + * * Redistributions in binary form must reproduce the above copyright
  2550. + * notice, this list of conditions and the following disclaimer in the
  2551. + * documentation and/or other materials provided with the distribution.
  2552. + * * Neither the name of the above-listed copyright holders nor the
  2553. + * names of any contributors may be used to endorse or promote products
  2554. + * derived from this software without specific prior written permission.
  2555. + *
  2556. + * ALTERNATIVELY, this software may be distributed under the terms of the
  2557. + * GNU General Public License ("GPL") as published by the Free Software
  2558. + * Foundation, either version 2 of that License or (at your option) any
  2559. + * later version.
  2560. + *
  2561. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  2562. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  2563. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  2564. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  2565. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  2566. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  2567. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  2568. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  2569. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  2570. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  2571. + * POSSIBILITY OF SUCH DAMAGE.
  2572. + */
  2573. +#ifndef __FSL_DPIO_H
  2574. +#define __FSL_DPIO_H
  2575. +
  2576. +struct fsl_mc_io;
  2577. +
  2578. +int dpio_open(struct fsl_mc_io *mc_io,
  2579. + u32 cmd_flags,
  2580. + int dpio_id,
  2581. + u16 *token);
  2582. +
  2583. +int dpio_close(struct fsl_mc_io *mc_io,
  2584. + u32 cmd_flags,
  2585. + u16 token);
  2586. +
  2587. +/**
  2588. + * enum dpio_channel_mode - DPIO notification channel mode
  2589. + * @DPIO_NO_CHANNEL: No support for notification channel
  2590. + * @DPIO_LOCAL_CHANNEL: Notifications on data availability can be received by a
  2591. + * dedicated channel in the DPIO; user should point the queue's
  2592. + * destination in the relevant interface to this DPIO
  2593. + */
  2594. +enum dpio_channel_mode {
  2595. + DPIO_NO_CHANNEL = 0,
  2596. + DPIO_LOCAL_CHANNEL = 1,
  2597. +};
  2598. +
  2599. +/**
  2600. + * struct dpio_cfg - Structure representing DPIO configuration
  2601. + * @channel_mode: Notification channel mode
  2602. + * @num_priorities: Number of priorities for the notification channel (1-8);
  2603. + * relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
  2604. + */
  2605. +struct dpio_cfg {
  2606. + enum dpio_channel_mode channel_mode;
  2607. + u8 num_priorities;
  2608. +};
  2609. +
  2610. +int dpio_enable(struct fsl_mc_io *mc_io,
  2611. + u32 cmd_flags,
  2612. + u16 token);
  2613. +
  2614. +int dpio_disable(struct fsl_mc_io *mc_io,
  2615. + u32 cmd_flags,
  2616. + u16 token);
  2617. +
  2618. +/**
  2619. + * struct dpio_attr - Structure representing DPIO attributes
  2620. + * @id: DPIO object ID
  2621. + * @qbman_portal_ce_offset: offset of the software portal cache-enabled area
  2622. + * @qbman_portal_ci_offset: offset of the software portal cache-inhibited area
  2623. + * @qbman_portal_id: Software portal ID
  2624. + * @channel_mode: Notification channel mode
  2625. + * @num_priorities: Number of priorities for the notification channel (1-8);
  2626. + * relevant only if 'channel_mode = DPIO_LOCAL_CHANNEL'
  2627. + * @qbman_version: QBMAN version
  2628. + */
  2629. +struct dpio_attr {
  2630. + int id;
  2631. + u64 qbman_portal_ce_offset;
  2632. + u64 qbman_portal_ci_offset;
  2633. + u16 qbman_portal_id;
  2634. + enum dpio_channel_mode channel_mode;
  2635. + u8 num_priorities;
  2636. + u32 qbman_version;
  2637. +};
  2638. +
  2639. +int dpio_get_attributes(struct fsl_mc_io *mc_io,
  2640. + u32 cmd_flags,
  2641. + u16 token,
  2642. + struct dpio_attr *attr);
  2643. +
  2644. +int dpio_get_api_version(struct fsl_mc_io *mc_io,
  2645. + u32 cmd_flags,
  2646. + u16 *major_ver,
  2647. + u16 *minor_ver);
  2648. +
  2649. +#endif /* __FSL_DPIO_H */
  2650. --- /dev/null
  2651. +++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.c
  2652. @@ -0,0 +1,1049 @@
  2653. +/*
  2654. + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  2655. + * Copyright 2016 NXP
  2656. + *
  2657. + * Redistribution and use in source and binary forms, with or without
  2658. + * modification, are permitted provided that the following conditions are met:
  2659. + * * Redistributions of source code must retain the above copyright
  2660. + * notice, this list of conditions and the following disclaimer.
  2661. + * * Redistributions in binary form must reproduce the above copyright
  2662. + * notice, this list of conditions and the following disclaimer in the
  2663. + * documentation and/or other materials provided with the distribution.
  2664. + * * Neither the name of Freescale Semiconductor nor the
  2665. + * names of its contributors may be used to endorse or promote products
  2666. + * derived from this software without specific prior written permission.
  2667. + *
  2668. + * ALTERNATIVELY, this software may be distributed under the terms of the
  2669. + * GNU General Public License ("GPL") as published by the Free Software
  2670. + * Foundation, either version 2 of that License or (at your option) any
  2671. + * later version.
  2672. + *
  2673. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  2674. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  2675. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  2676. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  2677. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  2678. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  2679. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  2680. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  2681. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  2682. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  2683. + */
  2684. +
  2685. +#include <asm/cacheflush.h>
  2686. +#include <linux/io.h>
  2687. +#include <linux/slab.h>
  2688. +#include "../../include/dpaa2-global.h"
  2689. +
  2690. +#include "qbman-portal.h"
  2691. +
  2692. +struct qb_attr_code code_generic_verb = QB_CODE(0, 0, 7);
  2693. +struct qb_attr_code code_generic_rslt = QB_CODE(0, 8, 8);
  2694. +
  2695. +#define QMAN_REV_4000 0x04000000
  2696. +#define QMAN_REV_4100 0x04010000
  2697. +#define QMAN_REV_4101 0x04010001
  2698. +#define QMAN_REV_MASK 0xffff0000
  2699. +
  2700. +/* All QBMan command and result structures use this "valid bit" encoding */
  2701. +#define QB_VALID_BIT ((u32)0x80)
  2702. +
  2703. +/* QBMan portal management command codes */
  2704. +#define QBMAN_MC_ACQUIRE 0x30
  2705. +#define QBMAN_WQCHAN_CONFIGURE 0x46
  2706. +
  2707. +/* CINH register offsets */
  2708. +#define QBMAN_CINH_SWP_EQAR 0x8c0
  2709. +#define QBMAN_CINH_SWP_DQPI 0xa00
  2710. +#define QBMAN_CINH_SWP_DCAP 0xac0
  2711. +#define QBMAN_CINH_SWP_SDQCR 0xb00
  2712. +#define QBMAN_CINH_SWP_RAR 0xcc0
  2713. +#define QBMAN_CINH_SWP_ISR 0xe00
  2714. +#define QBMAN_CINH_SWP_IER 0xe40
  2715. +#define QBMAN_CINH_SWP_ISDR 0xe80
  2716. +#define QBMAN_CINH_SWP_IIR 0xec0
  2717. +
  2718. +/* CENA register offsets */
  2719. +#define QBMAN_CENA_SWP_EQCR(n) (0x000 + ((u32)(n) << 6))
  2720. +#define QBMAN_CENA_SWP_DQRR(n) (0x200 + ((u32)(n) << 6))
  2721. +#define QBMAN_CENA_SWP_RCR(n) (0x400 + ((u32)(n) << 6))
  2722. +#define QBMAN_CENA_SWP_CR 0x600
  2723. +#define QBMAN_CENA_SWP_RR(vb) (0x700 + ((u32)(vb) >> 1))
  2724. +#define QBMAN_CENA_SWP_VDQCR 0x780
  2725. +
  2726. +/* Reverse mapping of QBMAN_CENA_SWP_DQRR() */
  2727. +#define QBMAN_IDX_FROM_DQRR(p) (((unsigned long)(p) & 0x1ff) >> 6)
  2728. +
  2729. +/* Define token used to determine if response written to memory is valid */
  2730. +#define QMAN_DQ_TOKEN_VALID 1
  2731. +
  2732. +/* SDQCR attribute codes */
  2733. +#define QB_SDQCR_FC_SHIFT 29
  2734. +#define QB_SDQCR_FC_MASK 0x1
  2735. +#define QB_SDQCR_DCT_SHIFT 24
  2736. +#define QB_SDQCR_DCT_MASK 0x3
  2737. +#define QB_SDQCR_TOK_SHIFT 16
  2738. +#define QB_SDQCR_TOK_MASK 0xff
  2739. +#define QB_SDQCR_SRC_SHIFT 0
  2740. +#define QB_SDQCR_SRC_MASK 0xffff
  2741. +
  2742. +/* opaque token for static dequeues */
  2743. +#define QMAN_SDQCR_TOKEN 0xbb
  2744. +
  2745. +enum qbman_sdqcr_dct {
  2746. + qbman_sdqcr_dct_null = 0,
  2747. + qbman_sdqcr_dct_prio_ics,
  2748. + qbman_sdqcr_dct_active_ics,
  2749. + qbman_sdqcr_dct_active
  2750. +};
  2751. +
  2752. +enum qbman_sdqcr_fc {
  2753. + qbman_sdqcr_fc_one = 0,
  2754. + qbman_sdqcr_fc_up_to_3 = 1
  2755. +};
  2756. +
  2757. +#define dccvac(p) { asm volatile("dc cvac, %0;" : : "r" (p) : "memory"); }
  2758. +#define dcivac(p) { asm volatile("dc ivac, %0" : : "r"(p) : "memory"); }
  2759. +static inline void qbman_inval_prefetch(struct qbman_swp *p, uint32_t offset)
  2760. +{
  2761. + dcivac(p->addr_cena + offset);
  2762. + prefetch(p->addr_cena + offset);
  2763. +}
  2764. +
  2765. +/* Portal Access */
  2766. +
  2767. +static inline u32 qbman_read_register(struct qbman_swp *p, u32 offset)
  2768. +{
  2769. + return readl_relaxed(p->addr_cinh + offset);
  2770. +}
  2771. +
  2772. +static inline void qbman_write_register(struct qbman_swp *p, u32 offset,
  2773. + u32 value)
  2774. +{
  2775. + writel_relaxed(value, p->addr_cinh + offset);
  2776. +}
  2777. +
  2778. +static inline void *qbman_get_cmd(struct qbman_swp *p, u32 offset)
  2779. +{
  2780. + return p->addr_cena + offset;
  2781. +}
  2782. +
  2783. +#define QBMAN_CINH_SWP_CFG 0xd00
  2784. +
  2785. +#define SWP_CFG_DQRR_MF_SHIFT 20
  2786. +#define SWP_CFG_EST_SHIFT 16
  2787. +#define SWP_CFG_WN_SHIFT 14
  2788. +#define SWP_CFG_RPM_SHIFT 12
  2789. +#define SWP_CFG_DCM_SHIFT 10
  2790. +#define SWP_CFG_EPM_SHIFT 8
  2791. +#define SWP_CFG_SD_SHIFT 5
  2792. +#define SWP_CFG_SP_SHIFT 4
  2793. +#define SWP_CFG_SE_SHIFT 3
  2794. +#define SWP_CFG_DP_SHIFT 2
  2795. +#define SWP_CFG_DE_SHIFT 1
  2796. +#define SWP_CFG_EP_SHIFT 0
  2797. +
  2798. +static inline u32 qbman_set_swp_cfg(u8 max_fill, u8 wn, u8 est, u8 rpm, u8 dcm,
  2799. + u8 epm, int sd, int sp, int se,
  2800. + int dp, int de, int ep)
  2801. +{
  2802. + return cpu_to_le32 (max_fill << SWP_CFG_DQRR_MF_SHIFT |
  2803. + est << SWP_CFG_EST_SHIFT |
  2804. + wn << SWP_CFG_WN_SHIFT |
  2805. + rpm << SWP_CFG_RPM_SHIFT |
  2806. + dcm << SWP_CFG_DCM_SHIFT |
  2807. + epm << SWP_CFG_EPM_SHIFT |
  2808. + sd << SWP_CFG_SD_SHIFT |
  2809. + sp << SWP_CFG_SP_SHIFT |
  2810. + se << SWP_CFG_SE_SHIFT |
  2811. + dp << SWP_CFG_DP_SHIFT |
  2812. + de << SWP_CFG_DE_SHIFT |
  2813. + ep << SWP_CFG_EP_SHIFT);
  2814. +}
  2815. +
  2816. +/**
  2817. + * qbman_swp_init() - Create a functional object representing the given
  2818. + * QBMan portal descriptor.
  2819. + * @d: the given qbman swp descriptor
  2820. + *
  2821. + * Return qbman_swp portal for success, NULL if the object cannot
  2822. + * be created.
  2823. + */
  2824. +struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d)
  2825. +{
  2826. + struct qbman_swp *p = kmalloc(sizeof(*p), GFP_KERNEL);
  2827. + u32 reg;
  2828. +
  2829. + if (!p)
  2830. + return NULL;
  2831. + p->desc = d;
  2832. + p->mc.valid_bit = QB_VALID_BIT;
  2833. + p->sdq = 0;
  2834. + p->sdq |= qbman_sdqcr_dct_prio_ics << QB_SDQCR_DCT_SHIFT;
  2835. + p->sdq |= qbman_sdqcr_fc_up_to_3 << QB_SDQCR_FC_SHIFT;
  2836. + p->sdq |= QMAN_SDQCR_TOKEN << QB_SDQCR_TOK_SHIFT;
  2837. +
  2838. + atomic_set(&p->vdq.available, 1);
  2839. + p->vdq.valid_bit = QB_VALID_BIT;
  2840. + p->dqrr.next_idx = 0;
  2841. + p->dqrr.valid_bit = QB_VALID_BIT;
  2842. +
  2843. + if ((p->desc->qman_version & QMAN_REV_MASK) < QMAN_REV_4100) {
  2844. + p->dqrr.dqrr_size = 4;
  2845. + p->dqrr.reset_bug = 1;
  2846. + } else {
  2847. + p->dqrr.dqrr_size = 8;
  2848. + p->dqrr.reset_bug = 0;
  2849. + }
  2850. +
  2851. + p->addr_cena = d->cena_bar;
  2852. + p->addr_cinh = d->cinh_bar;
  2853. +
  2854. + reg = qbman_set_swp_cfg(p->dqrr.dqrr_size,
  2855. + 0, /* Writes cacheable */
  2856. + 0, /* EQCR_CI stashing threshold */
  2857. + 3, /* RPM: Valid bit mode, RCR in array mode */
  2858. + 2, /* DCM: Discrete consumption ack mode */
  2859. + 3, /* EPM: Valid bit mode, EQCR in array mode */
  2860. + 0, /* mem stashing drop enable == FALSE */
  2861. + 1, /* mem stashing priority == TRUE */
  2862. + 0, /* mem stashing enable == FALSE */
  2863. + 1, /* dequeue stashing priority == TRUE */
  2864. + 0, /* dequeue stashing enable == FALSE */
  2865. + 0); /* EQCR_CI stashing priority == FALSE */
  2866. +
  2867. + qbman_write_register(p, QBMAN_CINH_SWP_CFG, reg);
  2868. + reg = qbman_read_register(p, QBMAN_CINH_SWP_CFG);
  2869. + if (!reg) {
  2870. + pr_err("qbman: the portal is not enabled!\n");
  2871. + return NULL;
  2872. + }
  2873. +
  2874. + /*
  2875. + * SDQCR needs to be initialized to 0 when no channels are
  2876. + * being dequeued from or else the QMan HW will indicate an
  2877. + * error. The values that were calculated above will be
  2878. + * applied when dequeues from a specific channel are enabled.
  2879. + */
  2880. + qbman_write_register(p, QBMAN_CINH_SWP_SDQCR, 0);
  2881. + return p;
  2882. +}
  2883. +
  2884. +/**
  2885. + * qbman_swp_finish() - Create and destroy a functional object representing
  2886. + * the given QBMan portal descriptor.
  2887. + * @p: the qbman_swp object to be destroyed
  2888. + */
  2889. +void qbman_swp_finish(struct qbman_swp *p)
  2890. +{
  2891. + kfree(p);
  2892. +}
  2893. +
  2894. +/**
  2895. + * qbman_swp_interrupt_read_status()
  2896. + * @p: the given software portal
  2897. + *
  2898. + * Return the value in the SWP_ISR register.
  2899. + */
  2900. +u32 qbman_swp_interrupt_read_status(struct qbman_swp *p)
  2901. +{
  2902. + return qbman_read_register(p, QBMAN_CINH_SWP_ISR);
  2903. +}
  2904. +
  2905. +/**
  2906. + * qbman_swp_interrupt_clear_status()
  2907. + * @p: the given software portal
  2908. + * @mask: The mask to clear in SWP_ISR register
  2909. + */
  2910. +void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask)
  2911. +{
  2912. + qbman_write_register(p, QBMAN_CINH_SWP_ISR, mask);
  2913. +}
  2914. +
  2915. +/**
  2916. + * qbman_swp_interrupt_get_trigger() - read interrupt enable register
  2917. + * @p: the given software portal
  2918. + *
  2919. + * Return the value in the SWP_IER register.
  2920. + */
  2921. +u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p)
  2922. +{
  2923. + return qbman_read_register(p, QBMAN_CINH_SWP_IER);
  2924. +}
  2925. +
  2926. +/**
  2927. + * qbman_swp_interrupt_set_trigger() - enable interrupts for a swp
  2928. + * @p: the given software portal
  2929. + * @mask: The mask of bits to enable in SWP_IER
  2930. + */
  2931. +void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask)
  2932. +{
  2933. + qbman_write_register(p, QBMAN_CINH_SWP_IER, mask);
  2934. +}
  2935. +
  2936. +/**
  2937. + * qbman_swp_interrupt_get_inhibit() - read interrupt mask register
  2938. + * @p: the given software portal object
  2939. + *
  2940. + * Return the value in the SWP_IIR register.
  2941. + */
  2942. +int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p)
  2943. +{
  2944. + return qbman_read_register(p, QBMAN_CINH_SWP_IIR);
  2945. +}
  2946. +
  2947. +/**
  2948. + * qbman_swp_interrupt_set_inhibit() - write interrupt mask register
  2949. + * @p: the given software portal object
  2950. + * @mask: The mask to set in SWP_IIR register
  2951. + */
  2952. +void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit)
  2953. +{
  2954. + qbman_write_register(p, QBMAN_CINH_SWP_IIR, inhibit ? 0xffffffff : 0);
  2955. +}
  2956. +
  2957. +/*
  2958. + * Different management commands all use this common base layer of code to issue
  2959. + * commands and poll for results.
  2960. + */
  2961. +
  2962. +/*
  2963. + * Returns a pointer to where the caller should fill in their management command
  2964. + * (caller should ignore the verb byte)
  2965. + */
  2966. +void *qbman_swp_mc_start(struct qbman_swp *p)
  2967. +{
  2968. + return qbman_get_cmd(p, QBMAN_CENA_SWP_CR);
  2969. +}
  2970. +
  2971. +/*
  2972. + * Commits merges in the caller-supplied command verb (which should not include
  2973. + * the valid-bit) and submits the command to hardware
  2974. + */
  2975. +void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb)
  2976. +{
  2977. + u8 *v = cmd;
  2978. +
  2979. + dma_wmb();
  2980. + *v = cmd_verb | p->mc.valid_bit;
  2981. + dccvac(cmd);
  2982. +}
  2983. +
  2984. +/*
  2985. + * Checks for a completed response (returns non-NULL if only if the response
  2986. + * is complete).
  2987. + */
  2988. +void *qbman_swp_mc_result(struct qbman_swp *p)
  2989. +{
  2990. + u32 *ret, verb;
  2991. +
  2992. + qbman_inval_prefetch(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
  2993. + ret = qbman_get_cmd(p, QBMAN_CENA_SWP_RR(p->mc.valid_bit));
  2994. +
  2995. + /* Remove the valid-bit - command completed if the rest is non-zero */
  2996. + verb = ret[0] & ~QB_VALID_BIT;
  2997. + if (!verb)
  2998. + return NULL;
  2999. + p->mc.valid_bit ^= QB_VALID_BIT;
  3000. + return ret;
  3001. +}
  3002. +
  3003. +#define QB_ENQUEUE_CMD_OPTIONS_SHIFT 0
  3004. +enum qb_enqueue_commands {
  3005. + enqueue_empty = 0,
  3006. + enqueue_response_always = 1,
  3007. + enqueue_rejects_to_fq = 2
  3008. +};
  3009. +
  3010. +#define QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT 2
  3011. +#define QB_ENQUEUE_CMD_IRQ_ON_DISPATCH_SHIFT 3
  3012. +#define QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT 4
  3013. +
  3014. +/**
  3015. + * qbman_eq_desc_clear() - Clear the contents of a descriptor to
  3016. + * default/starting state.
  3017. + */
  3018. +void qbman_eq_desc_clear(struct qbman_eq_desc *d)
  3019. +{
  3020. + memset(d, 0, sizeof(*d));
  3021. +}
  3022. +
  3023. +/**
  3024. + * qbman_eq_desc_set_no_orp() - Set enqueue descriptor without orp
  3025. + * @d: the enqueue descriptor.
  3026. + * @response_success: 1 = enqueue with response always; 0 = enqueue with
  3027. + * rejections returned on a FQ.
  3028. + */
  3029. +void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success)
  3030. +{
  3031. + d->verb &= ~(1 << QB_ENQUEUE_CMD_ORP_ENABLE_SHIFT);
  3032. + if (respond_success)
  3033. + d->verb |= enqueue_response_always;
  3034. + else
  3035. + d->verb |= enqueue_rejects_to_fq;
  3036. +}
  3037. +
  3038. +/*
  3039. + * Exactly one of the following descriptor "targets" should be set. (Calling any
  3040. + * one of these will replace the effect of any prior call to one of these.)
  3041. + * -enqueue to a frame queue
  3042. + * -enqueue to a queuing destination
  3043. + */
  3044. +
  3045. +/**
  3046. + * qbman_eq_desc_set_fq() - set the FQ for the enqueue command
  3047. + * @d: the enqueue descriptor
  3048. + * @fqid: the id of the frame queue to be enqueued
  3049. + */
  3050. +void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid)
  3051. +{
  3052. + d->verb &= ~(1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT);
  3053. + d->tgtid = cpu_to_le32(fqid);
  3054. +}
  3055. +
  3056. +/**
  3057. + * qbman_eq_desc_set_qd() - Set Queuing Destination for the enqueue command
  3058. + * @d: the enqueue descriptor
  3059. + * @qdid: the id of the queuing destination to be enqueued
  3060. + * @qd_bin: the queuing destination bin
  3061. + * @qd_prio: the queuing destination priority
  3062. + */
  3063. +void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
  3064. + u32 qd_bin, u32 qd_prio)
  3065. +{
  3066. + d->verb |= 1 << QB_ENQUEUE_CMD_TARGET_TYPE_SHIFT;
  3067. + d->tgtid = cpu_to_le32(qdid);
  3068. + d->qdbin = cpu_to_le16(qd_bin);
  3069. + d->qpri = qd_prio;
  3070. +}
  3071. +
  3072. +#define EQAR_IDX(eqar) ((eqar) & 0x7)
  3073. +#define EQAR_VB(eqar) ((eqar) & 0x80)
  3074. +#define EQAR_SUCCESS(eqar) ((eqar) & 0x100)
  3075. +
  3076. +/**
  3077. + * qbman_swp_enqueue() - Issue an enqueue command
  3078. + * @s: the software portal used for enqueue
  3079. + * @d: the enqueue descriptor
  3080. + * @fd: the frame descriptor to be enqueued
  3081. + *
  3082. + * Please note that 'fd' should only be NULL if the "action" of the
  3083. + * descriptor is "orp_hole" or "orp_nesn".
  3084. + *
  3085. + * Return 0 for successful enqueue, -EBUSY if the EQCR is not ready.
  3086. + */
  3087. +int qbman_swp_enqueue(struct qbman_swp *s, const struct qbman_eq_desc *d,
  3088. + const struct dpaa2_fd *fd)
  3089. +{
  3090. + struct qbman_eq_desc *p;
  3091. + u32 eqar = qbman_read_register(s, QBMAN_CINH_SWP_EQAR);
  3092. +
  3093. + if (!EQAR_SUCCESS(eqar))
  3094. + return -EBUSY;
  3095. +
  3096. + p = qbman_get_cmd(s, QBMAN_CENA_SWP_EQCR(EQAR_IDX(eqar)));
  3097. + memcpy(&p->dca, &d->dca, 31);
  3098. + memcpy(&p->fd, fd, sizeof(*fd));
  3099. +
  3100. + /* Set the verb byte, have to substitute in the valid-bit */
  3101. + dma_wmb();
  3102. + p->verb = d->verb | EQAR_VB(eqar);
  3103. + dccvac(p);
  3104. +
  3105. + return 0;
  3106. +}
  3107. +
  3108. +/* Static (push) dequeue */
  3109. +
  3110. +/**
  3111. + * qbman_swp_push_get() - Get the push dequeue setup
  3112. + * @p: the software portal object
  3113. + * @channel_idx: the channel index to query
  3114. + * @enabled: returned boolean to show whether the push dequeue is enabled
  3115. + * for the given channel
  3116. + */
  3117. +void qbman_swp_push_get(struct qbman_swp *s, u8 channel_idx, int *enabled)
  3118. +{
  3119. + u16 src = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
  3120. +
  3121. + WARN_ON(channel_idx > 15);
  3122. + *enabled = src | (1 << channel_idx);
  3123. +}
  3124. +
  3125. +/**
  3126. + * qbman_swp_push_set() - Enable or disable push dequeue
  3127. + * @p: the software portal object
  3128. + * @channel_idx: the channel index (0 to 15)
  3129. + * @enable: enable or disable push dequeue
  3130. + */
  3131. +void qbman_swp_push_set(struct qbman_swp *s, u8 channel_idx, int enable)
  3132. +{
  3133. + u16 dqsrc;
  3134. +
  3135. + WARN_ON(channel_idx > 15);
  3136. + if (enable)
  3137. + s->sdq |= 1 << channel_idx;
  3138. + else
  3139. + s->sdq &= ~(1 << channel_idx);
  3140. +
  3141. + /* Read make the complete src map. If no channels are enabled
  3142. + * the SDQCR must be 0 or else QMan will assert errors
  3143. + */
  3144. + dqsrc = (s->sdq >> QB_SDQCR_SRC_SHIFT) & QB_SDQCR_SRC_MASK;
  3145. + if (dqsrc != 0)
  3146. + qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, s->sdq);
  3147. + else
  3148. + qbman_write_register(s, QBMAN_CINH_SWP_SDQCR, 0);
  3149. +}
  3150. +
  3151. +#define QB_VDQCR_VERB_DCT_SHIFT 0
  3152. +#define QB_VDQCR_VERB_DT_SHIFT 2
  3153. +#define QB_VDQCR_VERB_RLS_SHIFT 4
  3154. +#define QB_VDQCR_VERB_WAE_SHIFT 5
  3155. +
  3156. +enum qb_pull_dt_e {
  3157. + qb_pull_dt_channel,
  3158. + qb_pull_dt_workqueue,
  3159. + qb_pull_dt_framequeue
  3160. +};
  3161. +
  3162. +/**
  3163. + * qbman_pull_desc_clear() - Clear the contents of a descriptor to
  3164. + * default/starting state
  3165. + * @d: the pull dequeue descriptor to be cleared
  3166. + */
  3167. +void qbman_pull_desc_clear(struct qbman_pull_desc *d)
  3168. +{
  3169. + memset(d, 0, sizeof(*d));
  3170. +}
  3171. +
  3172. +/**
  3173. + * qbman_pull_desc_set_storage()- Set the pull dequeue storage
  3174. + * @d: the pull dequeue descriptor to be set
  3175. + * @storage: the pointer of the memory to store the dequeue result
  3176. + * @storage_phys: the physical address of the storage memory
  3177. + * @stash: to indicate whether write allocate is enabled
  3178. + *
  3179. + * If not called, or if called with 'storage' as NULL, the result pull dequeues
  3180. + * will produce results to DQRR. If 'storage' is non-NULL, then results are
  3181. + * produced to the given memory location (using the DMA address which
  3182. + * the caller provides in 'storage_phys'), and 'stash' controls whether or not
  3183. + * those writes to main-memory express a cache-warming attribute.
  3184. + */
  3185. +void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
  3186. + struct dpaa2_dq *storage,
  3187. + dma_addr_t storage_phys,
  3188. + int stash)
  3189. +{
  3190. + /* save the virtual address */
  3191. + d->rsp_addr_virt = (u64)storage;
  3192. +
  3193. + if (!storage) {
  3194. + d->verb &= ~(1 << QB_VDQCR_VERB_RLS_SHIFT);
  3195. + return;
  3196. + }
  3197. + d->verb |= 1 << QB_VDQCR_VERB_RLS_SHIFT;
  3198. + if (stash)
  3199. + d->verb |= 1 << QB_VDQCR_VERB_WAE_SHIFT;
  3200. + else
  3201. + d->verb &= ~(1 << QB_VDQCR_VERB_WAE_SHIFT);
  3202. +
  3203. + d->rsp_addr = cpu_to_le64(storage_phys);
  3204. +}
  3205. +
  3206. +/**
  3207. + * qbman_pull_desc_set_numframes() - Set the number of frames to be dequeued
  3208. + * @d: the pull dequeue descriptor to be set
  3209. + * @numframes: number of frames to be set, must be between 1 and 16, inclusive
  3210. + */
  3211. +void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes)
  3212. +{
  3213. + d->numf = numframes - 1;
  3214. +}
  3215. +
  3216. +void qbman_pull_desc_set_token(struct qbman_pull_desc *d, u8 token)
  3217. +{
  3218. + d->tok = token;
  3219. +}
  3220. +
  3221. +/*
  3222. + * Exactly one of the following descriptor "actions" should be set. (Calling any
  3223. + * one of these will replace the effect of any prior call to one of these.)
  3224. + * - pull dequeue from the given frame queue (FQ)
  3225. + * - pull dequeue from any FQ in the given work queue (WQ)
  3226. + * - pull dequeue from any FQ in any WQ in the given channel
  3227. + */
  3228. +
  3229. +/**
  3230. + * qbman_pull_desc_set_fq() - Set fqid from which the dequeue command dequeues
  3231. + * @fqid: the frame queue index of the given FQ
  3232. + */
  3233. +void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid)
  3234. +{
  3235. + d->verb |= 1 << QB_VDQCR_VERB_DCT_SHIFT;
  3236. + d->verb |= qb_pull_dt_framequeue << QB_VDQCR_VERB_DT_SHIFT;
  3237. + d->dq_src = cpu_to_le32(fqid);
  3238. +}
  3239. +
  3240. +/**
  3241. + * qbman_pull_desc_set_wq() - Set wqid from which the dequeue command dequeues
  3242. + * @wqid: composed of channel id and wqid within the channel
  3243. + * @dct: the dequeue command type
  3244. + */
  3245. +void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
  3246. + enum qbman_pull_type_e dct)
  3247. +{
  3248. + d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
  3249. + d->verb |= qb_pull_dt_workqueue << QB_VDQCR_VERB_DT_SHIFT;
  3250. + d->dq_src = cpu_to_le32(wqid);
  3251. +}
  3252. +
  3253. +/**
  3254. + * qbman_pull_desc_set_channel() - Set channelid from which the dequeue command
  3255. + * dequeues
  3256. + * @chid: the channel id to be dequeued
  3257. + * @dct: the dequeue command type
  3258. + */
  3259. +void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
  3260. + enum qbman_pull_type_e dct)
  3261. +{
  3262. + d->verb |= dct << QB_VDQCR_VERB_DCT_SHIFT;
  3263. + d->verb |= qb_pull_dt_channel << QB_VDQCR_VERB_DT_SHIFT;
  3264. + d->dq_src = cpu_to_le32(chid);
  3265. +}
  3266. +
  3267. +/**
  3268. + * qbman_swp_pull() - Issue the pull dequeue command
  3269. + * @s: the software portal object
  3270. + * @d: the software portal descriptor which has been configured with
  3271. + * the set of qbman_pull_desc_set_*() calls
  3272. + *
  3273. + * Return 0 for success, and -EBUSY if the software portal is not ready
  3274. + * to do pull dequeue.
  3275. + */
  3276. +int qbman_swp_pull(struct qbman_swp *s, struct qbman_pull_desc *d)
  3277. +{
  3278. + struct qbman_pull_desc *p;
  3279. +
  3280. + if (!atomic_dec_and_test(&s->vdq.available)) {
  3281. + atomic_inc(&s->vdq.available);
  3282. + return -EBUSY;
  3283. + }
  3284. + s->vdq.storage = (void *)d->rsp_addr_virt;
  3285. + p = qbman_get_cmd(s, QBMAN_CENA_SWP_VDQCR);
  3286. + p->numf = d->numf;
  3287. + p->tok = QMAN_DQ_TOKEN_VALID;
  3288. + p->dq_src = d->dq_src;
  3289. + p->rsp_addr = d->rsp_addr;
  3290. + p->rsp_addr_virt = d->rsp_addr_virt;
  3291. + dma_wmb();
  3292. +
  3293. + /* Set the verb byte, have to substitute in the valid-bit */
  3294. + p->verb = d->verb | s->vdq.valid_bit;
  3295. + s->vdq.valid_bit ^= QB_VALID_BIT;
  3296. + dccvac(p);
  3297. +
  3298. + return 0;
  3299. +}
  3300. +
  3301. +#define QMAN_DQRR_PI_MASK 0xf
  3302. +
  3303. +/**
  3304. + * qbman_swp_dqrr_next() - Get an valid DQRR entry
  3305. + * @s: the software portal object
  3306. + *
  3307. + * Return NULL if there are no unconsumed DQRR entries. Return a DQRR entry
  3308. + * only once, so repeated calls can return a sequence of DQRR entries, without
  3309. + * requiring they be consumed immediately or in any particular order.
  3310. + */
  3311. +const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s)
  3312. +{
  3313. + u32 verb;
  3314. + u32 response_verb;
  3315. + u32 flags;
  3316. + struct dpaa2_dq *p;
  3317. +
  3318. + /* Before using valid-bit to detect if something is there, we have to
  3319. + * handle the case of the DQRR reset bug...
  3320. + */
  3321. + if (unlikely(s->dqrr.reset_bug)) {
  3322. + /*
  3323. + * We pick up new entries by cache-inhibited producer index,
  3324. + * which means that a non-coherent mapping would require us to
  3325. + * invalidate and read *only* once that PI has indicated that
  3326. + * there's an entry here. The first trip around the DQRR ring
  3327. + * will be much less efficient than all subsequent trips around
  3328. + * it...
  3329. + */
  3330. + u8 pi = qbman_read_register(s, QBMAN_CINH_SWP_DQPI) &
  3331. + QMAN_DQRR_PI_MASK;
  3332. +
  3333. + /* there are new entries if pi != next_idx */
  3334. + if (pi == s->dqrr.next_idx)
  3335. + return NULL;
  3336. +
  3337. + /*
  3338. + * if next_idx is/was the last ring index, and 'pi' is
  3339. + * different, we can disable the workaround as all the ring
  3340. + * entries have now been DMA'd to so valid-bit checking is
  3341. + * repaired. Note: this logic needs to be based on next_idx
  3342. + * (which increments one at a time), rather than on pi (which
  3343. + * can burst and wrap-around between our snapshots of it).
  3344. + */
  3345. + if (s->dqrr.next_idx == (s->dqrr.dqrr_size - 1)) {
  3346. + pr_debug("next_idx=%d, pi=%d, clear reset bug\n",
  3347. + s->dqrr.next_idx, pi);
  3348. + s->dqrr.reset_bug = 0;
  3349. + }
  3350. + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  3351. + }
  3352. +
  3353. + p = qbman_get_cmd(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  3354. + verb = p->dq.verb;
  3355. +
  3356. + /*
  3357. + * If the valid-bit isn't of the expected polarity, nothing there. Note,
  3358. + * in the DQRR reset bug workaround, we shouldn't need to skip these
  3359. + * check, because we've already determined that a new entry is available
  3360. + * and we've invalidated the cacheline before reading it, so the
  3361. + * valid-bit behaviour is repaired and should tell us what we already
  3362. + * knew from reading PI.
  3363. + */
  3364. + if ((verb & QB_VALID_BIT) != s->dqrr.valid_bit) {
  3365. + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  3366. + return NULL;
  3367. + }
  3368. + /*
  3369. + * There's something there. Move "next_idx" attention to the next ring
  3370. + * entry (and prefetch it) before returning what we found.
  3371. + */
  3372. + s->dqrr.next_idx++;
  3373. + s->dqrr.next_idx &= s->dqrr.dqrr_size - 1; /* Wrap around */
  3374. + if (!s->dqrr.next_idx)
  3375. + s->dqrr.valid_bit ^= QB_VALID_BIT;
  3376. +
  3377. + /*
  3378. + * If this is the final response to a volatile dequeue command
  3379. + * indicate that the vdq is available
  3380. + */
  3381. + flags = p->dq.stat;
  3382. + response_verb = verb & QBMAN_RESULT_MASK;
  3383. + if ((response_verb == QBMAN_RESULT_DQ) &&
  3384. + (flags & DPAA2_DQ_STAT_VOLATILE) &&
  3385. + (flags & DPAA2_DQ_STAT_EXPIRED))
  3386. + atomic_inc(&s->vdq.available);
  3387. +
  3388. + qbman_inval_prefetch(s, QBMAN_CENA_SWP_DQRR(s->dqrr.next_idx));
  3389. +
  3390. + return p;
  3391. +}
  3392. +
  3393. +/**
  3394. + * qbman_swp_dqrr_consume() - Consume DQRR entries previously returned from
  3395. + * qbman_swp_dqrr_next().
  3396. + * @s: the software portal object
  3397. + * @dq: the DQRR entry to be consumed
  3398. + */
  3399. +void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq)
  3400. +{
  3401. + qbman_write_register(s, QBMAN_CINH_SWP_DCAP, QBMAN_IDX_FROM_DQRR(dq));
  3402. +}
  3403. +
  3404. +/**
  3405. + * qbman_result_has_new_result() - Check and get the dequeue response from the
  3406. + * dq storage memory set in pull dequeue command
  3407. + * @s: the software portal object
  3408. + * @dq: the dequeue result read from the memory
  3409. + *
  3410. + * Return 1 for getting a valid dequeue result, or 0 for not getting a valid
  3411. + * dequeue result.
  3412. + *
  3413. + * Only used for user-provided storage of dequeue results, not DQRR. For
  3414. + * efficiency purposes, the driver will perform any required endianness
  3415. + * conversion to ensure that the user's dequeue result storage is in host-endian
  3416. + * format. As such, once the user has called qbman_result_has_new_result() and
  3417. + * been returned a valid dequeue result, they should not call it again on
  3418. + * the same memory location (except of course if another dequeue command has
  3419. + * been executed to produce a new result to that location).
  3420. + */
  3421. +int qbman_result_has_new_result(struct qbman_swp *s, const struct dpaa2_dq *dq)
  3422. +{
  3423. + if (dq->dq.tok != QMAN_DQ_TOKEN_VALID)
  3424. + return 0;
  3425. +
  3426. + /*
  3427. + * Set token to be 0 so we will detect change back to 1
  3428. + * next time the looping is traversed. Const is cast away here
  3429. + * as we want users to treat the dequeue responses as read only.
  3430. + */
  3431. + ((struct dpaa2_dq *)dq)->dq.tok = 0;
  3432. +
  3433. + /*
  3434. + * Determine whether VDQCR is available based on whether the
  3435. + * current result is sitting in the first storage location of
  3436. + * the busy command.
  3437. + */
  3438. + if (s->vdq.storage == dq) {
  3439. + s->vdq.storage = NULL;
  3440. + atomic_inc(&s->vdq.available);
  3441. + }
  3442. +
  3443. + return 1;
  3444. +}
  3445. +
  3446. +/**
  3447. + * qbman_release_desc_clear() - Clear the contents of a descriptor to
  3448. + * default/starting state.
  3449. + */
  3450. +void qbman_release_desc_clear(struct qbman_release_desc *d)
  3451. +{
  3452. + memset(d, 0, sizeof(*d));
  3453. + d->verb = 1 << 5; /* Release Command Valid */
  3454. +}
  3455. +
  3456. +/**
  3457. + * qbman_release_desc_set_bpid() - Set the ID of the buffer pool to release to
  3458. + */
  3459. +void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid)
  3460. +{
  3461. + d->bpid = cpu_to_le16(bpid);
  3462. +}
  3463. +
  3464. +/**
  3465. + * qbman_release_desc_set_rcdi() - Determines whether or not the portal's RCDI
  3466. + * interrupt source should be asserted after the release command is completed.
  3467. + */
  3468. +void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable)
  3469. +{
  3470. + if (enable)
  3471. + d->verb |= 1 << 6;
  3472. + else
  3473. + d->verb &= ~(1 << 6);
  3474. +}
  3475. +
  3476. +#define RAR_IDX(rar) ((rar) & 0x7)
  3477. +#define RAR_VB(rar) ((rar) & 0x80)
  3478. +#define RAR_SUCCESS(rar) ((rar) & 0x100)
  3479. +
  3480. +/**
  3481. + * qbman_swp_release() - Issue a buffer release command
  3482. + * @s: the software portal object
  3483. + * @d: the release descriptor
  3484. + * @buffers: a pointer pointing to the buffer address to be released
  3485. + * @num_buffers: number of buffers to be released, must be less than 8
  3486. + *
  3487. + * Return 0 for success, -EBUSY if the release command ring is not ready.
  3488. + */
  3489. +int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
  3490. + const u64 *buffers, unsigned int num_buffers)
  3491. +{
  3492. + int i;
  3493. + struct qbman_release_desc *p;
  3494. + u32 rar;
  3495. +
  3496. + if (!num_buffers || (num_buffers > 7))
  3497. + return -EINVAL;
  3498. +
  3499. + rar = qbman_read_register(s, QBMAN_CINH_SWP_RAR);
  3500. + if (!RAR_SUCCESS(rar))
  3501. + return -EBUSY;
  3502. +
  3503. + /* Start the release command */
  3504. + p = qbman_get_cmd(s, QBMAN_CENA_SWP_RCR(RAR_IDX(rar)));
  3505. + /* Copy the caller's buffer pointers to the command */
  3506. + for (i = 0; i < num_buffers; i++)
  3507. + p->buf[i] = cpu_to_le64(buffers[i]);
  3508. + p->bpid = d->bpid;
  3509. +
  3510. + /*
  3511. + * Set the verb byte, have to substitute in the valid-bit and the number
  3512. + * of buffers.
  3513. + */
  3514. + dma_wmb();
  3515. + p->verb = d->verb | RAR_VB(rar) | num_buffers;
  3516. + dccvac(p);
  3517. +
  3518. + return 0;
  3519. +}
  3520. +
  3521. +struct qbman_acquire_desc {
  3522. + u8 verb;
  3523. + u8 reserved;
  3524. + u16 bpid;
  3525. + u8 num;
  3526. + u8 reserved2[59];
  3527. +};
  3528. +
  3529. +struct qbman_acquire_rslt {
  3530. + u8 verb;
  3531. + u8 rslt;
  3532. + u16 reserved;
  3533. + u8 num;
  3534. + u8 reserved2[3];
  3535. + u64 buf[7];
  3536. +};
  3537. +
  3538. +/**
  3539. + * qbman_swp_acquire() - Issue a buffer acquire command
  3540. + * @s: the software portal object
  3541. + * @bpid: the buffer pool index
  3542. + * @buffers: a pointer pointing to the acquired buffer addresses
  3543. + * @num_buffers: number of buffers to be acquired, must be less than 8
  3544. + *
  3545. + * Return 0 for success, or negative error code if the acquire command
  3546. + * fails.
  3547. + */
  3548. +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
  3549. + unsigned int num_buffers)
  3550. +{
  3551. + struct qbman_acquire_desc *p;
  3552. + struct qbman_acquire_rslt *r;
  3553. + int i;
  3554. +
  3555. + if (!num_buffers || (num_buffers > 7))
  3556. + return -EINVAL;
  3557. +
  3558. + /* Start the management command */
  3559. + p = qbman_swp_mc_start(s);
  3560. +
  3561. + if (!p)
  3562. + return -EBUSY;
  3563. +
  3564. + /* Encode the caller-provided attributes */
  3565. + p->bpid = cpu_to_le16(bpid);
  3566. + p->num = num_buffers;
  3567. +
  3568. + /* Complete the management command */
  3569. + r = qbman_swp_mc_complete(s, p, QBMAN_MC_ACQUIRE);
  3570. + if (unlikely(!r)) {
  3571. + pr_err("qbman: acquire from BPID %d failed, no response\n",
  3572. + bpid);
  3573. + return -EIO;
  3574. + }
  3575. +
  3576. + /* Decode the outcome */
  3577. + WARN_ON((r->verb & 0x7f) != QBMAN_MC_ACQUIRE);
  3578. +
  3579. + /* Determine success or failure */
  3580. + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
  3581. + pr_err("qbman: acquire from BPID 0x%x failed, code=0x%02x\n",
  3582. + bpid, r->rslt);
  3583. + return -EIO;
  3584. + }
  3585. +
  3586. + WARN_ON(r->num > num_buffers);
  3587. +
  3588. + /* Copy the acquired buffers to the caller's array */
  3589. + for (i = 0; i < r->num; i++)
  3590. + buffers[i] = le64_to_cpu(r->buf[i]);
  3591. +
  3592. + return (int)r->num;
  3593. +}
  3594. +
  3595. +struct qbman_alt_fq_state_desc {
  3596. + u8 verb;
  3597. + u8 reserved[3];
  3598. + u32 fqid;
  3599. + u8 reserved2[56];
  3600. +};
  3601. +
  3602. +struct qbman_alt_fq_state_rslt {
  3603. + u8 verb;
  3604. + u8 rslt;
  3605. + u8 reserved[62];
  3606. +};
  3607. +
  3608. +#define ALT_FQ_FQID_MASK 0x00FFFFFF
  3609. +
  3610. +int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
  3611. + u8 alt_fq_verb)
  3612. +{
  3613. + struct qbman_alt_fq_state_desc *p;
  3614. + struct qbman_alt_fq_state_rslt *r;
  3615. +
  3616. + /* Start the management command */
  3617. + p = qbman_swp_mc_start(s);
  3618. + if (!p)
  3619. + return -EBUSY;
  3620. +
  3621. + p->fqid = cpu_to_le32(fqid) & ALT_FQ_FQID_MASK;
  3622. +
  3623. + /* Complete the management command */
  3624. + r = qbman_swp_mc_complete(s, p, alt_fq_verb);
  3625. + if (unlikely(!r)) {
  3626. + pr_err("qbman: mgmt cmd failed, no response (verb=0x%x)\n",
  3627. + alt_fq_verb);
  3628. + return -EIO;
  3629. + }
  3630. +
  3631. + /* Decode the outcome */
  3632. + WARN_ON((r->verb & QBMAN_RESULT_MASK) != alt_fq_verb);
  3633. +
  3634. + /* Determine success or failure */
  3635. + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
  3636. + pr_err("qbman: ALT FQID %d failed: verb = 0x%08x code = 0x%02x\n",
  3637. + fqid, r->verb, r->rslt);
  3638. + return -EIO;
  3639. + }
  3640. +
  3641. + return 0;
  3642. +}
  3643. +
  3644. +struct qbman_cdan_ctrl_desc {
  3645. + u8 verb;
  3646. + u8 reserved;
  3647. + u16 ch;
  3648. + u8 we;
  3649. + u8 ctrl;
  3650. + u16 reserved2;
  3651. + u64 cdan_ctx;
  3652. + u8 reserved3[48];
  3653. +
  3654. +};
  3655. +
  3656. +struct qbman_cdan_ctrl_rslt {
  3657. + u8 verb;
  3658. + u8 rslt;
  3659. + u16 ch;
  3660. + u8 reserved[60];
  3661. +};
  3662. +
  3663. +int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
  3664. + u8 we_mask, u8 cdan_en,
  3665. + u64 ctx)
  3666. +{
  3667. + struct qbman_cdan_ctrl_desc *p = NULL;
  3668. + struct qbman_cdan_ctrl_rslt *r = NULL;
  3669. +
  3670. + /* Start the management command */
  3671. + p = qbman_swp_mc_start(s);
  3672. + if (!p)
  3673. + return -EBUSY;
  3674. +
  3675. + /* Encode the caller-provided attributes */
  3676. + p->ch = cpu_to_le16(channelid);
  3677. + p->we = we_mask;
  3678. + if (cdan_en)
  3679. + p->ctrl = 1;
  3680. + else
  3681. + p->ctrl = 0;
  3682. + p->cdan_ctx = cpu_to_le64(ctx);
  3683. +
  3684. + /* Complete the management command */
  3685. + r = qbman_swp_mc_complete(s, p, QBMAN_WQCHAN_CONFIGURE);
  3686. + if (unlikely(!r)) {
  3687. + pr_err("qbman: wqchan config failed, no response\n");
  3688. + return -EIO;
  3689. + }
  3690. +
  3691. + WARN_ON((r->verb & 0x7f) != QBMAN_WQCHAN_CONFIGURE);
  3692. +
  3693. + /* Determine success or failure */
  3694. + if (unlikely(r->rslt != QBMAN_MC_RSLT_OK)) {
  3695. + pr_err("qbman: CDAN cQID %d failed: code = 0x%02x\n",
  3696. + channelid, r->rslt);
  3697. + return -EIO;
  3698. + }
  3699. +
  3700. + return 0;
  3701. +}
  3702. --- /dev/null
  3703. +++ b/drivers/staging/fsl-mc/bus/dpio/qbman-portal.h
  3704. @@ -0,0 +1,662 @@
  3705. +/*
  3706. + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  3707. + * Copyright 2016 NXP
  3708. + *
  3709. + * Redistribution and use in source and binary forms, with or without
  3710. + * modification, are permitted provided that the following conditions are met:
  3711. + * * Redistributions of source code must retain the above copyright
  3712. + * notice, this list of conditions and the following disclaimer.
  3713. + * * Redistributions in binary form must reproduce the above copyright
  3714. + * notice, this list of conditions and the following disclaimer in the
  3715. + * documentation and/or other materials provided with the distribution.
  3716. + * * Neither the name of Freescale Semiconductor nor the
  3717. + * names of its contributors may be used to endorse or promote products
  3718. + * derived from this software without specific prior written permission.
  3719. + *
  3720. + * ALTERNATIVELY, this software may be distributed under the terms of the
  3721. + * GNU General Public License ("GPL") as published by the Free Software
  3722. + * Foundation, either version 2 of that License or (at your option) any
  3723. + * later version.
  3724. + *
  3725. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  3726. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  3727. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  3728. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  3729. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  3730. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  3731. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  3732. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  3733. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  3734. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  3735. + */
  3736. +#ifndef __FSL_QBMAN_PORTAL_H
  3737. +#define __FSL_QBMAN_PORTAL_H
  3738. +
  3739. +#include "qbman_private.h"
  3740. +#include "../../include/dpaa2-fd.h"
  3741. +
  3742. +struct dpaa2_dq;
  3743. +struct qbman_swp;
  3744. +
  3745. +/* qbman software portal descriptor structure */
  3746. +struct qbman_swp_desc {
  3747. + void *cena_bar; /* Cache-enabled portal base address */
  3748. + void *cinh_bar; /* Cache-inhibited portal base address */
  3749. + u32 qman_version;
  3750. +};
  3751. +
  3752. +#define QBMAN_SWP_INTERRUPT_EQRI 0x01
  3753. +#define QBMAN_SWP_INTERRUPT_EQDI 0x02
  3754. +#define QBMAN_SWP_INTERRUPT_DQRI 0x04
  3755. +#define QBMAN_SWP_INTERRUPT_RCRI 0x08
  3756. +#define QBMAN_SWP_INTERRUPT_RCDI 0x10
  3757. +#define QBMAN_SWP_INTERRUPT_VDCI 0x20
  3758. +
  3759. +/* the structure for pull dequeue descriptor */
  3760. +struct qbman_pull_desc {
  3761. + u8 verb;
  3762. + u8 numf;
  3763. + u8 tok;
  3764. + u8 reserved;
  3765. + u32 dq_src;
  3766. + u64 rsp_addr;
  3767. + u64 rsp_addr_virt;
  3768. + u8 padding[40];
  3769. +};
  3770. +
  3771. +enum qbman_pull_type_e {
  3772. + /* dequeue with priority precedence, respect intra-class scheduling */
  3773. + qbman_pull_type_prio = 1,
  3774. + /* dequeue with active FQ precedence, respect ICS */
  3775. + qbman_pull_type_active,
  3776. + /* dequeue with active FQ precedence, no ICS */
  3777. + qbman_pull_type_active_noics
  3778. +};
  3779. +
  3780. +/* Definitions for parsing dequeue entries */
  3781. +#define QBMAN_RESULT_MASK 0x7f
  3782. +#define QBMAN_RESULT_DQ 0x60
  3783. +#define QBMAN_RESULT_FQRN 0x21
  3784. +#define QBMAN_RESULT_FQRNI 0x22
  3785. +#define QBMAN_RESULT_FQPN 0x24
  3786. +#define QBMAN_RESULT_FQDAN 0x25
  3787. +#define QBMAN_RESULT_CDAN 0x26
  3788. +#define QBMAN_RESULT_CSCN_MEM 0x27
  3789. +#define QBMAN_RESULT_CGCU 0x28
  3790. +#define QBMAN_RESULT_BPSCN 0x29
  3791. +#define QBMAN_RESULT_CSCN_WQ 0x2a
  3792. +
  3793. +/* QBMan FQ management command codes */
  3794. +#define QBMAN_FQ_SCHEDULE 0x48
  3795. +#define QBMAN_FQ_FORCE 0x49
  3796. +#define QBMAN_FQ_XON 0x4d
  3797. +#define QBMAN_FQ_XOFF 0x4e
  3798. +
  3799. +/* structure of enqueue descriptor */
  3800. +struct qbman_eq_desc {
  3801. + u8 verb;
  3802. + u8 dca;
  3803. + u16 seqnum;
  3804. + u16 orpid;
  3805. + u16 reserved1;
  3806. + u32 tgtid;
  3807. + u32 tag;
  3808. + u16 qdbin;
  3809. + u8 qpri;
  3810. + u8 reserved[3];
  3811. + u8 wae;
  3812. + u8 rspid;
  3813. + u64 rsp_addr;
  3814. + u8 fd[32];
  3815. +};
  3816. +
  3817. +/* buffer release descriptor */
  3818. +struct qbman_release_desc {
  3819. + u8 verb;
  3820. + u8 reserved;
  3821. + u16 bpid;
  3822. + u32 reserved2;
  3823. + u64 buf[7];
  3824. +};
  3825. +
  3826. +/* Management command result codes */
  3827. +#define QBMAN_MC_RSLT_OK 0xf0
  3828. +
  3829. +#define CODE_CDAN_WE_EN 0x1
  3830. +#define CODE_CDAN_WE_CTX 0x4
  3831. +
  3832. +/* portal data structure */
  3833. +struct qbman_swp {
  3834. + const struct qbman_swp_desc *desc;
  3835. + void __iomem *addr_cena;
  3836. + void __iomem *addr_cinh;
  3837. +
  3838. + /* Management commands */
  3839. + struct {
  3840. + u32 valid_bit; /* 0x00 or 0x80 */
  3841. + } mc;
  3842. +
  3843. + /* Push dequeues */
  3844. + u32 sdq;
  3845. +
  3846. + /* Volatile dequeues */
  3847. + struct {
  3848. + atomic_t available; /* indicates if a command can be sent */
  3849. + u32 valid_bit; /* 0x00 or 0x80 */
  3850. + struct dpaa2_dq *storage; /* NULL if DQRR */
  3851. + } vdq;
  3852. +
  3853. + /* DQRR */
  3854. + struct {
  3855. + u32 next_idx;
  3856. + u32 valid_bit;
  3857. + u8 dqrr_size;
  3858. + int reset_bug; /* indicates dqrr reset workaround is needed */
  3859. + } dqrr;
  3860. +};
  3861. +
  3862. +struct qbman_swp *qbman_swp_init(const struct qbman_swp_desc *d);
  3863. +void qbman_swp_finish(struct qbman_swp *p);
  3864. +u32 qbman_swp_interrupt_read_status(struct qbman_swp *p);
  3865. +void qbman_swp_interrupt_clear_status(struct qbman_swp *p, u32 mask);
  3866. +u32 qbman_swp_interrupt_get_trigger(struct qbman_swp *p);
  3867. +void qbman_swp_interrupt_set_trigger(struct qbman_swp *p, u32 mask);
  3868. +int qbman_swp_interrupt_get_inhibit(struct qbman_swp *p);
  3869. +void qbman_swp_interrupt_set_inhibit(struct qbman_swp *p, int inhibit);
  3870. +
  3871. +void qbman_swp_push_get(struct qbman_swp *p, u8 channel_idx, int *enabled);
  3872. +void qbman_swp_push_set(struct qbman_swp *p, u8 channel_idx, int enable);
  3873. +
  3874. +void qbman_pull_desc_clear(struct qbman_pull_desc *d);
  3875. +void qbman_pull_desc_set_storage(struct qbman_pull_desc *d,
  3876. + struct dpaa2_dq *storage,
  3877. + dma_addr_t storage_phys,
  3878. + int stash);
  3879. +void qbman_pull_desc_set_numframes(struct qbman_pull_desc *d, u8 numframes);
  3880. +void qbman_pull_desc_set_fq(struct qbman_pull_desc *d, u32 fqid);
  3881. +void qbman_pull_desc_set_wq(struct qbman_pull_desc *d, u32 wqid,
  3882. + enum qbman_pull_type_e dct);
  3883. +void qbman_pull_desc_set_channel(struct qbman_pull_desc *d, u32 chid,
  3884. + enum qbman_pull_type_e dct);
  3885. +
  3886. +int qbman_swp_pull(struct qbman_swp *p, struct qbman_pull_desc *d);
  3887. +
  3888. +const struct dpaa2_dq *qbman_swp_dqrr_next(struct qbman_swp *s);
  3889. +void qbman_swp_dqrr_consume(struct qbman_swp *s, const struct dpaa2_dq *dq);
  3890. +
  3891. +int qbman_result_has_new_result(struct qbman_swp *p, const struct dpaa2_dq *dq);
  3892. +
  3893. +void qbman_eq_desc_clear(struct qbman_eq_desc *d);
  3894. +void qbman_eq_desc_set_no_orp(struct qbman_eq_desc *d, int respond_success);
  3895. +void qbman_eq_desc_set_token(struct qbman_eq_desc *d, u8 token);
  3896. +void qbman_eq_desc_set_fq(struct qbman_eq_desc *d, u32 fqid);
  3897. +void qbman_eq_desc_set_qd(struct qbman_eq_desc *d, u32 qdid,
  3898. + u32 qd_bin, u32 qd_prio);
  3899. +
  3900. +int qbman_swp_enqueue(struct qbman_swp *p, const struct qbman_eq_desc *d,
  3901. + const struct dpaa2_fd *fd);
  3902. +
  3903. +void qbman_release_desc_clear(struct qbman_release_desc *d);
  3904. +void qbman_release_desc_set_bpid(struct qbman_release_desc *d, u16 bpid);
  3905. +void qbman_release_desc_set_rcdi(struct qbman_release_desc *d, int enable);
  3906. +
  3907. +int qbman_swp_release(struct qbman_swp *s, const struct qbman_release_desc *d,
  3908. + const u64 *buffers, unsigned int num_buffers);
  3909. +int qbman_swp_acquire(struct qbman_swp *s, u16 bpid, u64 *buffers,
  3910. + unsigned int num_buffers);
  3911. +int qbman_swp_alt_fq_state(struct qbman_swp *s, u32 fqid,
  3912. + u8 alt_fq_verb);
  3913. +int qbman_swp_CDAN_set(struct qbman_swp *s, u16 channelid,
  3914. + u8 we_mask, u8 cdan_en,
  3915. + u64 ctx);
  3916. +
  3917. +void *qbman_swp_mc_start(struct qbman_swp *p);
  3918. +void qbman_swp_mc_submit(struct qbman_swp *p, void *cmd, u8 cmd_verb);
  3919. +void *qbman_swp_mc_result(struct qbman_swp *p);
  3920. +
  3921. +/**
  3922. + * qbman_result_is_DQ() - check if the dequeue result is a dequeue response
  3923. + * @dq: the dequeue result to be checked
  3924. + *
  3925. + * DQRR entries may contain non-dequeue results, ie. notifications
  3926. + */
  3927. +static inline int qbman_result_is_DQ(const struct dpaa2_dq *dq)
  3928. +{
  3929. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_DQ);
  3930. +}
  3931. +
  3932. +/**
  3933. + * qbman_result_is_SCN() - Check the dequeue result is notification or not
  3934. + * @dq: the dequeue result to be checked
  3935. + *
  3936. + */
  3937. +static inline int qbman_result_is_SCN(const struct dpaa2_dq *dq)
  3938. +{
  3939. + return !qbman_result_is_DQ(dq);
  3940. +}
  3941. +
  3942. +/* FQ Data Availability */
  3943. +static inline int qbman_result_is_FQDAN(const struct dpaa2_dq *dq)
  3944. +{
  3945. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQDAN);
  3946. +}
  3947. +
  3948. +/* Channel Data Availability */
  3949. +static inline int qbman_result_is_CDAN(const struct dpaa2_dq *dq)
  3950. +{
  3951. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CDAN);
  3952. +}
  3953. +
  3954. +/* Congestion State Change */
  3955. +static inline int qbman_result_is_CSCN(const struct dpaa2_dq *dq)
  3956. +{
  3957. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CSCN_WQ);
  3958. +}
  3959. +
  3960. +/* Buffer Pool State Change */
  3961. +static inline int qbman_result_is_BPSCN(const struct dpaa2_dq *dq)
  3962. +{
  3963. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_BPSCN);
  3964. +}
  3965. +
  3966. +/* Congestion Group Count Update */
  3967. +static inline int qbman_result_is_CGCU(const struct dpaa2_dq *dq)
  3968. +{
  3969. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_CGCU);
  3970. +}
  3971. +
  3972. +/* Retirement */
  3973. +static inline int qbman_result_is_FQRN(const struct dpaa2_dq *dq)
  3974. +{
  3975. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRN);
  3976. +}
  3977. +
  3978. +/* Retirement Immediate */
  3979. +static inline int qbman_result_is_FQRNI(const struct dpaa2_dq *dq)
  3980. +{
  3981. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQRNI);
  3982. +}
  3983. +
  3984. + /* Park */
  3985. +static inline int qbman_result_is_FQPN(const struct dpaa2_dq *dq)
  3986. +{
  3987. + return ((dq->dq.verb & QBMAN_RESULT_MASK) == QBMAN_RESULT_FQPN);
  3988. +}
  3989. +
  3990. +/**
  3991. + * qbman_result_SCN_state() - Get the state field in State-change notification
  3992. + */
  3993. +static inline u8 qbman_result_SCN_state(const struct dpaa2_dq *scn)
  3994. +{
  3995. + return scn->scn.state;
  3996. +}
  3997. +
  3998. +#define SCN_RID_MASK 0x00FFFFFF
  3999. +
  4000. +/**
  4001. + * qbman_result_SCN_rid() - Get the resource id in State-change notification
  4002. + */
  4003. +static inline u32 qbman_result_SCN_rid(const struct dpaa2_dq *scn)
  4004. +{
  4005. + return le32_to_cpu(scn->scn.rid_tok) & SCN_RID_MASK;
  4006. +}
  4007. +
  4008. +/**
  4009. + * qbman_result_SCN_ctx() - Get the context data in State-change notification
  4010. + */
  4011. +static inline u64 qbman_result_SCN_ctx(const struct dpaa2_dq *scn)
  4012. +{
  4013. + return le64_to_cpu(scn->scn.ctx);
  4014. +}
  4015. +
  4016. +/**
  4017. + * qbman_swp_fq_schedule() - Move the fq to the scheduled state
  4018. + * @s: the software portal object
  4019. + * @fqid: the index of frame queue to be scheduled
  4020. + *
  4021. + * There are a couple of different ways that a FQ can end up parked state,
  4022. + * This schedules it.
  4023. + *
  4024. + * Return 0 for success, or negative error code for failure.
  4025. + */
  4026. +static inline int qbman_swp_fq_schedule(struct qbman_swp *s, u32 fqid)
  4027. +{
  4028. + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_SCHEDULE);
  4029. +}
  4030. +
  4031. +/**
  4032. + * qbman_swp_fq_force() - Force the FQ to fully scheduled state
  4033. + * @s: the software portal object
  4034. + * @fqid: the index of frame queue to be forced
  4035. + *
  4036. + * Force eligible will force a tentatively-scheduled FQ to be fully-scheduled
  4037. + * and thus be available for selection by any channel-dequeuing behaviour (push
  4038. + * or pull). If the FQ is subsequently "dequeued" from the channel and is still
  4039. + * empty at the time this happens, the resulting dq_entry will have no FD.
  4040. + * (qbman_result_DQ_fd() will return NULL.)
  4041. + *
  4042. + * Return 0 for success, or negative error code for failure.
  4043. + */
  4044. +static inline int qbman_swp_fq_force(struct qbman_swp *s, u32 fqid)
  4045. +{
  4046. + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_FORCE);
  4047. +}
  4048. +
  4049. +/**
  4050. + * qbman_swp_fq_xon() - sets FQ flow-control to XON
  4051. + * @s: the software portal object
  4052. + * @fqid: the index of frame queue
  4053. + *
  4054. + * This setting doesn't affect enqueues to the FQ, just dequeues.
  4055. + *
  4056. + * Return 0 for success, or negative error code for failure.
  4057. + */
  4058. +static inline int qbman_swp_fq_xon(struct qbman_swp *s, u32 fqid)
  4059. +{
  4060. + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XON);
  4061. +}
  4062. +
  4063. +/**
  4064. + * qbman_swp_fq_xoff() - sets FQ flow-control to XOFF
  4065. + * @s: the software portal object
  4066. + * @fqid: the index of frame queue
  4067. + *
  4068. + * This setting doesn't affect enqueues to the FQ, just dequeues.
  4069. + * XOFF FQs will remain in the tenatively-scheduled state, even when
  4070. + * non-empty, meaning they won't be selected for scheduled dequeuing.
  4071. + * If a FQ is changed to XOFF after it had already become truly-scheduled
  4072. + * to a channel, and a pull dequeue of that channel occurs that selects
  4073. + * that FQ for dequeuing, then the resulting dq_entry will have no FD.
  4074. + * (qbman_result_DQ_fd() will return NULL.)
  4075. + *
  4076. + * Return 0 for success, or negative error code for failure.
  4077. + */
  4078. +static inline int qbman_swp_fq_xoff(struct qbman_swp *s, u32 fqid)
  4079. +{
  4080. + return qbman_swp_alt_fq_state(s, fqid, QBMAN_FQ_XOFF);
  4081. +}
  4082. +
  4083. +/* If the user has been allocated a channel object that is going to generate
  4084. + * CDANs to another channel, then the qbman_swp_CDAN* functions will be
  4085. + * necessary.
  4086. + *
  4087. + * CDAN-enabled channels only generate a single CDAN notification, after which
  4088. + * they need to be reenabled before they'll generate another. The idea is
  4089. + * that pull dequeuing will occur in reaction to the CDAN, followed by a
  4090. + * reenable step. Each function generates a distinct command to hardware, so a
  4091. + * combination function is provided if the user wishes to modify the "context"
  4092. + * (which shows up in each CDAN message) each time they reenable, as a single
  4093. + * command to hardware.
  4094. + */
  4095. +
  4096. +/**
  4097. + * qbman_swp_CDAN_set_context() - Set CDAN context
  4098. + * @s: the software portal object
  4099. + * @channelid: the channel index
  4100. + * @ctx: the context to be set in CDAN
  4101. + *
  4102. + * Return 0 for success, or negative error code for failure.
  4103. + */
  4104. +static inline int qbman_swp_CDAN_set_context(struct qbman_swp *s, u16 channelid,
  4105. + u64 ctx)
  4106. +{
  4107. + return qbman_swp_CDAN_set(s, channelid,
  4108. + CODE_CDAN_WE_CTX,
  4109. + 0, ctx);
  4110. +}
  4111. +
  4112. +/**
  4113. + * qbman_swp_CDAN_enable() - Enable CDAN for the channel
  4114. + * @s: the software portal object
  4115. + * @channelid: the index of the channel to generate CDAN
  4116. + *
  4117. + * Return 0 for success, or negative error code for failure.
  4118. + */
  4119. +static inline int qbman_swp_CDAN_enable(struct qbman_swp *s, u16 channelid)
  4120. +{
  4121. + return qbman_swp_CDAN_set(s, channelid,
  4122. + CODE_CDAN_WE_EN,
  4123. + 1, 0);
  4124. +}
  4125. +
  4126. +/**
  4127. + * qbman_swp_CDAN_disable() - disable CDAN for the channel
  4128. + * @s: the software portal object
  4129. + * @channelid: the index of the channel to generate CDAN
  4130. + *
  4131. + * Return 0 for success, or negative error code for failure.
  4132. + */
  4133. +static inline int qbman_swp_CDAN_disable(struct qbman_swp *s, u16 channelid)
  4134. +{
  4135. + return qbman_swp_CDAN_set(s, channelid,
  4136. + CODE_CDAN_WE_EN,
  4137. + 0, 0);
  4138. +}
  4139. +
  4140. +/**
  4141. + * qbman_swp_CDAN_set_context_enable() - Set CDAN contest and enable CDAN
  4142. + * @s: the software portal object
  4143. + * @channelid: the index of the channel to generate CDAN
  4144. + * @ctx:i the context set in CDAN
  4145. + *
  4146. + * Return 0 for success, or negative error code for failure.
  4147. + */
  4148. +static inline int qbman_swp_CDAN_set_context_enable(struct qbman_swp *s,
  4149. + u16 channelid,
  4150. + u64 ctx)
  4151. +{
  4152. + return qbman_swp_CDAN_set(s, channelid,
  4153. + CODE_CDAN_WE_EN | CODE_CDAN_WE_CTX,
  4154. + 1, ctx);
  4155. +}
  4156. +
  4157. +/* Wraps up submit + poll-for-result */
  4158. +static inline void *qbman_swp_mc_complete(struct qbman_swp *swp, void *cmd,
  4159. + u8 cmd_verb)
  4160. +{
  4161. + int loopvar = 1000;
  4162. +
  4163. + qbman_swp_mc_submit(swp, cmd, cmd_verb);
  4164. +
  4165. + do {
  4166. + cmd = qbman_swp_mc_result(swp);
  4167. + } while (!cmd && loopvar--);
  4168. +
  4169. + WARN_ON(!loopvar);
  4170. +
  4171. + return cmd;
  4172. +}
  4173. +
  4174. +/* ------------ */
  4175. +/* qb_attr_code */
  4176. +/* ------------ */
  4177. +
  4178. +/* This struct locates a sub-field within a QBMan portal (CENA) cacheline which
  4179. + * is either serving as a configuration command or a query result. The
  4180. + * representation is inherently little-endian, as the indexing of the words is
  4181. + * itself little-endian in nature and layerscape is little endian for anything
  4182. + * that crosses a word boundary too (64-bit fields are the obvious examples).
  4183. + */
  4184. +struct qb_attr_code {
  4185. + unsigned int word; /* which u32[] array member encodes the field */
  4186. + unsigned int lsoffset; /* encoding offset from ls-bit */
  4187. + unsigned int width; /* encoding width. (bool must be 1.) */
  4188. +};
  4189. +
  4190. +/* Some pre-defined codes */
  4191. +extern struct qb_attr_code code_generic_verb;
  4192. +extern struct qb_attr_code code_generic_rslt;
  4193. +
  4194. +/* Macros to define codes */
  4195. +#define QB_CODE(a, b, c) { a, b, c}
  4196. +#define QB_CODE_NULL \
  4197. + QB_CODE((unsigned int)-1, (unsigned int)-1, (unsigned int)-1)
  4198. +
  4199. +/* Rotate a code "ms", meaning that it moves from less-significant bytes to
  4200. + * more-significant, from less-significant words to more-significant, etc. The
  4201. + * "ls" version does the inverse, from more-significant towards
  4202. + * less-significant.
  4203. + */
  4204. +static inline void qb_attr_code_rotate_ms(struct qb_attr_code *code,
  4205. + unsigned int bits)
  4206. +{
  4207. + code->lsoffset += bits;
  4208. + while (code->lsoffset > 31) {
  4209. + code->word++;
  4210. + code->lsoffset -= 32;
  4211. + }
  4212. +}
  4213. +
  4214. +static inline void qb_attr_code_rotate_ls(struct qb_attr_code *code,
  4215. + unsigned int bits)
  4216. +{
  4217. + /* Don't be fooled, this trick should work because the types are
  4218. + * unsigned. So the case that interests the while loop (the rotate has
  4219. + * gone too far and the word count needs to compensate for it), is
  4220. + * manifested when lsoffset is negative. But that equates to a really
  4221. + * large unsigned value, starting with lots of "F"s. As such, we can
  4222. + * continue adding 32 back to it until it wraps back round above zero,
  4223. + * to a value of 31 or less...
  4224. + */
  4225. + code->lsoffset -= bits;
  4226. + while (code->lsoffset > 31) {
  4227. + code->word--;
  4228. + code->lsoffset += 32;
  4229. + }
  4230. +}
  4231. +
  4232. +/* Implement a loop of code rotations until 'expr' evaluates to FALSE (0). */
  4233. +#define qb_attr_code_for_ms(code, bits, expr) \
  4234. + for (; expr; qb_attr_code_rotate_ms(code, bits))
  4235. +#define qb_attr_code_for_ls(code, bits, expr) \
  4236. + for (; expr; qb_attr_code_rotate_ls(code, bits))
  4237. +
  4238. +static inline void word_copy(void *d, const void *s, unsigned int cnt)
  4239. +{
  4240. + u32 *dd = d;
  4241. + const u32 *ss = s;
  4242. +
  4243. + while (cnt--)
  4244. + *(dd++) = *(ss++);
  4245. +}
  4246. +
  4247. +/*
  4248. + * Currently, the CENA support code expects each 32-bit word to be written in
  4249. + * host order, and these are converted to hardware (little-endian) order on
  4250. + * command submission. However, 64-bit quantities are must be written (and read)
  4251. + * as two 32-bit words with the least-significant word first, irrespective of
  4252. + * host endianness.
  4253. + */
  4254. +static inline void u64_to_le32_copy(void *d, const u64 *s,
  4255. + unsigned int cnt)
  4256. +{
  4257. + u32 *dd = d;
  4258. + const u32 *ss = (const u32 *)s;
  4259. +
  4260. + while (cnt--) {
  4261. + /*
  4262. + * TBD: the toolchain was choking on the use of 64-bit types up
  4263. + * until recently so this works entirely with 32-bit variables.
  4264. + * When 64-bit types become usable again, investigate better
  4265. + * ways of doing this.
  4266. + */
  4267. +#if defined(__BIG_ENDIAN)
  4268. + *(dd++) = ss[1];
  4269. + *(dd++) = ss[0];
  4270. + ss += 2;
  4271. +#else
  4272. + *(dd++) = *(ss++);
  4273. + *(dd++) = *(ss++);
  4274. +#endif
  4275. + }
  4276. +}
  4277. +
  4278. +static inline void u64_from_le32_copy(u64 *d, const void *s,
  4279. + unsigned int cnt)
  4280. +{
  4281. + const u32 *ss = s;
  4282. + u32 *dd = (u32 *)d;
  4283. +
  4284. + while (cnt--) {
  4285. +#if defined(__BIG_ENDIAN)
  4286. + dd[1] = *(ss++);
  4287. + dd[0] = *(ss++);
  4288. + dd += 2;
  4289. +#else
  4290. + *(dd++) = *(ss++);
  4291. + *(dd++) = *(ss++);
  4292. +#endif
  4293. + }
  4294. +}
  4295. +
  4296. +/* decode a field from a cacheline */
  4297. +static inline u32 qb_attr_code_decode(const struct qb_attr_code *code,
  4298. + const u32 *cacheline)
  4299. +{
  4300. + return d32_u32(code->lsoffset, code->width, cacheline[code->word]);
  4301. +}
  4302. +
  4303. +static inline u64 qb_attr_code_decode_64(const struct qb_attr_code *code,
  4304. + const u64 *cacheline)
  4305. +{
  4306. + u64 res;
  4307. +
  4308. + u64_from_le32_copy(&res, &cacheline[code->word / 2], 1);
  4309. + return res;
  4310. +}
  4311. +
  4312. +/* encode a field to a cacheline */
  4313. +static inline void qb_attr_code_encode(const struct qb_attr_code *code,
  4314. + u32 *cacheline, u32 val)
  4315. +{
  4316. + cacheline[code->word] =
  4317. + r32_u32(code->lsoffset, code->width, cacheline[code->word])
  4318. + | e32_u32(code->lsoffset, code->width, val);
  4319. +}
  4320. +
  4321. +static inline void qb_attr_code_encode_64(const struct qb_attr_code *code,
  4322. + u64 *cacheline, u64 val)
  4323. +{
  4324. + u64_to_le32_copy(&cacheline[code->word / 2], &val, 1);
  4325. +}
  4326. +
  4327. +/* Small-width signed values (two's-complement) will decode into medium-width
  4328. + * positives. (Eg. for an 8-bit signed field, which stores values from -128 to
  4329. + * +127, a setting of -7 would appear to decode to the 32-bit unsigned value
  4330. + * 249. Likewise -120 would decode as 136.) This function allows the caller to
  4331. + * "re-sign" such fields to 32-bit signed. (Eg. -7, which was 249 with an 8-bit
  4332. + * encoding, will become 0xfffffff9 if you cast the return value to u32).
  4333. + */
  4334. +static inline int32_t qb_attr_code_makesigned(const struct qb_attr_code *code,
  4335. + u32 val)
  4336. +{
  4337. + WARN_ON(val >= (1 << code->width));
  4338. + /* If the high bit was set, it was encoding a negative */
  4339. + if (val >= (1 << (code->width - 1)))
  4340. + return (int32_t)0 - (int32_t)(((u32)1 << code->width) -
  4341. + val);
  4342. + /* Otherwise, it was encoding a positive */
  4343. + return (int32_t)val;
  4344. +}
  4345. +
  4346. +/* ---------------------- */
  4347. +/* Descriptors/cachelines */
  4348. +/* ---------------------- */
  4349. +
  4350. +/* To avoid needless dynamic allocation, the driver API often gives the caller
  4351. + * a "descriptor" type that the caller can instantiate however they like.
  4352. + * Ultimately though, it is just a cacheline of binary storage (or something
  4353. + * smaller when it is known that the descriptor doesn't need all 64 bytes) for
  4354. + * holding pre-formatted pieces of hardware commands. The performance-critical
  4355. + * code can then copy these descriptors directly into hardware command
  4356. + * registers more efficiently than trying to construct/format commands
  4357. + * on-the-fly. The API user sees the descriptor as an array of 32-bit words in
  4358. + * order for the compiler to know its size, but the internal details are not
  4359. + * exposed. The following macro is used within the driver for converting *any*
  4360. + * descriptor pointer to a usable array pointer. The use of a macro (instead of
  4361. + * an inline) is necessary to work with different descriptor types and to work
  4362. + * correctly with const and non-const inputs (and similarly-qualified outputs).
  4363. + */
  4364. +#define qb_cl(d) (&(d)->dont_manipulate_directly[0])
  4365. +
  4366. +#endif /* __FSL_QBMAN_PORTAL_H */
  4367. --- /dev/null
  4368. +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.c
  4369. @@ -0,0 +1,853 @@
  4370. +/* Copyright (C) 2015 Freescale Semiconductor, Inc.
  4371. + *
  4372. + * Redistribution and use in source and binary forms, with or without
  4373. + * modification, are permitted provided that the following conditions are met:
  4374. + * * Redistributions of source code must retain the above copyright
  4375. + * notice, this list of conditions and the following disclaimer.
  4376. + * * Redistributions in binary form must reproduce the above copyright
  4377. + * notice, this list of conditions and the following disclaimer in the
  4378. + * documentation and/or other materials provided with the distribution.
  4379. + * * Neither the name of Freescale Semiconductor nor the
  4380. + * names of its contributors may be used to endorse or promote products
  4381. + * derived from this software without specific prior written permission.
  4382. + *
  4383. + *
  4384. + * ALTERNATIVELY, this software may be distributed under the terms of the
  4385. + * GNU General Public License ("GPL") as published by the Free Software
  4386. + * Foundation, either version 2 of that License or (at your option) any
  4387. + * later version.
  4388. + *
  4389. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  4390. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  4391. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  4392. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  4393. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  4394. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  4395. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  4396. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  4397. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  4398. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  4399. + */
  4400. +
  4401. +#include <linux/errno.h>
  4402. +
  4403. +#include "../../include/dpaa2-global.h"
  4404. +#include "qbman-portal.h"
  4405. +#include "qbman_debug.h"
  4406. +
  4407. +/* QBMan portal management command code */
  4408. +#define QBMAN_BP_QUERY 0x32
  4409. +#define QBMAN_FQ_QUERY 0x44
  4410. +#define QBMAN_FQ_QUERY_NP 0x45
  4411. +#define QBMAN_CGR_QUERY 0x51
  4412. +#define QBMAN_WRED_QUERY 0x54
  4413. +#define QBMAN_CGR_STAT_QUERY 0x55
  4414. +#define QBMAN_CGR_STAT_QUERY_CLR 0x56
  4415. +
  4416. +enum qbman_attr_usage_e {
  4417. + qbman_attr_usage_fq,
  4418. + qbman_attr_usage_bpool,
  4419. + qbman_attr_usage_cgr,
  4420. +};
  4421. +
  4422. +struct int_qbman_attr {
  4423. + u32 words[32];
  4424. + enum qbman_attr_usage_e usage;
  4425. +};
  4426. +
  4427. +#define attr_type_set(a, e) \
  4428. +{ \
  4429. + struct qbman_attr *__attr = a; \
  4430. + enum qbman_attr_usage_e __usage = e; \
  4431. + ((struct int_qbman_attr *)__attr)->usage = __usage; \
  4432. +}
  4433. +
  4434. +#define ATTR32(d) (&(d)->dont_manipulate_directly[0])
  4435. +#define ATTR32_1(d) (&(d)->dont_manipulate_directly[16])
  4436. +
  4437. +static struct qb_attr_code code_bp_bpid = QB_CODE(0, 16, 16);
  4438. +static struct qb_attr_code code_bp_bdi = QB_CODE(1, 16, 1);
  4439. +static struct qb_attr_code code_bp_va = QB_CODE(1, 17, 1);
  4440. +static struct qb_attr_code code_bp_wae = QB_CODE(1, 18, 1);
  4441. +static struct qb_attr_code code_bp_swdet = QB_CODE(4, 0, 16);
  4442. +static struct qb_attr_code code_bp_swdxt = QB_CODE(4, 16, 16);
  4443. +static struct qb_attr_code code_bp_hwdet = QB_CODE(5, 0, 16);
  4444. +static struct qb_attr_code code_bp_hwdxt = QB_CODE(5, 16, 16);
  4445. +static struct qb_attr_code code_bp_swset = QB_CODE(6, 0, 16);
  4446. +static struct qb_attr_code code_bp_swsxt = QB_CODE(6, 16, 16);
  4447. +static struct qb_attr_code code_bp_vbpid = QB_CODE(7, 0, 14);
  4448. +static struct qb_attr_code code_bp_icid = QB_CODE(7, 16, 15);
  4449. +static struct qb_attr_code code_bp_pl = QB_CODE(7, 31, 1);
  4450. +static struct qb_attr_code code_bp_bpscn_addr_lo = QB_CODE(8, 0, 32);
  4451. +static struct qb_attr_code code_bp_bpscn_addr_hi = QB_CODE(9, 0, 32);
  4452. +static struct qb_attr_code code_bp_bpscn_ctx_lo = QB_CODE(10, 0, 32);
  4453. +static struct qb_attr_code code_bp_bpscn_ctx_hi = QB_CODE(11, 0, 32);
  4454. +static struct qb_attr_code code_bp_hw_targ = QB_CODE(12, 0, 16);
  4455. +static struct qb_attr_code code_bp_state = QB_CODE(1, 24, 3);
  4456. +static struct qb_attr_code code_bp_fill = QB_CODE(2, 0, 32);
  4457. +static struct qb_attr_code code_bp_hdptr = QB_CODE(3, 0, 32);
  4458. +static struct qb_attr_code code_bp_sdcnt = QB_CODE(13, 0, 8);
  4459. +static struct qb_attr_code code_bp_hdcnt = QB_CODE(13, 1, 8);
  4460. +static struct qb_attr_code code_bp_sscnt = QB_CODE(13, 2, 8);
  4461. +
  4462. +void qbman_bp_attr_clear(struct qbman_attr *a)
  4463. +{
  4464. + memset(a, 0, sizeof(*a));
  4465. + attr_type_set(a, qbman_attr_usage_bpool);
  4466. +}
  4467. +
  4468. +int qbman_bp_query(struct qbman_swp *s, u32 bpid,
  4469. + struct qbman_attr *a)
  4470. +{
  4471. + u32 *p;
  4472. + u32 verb, rslt;
  4473. + u32 *attr = ATTR32(a);
  4474. +
  4475. + qbman_bp_attr_clear(a);
  4476. +
  4477. + /* Start the management command */
  4478. + p = qbman_swp_mc_start(s);
  4479. + if (!p)
  4480. + return -EBUSY;
  4481. +
  4482. + /* Encode the caller-provided attributes */
  4483. + qb_attr_code_encode(&code_bp_bpid, p, bpid);
  4484. +
  4485. + /* Complete the management command */
  4486. + p = qbman_swp_mc_complete(s, p, QBMAN_BP_QUERY);
  4487. +
  4488. + /* Decode the outcome */
  4489. + verb = qb_attr_code_decode(&code_generic_verb, p);
  4490. + rslt = qb_attr_code_decode(&code_generic_rslt, p);
  4491. + WARN_ON(verb != QBMAN_BP_QUERY);
  4492. +
  4493. + /* Determine success or failure */
  4494. + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
  4495. + pr_err("Query of BPID 0x%x failed, code=0x%02x\n", bpid, rslt);
  4496. + return -EIO;
  4497. + }
  4498. +
  4499. + /* For the query, word[0] of the result contains only the
  4500. + * verb/rslt fields, so skip word[0].
  4501. + */
  4502. + word_copy(&attr[1], &p[1], 15);
  4503. + return 0;
  4504. +}
  4505. +
  4506. +void qbman_bp_attr_get_bdi(struct qbman_attr *a, int *bdi, int *va, int *wae)
  4507. +{
  4508. + u32 *p = ATTR32(a);
  4509. +
  4510. + *bdi = !!qb_attr_code_decode(&code_bp_bdi, p);
  4511. + *va = !!qb_attr_code_decode(&code_bp_va, p);
  4512. + *wae = !!qb_attr_code_decode(&code_bp_wae, p);
  4513. +}
  4514. +
  4515. +static u32 qbman_bp_thresh_to_value(u32 val)
  4516. +{
  4517. + return (val & 0xff) << ((val & 0xf00) >> 8);
  4518. +}
  4519. +
  4520. +void qbman_bp_attr_get_swdet(struct qbman_attr *a, u32 *swdet)
  4521. +{
  4522. + u32 *p = ATTR32(a);
  4523. +
  4524. + *swdet = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swdet,
  4525. + p));
  4526. +}
  4527. +
  4528. +void qbman_bp_attr_get_swdxt(struct qbman_attr *a, u32 *swdxt)
  4529. +{
  4530. + u32 *p = ATTR32(a);
  4531. +
  4532. + *swdxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swdxt,
  4533. + p));
  4534. +}
  4535. +
  4536. +void qbman_bp_attr_get_hwdet(struct qbman_attr *a, u32 *hwdet)
  4537. +{
  4538. + u32 *p = ATTR32(a);
  4539. +
  4540. + *hwdet = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_hwdet,
  4541. + p));
  4542. +}
  4543. +
  4544. +void qbman_bp_attr_get_hwdxt(struct qbman_attr *a, u32 *hwdxt)
  4545. +{
  4546. + u32 *p = ATTR32(a);
  4547. +
  4548. + *hwdxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_hwdxt,
  4549. + p));
  4550. +}
  4551. +
  4552. +void qbman_bp_attr_get_swset(struct qbman_attr *a, u32 *swset)
  4553. +{
  4554. + u32 *p = ATTR32(a);
  4555. +
  4556. + *swset = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swset,
  4557. + p));
  4558. +}
  4559. +
  4560. +void qbman_bp_attr_get_swsxt(struct qbman_attr *a, u32 *swsxt)
  4561. +{
  4562. + u32 *p = ATTR32(a);
  4563. +
  4564. + *swsxt = qbman_bp_thresh_to_value(qb_attr_code_decode(&code_bp_swsxt,
  4565. + p));
  4566. +}
  4567. +
  4568. +void qbman_bp_attr_get_vbpid(struct qbman_attr *a, u32 *vbpid)
  4569. +{
  4570. + u32 *p = ATTR32(a);
  4571. +
  4572. + *vbpid = qb_attr_code_decode(&code_bp_vbpid, p);
  4573. +}
  4574. +
  4575. +void qbman_bp_attr_get_icid(struct qbman_attr *a, u32 *icid, int *pl)
  4576. +{
  4577. + u32 *p = ATTR32(a);
  4578. +
  4579. + *icid = qb_attr_code_decode(&code_bp_icid, p);
  4580. + *pl = !!qb_attr_code_decode(&code_bp_pl, p);
  4581. +}
  4582. +
  4583. +void qbman_bp_attr_get_bpscn_addr(struct qbman_attr *a, u64 *bpscn_addr)
  4584. +{
  4585. + u32 *p = ATTR32(a);
  4586. +
  4587. + *bpscn_addr = ((u64)qb_attr_code_decode(&code_bp_bpscn_addr_hi,
  4588. + p) << 32) |
  4589. + (u64)qb_attr_code_decode(&code_bp_bpscn_addr_lo,
  4590. + p);
  4591. +}
  4592. +
  4593. +void qbman_bp_attr_get_bpscn_ctx(struct qbman_attr *a, u64 *bpscn_ctx)
  4594. +{
  4595. + u32 *p = ATTR32(a);
  4596. +
  4597. + *bpscn_ctx = ((u64)qb_attr_code_decode(&code_bp_bpscn_ctx_hi, p)
  4598. + << 32) |
  4599. + (u64)qb_attr_code_decode(&code_bp_bpscn_ctx_lo,
  4600. + p);
  4601. +}
  4602. +
  4603. +void qbman_bp_attr_get_hw_targ(struct qbman_attr *a, u32 *hw_targ)
  4604. +{
  4605. + u32 *p = ATTR32(a);
  4606. +
  4607. + *hw_targ = qb_attr_code_decode(&code_bp_hw_targ, p);
  4608. +}
  4609. +
  4610. +int qbman_bp_info_has_free_bufs(struct qbman_attr *a)
  4611. +{
  4612. + u32 *p = ATTR32(a);
  4613. +
  4614. + return !(int)(qb_attr_code_decode(&code_bp_state, p) & 0x1);
  4615. +}
  4616. +
  4617. +int qbman_bp_info_is_depleted(struct qbman_attr *a)
  4618. +{
  4619. + u32 *p = ATTR32(a);
  4620. +
  4621. + return (int)(qb_attr_code_decode(&code_bp_state, p) & 0x2);
  4622. +}
  4623. +
  4624. +int qbman_bp_info_is_surplus(struct qbman_attr *a)
  4625. +{
  4626. + u32 *p = ATTR32(a);
  4627. +
  4628. + return (int)(qb_attr_code_decode(&code_bp_state, p) & 0x4);
  4629. +}
  4630. +
  4631. +u32 qbman_bp_info_num_free_bufs(struct qbman_attr *a)
  4632. +{
  4633. + u32 *p = ATTR32(a);
  4634. +
  4635. + return qb_attr_code_decode(&code_bp_fill, p);
  4636. +}
  4637. +
  4638. +u32 qbman_bp_info_hdptr(struct qbman_attr *a)
  4639. +{
  4640. + u32 *p = ATTR32(a);
  4641. +
  4642. + return qb_attr_code_decode(&code_bp_hdptr, p);
  4643. +}
  4644. +
  4645. +u32 qbman_bp_info_sdcnt(struct qbman_attr *a)
  4646. +{
  4647. + u32 *p = ATTR32(a);
  4648. +
  4649. + return qb_attr_code_decode(&code_bp_sdcnt, p);
  4650. +}
  4651. +
  4652. +u32 qbman_bp_info_hdcnt(struct qbman_attr *a)
  4653. +{
  4654. + u32 *p = ATTR32(a);
  4655. +
  4656. + return qb_attr_code_decode(&code_bp_hdcnt, p);
  4657. +}
  4658. +
  4659. +u32 qbman_bp_info_sscnt(struct qbman_attr *a)
  4660. +{
  4661. + u32 *p = ATTR32(a);
  4662. +
  4663. + return qb_attr_code_decode(&code_bp_sscnt, p);
  4664. +}
  4665. +
  4666. +static struct qb_attr_code code_fq_fqid = QB_CODE(1, 0, 24);
  4667. +static struct qb_attr_code code_fq_cgrid = QB_CODE(2, 16, 16);
  4668. +static struct qb_attr_code code_fq_destwq = QB_CODE(3, 0, 15);
  4669. +static struct qb_attr_code code_fq_fqctrl = QB_CODE(3, 24, 8);
  4670. +static struct qb_attr_code code_fq_icscred = QB_CODE(4, 0, 15);
  4671. +static struct qb_attr_code code_fq_tdthresh = QB_CODE(4, 16, 13);
  4672. +static struct qb_attr_code code_fq_oa_len = QB_CODE(5, 0, 12);
  4673. +static struct qb_attr_code code_fq_oa_ics = QB_CODE(5, 14, 1);
  4674. +static struct qb_attr_code code_fq_oa_cgr = QB_CODE(5, 15, 1);
  4675. +static struct qb_attr_code code_fq_mctl_bdi = QB_CODE(5, 24, 1);
  4676. +static struct qb_attr_code code_fq_mctl_ff = QB_CODE(5, 25, 1);
  4677. +static struct qb_attr_code code_fq_mctl_va = QB_CODE(5, 26, 1);
  4678. +static struct qb_attr_code code_fq_mctl_ps = QB_CODE(5, 27, 1);
  4679. +static struct qb_attr_code code_fq_ctx_lower32 = QB_CODE(6, 0, 32);
  4680. +static struct qb_attr_code code_fq_ctx_upper32 = QB_CODE(7, 0, 32);
  4681. +static struct qb_attr_code code_fq_icid = QB_CODE(8, 0, 15);
  4682. +static struct qb_attr_code code_fq_pl = QB_CODE(8, 15, 1);
  4683. +static struct qb_attr_code code_fq_vfqid = QB_CODE(9, 0, 24);
  4684. +static struct qb_attr_code code_fq_erfqid = QB_CODE(10, 0, 24);
  4685. +
  4686. +void qbman_fq_attr_clear(struct qbman_attr *a)
  4687. +{
  4688. + memset(a, 0, sizeof(*a));
  4689. + attr_type_set(a, qbman_attr_usage_fq);
  4690. +}
  4691. +
  4692. +/* FQ query function for programmable fields */
  4693. +int qbman_fq_query(struct qbman_swp *s, u32 fqid, struct qbman_attr *desc)
  4694. +{
  4695. + u32 *p;
  4696. + u32 verb, rslt;
  4697. + u32 *d = ATTR32(desc);
  4698. +
  4699. + qbman_fq_attr_clear(desc);
  4700. +
  4701. + p = qbman_swp_mc_start(s);
  4702. + if (!p)
  4703. + return -EBUSY;
  4704. + qb_attr_code_encode(&code_fq_fqid, p, fqid);
  4705. + p = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY);
  4706. +
  4707. + /* Decode the outcome */
  4708. + verb = qb_attr_code_decode(&code_generic_verb, p);
  4709. + rslt = qb_attr_code_decode(&code_generic_rslt, p);
  4710. + WARN_ON(verb != QBMAN_FQ_QUERY);
  4711. +
  4712. + /* Determine success or failure */
  4713. + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
  4714. + pr_err("Query of FQID 0x%x failed, code=0x%02x\n",
  4715. + fqid, rslt);
  4716. + return -EIO;
  4717. + }
  4718. + /*
  4719. + * For the configure, word[0] of the command contains only the WE-mask.
  4720. + * For the query, word[0] of the result contains only the verb/rslt
  4721. + * fields. Skip word[0] in the latter case.
  4722. + */
  4723. + word_copy(&d[1], &p[1], 15);
  4724. + return 0;
  4725. +}
  4726. +
  4727. +void qbman_fq_attr_get_fqctrl(struct qbman_attr *d, u32 *fqctrl)
  4728. +{
  4729. + u32 *p = ATTR32(d);
  4730. +
  4731. + *fqctrl = qb_attr_code_decode(&code_fq_fqctrl, p);
  4732. +}
  4733. +
  4734. +void qbman_fq_attr_get_cgrid(struct qbman_attr *d, u32 *cgrid)
  4735. +{
  4736. + u32 *p = ATTR32(d);
  4737. +
  4738. + *cgrid = qb_attr_code_decode(&code_fq_cgrid, p);
  4739. +}
  4740. +
  4741. +void qbman_fq_attr_get_destwq(struct qbman_attr *d, u32 *destwq)
  4742. +{
  4743. + u32 *p = ATTR32(d);
  4744. +
  4745. + *destwq = qb_attr_code_decode(&code_fq_destwq, p);
  4746. +}
  4747. +
  4748. +void qbman_fq_attr_get_icscred(struct qbman_attr *d, u32 *icscred)
  4749. +{
  4750. + u32 *p = ATTR32(d);
  4751. +
  4752. + *icscred = qb_attr_code_decode(&code_fq_icscred, p);
  4753. +}
  4754. +
  4755. +static struct qb_attr_code code_tdthresh_exp = QB_CODE(0, 0, 5);
  4756. +static struct qb_attr_code code_tdthresh_mant = QB_CODE(0, 5, 8);
  4757. +static u32 qbman_thresh_to_value(u32 val)
  4758. +{
  4759. + u32 m, e;
  4760. +
  4761. + m = qb_attr_code_decode(&code_tdthresh_mant, &val);
  4762. + e = qb_attr_code_decode(&code_tdthresh_exp, &val);
  4763. + return m << e;
  4764. +}
  4765. +
  4766. +void qbman_fq_attr_get_tdthresh(struct qbman_attr *d, u32 *tdthresh)
  4767. +{
  4768. + u32 *p = ATTR32(d);
  4769. +
  4770. + *tdthresh = qbman_thresh_to_value(qb_attr_code_decode(&code_fq_tdthresh,
  4771. + p));
  4772. +}
  4773. +
  4774. +void qbman_fq_attr_get_oa(struct qbman_attr *d,
  4775. + int *oa_ics, int *oa_cgr, int32_t *oa_len)
  4776. +{
  4777. + u32 *p = ATTR32(d);
  4778. +
  4779. + *oa_ics = !!qb_attr_code_decode(&code_fq_oa_ics, p);
  4780. + *oa_cgr = !!qb_attr_code_decode(&code_fq_oa_cgr, p);
  4781. + *oa_len = qb_attr_code_makesigned(&code_fq_oa_len,
  4782. + qb_attr_code_decode(&code_fq_oa_len, p));
  4783. +}
  4784. +
  4785. +void qbman_fq_attr_get_mctl(struct qbman_attr *d,
  4786. + int *bdi, int *ff, int *va, int *ps)
  4787. +{
  4788. + u32 *p = ATTR32(d);
  4789. +
  4790. + *bdi = !!qb_attr_code_decode(&code_fq_mctl_bdi, p);
  4791. + *ff = !!qb_attr_code_decode(&code_fq_mctl_ff, p);
  4792. + *va = !!qb_attr_code_decode(&code_fq_mctl_va, p);
  4793. + *ps = !!qb_attr_code_decode(&code_fq_mctl_ps, p);
  4794. +}
  4795. +
  4796. +void qbman_fq_attr_get_ctx(struct qbman_attr *d, u32 *hi, u32 *lo)
  4797. +{
  4798. + u32 *p = ATTR32(d);
  4799. +
  4800. + *hi = qb_attr_code_decode(&code_fq_ctx_upper32, p);
  4801. + *lo = qb_attr_code_decode(&code_fq_ctx_lower32, p);
  4802. +}
  4803. +
  4804. +void qbman_fq_attr_get_icid(struct qbman_attr *d, u32 *icid, int *pl)
  4805. +{
  4806. + u32 *p = ATTR32(d);
  4807. +
  4808. + *icid = qb_attr_code_decode(&code_fq_icid, p);
  4809. + *pl = !!qb_attr_code_decode(&code_fq_pl, p);
  4810. +}
  4811. +
  4812. +void qbman_fq_attr_get_vfqid(struct qbman_attr *d, u32 *vfqid)
  4813. +{
  4814. + u32 *p = ATTR32(d);
  4815. +
  4816. + *vfqid = qb_attr_code_decode(&code_fq_vfqid, p);
  4817. +}
  4818. +
  4819. +void qbman_fq_attr_get_erfqid(struct qbman_attr *d, u32 *erfqid)
  4820. +{
  4821. + u32 *p = ATTR32(d);
  4822. +
  4823. + *erfqid = qb_attr_code_decode(&code_fq_erfqid, p);
  4824. +}
  4825. +
  4826. +/* Query FQ Non-Programmalbe Fields */
  4827. +static struct qb_attr_code code_fq_np_state = QB_CODE(0, 16, 3);
  4828. +static struct qb_attr_code code_fq_np_fe = QB_CODE(0, 19, 1);
  4829. +static struct qb_attr_code code_fq_np_x = QB_CODE(0, 20, 1);
  4830. +static struct qb_attr_code code_fq_np_r = QB_CODE(0, 21, 1);
  4831. +static struct qb_attr_code code_fq_np_oe = QB_CODE(0, 22, 1);
  4832. +static struct qb_attr_code code_fq_np_frm_cnt = QB_CODE(6, 0, 24);
  4833. +static struct qb_attr_code code_fq_np_byte_cnt = QB_CODE(7, 0, 32);
  4834. +
  4835. +int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
  4836. + struct qbman_attr *state)
  4837. +{
  4838. + u32 *p;
  4839. + u32 verb, rslt;
  4840. + u32 *d = ATTR32(state);
  4841. +
  4842. + qbman_fq_attr_clear(state);
  4843. +
  4844. + p = qbman_swp_mc_start(s);
  4845. + if (!p)
  4846. + return -EBUSY;
  4847. + qb_attr_code_encode(&code_fq_fqid, p, fqid);
  4848. + p = qbman_swp_mc_complete(s, p, QBMAN_FQ_QUERY_NP);
  4849. +
  4850. + /* Decode the outcome */
  4851. + verb = qb_attr_code_decode(&code_generic_verb, p);
  4852. + rslt = qb_attr_code_decode(&code_generic_rslt, p);
  4853. + WARN_ON(verb != QBMAN_FQ_QUERY_NP);
  4854. +
  4855. + /* Determine success or failure */
  4856. + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
  4857. + pr_err("Query NP fields of FQID 0x%x failed, code=0x%02x\n",
  4858. + fqid, rslt);
  4859. + return -EIO;
  4860. + }
  4861. + word_copy(&d[0], &p[0], 16);
  4862. + return 0;
  4863. +}
  4864. +
  4865. +u32 qbman_fq_state_schedstate(const struct qbman_attr *state)
  4866. +{
  4867. + const u32 *p = ATTR32(state);
  4868. +
  4869. + return qb_attr_code_decode(&code_fq_np_state, p);
  4870. +}
  4871. +
  4872. +int qbman_fq_state_force_eligible(const struct qbman_attr *state)
  4873. +{
  4874. + const u32 *p = ATTR32(state);
  4875. +
  4876. + return !!qb_attr_code_decode(&code_fq_np_fe, p);
  4877. +}
  4878. +
  4879. +int qbman_fq_state_xoff(const struct qbman_attr *state)
  4880. +{
  4881. + const u32 *p = ATTR32(state);
  4882. +
  4883. + return !!qb_attr_code_decode(&code_fq_np_x, p);
  4884. +}
  4885. +
  4886. +int qbman_fq_state_retirement_pending(const struct qbman_attr *state)
  4887. +{
  4888. + const u32 *p = ATTR32(state);
  4889. +
  4890. + return !!qb_attr_code_decode(&code_fq_np_r, p);
  4891. +}
  4892. +
  4893. +int qbman_fq_state_overflow_error(const struct qbman_attr *state)
  4894. +{
  4895. + const u32 *p = ATTR32(state);
  4896. +
  4897. + return !!qb_attr_code_decode(&code_fq_np_oe, p);
  4898. +}
  4899. +
  4900. +u32 qbman_fq_state_frame_count(const struct qbman_attr *state)
  4901. +{
  4902. + const u32 *p = ATTR32(state);
  4903. +
  4904. + return qb_attr_code_decode(&code_fq_np_frm_cnt, p);
  4905. +}
  4906. +
  4907. +u32 qbman_fq_state_byte_count(const struct qbman_attr *state)
  4908. +{
  4909. + const u32 *p = ATTR32(state);
  4910. +
  4911. + return qb_attr_code_decode(&code_fq_np_byte_cnt, p);
  4912. +}
  4913. +
  4914. +/* Query CGR */
  4915. +static struct qb_attr_code code_cgr_cgid = QB_CODE(0, 16, 16);
  4916. +static struct qb_attr_code code_cgr_cscn_wq_en_enter = QB_CODE(2, 0, 1);
  4917. +static struct qb_attr_code code_cgr_cscn_wq_en_exit = QB_CODE(2, 1, 1);
  4918. +static struct qb_attr_code code_cgr_cscn_wq_icd = QB_CODE(2, 2, 1);
  4919. +static struct qb_attr_code code_cgr_mode = QB_CODE(3, 16, 2);
  4920. +static struct qb_attr_code code_cgr_rej_cnt_mode = QB_CODE(3, 18, 1);
  4921. +static struct qb_attr_code code_cgr_cscn_bdi = QB_CODE(3, 19, 1);
  4922. +static struct qb_attr_code code_cgr_cscn_wr_en_enter = QB_CODE(3, 24, 1);
  4923. +static struct qb_attr_code code_cgr_cscn_wr_en_exit = QB_CODE(3, 25, 1);
  4924. +static struct qb_attr_code code_cgr_cg_wr_ae = QB_CODE(3, 26, 1);
  4925. +static struct qb_attr_code code_cgr_cscn_dcp_en = QB_CODE(3, 27, 1);
  4926. +static struct qb_attr_code code_cgr_cg_wr_va = QB_CODE(3, 28, 1);
  4927. +static struct qb_attr_code code_cgr_i_cnt_wr_en = QB_CODE(4, 0, 1);
  4928. +static struct qb_attr_code code_cgr_i_cnt_wr_bnd = QB_CODE(4, 1, 5);
  4929. +static struct qb_attr_code code_cgr_td_en = QB_CODE(4, 8, 1);
  4930. +static struct qb_attr_code code_cgr_cs_thres = QB_CODE(4, 16, 13);
  4931. +static struct qb_attr_code code_cgr_cs_thres_x = QB_CODE(5, 0, 13);
  4932. +static struct qb_attr_code code_cgr_td_thres = QB_CODE(5, 16, 13);
  4933. +static struct qb_attr_code code_cgr_cscn_tdcp = QB_CODE(6, 0, 16);
  4934. +static struct qb_attr_code code_cgr_cscn_wqid = QB_CODE(6, 16, 16);
  4935. +static struct qb_attr_code code_cgr_cscn_vcgid = QB_CODE(7, 0, 16);
  4936. +static struct qb_attr_code code_cgr_cg_icid = QB_CODE(7, 16, 15);
  4937. +static struct qb_attr_code code_cgr_cg_pl = QB_CODE(7, 31, 1);
  4938. +static struct qb_attr_code code_cgr_cg_wr_addr_lo = QB_CODE(8, 0, 32);
  4939. +static struct qb_attr_code code_cgr_cg_wr_addr_hi = QB_CODE(9, 0, 32);
  4940. +static struct qb_attr_code code_cgr_cscn_ctx_lo = QB_CODE(10, 0, 32);
  4941. +static struct qb_attr_code code_cgr_cscn_ctx_hi = QB_CODE(11, 0, 32);
  4942. +
  4943. +void qbman_cgr_attr_clear(struct qbman_attr *a)
  4944. +{
  4945. + memset(a, 0, sizeof(*a));
  4946. + attr_type_set(a, qbman_attr_usage_cgr);
  4947. +}
  4948. +
  4949. +int qbman_cgr_query(struct qbman_swp *s, u32 cgid, struct qbman_attr *attr)
  4950. +{
  4951. + u32 *p;
  4952. + u32 verb, rslt;
  4953. + u32 *d[2];
  4954. + int i;
  4955. + u32 query_verb;
  4956. +
  4957. + d[0] = ATTR32(attr);
  4958. + d[1] = ATTR32_1(attr);
  4959. +
  4960. + qbman_cgr_attr_clear(attr);
  4961. +
  4962. + for (i = 0; i < 2; i++) {
  4963. + p = qbman_swp_mc_start(s);
  4964. + if (!p)
  4965. + return -EBUSY;
  4966. + query_verb = i ? QBMAN_WRED_QUERY : QBMAN_CGR_QUERY;
  4967. +
  4968. + qb_attr_code_encode(&code_cgr_cgid, p, cgid);
  4969. + p = qbman_swp_mc_complete(s, p, p[0] | query_verb);
  4970. +
  4971. + /* Decode the outcome */
  4972. + verb = qb_attr_code_decode(&code_generic_verb, p);
  4973. + rslt = qb_attr_code_decode(&code_generic_rslt, p);
  4974. + WARN_ON(verb != query_verb);
  4975. +
  4976. + /* Determine success or failure */
  4977. + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
  4978. + pr_err("Query CGID 0x%x failed,", cgid);
  4979. + pr_err(" verb=0x%02x, code=0x%02x\n", verb, rslt);
  4980. + return -EIO;
  4981. + }
  4982. + /* For the configure, word[0] of the command contains only the
  4983. + * verb/cgid. For the query, word[0] of the result contains
  4984. + * only the verb/rslt fields. Skip word[0] in the latter case.
  4985. + */
  4986. + word_copy(&d[i][1], &p[1], 15);
  4987. + }
  4988. + return 0;
  4989. +}
  4990. +
  4991. +void qbman_cgr_attr_get_ctl1(struct qbman_attr *d, int *cscn_wq_en_enter,
  4992. + int *cscn_wq_en_exit, int *cscn_wq_icd)
  4993. + {
  4994. + u32 *p = ATTR32(d);
  4995. + *cscn_wq_en_enter = !!qb_attr_code_decode(&code_cgr_cscn_wq_en_enter,
  4996. + p);
  4997. + *cscn_wq_en_exit = !!qb_attr_code_decode(&code_cgr_cscn_wq_en_exit, p);
  4998. + *cscn_wq_icd = !!qb_attr_code_decode(&code_cgr_cscn_wq_icd, p);
  4999. +}
  5000. +
  5001. +void qbman_cgr_attr_get_mode(struct qbman_attr *d, u32 *mode,
  5002. + int *rej_cnt_mode, int *cscn_bdi)
  5003. +{
  5004. + u32 *p = ATTR32(d);
  5005. + *mode = qb_attr_code_decode(&code_cgr_mode, p);
  5006. + *rej_cnt_mode = !!qb_attr_code_decode(&code_cgr_rej_cnt_mode, p);
  5007. + *cscn_bdi = !!qb_attr_code_decode(&code_cgr_cscn_bdi, p);
  5008. +}
  5009. +
  5010. +void qbman_cgr_attr_get_ctl2(struct qbman_attr *d, int *cscn_wr_en_enter,
  5011. + int *cscn_wr_en_exit, int *cg_wr_ae,
  5012. + int *cscn_dcp_en, int *cg_wr_va)
  5013. +{
  5014. + u32 *p = ATTR32(d);
  5015. + *cscn_wr_en_enter = !!qb_attr_code_decode(&code_cgr_cscn_wr_en_enter,
  5016. + p);
  5017. + *cscn_wr_en_exit = !!qb_attr_code_decode(&code_cgr_cscn_wr_en_exit, p);
  5018. + *cg_wr_ae = !!qb_attr_code_decode(&code_cgr_cg_wr_ae, p);
  5019. + *cscn_dcp_en = !!qb_attr_code_decode(&code_cgr_cscn_dcp_en, p);
  5020. + *cg_wr_va = !!qb_attr_code_decode(&code_cgr_cg_wr_va, p);
  5021. +}
  5022. +
  5023. +void qbman_cgr_attr_get_iwc(struct qbman_attr *d, int *i_cnt_wr_en,
  5024. + u32 *i_cnt_wr_bnd)
  5025. +{
  5026. + u32 *p = ATTR32(d);
  5027. + *i_cnt_wr_en = !!qb_attr_code_decode(&code_cgr_i_cnt_wr_en, p);
  5028. + *i_cnt_wr_bnd = qb_attr_code_decode(&code_cgr_i_cnt_wr_bnd, p);
  5029. +}
  5030. +
  5031. +void qbman_cgr_attr_get_tdc(struct qbman_attr *d, int *td_en)
  5032. +{
  5033. + u32 *p = ATTR32(d);
  5034. + *td_en = !!qb_attr_code_decode(&code_cgr_td_en, p);
  5035. +}
  5036. +
  5037. +void qbman_cgr_attr_get_cs_thres(struct qbman_attr *d, u32 *cs_thres)
  5038. +{
  5039. + u32 *p = ATTR32(d);
  5040. + *cs_thres = qbman_thresh_to_value(qb_attr_code_decode(
  5041. + &code_cgr_cs_thres, p));
  5042. +}
  5043. +
  5044. +void qbman_cgr_attr_get_cs_thres_x(struct qbman_attr *d,
  5045. + u32 *cs_thres_x)
  5046. +{
  5047. + u32 *p = ATTR32(d);
  5048. + *cs_thres_x = qbman_thresh_to_value(qb_attr_code_decode(
  5049. + &code_cgr_cs_thres_x, p));
  5050. +}
  5051. +
  5052. +void qbman_cgr_attr_get_td_thres(struct qbman_attr *d, u32 *td_thres)
  5053. +{
  5054. + u32 *p = ATTR32(d);
  5055. + *td_thres = qbman_thresh_to_value(qb_attr_code_decode(
  5056. + &code_cgr_td_thres, p));
  5057. +}
  5058. +
  5059. +void qbman_cgr_attr_get_cscn_tdcp(struct qbman_attr *d, u32 *cscn_tdcp)
  5060. +{
  5061. + u32 *p = ATTR32(d);
  5062. + *cscn_tdcp = qb_attr_code_decode(&code_cgr_cscn_tdcp, p);
  5063. +}
  5064. +
  5065. +void qbman_cgr_attr_get_cscn_wqid(struct qbman_attr *d, u32 *cscn_wqid)
  5066. +{
  5067. + u32 *p = ATTR32(d);
  5068. + *cscn_wqid = qb_attr_code_decode(&code_cgr_cscn_wqid, p);
  5069. +}
  5070. +
  5071. +void qbman_cgr_attr_get_cscn_vcgid(struct qbman_attr *d,
  5072. + u32 *cscn_vcgid)
  5073. +{
  5074. + u32 *p = ATTR32(d);
  5075. + *cscn_vcgid = qb_attr_code_decode(&code_cgr_cscn_vcgid, p);
  5076. +}
  5077. +
  5078. +void qbman_cgr_attr_get_cg_icid(struct qbman_attr *d, u32 *icid,
  5079. + int *pl)
  5080. +{
  5081. + u32 *p = ATTR32(d);
  5082. + *icid = qb_attr_code_decode(&code_cgr_cg_icid, p);
  5083. + *pl = !!qb_attr_code_decode(&code_cgr_cg_pl, p);
  5084. +}
  5085. +
  5086. +void qbman_cgr_attr_get_cg_wr_addr(struct qbman_attr *d,
  5087. + u64 *cg_wr_addr)
  5088. +{
  5089. + u32 *p = ATTR32(d);
  5090. + *cg_wr_addr = ((u64)qb_attr_code_decode(&code_cgr_cg_wr_addr_hi,
  5091. + p) << 32) |
  5092. + (u64)qb_attr_code_decode(&code_cgr_cg_wr_addr_lo,
  5093. + p);
  5094. +}
  5095. +
  5096. +void qbman_cgr_attr_get_cscn_ctx(struct qbman_attr *d, u64 *cscn_ctx)
  5097. +{
  5098. + u32 *p = ATTR32(d);
  5099. + *cscn_ctx = ((u64)qb_attr_code_decode(&code_cgr_cscn_ctx_hi, p)
  5100. + << 32) |
  5101. + (u64)qb_attr_code_decode(&code_cgr_cscn_ctx_lo, p);
  5102. +}
  5103. +
  5104. +#define WRED_EDP_WORD(n) (18 + (n) / 4)
  5105. +#define WRED_EDP_OFFSET(n) (8 * ((n) % 4))
  5106. +#define WRED_PARM_DP_WORD(n) ((n) + 20)
  5107. +#define WRED_WE_EDP(n) (16 + (n) * 2)
  5108. +#define WRED_WE_PARM_DP(n) (17 + (n) * 2)
  5109. +void qbman_cgr_attr_wred_get_edp(struct qbman_attr *d, u32 idx,
  5110. + int *edp)
  5111. +{
  5112. + u32 *p = ATTR32(d);
  5113. + struct qb_attr_code code_wred_edp = QB_CODE(WRED_EDP_WORD(idx),
  5114. + WRED_EDP_OFFSET(idx), 8);
  5115. + *edp = (int)qb_attr_code_decode(&code_wred_edp, p);
  5116. +}
  5117. +
  5118. +void qbman_cgr_attr_wred_dp_decompose(u32 dp, u64 *minth,
  5119. + u64 *maxth, u8 *maxp)
  5120. +{
  5121. + u8 ma, mn, step_i, step_s, pn;
  5122. +
  5123. + ma = (u8)(dp >> 24);
  5124. + mn = (u8)(dp >> 19) & 0x1f;
  5125. + step_i = (u8)(dp >> 11);
  5126. + step_s = (u8)(dp >> 6) & 0x1f;
  5127. + pn = (u8)dp & 0x3f;
  5128. +
  5129. + *maxp = ((pn << 2) * 100) / 256;
  5130. +
  5131. + if (mn == 0)
  5132. + *maxth = ma;
  5133. + else
  5134. + *maxth = ((ma + 256) * (1 << (mn - 1)));
  5135. +
  5136. + if (step_s == 0)
  5137. + *minth = *maxth - step_i;
  5138. + else
  5139. + *minth = *maxth - (256 + step_i) * (1 << (step_s - 1));
  5140. +}
  5141. +
  5142. +void qbman_cgr_attr_wred_get_parm_dp(struct qbman_attr *d, u32 idx,
  5143. + u32 *dp)
  5144. +{
  5145. + u32 *p = ATTR32(d);
  5146. + struct qb_attr_code code_wred_parm_dp = QB_CODE(WRED_PARM_DP_WORD(idx),
  5147. + 0, 8);
  5148. + *dp = qb_attr_code_decode(&code_wred_parm_dp, p);
  5149. +}
  5150. +
  5151. +/* Query CGR/CCGR/CQ statistics */
  5152. +static struct qb_attr_code code_cgr_stat_ct = QB_CODE(4, 0, 32);
  5153. +static struct qb_attr_code code_cgr_stat_frame_cnt_lo = QB_CODE(4, 0, 32);
  5154. +static struct qb_attr_code code_cgr_stat_frame_cnt_hi = QB_CODE(5, 0, 8);
  5155. +static struct qb_attr_code code_cgr_stat_byte_cnt_lo = QB_CODE(6, 0, 32);
  5156. +static struct qb_attr_code code_cgr_stat_byte_cnt_hi = QB_CODE(7, 0, 16);
  5157. +static int qbman_cgr_statistics_query(struct qbman_swp *s, u32 cgid,
  5158. + int clear, u32 command_type,
  5159. + u64 *frame_cnt, u64 *byte_cnt)
  5160. +{
  5161. + u32 *p;
  5162. + u32 verb, rslt;
  5163. + u32 query_verb;
  5164. + u32 hi, lo;
  5165. +
  5166. + p = qbman_swp_mc_start(s);
  5167. + if (!p)
  5168. + return -EBUSY;
  5169. +
  5170. + qb_attr_code_encode(&code_cgr_cgid, p, cgid);
  5171. + if (command_type < 2)
  5172. + qb_attr_code_encode(&code_cgr_stat_ct, p, command_type);
  5173. + query_verb = clear ?
  5174. + QBMAN_CGR_STAT_QUERY_CLR : QBMAN_CGR_STAT_QUERY;
  5175. + p = qbman_swp_mc_complete(s, p, p[0] | query_verb);
  5176. +
  5177. + /* Decode the outcome */
  5178. + verb = qb_attr_code_decode(&code_generic_verb, p);
  5179. + rslt = qb_attr_code_decode(&code_generic_rslt, p);
  5180. + WARN_ON(verb != query_verb);
  5181. +
  5182. + /* Determine success or failure */
  5183. + if (unlikely(rslt != QBMAN_MC_RSLT_OK)) {
  5184. + pr_err("Query statistics of CGID 0x%x failed,", cgid);
  5185. + pr_err(" verb=0x%02x code=0x%02x\n", verb, rslt);
  5186. + return -EIO;
  5187. + }
  5188. +
  5189. + if (*frame_cnt) {
  5190. + hi = qb_attr_code_decode(&code_cgr_stat_frame_cnt_hi, p);
  5191. + lo = qb_attr_code_decode(&code_cgr_stat_frame_cnt_lo, p);
  5192. + *frame_cnt = ((u64)hi << 32) | (u64)lo;
  5193. + }
  5194. + if (*byte_cnt) {
  5195. + hi = qb_attr_code_decode(&code_cgr_stat_byte_cnt_hi, p);
  5196. + lo = qb_attr_code_decode(&code_cgr_stat_byte_cnt_lo, p);
  5197. + *byte_cnt = ((u64)hi << 32) | (u64)lo;
  5198. + }
  5199. +
  5200. + return 0;
  5201. +}
  5202. +
  5203. +int qbman_cgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
  5204. + u64 *frame_cnt, u64 *byte_cnt)
  5205. +{
  5206. + return qbman_cgr_statistics_query(s, cgid, clear, 0xff,
  5207. + frame_cnt, byte_cnt);
  5208. +}
  5209. +
  5210. +int qbman_ccgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
  5211. + u64 *frame_cnt, u64 *byte_cnt)
  5212. +{
  5213. + return qbman_cgr_statistics_query(s, cgid, clear, 1,
  5214. + frame_cnt, byte_cnt);
  5215. +}
  5216. +
  5217. +int qbman_cq_dequeue_statistics(struct qbman_swp *s, u32 cgid, int clear,
  5218. + u64 *frame_cnt, u64 *byte_cnt)
  5219. +{
  5220. + return qbman_cgr_statistics_query(s, cgid, clear, 0,
  5221. + frame_cnt, byte_cnt);
  5222. +}
  5223. --- /dev/null
  5224. +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_debug.h
  5225. @@ -0,0 +1,136 @@
  5226. +/* Copyright (C) 2015 Freescale Semiconductor, Inc.
  5227. + *
  5228. + * Redistribution and use in source and binary forms, with or without
  5229. + * modification, are permitted provided that the following conditions are met:
  5230. + * * Redistributions of source code must retain the above copyright
  5231. + * notice, this list of conditions and the following disclaimer.
  5232. + * * Redistributions in binary form must reproduce the above copyright
  5233. + * notice, this list of conditions and the following disclaimer in the
  5234. + * documentation and/or other materials provided with the distribution.
  5235. + * * Neither the name of Freescale Semiconductor nor the
  5236. + * names of its contributors may be used to endorse or promote products
  5237. + * derived from this software without specific prior written permission.
  5238. + *
  5239. + *
  5240. + * ALTERNATIVELY, this software may be distributed under the terms of the
  5241. + * GNU General Public License ("GPL") as published by the Free Software
  5242. + * Foundation, either version 2 of that License or (at your option) any
  5243. + * later version.
  5244. + *
  5245. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  5246. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5247. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5248. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  5249. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5250. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5251. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5252. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5253. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5254. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5255. + */
  5256. +
  5257. +struct qbman_attr {
  5258. + u32 dont_manipulate_directly[40];
  5259. +};
  5260. +
  5261. +/* Buffer pool query commands */
  5262. +int qbman_bp_query(struct qbman_swp *s, u32 bpid,
  5263. + struct qbman_attr *a);
  5264. +void qbman_bp_attr_get_bdi(struct qbman_attr *a, int *bdi, int *va, int *wae);
  5265. +void qbman_bp_attr_get_swdet(struct qbman_attr *a, u32 *swdet);
  5266. +void qbman_bp_attr_get_swdxt(struct qbman_attr *a, u32 *swdxt);
  5267. +void qbman_bp_attr_get_hwdet(struct qbman_attr *a, u32 *hwdet);
  5268. +void qbman_bp_attr_get_hwdxt(struct qbman_attr *a, u32 *hwdxt);
  5269. +void qbman_bp_attr_get_swset(struct qbman_attr *a, u32 *swset);
  5270. +void qbman_bp_attr_get_swsxt(struct qbman_attr *a, u32 *swsxt);
  5271. +void qbman_bp_attr_get_vbpid(struct qbman_attr *a, u32 *vbpid);
  5272. +void qbman_bp_attr_get_icid(struct qbman_attr *a, u32 *icid, int *pl);
  5273. +void qbman_bp_attr_get_bpscn_addr(struct qbman_attr *a, u64 *bpscn_addr);
  5274. +void qbman_bp_attr_get_bpscn_ctx(struct qbman_attr *a, u64 *bpscn_ctx);
  5275. +void qbman_bp_attr_get_hw_targ(struct qbman_attr *a, u32 *hw_targ);
  5276. +int qbman_bp_info_has_free_bufs(struct qbman_attr *a);
  5277. +int qbman_bp_info_is_depleted(struct qbman_attr *a);
  5278. +int qbman_bp_info_is_surplus(struct qbman_attr *a);
  5279. +u32 qbman_bp_info_num_free_bufs(struct qbman_attr *a);
  5280. +u32 qbman_bp_info_hdptr(struct qbman_attr *a);
  5281. +u32 qbman_bp_info_sdcnt(struct qbman_attr *a);
  5282. +u32 qbman_bp_info_hdcnt(struct qbman_attr *a);
  5283. +u32 qbman_bp_info_sscnt(struct qbman_attr *a);
  5284. +
  5285. +/* FQ query function for programmable fields */
  5286. +int qbman_fq_query(struct qbman_swp *s, u32 fqid,
  5287. + struct qbman_attr *desc);
  5288. +void qbman_fq_attr_get_fqctrl(struct qbman_attr *d, u32 *fqctrl);
  5289. +void qbman_fq_attr_get_cgrid(struct qbman_attr *d, u32 *cgrid);
  5290. +void qbman_fq_attr_get_destwq(struct qbman_attr *d, u32 *destwq);
  5291. +void qbman_fq_attr_get_icscred(struct qbman_attr *d, u32 *icscred);
  5292. +void qbman_fq_attr_get_tdthresh(struct qbman_attr *d, u32 *tdthresh);
  5293. +void qbman_fq_attr_get_oa(struct qbman_attr *d,
  5294. + int *oa_ics, int *oa_cgr, int32_t *oa_len);
  5295. +void qbman_fq_attr_get_mctl(struct qbman_attr *d,
  5296. + int *bdi, int *ff, int *va, int *ps);
  5297. +void qbman_fq_attr_get_ctx(struct qbman_attr *d, u32 *hi, u32 *lo);
  5298. +void qbman_fq_attr_get_icid(struct qbman_attr *d, u32 *icid, int *pl);
  5299. +void qbman_fq_attr_get_vfqid(struct qbman_attr *d, u32 *vfqid);
  5300. +void qbman_fq_attr_get_erfqid(struct qbman_attr *d, u32 *erfqid);
  5301. +
  5302. +/* FQ query command for non-programmable fields*/
  5303. +enum qbman_fq_schedstate_e {
  5304. + qbman_fq_schedstate_oos = 0,
  5305. + qbman_fq_schedstate_retired,
  5306. + qbman_fq_schedstate_tentatively_scheduled,
  5307. + qbman_fq_schedstate_truly_scheduled,
  5308. + qbman_fq_schedstate_parked,
  5309. + qbman_fq_schedstate_held_active,
  5310. +};
  5311. +
  5312. +int qbman_fq_query_state(struct qbman_swp *s, u32 fqid,
  5313. + struct qbman_attr *state);
  5314. +u32 qbman_fq_state_schedstate(const struct qbman_attr *state);
  5315. +int qbman_fq_state_force_eligible(const struct qbman_attr *state);
  5316. +int qbman_fq_state_xoff(const struct qbman_attr *state);
  5317. +int qbman_fq_state_retirement_pending(const struct qbman_attr *state);
  5318. +int qbman_fq_state_overflow_error(const struct qbman_attr *state);
  5319. +u32 qbman_fq_state_frame_count(const struct qbman_attr *state);
  5320. +u32 qbman_fq_state_byte_count(const struct qbman_attr *state);
  5321. +
  5322. +/* CGR query */
  5323. +int qbman_cgr_query(struct qbman_swp *s, u32 cgid,
  5324. + struct qbman_attr *attr);
  5325. +void qbman_cgr_attr_get_ctl1(struct qbman_attr *d, int *cscn_wq_en_enter,
  5326. + int *cscn_wq_en_exit, int *cscn_wq_icd);
  5327. +void qbman_cgr_attr_get_mode(struct qbman_attr *d, u32 *mode,
  5328. + int *rej_cnt_mode, int *cscn_bdi);
  5329. +void qbman_cgr_attr_get_ctl2(struct qbman_attr *d, int *cscn_wr_en_enter,
  5330. + int *cscn_wr_en_exit, int *cg_wr_ae,
  5331. + int *cscn_dcp_en, int *cg_wr_va);
  5332. +void qbman_cgr_attr_get_iwc(struct qbman_attr *d, int *i_cnt_wr_en,
  5333. + u32 *i_cnt_wr_bnd);
  5334. +void qbman_cgr_attr_get_tdc(struct qbman_attr *d, int *td_en);
  5335. +void qbman_cgr_attr_get_cs_thres(struct qbman_attr *d, u32 *cs_thres);
  5336. +void qbman_cgr_attr_get_cs_thres_x(struct qbman_attr *d,
  5337. + u32 *cs_thres_x);
  5338. +void qbman_cgr_attr_get_td_thres(struct qbman_attr *d, u32 *td_thres);
  5339. +void qbman_cgr_attr_get_cscn_tdcp(struct qbman_attr *d, u32 *cscn_tdcp);
  5340. +void qbman_cgr_attr_get_cscn_wqid(struct qbman_attr *d, u32 *cscn_wqid);
  5341. +void qbman_cgr_attr_get_cscn_vcgid(struct qbman_attr *d,
  5342. + u32 *cscn_vcgid);
  5343. +void qbman_cgr_attr_get_cg_icid(struct qbman_attr *d, u32 *icid,
  5344. + int *pl);
  5345. +void qbman_cgr_attr_get_cg_wr_addr(struct qbman_attr *d,
  5346. + u64 *cg_wr_addr);
  5347. +void qbman_cgr_attr_get_cscn_ctx(struct qbman_attr *d, u64 *cscn_ctx);
  5348. +void qbman_cgr_attr_wred_get_edp(struct qbman_attr *d, u32 idx,
  5349. + int *edp);
  5350. +void qbman_cgr_attr_wred_dp_decompose(u32 dp, u64 *minth,
  5351. + u64 *maxth, u8 *maxp);
  5352. +void qbman_cgr_attr_wred_get_parm_dp(struct qbman_attr *d, u32 idx,
  5353. + u32 *dp);
  5354. +
  5355. +/* CGR/CCGR/CQ statistics query */
  5356. +int qbman_cgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
  5357. + u64 *frame_cnt, u64 *byte_cnt);
  5358. +int qbman_ccgr_reject_statistics(struct qbman_swp *s, u32 cgid, int clear,
  5359. + u64 *frame_cnt, u64 *byte_cnt);
  5360. +int qbman_cq_dequeue_statistics(struct qbman_swp *s, u32 cgid, int clear,
  5361. + u64 *frame_cnt, u64 *byte_cnt);
  5362. --- /dev/null
  5363. +++ b/drivers/staging/fsl-mc/bus/dpio/qbman_private.h
  5364. @@ -0,0 +1,171 @@
  5365. +/* Copyright (C) 2014 Freescale Semiconductor, Inc.
  5366. + *
  5367. + * Redistribution and use in source and binary forms, with or without
  5368. + * modification, are permitted provided that the following conditions are met:
  5369. + * * Redistributions of source code must retain the above copyright
  5370. + * notice, this list of conditions and the following disclaimer.
  5371. + * * Redistributions in binary form must reproduce the above copyright
  5372. + * notice, this list of conditions and the following disclaimer in the
  5373. + * documentation and/or other materials provided with the distribution.
  5374. + * * Neither the name of Freescale Semiconductor nor the
  5375. + * names of its contributors may be used to endorse or promote products
  5376. + * derived from this software without specific prior written permission.
  5377. + *
  5378. + *
  5379. + * ALTERNATIVELY, this software may be distributed under the terms of the
  5380. + * GNU General Public License ("GPL") as published by the Free Software
  5381. + * Foundation, either version 2 of that License or (at your option) any
  5382. + * later version.
  5383. + *
  5384. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  5385. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  5386. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  5387. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  5388. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  5389. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  5390. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  5391. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  5392. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  5393. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  5394. + */
  5395. +
  5396. +/* Perform extra checking */
  5397. +#define QBMAN_CHECKING
  5398. +
  5399. +/* To maximise the amount of logic that is common between the Linux driver and
  5400. + * other targets (such as the embedded MC firmware), we pivot here between the
  5401. + * inclusion of two platform-specific headers.
  5402. + *
  5403. + * The first, qbman_sys_decl.h, includes any and all required system headers as
  5404. + * well as providing any definitions for the purposes of compatibility. The
  5405. + * second, qbman_sys.h, is where platform-specific routines go.
  5406. + *
  5407. + * The point of the split is that the platform-independent code (including this
  5408. + * header) may depend on platform-specific declarations, yet other
  5409. + * platform-specific routines may depend on platform-independent definitions.
  5410. + */
  5411. +
  5412. +#define QMAN_REV_4000 0x04000000
  5413. +#define QMAN_REV_4100 0x04010000
  5414. +#define QMAN_REV_4101 0x04010001
  5415. +
  5416. +/* When things go wrong, it is a convenient trick to insert a few FOO()
  5417. + * statements in the code to trace progress. TODO: remove this once we are
  5418. + * hacking the code less actively.
  5419. + */
  5420. +#define FOO() fsl_os_print("FOO: %s:%d\n", __FILE__, __LINE__)
  5421. +
  5422. +/* Any time there is a register interface which we poll on, this provides a
  5423. + * "break after x iterations" scheme for it. It's handy for debugging, eg.
  5424. + * where you don't want millions of lines of log output from a polling loop
  5425. + * that won't, because such things tend to drown out the earlier log output
  5426. + * that might explain what caused the problem. (NB: put ";" after each macro!)
  5427. + * TODO: we should probably remove this once we're done sanitising the
  5428. + * simulator...
  5429. + */
  5430. +#define DBG_POLL_START(loopvar) (loopvar = 1000)
  5431. +#define DBG_POLL_CHECK(loopvar) \
  5432. + do {if (!((loopvar)--)) WARN_ON(1); } while (0)
  5433. +
  5434. +/* For CCSR or portal-CINH registers that contain fields at arbitrary offsets
  5435. + * and widths, these macro-generated encode/decode/isolate/remove inlines can
  5436. + * be used.
  5437. + *
  5438. + * Eg. to "d"ecode a 14-bit field out of a register (into a "u16" type),
  5439. + * where the field is located 3 bits "up" from the least-significant bit of the
  5440. + * register (ie. the field location within the 32-bit register corresponds to a
  5441. + * mask of 0x0001fff8), you would do;
  5442. + * u16 field = d32_u16(3, 14, reg_value);
  5443. + *
  5444. + * Or to "e"ncode a 1-bit boolean value (input type is "int", zero is FALSE,
  5445. + * non-zero is TRUE, so must convert all non-zero inputs to 1, hence the "!!"
  5446. + * operator) into a register at bit location 0x00080000 (19 bits "in" from the
  5447. + * LS bit), do;
  5448. + * reg_value |= e32_int(19, 1, !!field);
  5449. + *
  5450. + * If you wish to read-modify-write a register, such that you leave the 14-bit
  5451. + * field as-is but have all other fields set to zero, then "i"solate the 14-bit
  5452. + * value using;
  5453. + * reg_value = i32_u16(3, 14, reg_value);
  5454. + *
  5455. + * Alternatively, you could "r"emove the 1-bit boolean field (setting it to
  5456. + * zero) but leaving all other fields as-is;
  5457. + * reg_val = r32_int(19, 1, reg_value);
  5458. + *
  5459. + */
  5460. +#define MAKE_MASK32(width) (width == 32 ? 0xffffffff : \
  5461. + (u32)((1 << width) - 1))
  5462. +#define DECLARE_CODEC32(t) \
  5463. +static inline u32 e32_##t(u32 lsoffset, u32 width, t val) \
  5464. +{ \
  5465. + WARN_ON(width > (sizeof(t) * 8)); \
  5466. + return ((u32)val & MAKE_MASK32(width)) << lsoffset; \
  5467. +} \
  5468. +static inline t d32_##t(u32 lsoffset, u32 width, u32 val) \
  5469. +{ \
  5470. + WARN_ON(width > (sizeof(t) * 8)); \
  5471. + return (t)((val >> lsoffset) & MAKE_MASK32(width)); \
  5472. +} \
  5473. +static inline u32 i32_##t(u32 lsoffset, u32 width, \
  5474. + u32 val) \
  5475. +{ \
  5476. + WARN_ON(width > (sizeof(t) * 8)); \
  5477. + return e32_##t(lsoffset, width, d32_##t(lsoffset, width, val)); \
  5478. +} \
  5479. +static inline u32 r32_##t(u32 lsoffset, u32 width, \
  5480. + u32 val) \
  5481. +{ \
  5482. + WARN_ON(width > (sizeof(t) * 8)); \
  5483. + return ~(MAKE_MASK32(width) << lsoffset) & val; \
  5484. +}
  5485. +DECLARE_CODEC32(u32)
  5486. +DECLARE_CODEC32(u16)
  5487. +DECLARE_CODEC32(u8)
  5488. +DECLARE_CODEC32(int)
  5489. +
  5490. + /*********************/
  5491. + /* Debugging assists */
  5492. + /*********************/
  5493. +
  5494. +static inline void __hexdump(unsigned long start, unsigned long end,
  5495. + unsigned long p, size_t sz,
  5496. + const unsigned char *c)
  5497. +{
  5498. + while (start < end) {
  5499. + unsigned int pos = 0;
  5500. + char buf[64];
  5501. + int nl = 0;
  5502. +
  5503. + pos += sprintf(buf + pos, "%08lx: ", start);
  5504. + do {
  5505. + if ((start < p) || (start >= (p + sz)))
  5506. + pos += sprintf(buf + pos, "..");
  5507. + else
  5508. + pos += sprintf(buf + pos, "%02x", *(c++));
  5509. + if (!(++start & 15)) {
  5510. + buf[pos++] = '\n';
  5511. + nl = 1;
  5512. + } else {
  5513. + nl = 0;
  5514. + if (!(start & 1))
  5515. + buf[pos++] = ' ';
  5516. + if (!(start & 3))
  5517. + buf[pos++] = ' ';
  5518. + }
  5519. + } while (start & 15);
  5520. + if (!nl)
  5521. + buf[pos++] = '\n';
  5522. + buf[pos] = '\0';
  5523. + pr_info("%s", buf);
  5524. + }
  5525. +}
  5526. +
  5527. +static inline void hexdump(const void *ptr, size_t sz)
  5528. +{
  5529. + unsigned long p = (unsigned long)ptr;
  5530. + unsigned long start = p & ~15ul;
  5531. + unsigned long end = (p + sz + 15) & ~15ul;
  5532. + const unsigned char *c = ptr;
  5533. +
  5534. + __hexdump(start, end, p, sz, c);
  5535. +}
  5536. --- a/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
  5537. +++ b/drivers/staging/fsl-mc/bus/dpmcp-cmd.h
  5538. @@ -1,4 +1,5 @@
  5539. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  5540. +/*
  5541. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  5542. *
  5543. * Redistribution and use in source and binary forms, with or without
  5544. * modification, are permitted provided that the following conditions are met:
  5545. @@ -11,7 +12,6 @@
  5546. * names of any contributors may be used to endorse or promote products
  5547. * derived from this software without specific prior written permission.
  5548. *
  5549. - *
  5550. * ALTERNATIVELY, this software may be distributed under the terms of the
  5551. * GNU General Public License ("GPL") as published by the Free Software
  5552. * Foundation, either version 2 of that License or (at your option) any
  5553. @@ -33,108 +33,24 @@
  5554. #define _FSL_DPMCP_CMD_H
  5555. /* Minimal supported DPMCP Version */
  5556. -#define DPMCP_MIN_VER_MAJOR 3
  5557. -#define DPMCP_MIN_VER_MINOR 0
  5558. -
  5559. -/* Command IDs */
  5560. -#define DPMCP_CMDID_CLOSE 0x800
  5561. -#define DPMCP_CMDID_OPEN 0x80b
  5562. -#define DPMCP_CMDID_CREATE 0x90b
  5563. -#define DPMCP_CMDID_DESTROY 0x900
  5564. -
  5565. -#define DPMCP_CMDID_GET_ATTR 0x004
  5566. -#define DPMCP_CMDID_RESET 0x005
  5567. -
  5568. -#define DPMCP_CMDID_SET_IRQ 0x010
  5569. -#define DPMCP_CMDID_GET_IRQ 0x011
  5570. -#define DPMCP_CMDID_SET_IRQ_ENABLE 0x012
  5571. -#define DPMCP_CMDID_GET_IRQ_ENABLE 0x013
  5572. -#define DPMCP_CMDID_SET_IRQ_MASK 0x014
  5573. -#define DPMCP_CMDID_GET_IRQ_MASK 0x015
  5574. -#define DPMCP_CMDID_GET_IRQ_STATUS 0x016
  5575. -
  5576. -struct dpmcp_cmd_open {
  5577. - __le32 dpmcp_id;
  5578. -};
  5579. -
  5580. -struct dpmcp_cmd_create {
  5581. - __le32 portal_id;
  5582. -};
  5583. -
  5584. -struct dpmcp_cmd_set_irq {
  5585. - /* cmd word 0 */
  5586. - u8 irq_index;
  5587. - u8 pad[3];
  5588. - __le32 irq_val;
  5589. - /* cmd word 1 */
  5590. - __le64 irq_addr;
  5591. - /* cmd word 2 */
  5592. - __le32 irq_num;
  5593. -};
  5594. -
  5595. -struct dpmcp_cmd_get_irq {
  5596. - __le32 pad;
  5597. - u8 irq_index;
  5598. -};
  5599. -
  5600. -struct dpmcp_rsp_get_irq {
  5601. - /* cmd word 0 */
  5602. - __le32 irq_val;
  5603. - __le32 pad;
  5604. - /* cmd word 1 */
  5605. - __le64 irq_paddr;
  5606. - /* cmd word 2 */
  5607. - __le32 irq_num;
  5608. - __le32 type;
  5609. -};
  5610. +#define DPMCP_MIN_VER_MAJOR 3
  5611. +#define DPMCP_MIN_VER_MINOR 0
  5612. -#define DPMCP_ENABLE 0x1
  5613. +/* Command versioning */
  5614. +#define DPMCP_CMD_BASE_VERSION 1
  5615. +#define DPMCP_CMD_ID_OFFSET 4
  5616. -struct dpmcp_cmd_set_irq_enable {
  5617. - u8 enable;
  5618. - u8 pad[3];
  5619. - u8 irq_index;
  5620. -};
  5621. +#define DPMCP_CMD(id) ((id << DPMCP_CMD_ID_OFFSET) | DPMCP_CMD_BASE_VERSION)
  5622. -struct dpmcp_cmd_get_irq_enable {
  5623. - __le32 pad;
  5624. - u8 irq_index;
  5625. -};
  5626. -
  5627. -struct dpmcp_rsp_get_irq_enable {
  5628. - u8 enabled;
  5629. -};
  5630. -
  5631. -struct dpmcp_cmd_set_irq_mask {
  5632. - __le32 mask;
  5633. - u8 irq_index;
  5634. -};
  5635. -
  5636. -struct dpmcp_cmd_get_irq_mask {
  5637. - __le32 pad;
  5638. - u8 irq_index;
  5639. -};
  5640. -
  5641. -struct dpmcp_rsp_get_irq_mask {
  5642. - __le32 mask;
  5643. -};
  5644. +/* Command IDs */
  5645. +#define DPMCP_CMDID_CLOSE DPMCP_CMD(0x800)
  5646. +#define DPMCP_CMDID_OPEN DPMCP_CMD(0x80b)
  5647. +#define DPMCP_CMDID_GET_API_VERSION DPMCP_CMD(0xa0b)
  5648. -struct dpmcp_cmd_get_irq_status {
  5649. - __le32 status;
  5650. - u8 irq_index;
  5651. -};
  5652. +#define DPMCP_CMDID_RESET DPMCP_CMD(0x005)
  5653. -struct dpmcp_rsp_get_irq_status {
  5654. - __le32 status;
  5655. -};
  5656. -
  5657. -struct dpmcp_rsp_get_attributes {
  5658. - /* response word 0 */
  5659. - __le32 pad;
  5660. - __le32 id;
  5661. - /* response word 1 */
  5662. - __le16 version_major;
  5663. - __le16 version_minor;
  5664. +struct dpmcp_cmd_open {
  5665. + __le32 dpmcp_id;
  5666. };
  5667. #endif /* _FSL_DPMCP_CMD_H */
  5668. --- a/drivers/staging/fsl-mc/bus/dpmcp.c
  5669. +++ b/drivers/staging/fsl-mc/bus/dpmcp.c
  5670. @@ -1,4 +1,5 @@
  5671. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  5672. +/*
  5673. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  5674. *
  5675. * Redistribution and use in source and binary forms, with or without
  5676. * modification, are permitted provided that the following conditions are met:
  5677. @@ -11,7 +12,6 @@
  5678. * names of any contributors may be used to endorse or promote products
  5679. * derived from this software without specific prior written permission.
  5680. *
  5681. - *
  5682. * ALTERNATIVELY, this software may be distributed under the terms of the
  5683. * GNU General Public License ("GPL") as published by the Free Software
  5684. * Foundation, either version 2 of that License or (at your option) any
  5685. @@ -104,76 +104,6 @@ int dpmcp_close(struct fsl_mc_io *mc_io,
  5686. }
  5687. /**
  5688. - * dpmcp_create() - Create the DPMCP object.
  5689. - * @mc_io: Pointer to MC portal's I/O object
  5690. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5691. - * @cfg: Configuration structure
  5692. - * @token: Returned token; use in subsequent API calls
  5693. - *
  5694. - * Create the DPMCP object, allocate required resources and
  5695. - * perform required initialization.
  5696. - *
  5697. - * The object can be created either by declaring it in the
  5698. - * DPL file, or by calling this function.
  5699. - * This function returns a unique authentication token,
  5700. - * associated with the specific object ID and the specific MC
  5701. - * portal; this token must be used in all subsequent calls to
  5702. - * this specific object. For objects that are created using the
  5703. - * DPL file, call dpmcp_open function to get an authentication
  5704. - * token first.
  5705. - *
  5706. - * Return: '0' on Success; Error code otherwise.
  5707. - */
  5708. -int dpmcp_create(struct fsl_mc_io *mc_io,
  5709. - u32 cmd_flags,
  5710. - const struct dpmcp_cfg *cfg,
  5711. - u16 *token)
  5712. -{
  5713. - struct mc_command cmd = { 0 };
  5714. - struct dpmcp_cmd_create *cmd_params;
  5715. -
  5716. - int err;
  5717. -
  5718. - /* prepare command */
  5719. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CREATE,
  5720. - cmd_flags, 0);
  5721. - cmd_params = (struct dpmcp_cmd_create *)cmd.params;
  5722. - cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
  5723. -
  5724. - /* send command to mc*/
  5725. - err = mc_send_command(mc_io, &cmd);
  5726. - if (err)
  5727. - return err;
  5728. -
  5729. - /* retrieve response parameters */
  5730. - *token = mc_cmd_hdr_read_token(&cmd);
  5731. -
  5732. - return 0;
  5733. -}
  5734. -
  5735. -/**
  5736. - * dpmcp_destroy() - Destroy the DPMCP object and release all its resources.
  5737. - * @mc_io: Pointer to MC portal's I/O object
  5738. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5739. - * @token: Token of DPMCP object
  5740. - *
  5741. - * Return: '0' on Success; error code otherwise.
  5742. - */
  5743. -int dpmcp_destroy(struct fsl_mc_io *mc_io,
  5744. - u32 cmd_flags,
  5745. - u16 token)
  5746. -{
  5747. - struct mc_command cmd = { 0 };
  5748. -
  5749. - /* prepare command */
  5750. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_DESTROY,
  5751. - cmd_flags, token);
  5752. -
  5753. - /* send command to mc*/
  5754. - return mc_send_command(mc_io, &cmd);
  5755. -}
  5756. -
  5757. -/**
  5758. * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
  5759. * @mc_io: Pointer to MC portal's I/O object
  5760. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5761. @@ -196,309 +126,33 @@ int dpmcp_reset(struct fsl_mc_io *mc_io,
  5762. }
  5763. /**
  5764. - * dpmcp_set_irq() - Set IRQ information for the DPMCP to trigger an interrupt.
  5765. - * @mc_io: Pointer to MC portal's I/O object
  5766. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5767. - * @token: Token of DPMCP object
  5768. - * @irq_index: Identifies the interrupt index to configure
  5769. - * @irq_cfg: IRQ configuration
  5770. - *
  5771. - * Return: '0' on Success; Error code otherwise.
  5772. - */
  5773. -int dpmcp_set_irq(struct fsl_mc_io *mc_io,
  5774. - u32 cmd_flags,
  5775. - u16 token,
  5776. - u8 irq_index,
  5777. - struct dpmcp_irq_cfg *irq_cfg)
  5778. -{
  5779. - struct mc_command cmd = { 0 };
  5780. - struct dpmcp_cmd_set_irq *cmd_params;
  5781. -
  5782. - /* prepare command */
  5783. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ,
  5784. - cmd_flags, token);
  5785. - cmd_params = (struct dpmcp_cmd_set_irq *)cmd.params;
  5786. - cmd_params->irq_index = irq_index;
  5787. - cmd_params->irq_val = cpu_to_le32(irq_cfg->val);
  5788. - cmd_params->irq_addr = cpu_to_le64(irq_cfg->paddr);
  5789. - cmd_params->irq_num = cpu_to_le32(irq_cfg->irq_num);
  5790. -
  5791. - /* send command to mc*/
  5792. - return mc_send_command(mc_io, &cmd);
  5793. -}
  5794. -
  5795. -/**
  5796. - * dpmcp_get_irq() - Get IRQ information from the DPMCP.
  5797. - * @mc_io: Pointer to MC portal's I/O object
  5798. + * dpmcp_get_api_version - Get Data Path Management Command Portal API version
  5799. + * @mc_io: Pointer to Mc portal's I/O object
  5800. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5801. - * @token: Token of DPMCP object
  5802. - * @irq_index: The interrupt index to configure
  5803. - * @type: Interrupt type: 0 represents message interrupt
  5804. - * type (both irq_addr and irq_val are valid)
  5805. - * @irq_cfg: IRQ attributes
  5806. + * @major_ver: Major version of Data Path Management Command Portal API
  5807. + * @minor_ver: Minor version of Data Path Management Command Portal API
  5808. *
  5809. * Return: '0' on Success; Error code otherwise.
  5810. */
  5811. -int dpmcp_get_irq(struct fsl_mc_io *mc_io,
  5812. - u32 cmd_flags,
  5813. - u16 token,
  5814. - u8 irq_index,
  5815. - int *type,
  5816. - struct dpmcp_irq_cfg *irq_cfg)
  5817. +int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
  5818. + u32 cmd_flags,
  5819. + u16 *major_ver,
  5820. + u16 *minor_ver)
  5821. {
  5822. struct mc_command cmd = { 0 };
  5823. - struct dpmcp_cmd_get_irq *cmd_params;
  5824. - struct dpmcp_rsp_get_irq *rsp_params;
  5825. int err;
  5826. /* prepare command */
  5827. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ,
  5828. - cmd_flags, token);
  5829. - cmd_params = (struct dpmcp_cmd_get_irq *)cmd.params;
  5830. - cmd_params->irq_index = irq_index;
  5831. -
  5832. - /* send command to mc*/
  5833. - err = mc_send_command(mc_io, &cmd);
  5834. - if (err)
  5835. - return err;
  5836. -
  5837. - /* retrieve response parameters */
  5838. - rsp_params = (struct dpmcp_rsp_get_irq *)cmd.params;
  5839. - irq_cfg->val = le32_to_cpu(rsp_params->irq_val);
  5840. - irq_cfg->paddr = le64_to_cpu(rsp_params->irq_paddr);
  5841. - irq_cfg->irq_num = le32_to_cpu(rsp_params->irq_num);
  5842. - *type = le32_to_cpu(rsp_params->type);
  5843. - return 0;
  5844. -}
  5845. -
  5846. -/**
  5847. - * dpmcp_set_irq_enable() - Set overall interrupt state.
  5848. - * @mc_io: Pointer to MC portal's I/O object
  5849. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5850. - * @token: Token of DPMCP object
  5851. - * @irq_index: The interrupt index to configure
  5852. - * @en: Interrupt state - enable = 1, disable = 0
  5853. - *
  5854. - * Allows GPP software to control when interrupts are generated.
  5855. - * Each interrupt can have up to 32 causes. The enable/disable control's the
  5856. - * overall interrupt state. if the interrupt is disabled no causes will cause
  5857. - * an interrupt.
  5858. - *
  5859. - * Return: '0' on Success; Error code otherwise.
  5860. - */
  5861. -int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
  5862. - u32 cmd_flags,
  5863. - u16 token,
  5864. - u8 irq_index,
  5865. - u8 en)
  5866. -{
  5867. - struct mc_command cmd = { 0 };
  5868. - struct dpmcp_cmd_set_irq_enable *cmd_params;
  5869. -
  5870. - /* prepare command */
  5871. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_ENABLE,
  5872. - cmd_flags, token);
  5873. - cmd_params = (struct dpmcp_cmd_set_irq_enable *)cmd.params;
  5874. - cmd_params->enable = en & DPMCP_ENABLE;
  5875. - cmd_params->irq_index = irq_index;
  5876. -
  5877. - /* send command to mc*/
  5878. - return mc_send_command(mc_io, &cmd);
  5879. -}
  5880. -
  5881. -/**
  5882. - * dpmcp_get_irq_enable() - Get overall interrupt state
  5883. - * @mc_io: Pointer to MC portal's I/O object
  5884. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5885. - * @token: Token of DPMCP object
  5886. - * @irq_index: The interrupt index to configure
  5887. - * @en: Returned interrupt state - enable = 1, disable = 0
  5888. - *
  5889. - * Return: '0' on Success; Error code otherwise.
  5890. - */
  5891. -int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
  5892. - u32 cmd_flags,
  5893. - u16 token,
  5894. - u8 irq_index,
  5895. - u8 *en)
  5896. -{
  5897. - struct mc_command cmd = { 0 };
  5898. - struct dpmcp_cmd_get_irq_enable *cmd_params;
  5899. - struct dpmcp_rsp_get_irq_enable *rsp_params;
  5900. - int err;
  5901. -
  5902. - /* prepare command */
  5903. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_ENABLE,
  5904. - cmd_flags, token);
  5905. - cmd_params = (struct dpmcp_cmd_get_irq_enable *)cmd.params;
  5906. - cmd_params->irq_index = irq_index;
  5907. -
  5908. - /* send command to mc*/
  5909. - err = mc_send_command(mc_io, &cmd);
  5910. - if (err)
  5911. - return err;
  5912. -
  5913. - /* retrieve response parameters */
  5914. - rsp_params = (struct dpmcp_rsp_get_irq_enable *)cmd.params;
  5915. - *en = rsp_params->enabled & DPMCP_ENABLE;
  5916. - return 0;
  5917. -}
  5918. -
  5919. -/**
  5920. - * dpmcp_set_irq_mask() - Set interrupt mask.
  5921. - * @mc_io: Pointer to MC portal's I/O object
  5922. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5923. - * @token: Token of DPMCP object
  5924. - * @irq_index: The interrupt index to configure
  5925. - * @mask: Event mask to trigger interrupt;
  5926. - * each bit:
  5927. - * 0 = ignore event
  5928. - * 1 = consider event for asserting IRQ
  5929. - *
  5930. - * Every interrupt can have up to 32 causes and the interrupt model supports
  5931. - * masking/unmasking each cause independently
  5932. - *
  5933. - * Return: '0' on Success; Error code otherwise.
  5934. - */
  5935. -int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
  5936. - u32 cmd_flags,
  5937. - u16 token,
  5938. - u8 irq_index,
  5939. - u32 mask)
  5940. -{
  5941. - struct mc_command cmd = { 0 };
  5942. - struct dpmcp_cmd_set_irq_mask *cmd_params;
  5943. -
  5944. - /* prepare command */
  5945. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_SET_IRQ_MASK,
  5946. - cmd_flags, token);
  5947. - cmd_params = (struct dpmcp_cmd_set_irq_mask *)cmd.params;
  5948. - cmd_params->mask = cpu_to_le32(mask);
  5949. - cmd_params->irq_index = irq_index;
  5950. -
  5951. - /* send command to mc*/
  5952. - return mc_send_command(mc_io, &cmd);
  5953. -}
  5954. -
  5955. -/**
  5956. - * dpmcp_get_irq_mask() - Get interrupt mask.
  5957. - * @mc_io: Pointer to MC portal's I/O object
  5958. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  5959. - * @token: Token of DPMCP object
  5960. - * @irq_index: The interrupt index to configure
  5961. - * @mask: Returned event mask to trigger interrupt
  5962. - *
  5963. - * Every interrupt can have up to 32 causes and the interrupt model supports
  5964. - * masking/unmasking each cause independently
  5965. - *
  5966. - * Return: '0' on Success; Error code otherwise.
  5967. - */
  5968. -int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
  5969. - u32 cmd_flags,
  5970. - u16 token,
  5971. - u8 irq_index,
  5972. - u32 *mask)
  5973. -{
  5974. - struct mc_command cmd = { 0 };
  5975. - struct dpmcp_cmd_get_irq_mask *cmd_params;
  5976. - struct dpmcp_rsp_get_irq_mask *rsp_params;
  5977. -
  5978. - int err;
  5979. -
  5980. - /* prepare command */
  5981. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_MASK,
  5982. - cmd_flags, token);
  5983. - cmd_params = (struct dpmcp_cmd_get_irq_mask *)cmd.params;
  5984. - cmd_params->irq_index = irq_index;
  5985. -
  5986. - /* send command to mc*/
  5987. - err = mc_send_command(mc_io, &cmd);
  5988. - if (err)
  5989. - return err;
  5990. -
  5991. - /* retrieve response parameters */
  5992. - rsp_params = (struct dpmcp_rsp_get_irq_mask *)cmd.params;
  5993. - *mask = le32_to_cpu(rsp_params->mask);
  5994. -
  5995. - return 0;
  5996. -}
  5997. -
  5998. -/**
  5999. - * dpmcp_get_irq_status() - Get the current status of any pending interrupts.
  6000. - *
  6001. - * @mc_io: Pointer to MC portal's I/O object
  6002. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6003. - * @token: Token of DPMCP object
  6004. - * @irq_index: The interrupt index to configure
  6005. - * @status: Returned interrupts status - one bit per cause:
  6006. - * 0 = no interrupt pending
  6007. - * 1 = interrupt pending
  6008. - *
  6009. - * Return: '0' on Success; Error code otherwise.
  6010. - */
  6011. -int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
  6012. - u32 cmd_flags,
  6013. - u16 token,
  6014. - u8 irq_index,
  6015. - u32 *status)
  6016. -{
  6017. - struct mc_command cmd = { 0 };
  6018. - struct dpmcp_cmd_get_irq_status *cmd_params;
  6019. - struct dpmcp_rsp_get_irq_status *rsp_params;
  6020. - int err;
  6021. -
  6022. - /* prepare command */
  6023. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_IRQ_STATUS,
  6024. - cmd_flags, token);
  6025. - cmd_params = (struct dpmcp_cmd_get_irq_status *)cmd.params;
  6026. - cmd_params->status = cpu_to_le32(*status);
  6027. - cmd_params->irq_index = irq_index;
  6028. -
  6029. - /* send command to mc*/
  6030. - err = mc_send_command(mc_io, &cmd);
  6031. - if (err)
  6032. - return err;
  6033. -
  6034. - /* retrieve response parameters */
  6035. - rsp_params = (struct dpmcp_rsp_get_irq_status *)cmd.params;
  6036. - *status = le32_to_cpu(rsp_params->status);
  6037. -
  6038. - return 0;
  6039. -}
  6040. -
  6041. -/**
  6042. - * dpmcp_get_attributes - Retrieve DPMCP attributes.
  6043. - *
  6044. - * @mc_io: Pointer to MC portal's I/O object
  6045. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6046. - * @token: Token of DPMCP object
  6047. - * @attr: Returned object's attributes
  6048. - *
  6049. - * Return: '0' on Success; Error code otherwise.
  6050. - */
  6051. -int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
  6052. - u32 cmd_flags,
  6053. - u16 token,
  6054. - struct dpmcp_attr *attr)
  6055. -{
  6056. - struct mc_command cmd = { 0 };
  6057. - struct dpmcp_rsp_get_attributes *rsp_params;
  6058. - int err;
  6059. -
  6060. - /* prepare command */
  6061. - cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_ATTR,
  6062. - cmd_flags, token);
  6063. + cmd.header = mc_encode_cmd_header(DPMCP_CMDID_GET_API_VERSION,
  6064. + cmd_flags, 0);
  6065. - /* send command to mc*/
  6066. + /* send command to mc */
  6067. err = mc_send_command(mc_io, &cmd);
  6068. if (err)
  6069. return err;
  6070. /* retrieve response parameters */
  6071. - rsp_params = (struct dpmcp_rsp_get_attributes *)cmd.params;
  6072. - attr->id = le32_to_cpu(rsp_params->id);
  6073. - attr->version.major = le16_to_cpu(rsp_params->version_major);
  6074. - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
  6075. + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  6076. return 0;
  6077. }
  6078. --- a/drivers/staging/fsl-mc/bus/dpmcp.h
  6079. +++ b/drivers/staging/fsl-mc/bus/dpmcp.h
  6080. @@ -1,4 +1,5 @@
  6081. -/* Copyright 2013-2015 Freescale Semiconductor Inc.
  6082. +/*
  6083. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  6084. *
  6085. * Redistribution and use in source and binary forms, with or without
  6086. * modification, are permitted provided that the following conditions are met:
  6087. @@ -11,7 +12,6 @@
  6088. * names of any contributors may be used to endorse or promote products
  6089. * derived from this software without specific prior written permission.
  6090. *
  6091. - *
  6092. * ALTERNATIVELY, this software may be distributed under the terms of the
  6093. * GNU General Public License ("GPL") as published by the Free Software
  6094. * Foundation, either version 2 of that License or (at your option) any
  6095. @@ -32,128 +32,29 @@
  6096. #ifndef __FSL_DPMCP_H
  6097. #define __FSL_DPMCP_H
  6098. -/* Data Path Management Command Portal API
  6099. +/*
  6100. + * Data Path Management Command Portal API
  6101. * Contains initialization APIs and runtime control APIs for DPMCP
  6102. */
  6103. struct fsl_mc_io;
  6104. int dpmcp_open(struct fsl_mc_io *mc_io,
  6105. - uint32_t cmd_flags,
  6106. + u32 cmd_flags,
  6107. int dpmcp_id,
  6108. - uint16_t *token);
  6109. -
  6110. -/* Get portal ID from pool */
  6111. -#define DPMCP_GET_PORTAL_ID_FROM_POOL (-1)
  6112. + u16 *token);
  6113. int dpmcp_close(struct fsl_mc_io *mc_io,
  6114. - uint32_t cmd_flags,
  6115. - uint16_t token);
  6116. + u32 cmd_flags,
  6117. + u16 token);
  6118. -/**
  6119. - * struct dpmcp_cfg - Structure representing DPMCP configuration
  6120. - * @portal_id: Portal ID; 'DPMCP_GET_PORTAL_ID_FROM_POOL' to get the portal ID
  6121. - * from pool
  6122. - */
  6123. -struct dpmcp_cfg {
  6124. - int portal_id;
  6125. -};
  6126. -
  6127. -int dpmcp_create(struct fsl_mc_io *mc_io,
  6128. - uint32_t cmd_flags,
  6129. - const struct dpmcp_cfg *cfg,
  6130. - uint16_t *token);
  6131. -
  6132. -int dpmcp_destroy(struct fsl_mc_io *mc_io,
  6133. - uint32_t cmd_flags,
  6134. - uint16_t token);
  6135. +int dpmcp_get_api_version(struct fsl_mc_io *mc_io,
  6136. + u32 cmd_flags,
  6137. + u16 *major_ver,
  6138. + u16 *minor_ver);
  6139. int dpmcp_reset(struct fsl_mc_io *mc_io,
  6140. - uint32_t cmd_flags,
  6141. - uint16_t token);
  6142. -
  6143. -/* IRQ */
  6144. -/* IRQ Index */
  6145. -#define DPMCP_IRQ_INDEX 0
  6146. -/* irq event - Indicates that the link state changed */
  6147. -#define DPMCP_IRQ_EVENT_CMD_DONE 0x00000001
  6148. -
  6149. -/**
  6150. - * struct dpmcp_irq_cfg - IRQ configuration
  6151. - * @paddr: Address that must be written to signal a message-based interrupt
  6152. - * @val: Value to write into irq_addr address
  6153. - * @irq_num: A user defined number associated with this IRQ
  6154. - */
  6155. -struct dpmcp_irq_cfg {
  6156. - uint64_t paddr;
  6157. - uint32_t val;
  6158. - int irq_num;
  6159. -};
  6160. -
  6161. -int dpmcp_set_irq(struct fsl_mc_io *mc_io,
  6162. - uint32_t cmd_flags,
  6163. - uint16_t token,
  6164. - uint8_t irq_index,
  6165. - struct dpmcp_irq_cfg *irq_cfg);
  6166. -
  6167. -int dpmcp_get_irq(struct fsl_mc_io *mc_io,
  6168. - uint32_t cmd_flags,
  6169. - uint16_t token,
  6170. - uint8_t irq_index,
  6171. - int *type,
  6172. - struct dpmcp_irq_cfg *irq_cfg);
  6173. -
  6174. -int dpmcp_set_irq_enable(struct fsl_mc_io *mc_io,
  6175. - uint32_t cmd_flags,
  6176. - uint16_t token,
  6177. - uint8_t irq_index,
  6178. - uint8_t en);
  6179. -
  6180. -int dpmcp_get_irq_enable(struct fsl_mc_io *mc_io,
  6181. - uint32_t cmd_flags,
  6182. - uint16_t token,
  6183. - uint8_t irq_index,
  6184. - uint8_t *en);
  6185. -
  6186. -int dpmcp_set_irq_mask(struct fsl_mc_io *mc_io,
  6187. - uint32_t cmd_flags,
  6188. - uint16_t token,
  6189. - uint8_t irq_index,
  6190. - uint32_t mask);
  6191. -
  6192. -int dpmcp_get_irq_mask(struct fsl_mc_io *mc_io,
  6193. - uint32_t cmd_flags,
  6194. - uint16_t token,
  6195. - uint8_t irq_index,
  6196. - uint32_t *mask);
  6197. -
  6198. -int dpmcp_get_irq_status(struct fsl_mc_io *mc_io,
  6199. - uint32_t cmd_flags,
  6200. - uint16_t token,
  6201. - uint8_t irq_index,
  6202. - uint32_t *status);
  6203. -
  6204. -/**
  6205. - * struct dpmcp_attr - Structure representing DPMCP attributes
  6206. - * @id: DPMCP object ID
  6207. - * @version: DPMCP version
  6208. - */
  6209. -struct dpmcp_attr {
  6210. - int id;
  6211. - /**
  6212. - * struct version - Structure representing DPMCP version
  6213. - * @major: DPMCP major version
  6214. - * @minor: DPMCP minor version
  6215. - */
  6216. - struct {
  6217. - uint16_t major;
  6218. - uint16_t minor;
  6219. - } version;
  6220. -};
  6221. -
  6222. -int dpmcp_get_attributes(struct fsl_mc_io *mc_io,
  6223. - uint32_t cmd_flags,
  6224. - uint16_t token,
  6225. - struct dpmcp_attr *attr);
  6226. + u32 cmd_flags,
  6227. + u16 token);
  6228. #endif /* __FSL_DPMCP_H */
  6229. --- a/drivers/staging/fsl-mc/bus/dpmng-cmd.h
  6230. +++ b/drivers/staging/fsl-mc/bus/dpmng-cmd.h
  6231. @@ -12,7 +12,6 @@
  6232. * names of any contributors may be used to endorse or promote products
  6233. * derived from this software without specific prior written permission.
  6234. *
  6235. - *
  6236. * ALTERNATIVELY, this software may be distributed under the terms of the
  6237. * GNU General Public License ("GPL") as published by the Free Software
  6238. * Foundation, either version 2 of that License or (at your option) any
  6239. @@ -41,13 +40,14 @@
  6240. #ifndef __FSL_DPMNG_CMD_H
  6241. #define __FSL_DPMNG_CMD_H
  6242. -/* Command IDs */
  6243. -#define DPMNG_CMDID_GET_CONT_ID 0x830
  6244. -#define DPMNG_CMDID_GET_VERSION 0x831
  6245. +/* Command versioning */
  6246. +#define DPMNG_CMD_BASE_VERSION 1
  6247. +#define DPMNG_CMD_ID_OFFSET 4
  6248. -struct dpmng_rsp_get_container_id {
  6249. - __le32 container_id;
  6250. -};
  6251. +#define DPMNG_CMD(id) ((id << DPMNG_CMD_ID_OFFSET) | DPMNG_CMD_BASE_VERSION)
  6252. +
  6253. +/* Command IDs */
  6254. +#define DPMNG_CMDID_GET_VERSION DPMNG_CMD(0x831)
  6255. struct dpmng_rsp_get_version {
  6256. __le32 revision;
  6257. --- a/drivers/staging/fsl-mc/bus/dpmng.c
  6258. +++ b/drivers/staging/fsl-mc/bus/dpmng.c
  6259. @@ -1,4 +1,5 @@
  6260. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  6261. +/*
  6262. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  6263. *
  6264. * Redistribution and use in source and binary forms, with or without
  6265. * modification, are permitted provided that the following conditions are met:
  6266. @@ -11,7 +12,6 @@
  6267. * names of any contributors may be used to endorse or promote products
  6268. * derived from this software without specific prior written permission.
  6269. *
  6270. - *
  6271. * ALTERNATIVELY, this software may be distributed under the terms of the
  6272. * GNU General Public License ("GPL") as published by the Free Software
  6273. * Foundation, either version 2 of that License or (at your option) any
  6274. @@ -72,36 +72,3 @@ int mc_get_version(struct fsl_mc_io *mc_
  6275. }
  6276. EXPORT_SYMBOL(mc_get_version);
  6277. -/**
  6278. - * dpmng_get_container_id() - Get container ID associated with a given portal.
  6279. - * @mc_io: Pointer to MC portal's I/O object
  6280. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6281. - * @container_id: Requested container ID
  6282. - *
  6283. - * Return: '0' on Success; Error code otherwise.
  6284. - */
  6285. -int dpmng_get_container_id(struct fsl_mc_io *mc_io,
  6286. - u32 cmd_flags,
  6287. - int *container_id)
  6288. -{
  6289. - struct mc_command cmd = { 0 };
  6290. - struct dpmng_rsp_get_container_id *rsp_params;
  6291. - int err;
  6292. -
  6293. - /* prepare command */
  6294. - cmd.header = mc_encode_cmd_header(DPMNG_CMDID_GET_CONT_ID,
  6295. - cmd_flags,
  6296. - 0);
  6297. -
  6298. - /* send command to mc*/
  6299. - err = mc_send_command(mc_io, &cmd);
  6300. - if (err)
  6301. - return err;
  6302. -
  6303. - /* retrieve response parameters */
  6304. - rsp_params = (struct dpmng_rsp_get_container_id *)cmd.params;
  6305. - *container_id = le32_to_cpu(rsp_params->container_id);
  6306. -
  6307. - return 0;
  6308. -}
  6309. -
  6310. --- a/drivers/staging/fsl-mc/bus/dprc-cmd.h
  6311. +++ b/drivers/staging/fsl-mc/bus/dprc-cmd.h
  6312. @@ -12,7 +12,6 @@
  6313. * names of any contributors may be used to endorse or promote products
  6314. * derived from this software without specific prior written permission.
  6315. *
  6316. - *
  6317. * ALTERNATIVELY, this software may be distributed under the terms of the
  6318. * GNU General Public License ("GPL") as published by the Free Software
  6319. * Foundation, either version 2 of that License or (at your option) any
  6320. @@ -42,48 +41,39 @@
  6321. #define _FSL_DPRC_CMD_H
  6322. /* Minimal supported DPRC Version */
  6323. -#define DPRC_MIN_VER_MAJOR 5
  6324. +#define DPRC_MIN_VER_MAJOR 6
  6325. #define DPRC_MIN_VER_MINOR 0
  6326. -/* Command IDs */
  6327. -#define DPRC_CMDID_CLOSE 0x800
  6328. -#define DPRC_CMDID_OPEN 0x805
  6329. -#define DPRC_CMDID_CREATE 0x905
  6330. -
  6331. -#define DPRC_CMDID_GET_ATTR 0x004
  6332. -#define DPRC_CMDID_RESET_CONT 0x005
  6333. -
  6334. -#define DPRC_CMDID_SET_IRQ 0x010
  6335. -#define DPRC_CMDID_GET_IRQ 0x011
  6336. -#define DPRC_CMDID_SET_IRQ_ENABLE 0x012
  6337. -#define DPRC_CMDID_GET_IRQ_ENABLE 0x013
  6338. -#define DPRC_CMDID_SET_IRQ_MASK 0x014
  6339. -#define DPRC_CMDID_GET_IRQ_MASK 0x015
  6340. -#define DPRC_CMDID_GET_IRQ_STATUS 0x016
  6341. -#define DPRC_CMDID_CLEAR_IRQ_STATUS 0x017
  6342. -
  6343. -#define DPRC_CMDID_CREATE_CONT 0x151
  6344. -#define DPRC_CMDID_DESTROY_CONT 0x152
  6345. -#define DPRC_CMDID_SET_RES_QUOTA 0x155
  6346. -#define DPRC_CMDID_GET_RES_QUOTA 0x156
  6347. -#define DPRC_CMDID_ASSIGN 0x157
  6348. -#define DPRC_CMDID_UNASSIGN 0x158
  6349. -#define DPRC_CMDID_GET_OBJ_COUNT 0x159
  6350. -#define DPRC_CMDID_GET_OBJ 0x15A
  6351. -#define DPRC_CMDID_GET_RES_COUNT 0x15B
  6352. -#define DPRC_CMDID_GET_RES_IDS 0x15C
  6353. -#define DPRC_CMDID_GET_OBJ_REG 0x15E
  6354. -#define DPRC_CMDID_SET_OBJ_IRQ 0x15F
  6355. -#define DPRC_CMDID_GET_OBJ_IRQ 0x160
  6356. -#define DPRC_CMDID_SET_OBJ_LABEL 0x161
  6357. -#define DPRC_CMDID_GET_OBJ_DESC 0x162
  6358. -
  6359. -#define DPRC_CMDID_CONNECT 0x167
  6360. -#define DPRC_CMDID_DISCONNECT 0x168
  6361. -#define DPRC_CMDID_GET_POOL 0x169
  6362. -#define DPRC_CMDID_GET_POOL_COUNT 0x16A
  6363. +/* Command versioning */
  6364. +#define DPRC_CMD_BASE_VERSION 1
  6365. +#define DPRC_CMD_ID_OFFSET 4
  6366. -#define DPRC_CMDID_GET_CONNECTION 0x16C
  6367. +#define DPRC_CMD(id) ((id << DPRC_CMD_ID_OFFSET) | DPRC_CMD_BASE_VERSION)
  6368. +
  6369. +/* Command IDs */
  6370. +#define DPRC_CMDID_CLOSE DPRC_CMD(0x800)
  6371. +#define DPRC_CMDID_OPEN DPRC_CMD(0x805)
  6372. +#define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05)
  6373. +
  6374. +#define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004)
  6375. +#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005)
  6376. +
  6377. +#define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010)
  6378. +#define DPRC_CMDID_GET_IRQ DPRC_CMD(0x011)
  6379. +#define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012)
  6380. +#define DPRC_CMDID_GET_IRQ_ENABLE DPRC_CMD(0x013)
  6381. +#define DPRC_CMDID_SET_IRQ_MASK DPRC_CMD(0x014)
  6382. +#define DPRC_CMDID_GET_IRQ_MASK DPRC_CMD(0x015)
  6383. +#define DPRC_CMDID_GET_IRQ_STATUS DPRC_CMD(0x016)
  6384. +#define DPRC_CMDID_CLEAR_IRQ_STATUS DPRC_CMD(0x017)
  6385. +
  6386. +#define DPRC_CMDID_GET_CONT_ID DPRC_CMD(0x830)
  6387. +#define DPRC_CMDID_GET_OBJ_COUNT DPRC_CMD(0x159)
  6388. +#define DPRC_CMDID_GET_OBJ DPRC_CMD(0x15A)
  6389. +#define DPRC_CMDID_GET_RES_COUNT DPRC_CMD(0x15B)
  6390. +#define DPRC_CMDID_GET_OBJ_REG DPRC_CMD(0x15E)
  6391. +#define DPRC_CMDID_SET_OBJ_IRQ DPRC_CMD(0x15F)
  6392. +#define DPRC_CMDID_GET_OBJ_IRQ DPRC_CMD(0x160)
  6393. struct dprc_cmd_open {
  6394. __le32 container_id;
  6395. @@ -199,9 +189,6 @@ struct dprc_rsp_get_attributes {
  6396. /* response word 1 */
  6397. __le32 options;
  6398. __le32 portal_id;
  6399. - /* response word 2 */
  6400. - __le16 version_major;
  6401. - __le16 version_minor;
  6402. };
  6403. struct dprc_cmd_set_res_quota {
  6404. @@ -367,11 +354,16 @@ struct dprc_cmd_get_obj_region {
  6405. struct dprc_rsp_get_obj_region {
  6406. /* response word 0 */
  6407. - __le64 pad;
  6408. + __le64 pad0;
  6409. /* response word 1 */
  6410. - __le64 base_addr;
  6411. + __le32 base_addr;
  6412. + __le32 pad1;
  6413. /* response word 2 */
  6414. __le32 size;
  6415. + u8 type;
  6416. + u8 pad2[3];
  6417. + /* response word 3 */
  6418. + __le32 flags;
  6419. };
  6420. struct dprc_cmd_set_obj_label {
  6421. --- a/drivers/staging/fsl-mc/bus/dprc-driver.c
  6422. +++ b/drivers/staging/fsl-mc/bus/dprc-driver.c
  6423. @@ -1,7 +1,7 @@
  6424. /*
  6425. * Freescale data path resource container (DPRC) driver
  6426. *
  6427. - * Copyright (C) 2014 Freescale Semiconductor, Inc.
  6428. + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  6429. * Author: German Rivera <[email protected]>
  6430. *
  6431. * This file is licensed under the terms of the GNU General Public
  6432. @@ -160,6 +160,8 @@ static void check_plugged_state_change(s
  6433. * dprc_add_new_devices - Adds devices to the logical bus for a DPRC
  6434. *
  6435. * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
  6436. + * @driver_override: driver override to apply to new objects found in the
  6437. + * DPRC, or NULL, if none.
  6438. * @obj_desc_array: array of device descriptors for child devices currently
  6439. * present in the physical DPRC.
  6440. * @num_child_objects_in_mc: number of entries in obj_desc_array
  6441. @@ -169,6 +171,7 @@ static void check_plugged_state_change(s
  6442. * in the physical DPRC.
  6443. */
  6444. static void dprc_add_new_devices(struct fsl_mc_device *mc_bus_dev,
  6445. + const char *driver_override,
  6446. struct dprc_obj_desc *obj_desc_array,
  6447. int num_child_objects_in_mc)
  6448. {
  6449. @@ -188,11 +191,12 @@ static void dprc_add_new_devices(struct
  6450. child_dev = fsl_mc_device_lookup(obj_desc, mc_bus_dev);
  6451. if (child_dev) {
  6452. check_plugged_state_change(child_dev, obj_desc);
  6453. + put_device(&child_dev->dev);
  6454. continue;
  6455. }
  6456. error = fsl_mc_device_add(obj_desc, NULL, &mc_bus_dev->dev,
  6457. - &child_dev);
  6458. + driver_override, &child_dev);
  6459. if (error < 0)
  6460. continue;
  6461. }
  6462. @@ -202,6 +206,8 @@ static void dprc_add_new_devices(struct
  6463. * dprc_scan_objects - Discover objects in a DPRC
  6464. *
  6465. * @mc_bus_dev: pointer to the fsl-mc device that represents a DPRC object
  6466. + * @driver_override: driver override to apply to new objects found in the
  6467. + * DPRC, or NULL, if none.
  6468. * @total_irq_count: total number of IRQs needed by objects in the DPRC.
  6469. *
  6470. * Detects objects added and removed from a DPRC and synchronizes the
  6471. @@ -217,6 +223,7 @@ static void dprc_add_new_devices(struct
  6472. * of the device drivers for the non-allocatable devices.
  6473. */
  6474. int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
  6475. + const char *driver_override,
  6476. unsigned int *total_irq_count)
  6477. {
  6478. int num_child_objects;
  6479. @@ -297,7 +304,7 @@ int dprc_scan_objects(struct fsl_mc_devi
  6480. dprc_remove_devices(mc_bus_dev, child_obj_desc_array,
  6481. num_child_objects);
  6482. - dprc_add_new_devices(mc_bus_dev, child_obj_desc_array,
  6483. + dprc_add_new_devices(mc_bus_dev, driver_override, child_obj_desc_array,
  6484. num_child_objects);
  6485. if (child_obj_desc_array)
  6486. @@ -328,7 +335,7 @@ int dprc_scan_container(struct fsl_mc_de
  6487. * Discover objects in the DPRC:
  6488. */
  6489. mutex_lock(&mc_bus->scan_mutex);
  6490. - error = dprc_scan_objects(mc_bus_dev, &irq_count);
  6491. + error = dprc_scan_objects(mc_bus_dev, NULL, &irq_count);
  6492. mutex_unlock(&mc_bus->scan_mutex);
  6493. if (error < 0)
  6494. goto error;
  6495. @@ -415,7 +422,7 @@ static irqreturn_t dprc_irq0_handler_thr
  6496. DPRC_IRQ_EVENT_OBJ_CREATED)) {
  6497. unsigned int irq_count;
  6498. - error = dprc_scan_objects(mc_dev, &irq_count);
  6499. + error = dprc_scan_objects(mc_dev, NULL, &irq_count);
  6500. if (error < 0) {
  6501. /*
  6502. * If the error is -ENXIO, we ignore it, as it indicates
  6503. @@ -505,7 +512,7 @@ static int register_dprc_irq_handler(str
  6504. dprc_irq0_handler,
  6505. dprc_irq0_handler_thread,
  6506. IRQF_NO_SUSPEND | IRQF_ONESHOT,
  6507. - "FSL MC DPRC irq0",
  6508. + dev_name(&mc_dev->dev),
  6509. &mc_dev->dev);
  6510. if (error < 0) {
  6511. dev_err(&mc_dev->dev,
  6512. @@ -597,6 +604,7 @@ static int dprc_probe(struct fsl_mc_devi
  6513. struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
  6514. bool mc_io_created = false;
  6515. bool msi_domain_set = false;
  6516. + u16 major_ver, minor_ver;
  6517. if (WARN_ON(strcmp(mc_dev->obj_desc.type, "dprc") != 0))
  6518. return -EINVAL;
  6519. @@ -669,13 +677,21 @@ static int dprc_probe(struct fsl_mc_devi
  6520. goto error_cleanup_open;
  6521. }
  6522. - if (mc_bus->dprc_attr.version.major < DPRC_MIN_VER_MAJOR ||
  6523. - (mc_bus->dprc_attr.version.major == DPRC_MIN_VER_MAJOR &&
  6524. - mc_bus->dprc_attr.version.minor < DPRC_MIN_VER_MINOR)) {
  6525. + error = dprc_get_api_version(mc_dev->mc_io, 0,
  6526. + &major_ver,
  6527. + &minor_ver);
  6528. + if (error < 0) {
  6529. + dev_err(&mc_dev->dev, "dprc_get_api_version() failed: %d\n",
  6530. + error);
  6531. + goto error_cleanup_open;
  6532. + }
  6533. +
  6534. + if (major_ver < DPRC_MIN_VER_MAJOR ||
  6535. + (major_ver == DPRC_MIN_VER_MAJOR &&
  6536. + minor_ver < DPRC_MIN_VER_MINOR)) {
  6537. dev_err(&mc_dev->dev,
  6538. "ERROR: DPRC version %d.%d not supported\n",
  6539. - mc_bus->dprc_attr.version.major,
  6540. - mc_bus->dprc_attr.version.minor);
  6541. + major_ver, minor_ver);
  6542. error = -ENOTSUPP;
  6543. goto error_cleanup_open;
  6544. }
  6545. --- a/drivers/staging/fsl-mc/bus/dprc.c
  6546. +++ b/drivers/staging/fsl-mc/bus/dprc.c
  6547. @@ -1,4 +1,5 @@
  6548. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  6549. +/*
  6550. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  6551. *
  6552. * Redistribution and use in source and binary forms, with or without
  6553. * modification, are permitted provided that the following conditions are met:
  6554. @@ -11,7 +12,6 @@
  6555. * names of any contributors may be used to endorse or promote products
  6556. * derived from this software without specific prior written permission.
  6557. *
  6558. - *
  6559. * ALTERNATIVELY, this software may be distributed under the terms of the
  6560. * GNU General Public License ("GPL") as published by the Free Software
  6561. * Foundation, either version 2 of that License or (at your option) any
  6562. @@ -100,93 +100,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
  6563. EXPORT_SYMBOL(dprc_close);
  6564. /**
  6565. - * dprc_create_container() - Create child container
  6566. - * @mc_io: Pointer to MC portal's I/O object
  6567. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6568. - * @token: Token of DPRC object
  6569. - * @cfg: Child container configuration
  6570. - * @child_container_id: Returned child container ID
  6571. - * @child_portal_offset: Returned child portal offset from MC portal base
  6572. - *
  6573. - * Return: '0' on Success; Error code otherwise.
  6574. - */
  6575. -int dprc_create_container(struct fsl_mc_io *mc_io,
  6576. - u32 cmd_flags,
  6577. - u16 token,
  6578. - struct dprc_cfg *cfg,
  6579. - int *child_container_id,
  6580. - u64 *child_portal_offset)
  6581. -{
  6582. - struct mc_command cmd = { 0 };
  6583. - struct dprc_cmd_create_container *cmd_params;
  6584. - struct dprc_rsp_create_container *rsp_params;
  6585. - int err;
  6586. -
  6587. - /* prepare command */
  6588. - cmd_params = (struct dprc_cmd_create_container *)cmd.params;
  6589. - cmd_params->options = cpu_to_le32(cfg->options);
  6590. - cmd_params->icid = cpu_to_le16(cfg->icid);
  6591. - cmd_params->portal_id = cpu_to_le32(cfg->portal_id);
  6592. - strncpy(cmd_params->label, cfg->label, 16);
  6593. - cmd_params->label[15] = '\0';
  6594. -
  6595. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_CREATE_CONT,
  6596. - cmd_flags, token);
  6597. -
  6598. - /* send command to mc*/
  6599. - err = mc_send_command(mc_io, &cmd);
  6600. - if (err)
  6601. - return err;
  6602. -
  6603. - /* retrieve response parameters */
  6604. - rsp_params = (struct dprc_rsp_create_container *)cmd.params;
  6605. - *child_container_id = le32_to_cpu(rsp_params->child_container_id);
  6606. - *child_portal_offset = le64_to_cpu(rsp_params->child_portal_addr);
  6607. -
  6608. - return 0;
  6609. -}
  6610. -
  6611. -/**
  6612. - * dprc_destroy_container() - Destroy child container.
  6613. - * @mc_io: Pointer to MC portal's I/O object
  6614. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6615. - * @token: Token of DPRC object
  6616. - * @child_container_id: ID of the container to destroy
  6617. - *
  6618. - * This function terminates the child container, so following this call the
  6619. - * child container ID becomes invalid.
  6620. - *
  6621. - * Notes:
  6622. - * - All resources and objects of the destroyed container are returned to the
  6623. - * parent container or destroyed if were created be the destroyed container.
  6624. - * - This function destroy all the child containers of the specified
  6625. - * container prior to destroying the container itself.
  6626. - *
  6627. - * warning: Only the parent container is allowed to destroy a child policy
  6628. - * Container 0 can't be destroyed
  6629. - *
  6630. - * Return: '0' on Success; Error code otherwise.
  6631. - *
  6632. - */
  6633. -int dprc_destroy_container(struct fsl_mc_io *mc_io,
  6634. - u32 cmd_flags,
  6635. - u16 token,
  6636. - int child_container_id)
  6637. -{
  6638. - struct mc_command cmd = { 0 };
  6639. - struct dprc_cmd_destroy_container *cmd_params;
  6640. -
  6641. - /* prepare command */
  6642. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_DESTROY_CONT,
  6643. - cmd_flags, token);
  6644. - cmd_params = (struct dprc_cmd_destroy_container *)cmd.params;
  6645. - cmd_params->child_container_id = cpu_to_le32(child_container_id);
  6646. -
  6647. - /* send command to mc*/
  6648. - return mc_send_command(mc_io, &cmd);
  6649. -}
  6650. -
  6651. -/**
  6652. * dprc_reset_container - Reset child container.
  6653. * @mc_io: Pointer to MC portal's I/O object
  6654. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6655. @@ -565,279 +478,6 @@ int dprc_get_attributes(struct fsl_mc_io
  6656. attr->icid = le16_to_cpu(rsp_params->icid);
  6657. attr->options = le32_to_cpu(rsp_params->options);
  6658. attr->portal_id = le32_to_cpu(rsp_params->portal_id);
  6659. - attr->version.major = le16_to_cpu(rsp_params->version_major);
  6660. - attr->version.minor = le16_to_cpu(rsp_params->version_minor);
  6661. -
  6662. - return 0;
  6663. -}
  6664. -
  6665. -/**
  6666. - * dprc_set_res_quota() - Set allocation policy for a specific resource/object
  6667. - * type in a child container
  6668. - * @mc_io: Pointer to MC portal's I/O object
  6669. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6670. - * @token: Token of DPRC object
  6671. - * @child_container_id: ID of the child container
  6672. - * @type: Resource/object type
  6673. - * @quota: Sets the maximum number of resources of the selected type
  6674. - * that the child container is allowed to allocate from its parent;
  6675. - * when quota is set to -1, the policy is the same as container's
  6676. - * general policy.
  6677. - *
  6678. - * Allocation policy determines whether or not a container may allocate
  6679. - * resources from its parent. Each container has a 'global' allocation policy
  6680. - * that is set when the container is created.
  6681. - *
  6682. - * This function sets allocation policy for a specific resource type.
  6683. - * The default policy for all resource types matches the container's 'global'
  6684. - * allocation policy.
  6685. - *
  6686. - * Return: '0' on Success; Error code otherwise.
  6687. - *
  6688. - * @warning Only the parent container is allowed to change a child policy.
  6689. - */
  6690. -int dprc_set_res_quota(struct fsl_mc_io *mc_io,
  6691. - u32 cmd_flags,
  6692. - u16 token,
  6693. - int child_container_id,
  6694. - char *type,
  6695. - u16 quota)
  6696. -{
  6697. - struct mc_command cmd = { 0 };
  6698. - struct dprc_cmd_set_res_quota *cmd_params;
  6699. -
  6700. - /* prepare command */
  6701. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_RES_QUOTA,
  6702. - cmd_flags, token);
  6703. - cmd_params = (struct dprc_cmd_set_res_quota *)cmd.params;
  6704. - cmd_params->child_container_id = cpu_to_le32(child_container_id);
  6705. - cmd_params->quota = cpu_to_le16(quota);
  6706. - strncpy(cmd_params->type, type, 16);
  6707. - cmd_params->type[15] = '\0';
  6708. -
  6709. - /* send command to mc*/
  6710. - return mc_send_command(mc_io, &cmd);
  6711. -}
  6712. -
  6713. -/**
  6714. - * dprc_get_res_quota() - Gets the allocation policy of a specific
  6715. - * resource/object type in a child container
  6716. - * @mc_io: Pointer to MC portal's I/O object
  6717. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6718. - * @token: Token of DPRC object
  6719. - * @child_container_id; ID of the child container
  6720. - * @type: resource/object type
  6721. - * @quota: Returnes the maximum number of resources of the selected type
  6722. - * that the child container is allowed to allocate from the parent;
  6723. - * when quota is set to -1, the policy is the same as container's
  6724. - * general policy.
  6725. - *
  6726. - * Return: '0' on Success; Error code otherwise.
  6727. - */
  6728. -int dprc_get_res_quota(struct fsl_mc_io *mc_io,
  6729. - u32 cmd_flags,
  6730. - u16 token,
  6731. - int child_container_id,
  6732. - char *type,
  6733. - u16 *quota)
  6734. -{
  6735. - struct mc_command cmd = { 0 };
  6736. - struct dprc_cmd_get_res_quota *cmd_params;
  6737. - struct dprc_rsp_get_res_quota *rsp_params;
  6738. - int err;
  6739. -
  6740. - /* prepare command */
  6741. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_QUOTA,
  6742. - cmd_flags, token);
  6743. - cmd_params = (struct dprc_cmd_get_res_quota *)cmd.params;
  6744. - cmd_params->child_container_id = cpu_to_le32(child_container_id);
  6745. - strncpy(cmd_params->type, type, 16);
  6746. - cmd_params->type[15] = '\0';
  6747. -
  6748. - /* send command to mc*/
  6749. - err = mc_send_command(mc_io, &cmd);
  6750. - if (err)
  6751. - return err;
  6752. -
  6753. - /* retrieve response parameters */
  6754. - rsp_params = (struct dprc_rsp_get_res_quota *)cmd.params;
  6755. - *quota = le16_to_cpu(rsp_params->quota);
  6756. -
  6757. - return 0;
  6758. -}
  6759. -
  6760. -/**
  6761. - * dprc_assign() - Assigns objects or resource to a child container.
  6762. - * @mc_io: Pointer to MC portal's I/O object
  6763. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6764. - * @token: Token of DPRC object
  6765. - * @container_id: ID of the child container
  6766. - * @res_req: Describes the type and amount of resources to
  6767. - * assign to the given container
  6768. - *
  6769. - * Assignment is usually done by a parent (this DPRC) to one of its child
  6770. - * containers.
  6771. - *
  6772. - * According to the DPRC allocation policy, the assigned resources may be taken
  6773. - * (allocated) from the container's ancestors, if not enough resources are
  6774. - * available in the container itself.
  6775. - *
  6776. - * The type of assignment depends on the dprc_res_req options, as follows:
  6777. - * - DPRC_RES_REQ_OPT_EXPLICIT: indicates that assigned resources should have
  6778. - * the explicit base ID specified at the id_base_align field of res_req.
  6779. - * - DPRC_RES_REQ_OPT_ALIGNED: indicates that the assigned resources should be
  6780. - * aligned to the value given at id_base_align field of res_req.
  6781. - * - DPRC_RES_REQ_OPT_PLUGGED: Relevant only for object assignment,
  6782. - * and indicates that the object must be set to the plugged state.
  6783. - *
  6784. - * A container may use this function with its own ID in order to change a
  6785. - * object state to plugged or unplugged.
  6786. - *
  6787. - * If IRQ information has been set in the child DPRC, it will signal an
  6788. - * interrupt following every change in its object assignment.
  6789. - *
  6790. - * Return: '0' on Success; Error code otherwise.
  6791. - */
  6792. -int dprc_assign(struct fsl_mc_io *mc_io,
  6793. - u32 cmd_flags,
  6794. - u16 token,
  6795. - int container_id,
  6796. - struct dprc_res_req *res_req)
  6797. -{
  6798. - struct mc_command cmd = { 0 };
  6799. - struct dprc_cmd_assign *cmd_params;
  6800. -
  6801. - /* prepare command */
  6802. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_ASSIGN,
  6803. - cmd_flags, token);
  6804. - cmd_params = (struct dprc_cmd_assign *)cmd.params;
  6805. - cmd_params->container_id = cpu_to_le32(container_id);
  6806. - cmd_params->options = cpu_to_le32(res_req->options);
  6807. - cmd_params->num = cpu_to_le32(res_req->num);
  6808. - cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
  6809. - strncpy(cmd_params->type, res_req->type, 16);
  6810. - cmd_params->type[15] = '\0';
  6811. -
  6812. - /* send command to mc*/
  6813. - return mc_send_command(mc_io, &cmd);
  6814. -}
  6815. -
  6816. -/**
  6817. - * dprc_unassign() - Un-assigns objects or resources from a child container
  6818. - * and moves them into this (parent) DPRC.
  6819. - * @mc_io: Pointer to MC portal's I/O object
  6820. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6821. - * @token: Token of DPRC object
  6822. - * @child_container_id: ID of the child container
  6823. - * @res_req: Describes the type and amount of resources to un-assign from
  6824. - * the child container
  6825. - *
  6826. - * Un-assignment of objects can succeed only if the object is not in the
  6827. - * plugged or opened state.
  6828. - *
  6829. - * Return: '0' on Success; Error code otherwise.
  6830. - */
  6831. -int dprc_unassign(struct fsl_mc_io *mc_io,
  6832. - u32 cmd_flags,
  6833. - u16 token,
  6834. - int child_container_id,
  6835. - struct dprc_res_req *res_req)
  6836. -{
  6837. - struct mc_command cmd = { 0 };
  6838. - struct dprc_cmd_unassign *cmd_params;
  6839. -
  6840. - /* prepare command */
  6841. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_UNASSIGN,
  6842. - cmd_flags,
  6843. - token);
  6844. - cmd_params = (struct dprc_cmd_unassign *)cmd.params;
  6845. - cmd_params->child_container_id = cpu_to_le32(child_container_id);
  6846. - cmd_params->options = cpu_to_le32(res_req->options);
  6847. - cmd_params->num = cpu_to_le32(res_req->num);
  6848. - cmd_params->id_base_align = cpu_to_le32(res_req->id_base_align);
  6849. - strncpy(cmd_params->type, res_req->type, 16);
  6850. - cmd_params->type[15] = '\0';
  6851. -
  6852. - /* send command to mc*/
  6853. - return mc_send_command(mc_io, &cmd);
  6854. -}
  6855. -
  6856. -/**
  6857. - * dprc_get_pool_count() - Get the number of dprc's pools
  6858. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6859. - * @mc_io: Pointer to MC portal's I/O object
  6860. - * @token: Token of DPRC object
  6861. - * @pool_count: Returned number of resource pools in the dprc
  6862. - *
  6863. - * Return: '0' on Success; Error code otherwise.
  6864. - */
  6865. -int dprc_get_pool_count(struct fsl_mc_io *mc_io,
  6866. - u32 cmd_flags,
  6867. - u16 token,
  6868. - int *pool_count)
  6869. -{
  6870. - struct mc_command cmd = { 0 };
  6871. - struct dprc_rsp_get_pool_count *rsp_params;
  6872. - int err;
  6873. -
  6874. - /* prepare command */
  6875. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL_COUNT,
  6876. - cmd_flags, token);
  6877. -
  6878. - /* send command to mc*/
  6879. - err = mc_send_command(mc_io, &cmd);
  6880. - if (err)
  6881. - return err;
  6882. -
  6883. - /* retrieve response parameters */
  6884. - rsp_params = (struct dprc_rsp_get_pool_count *)cmd.params;
  6885. - *pool_count = le32_to_cpu(rsp_params->pool_count);
  6886. -
  6887. - return 0;
  6888. -}
  6889. -
  6890. -/**
  6891. - * dprc_get_pool() - Get the type (string) of a certain dprc's pool
  6892. - * @mc_io: Pointer to MC portal's I/O object
  6893. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6894. - * @token: Token of DPRC object
  6895. - * @pool_index; Index of the pool to be queried (< pool_count)
  6896. - * @type: The type of the pool
  6897. - *
  6898. - * The pool types retrieved one by one by incrementing
  6899. - * pool_index up to (not including) the value of pool_count returned
  6900. - * from dprc_get_pool_count(). dprc_get_pool_count() must
  6901. - * be called prior to dprc_get_pool().
  6902. - *
  6903. - * Return: '0' on Success; Error code otherwise.
  6904. - */
  6905. -int dprc_get_pool(struct fsl_mc_io *mc_io,
  6906. - u32 cmd_flags,
  6907. - u16 token,
  6908. - int pool_index,
  6909. - char *type)
  6910. -{
  6911. - struct mc_command cmd = { 0 };
  6912. - struct dprc_cmd_get_pool *cmd_params;
  6913. - struct dprc_rsp_get_pool *rsp_params;
  6914. - int err;
  6915. -
  6916. - /* prepare command */
  6917. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_POOL,
  6918. - cmd_flags,
  6919. - token);
  6920. - cmd_params = (struct dprc_cmd_get_pool *)cmd.params;
  6921. - cmd_params->pool_index = cpu_to_le32(pool_index);
  6922. -
  6923. - /* send command to mc*/
  6924. - err = mc_send_command(mc_io, &cmd);
  6925. - if (err)
  6926. - return err;
  6927. -
  6928. - /* retrieve response parameters */
  6929. - rsp_params = (struct dprc_rsp_get_pool *)cmd.params;
  6930. - strncpy(type, rsp_params->type, 16);
  6931. - type[15] = '\0';
  6932. return 0;
  6933. }
  6934. @@ -934,64 +574,6 @@ int dprc_get_obj(struct fsl_mc_io *mc_io
  6935. EXPORT_SYMBOL(dprc_get_obj);
  6936. /**
  6937. - * dprc_get_obj_desc() - Get object descriptor.
  6938. - *
  6939. - * @mc_io: Pointer to MC portal's I/O object
  6940. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6941. - * @token: Token of DPRC object
  6942. - * @obj_type: The type of the object to get its descriptor.
  6943. - * @obj_id: The id of the object to get its descriptor
  6944. - * @obj_desc: The returned descriptor to fill and return to the user
  6945. - *
  6946. - * Return: '0' on Success; Error code otherwise.
  6947. - *
  6948. - */
  6949. -int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
  6950. - u32 cmd_flags,
  6951. - u16 token,
  6952. - char *obj_type,
  6953. - int obj_id,
  6954. - struct dprc_obj_desc *obj_desc)
  6955. -{
  6956. - struct mc_command cmd = { 0 };
  6957. - struct dprc_cmd_get_obj_desc *cmd_params;
  6958. - struct dprc_rsp_get_obj_desc *rsp_params;
  6959. - int err;
  6960. -
  6961. - /* prepare command */
  6962. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_OBJ_DESC,
  6963. - cmd_flags,
  6964. - token);
  6965. - cmd_params = (struct dprc_cmd_get_obj_desc *)cmd.params;
  6966. - cmd_params->obj_id = cpu_to_le32(obj_id);
  6967. - strncpy(cmd_params->type, obj_type, 16);
  6968. - cmd_params->type[15] = '\0';
  6969. -
  6970. - /* send command to mc*/
  6971. - err = mc_send_command(mc_io, &cmd);
  6972. - if (err)
  6973. - return err;
  6974. -
  6975. - /* retrieve response parameters */
  6976. - rsp_params = (struct dprc_rsp_get_obj_desc *)cmd.params;
  6977. - obj_desc->id = le32_to_cpu(rsp_params->id);
  6978. - obj_desc->vendor = le16_to_cpu(rsp_params->vendor);
  6979. - obj_desc->irq_count = rsp_params->irq_count;
  6980. - obj_desc->region_count = rsp_params->region_count;
  6981. - obj_desc->state = le32_to_cpu(rsp_params->state);
  6982. - obj_desc->ver_major = le16_to_cpu(rsp_params->version_major);
  6983. - obj_desc->ver_minor = le16_to_cpu(rsp_params->version_minor);
  6984. - obj_desc->flags = le16_to_cpu(rsp_params->flags);
  6985. - strncpy(obj_desc->type, rsp_params->type, 16);
  6986. - obj_desc->type[15] = '\0';
  6987. - strncpy(obj_desc->label, rsp_params->label, 16);
  6988. - obj_desc->label[15] = '\0';
  6989. -
  6990. - return 0;
  6991. -}
  6992. -EXPORT_SYMBOL(dprc_get_obj_desc);
  6993. -
  6994. -/**
  6995. * dprc_set_obj_irq() - Set IRQ information for object to trigger an interrupt.
  6996. * @mc_io: Pointer to MC portal's I/O object
  6997. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  6998. @@ -1130,52 +712,6 @@ int dprc_get_res_count(struct fsl_mc_io
  6999. EXPORT_SYMBOL(dprc_get_res_count);
  7000. /**
  7001. - * dprc_get_res_ids() - Obtains IDs of free resources in the container
  7002. - * @mc_io: Pointer to MC portal's I/O object
  7003. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7004. - * @token: Token of DPRC object
  7005. - * @type: pool type
  7006. - * @range_desc: range descriptor
  7007. - *
  7008. - * Return: '0' on Success; Error code otherwise.
  7009. - */
  7010. -int dprc_get_res_ids(struct fsl_mc_io *mc_io,
  7011. - u32 cmd_flags,
  7012. - u16 token,
  7013. - char *type,
  7014. - struct dprc_res_ids_range_desc *range_desc)
  7015. -{
  7016. - struct mc_command cmd = { 0 };
  7017. - struct dprc_cmd_get_res_ids *cmd_params;
  7018. - struct dprc_rsp_get_res_ids *rsp_params;
  7019. - int err;
  7020. -
  7021. - /* prepare command */
  7022. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_RES_IDS,
  7023. - cmd_flags, token);
  7024. - cmd_params = (struct dprc_cmd_get_res_ids *)cmd.params;
  7025. - cmd_params->iter_status = range_desc->iter_status;
  7026. - cmd_params->base_id = cpu_to_le32(range_desc->base_id);
  7027. - cmd_params->last_id = cpu_to_le32(range_desc->last_id);
  7028. - strncpy(cmd_params->type, type, 16);
  7029. - cmd_params->type[15] = '\0';
  7030. -
  7031. - /* send command to mc*/
  7032. - err = mc_send_command(mc_io, &cmd);
  7033. - if (err)
  7034. - return err;
  7035. -
  7036. - /* retrieve response parameters */
  7037. - rsp_params = (struct dprc_rsp_get_res_ids *)cmd.params;
  7038. - range_desc->iter_status = rsp_params->iter_status;
  7039. - range_desc->base_id = le32_to_cpu(rsp_params->base_id);
  7040. - range_desc->last_id = le32_to_cpu(rsp_params->last_id);
  7041. -
  7042. - return 0;
  7043. -}
  7044. -EXPORT_SYMBOL(dprc_get_res_ids);
  7045. -
  7046. -/**
  7047. * dprc_get_obj_region() - Get region information for a specified object.
  7048. * @mc_io: Pointer to MC portal's I/O object
  7049. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7050. @@ -1216,160 +752,66 @@ int dprc_get_obj_region(struct fsl_mc_io
  7051. /* retrieve response parameters */
  7052. rsp_params = (struct dprc_rsp_get_obj_region *)cmd.params;
  7053. - region_desc->base_offset = le64_to_cpu(rsp_params->base_addr);
  7054. + region_desc->base_offset = le32_to_cpu(rsp_params->base_addr);
  7055. region_desc->size = le32_to_cpu(rsp_params->size);
  7056. + region_desc->type = rsp_params->type;
  7057. + region_desc->flags = le32_to_cpu(rsp_params->flags);
  7058. return 0;
  7059. }
  7060. EXPORT_SYMBOL(dprc_get_obj_region);
  7061. /**
  7062. - * dprc_set_obj_label() - Set object label.
  7063. - * @mc_io: Pointer to MC portal's I/O object
  7064. + * dprc_get_api_version - Get Data Path Resource Container API version
  7065. + * @mc_io: Pointer to Mc portal's I/O object
  7066. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7067. - * @token: Token of DPRC object
  7068. - * @obj_type: Object's type
  7069. - * @obj_id: Object's ID
  7070. - * @label: The required label. The maximum length is 16 chars.
  7071. + * @major_ver: Major version of Data Path Resource Container API
  7072. + * @minor_ver: Minor version of Data Path Resource Container API
  7073. *
  7074. * Return: '0' on Success; Error code otherwise.
  7075. */
  7076. -int dprc_set_obj_label(struct fsl_mc_io *mc_io,
  7077. - u32 cmd_flags,
  7078. - u16 token,
  7079. - char *obj_type,
  7080. - int obj_id,
  7081. - char *label)
  7082. +int dprc_get_api_version(struct fsl_mc_io *mc_io,
  7083. + u32 cmd_flags,
  7084. + u16 *major_ver,
  7085. + u16 *minor_ver)
  7086. {
  7087. struct mc_command cmd = { 0 };
  7088. - struct dprc_cmd_set_obj_label *cmd_params;
  7089. + int err;
  7090. /* prepare command */
  7091. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_SET_OBJ_LABEL,
  7092. - cmd_flags,
  7093. - token);
  7094. - cmd_params = (struct dprc_cmd_set_obj_label *)cmd.params;
  7095. - cmd_params->obj_id = cpu_to_le32(obj_id);
  7096. - strncpy(cmd_params->label, label, 16);
  7097. - cmd_params->label[15] = '\0';
  7098. - strncpy(cmd_params->obj_type, obj_type, 16);
  7099. - cmd_params->obj_type[15] = '\0';
  7100. + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_API_VERSION,
  7101. + cmd_flags, 0);
  7102. - /* send command to mc*/
  7103. - return mc_send_command(mc_io, &cmd);
  7104. -}
  7105. -EXPORT_SYMBOL(dprc_set_obj_label);
  7106. -
  7107. -/**
  7108. - * dprc_connect() - Connect two endpoints to create a network link between them
  7109. - * @mc_io: Pointer to MC portal's I/O object
  7110. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7111. - * @token: Token of DPRC object
  7112. - * @endpoint1: Endpoint 1 configuration parameters
  7113. - * @endpoint2: Endpoint 2 configuration parameters
  7114. - * @cfg: Connection configuration. The connection configuration is ignored for
  7115. - * connections made to DPMAC objects, where rate is retrieved from the
  7116. - * MAC configuration.
  7117. - *
  7118. - * Return: '0' on Success; Error code otherwise.
  7119. - */
  7120. -int dprc_connect(struct fsl_mc_io *mc_io,
  7121. - u32 cmd_flags,
  7122. - u16 token,
  7123. - const struct dprc_endpoint *endpoint1,
  7124. - const struct dprc_endpoint *endpoint2,
  7125. - const struct dprc_connection_cfg *cfg)
  7126. -{
  7127. - struct mc_command cmd = { 0 };
  7128. - struct dprc_cmd_connect *cmd_params;
  7129. + /* send command to mc */
  7130. + err = mc_send_command(mc_io, &cmd);
  7131. + if (err)
  7132. + return err;
  7133. - /* prepare command */
  7134. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_CONNECT,
  7135. - cmd_flags,
  7136. - token);
  7137. - cmd_params = (struct dprc_cmd_connect *)cmd.params;
  7138. - cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
  7139. - cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
  7140. - cmd_params->ep2_id = cpu_to_le32(endpoint2->id);
  7141. - cmd_params->ep2_interface_id = cpu_to_le32(endpoint2->if_id);
  7142. - strncpy(cmd_params->ep1_type, endpoint1->type, 16);
  7143. - cmd_params->ep1_type[15] = '\0';
  7144. - cmd_params->max_rate = cpu_to_le32(cfg->max_rate);
  7145. - cmd_params->committed_rate = cpu_to_le32(cfg->committed_rate);
  7146. - strncpy(cmd_params->ep2_type, endpoint2->type, 16);
  7147. - cmd_params->ep2_type[15] = '\0';
  7148. + /* retrieve response parameters */
  7149. + mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
  7150. - /* send command to mc*/
  7151. - return mc_send_command(mc_io, &cmd);
  7152. + return 0;
  7153. }
  7154. /**
  7155. - * dprc_disconnect() - Disconnect one endpoint to remove its network connection
  7156. - * @mc_io: Pointer to MC portal's I/O object
  7157. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7158. - * @token: Token of DPRC object
  7159. - * @endpoint: Endpoint configuration parameters
  7160. + * dprc_get_container_id - Get container ID associated with a given portal.
  7161. + * @mc_io: Pointer to Mc portal's I/O object
  7162. + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7163. + * @container_id: Requested container id
  7164. *
  7165. * Return: '0' on Success; Error code otherwise.
  7166. */
  7167. -int dprc_disconnect(struct fsl_mc_io *mc_io,
  7168. - u32 cmd_flags,
  7169. - u16 token,
  7170. - const struct dprc_endpoint *endpoint)
  7171. -{
  7172. - struct mc_command cmd = { 0 };
  7173. - struct dprc_cmd_disconnect *cmd_params;
  7174. -
  7175. - /* prepare command */
  7176. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_DISCONNECT,
  7177. - cmd_flags,
  7178. - token);
  7179. - cmd_params = (struct dprc_cmd_disconnect *)cmd.params;
  7180. - cmd_params->id = cpu_to_le32(endpoint->id);
  7181. - cmd_params->interface_id = cpu_to_le32(endpoint->if_id);
  7182. - strncpy(cmd_params->type, endpoint->type, 16);
  7183. - cmd_params->type[15] = '\0';
  7184. -
  7185. - /* send command to mc*/
  7186. - return mc_send_command(mc_io, &cmd);
  7187. -}
  7188. -
  7189. -/**
  7190. - * dprc_get_connection() - Get connected endpoint and link status if connection
  7191. - * exists.
  7192. - * @mc_io: Pointer to MC portal's I/O object
  7193. - * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  7194. - * @token: Token of DPRC object
  7195. - * @endpoint1: Endpoint 1 configuration parameters
  7196. - * @endpoint2: Returned endpoint 2 configuration parameters
  7197. - * @state: Returned link state:
  7198. - * 1 - link is up;
  7199. - * 0 - link is down;
  7200. - * -1 - no connection (endpoint2 information is irrelevant)
  7201. - *
  7202. - * Return: '0' on Success; -ENAVAIL if connection does not exist.
  7203. - */
  7204. -int dprc_get_connection(struct fsl_mc_io *mc_io,
  7205. - u32 cmd_flags,
  7206. - u16 token,
  7207. - const struct dprc_endpoint *endpoint1,
  7208. - struct dprc_endpoint *endpoint2,
  7209. - int *state)
  7210. +int dprc_get_container_id(struct fsl_mc_io *mc_io,
  7211. + u32 cmd_flags,
  7212. + int *container_id)
  7213. {
  7214. struct mc_command cmd = { 0 };
  7215. - struct dprc_cmd_get_connection *cmd_params;
  7216. - struct dprc_rsp_get_connection *rsp_params;
  7217. int err;
  7218. /* prepare command */
  7219. - cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONNECTION,
  7220. + cmd.header = mc_encode_cmd_header(DPRC_CMDID_GET_CONT_ID,
  7221. cmd_flags,
  7222. - token);
  7223. - cmd_params = (struct dprc_cmd_get_connection *)cmd.params;
  7224. - cmd_params->ep1_id = cpu_to_le32(endpoint1->id);
  7225. - cmd_params->ep1_interface_id = cpu_to_le32(endpoint1->if_id);
  7226. - strncpy(cmd_params->ep1_type, endpoint1->type, 16);
  7227. - cmd_params->ep1_type[15] = '\0';
  7228. + 0);
  7229. /* send command to mc*/
  7230. err = mc_send_command(mc_io, &cmd);
  7231. @@ -1377,12 +819,7 @@ int dprc_get_connection(struct fsl_mc_io
  7232. return err;
  7233. /* retrieve response parameters */
  7234. - rsp_params = (struct dprc_rsp_get_connection *)cmd.params;
  7235. - endpoint2->id = le32_to_cpu(rsp_params->ep2_id);
  7236. - endpoint2->if_id = le32_to_cpu(rsp_params->ep2_interface_id);
  7237. - strncpy(endpoint2->type, rsp_params->ep2_type, 16);
  7238. - endpoint2->type[15] = '\0';
  7239. - *state = le32_to_cpu(rsp_params->state);
  7240. + *container_id = (int)mc_cmd_read_object_id(&cmd);
  7241. return 0;
  7242. }
  7243. --- a/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
  7244. +++ b/drivers/staging/fsl-mc/bus/fsl-mc-allocator.c
  7245. @@ -1,7 +1,7 @@
  7246. /*
  7247. - * Freescale MC object device allocator driver
  7248. + * fsl-mc object allocator driver
  7249. *
  7250. - * Copyright (C) 2013 Freescale Semiconductor, Inc.
  7251. + * Copyright (C) 2013-2016 Freescale Semiconductor, Inc.
  7252. *
  7253. * This file is licensed under the terms of the GNU General Public
  7254. * License version 2. This program is licensed "as is" without any
  7255. @@ -12,9 +12,9 @@
  7256. #include <linux/msi.h>
  7257. #include "../include/mc-bus.h"
  7258. #include "../include/mc-sys.h"
  7259. -#include "../include/dpbp-cmd.h"
  7260. -#include "../include/dpcon-cmd.h"
  7261. +#include "dpbp-cmd.h"
  7262. +#include "dpcon-cmd.h"
  7263. #include "fsl-mc-private.h"
  7264. #define FSL_MC_IS_ALLOCATABLE(_obj_type) \
  7265. @@ -23,15 +23,12 @@
  7266. strcmp(_obj_type, "dpcon") == 0)
  7267. /**
  7268. - * fsl_mc_resource_pool_add_device - add allocatable device to a resource
  7269. - * pool of a given MC bus
  7270. + * fsl_mc_resource_pool_add_device - add allocatable object to a resource
  7271. + * pool of a given fsl-mc bus
  7272. *
  7273. - * @mc_bus: pointer to the MC bus
  7274. - * @pool_type: MC bus pool type
  7275. - * @mc_dev: Pointer to allocatable MC object device
  7276. - *
  7277. - * It adds an allocatable MC object device to a container's resource pool of
  7278. - * the given resource type
  7279. + * @mc_bus: pointer to the fsl-mc bus
  7280. + * @pool_type: pool type
  7281. + * @mc_dev: pointer to allocatable fsl-mc device
  7282. */
  7283. static int __must_check fsl_mc_resource_pool_add_device(struct fsl_mc_bus
  7284. *mc_bus,
  7285. @@ -95,10 +92,10 @@ out:
  7286. * fsl_mc_resource_pool_remove_device - remove an allocatable device from a
  7287. * resource pool
  7288. *
  7289. - * @mc_dev: Pointer to allocatable MC object device
  7290. + * @mc_dev: pointer to allocatable fsl-mc device
  7291. *
  7292. - * It permanently removes an allocatable MC object device from the resource
  7293. - * pool, the device is currently in, as long as it is in the pool's free list.
  7294. + * It permanently removes an allocatable fsl-mc device from the resource
  7295. + * pool. It's an error if the device is in use.
  7296. */
  7297. static int __must_check fsl_mc_resource_pool_remove_device(struct fsl_mc_device
  7298. *mc_dev)
  7299. @@ -255,17 +252,18 @@ out_unlock:
  7300. EXPORT_SYMBOL_GPL(fsl_mc_resource_free);
  7301. /**
  7302. - * fsl_mc_object_allocate - Allocates a MC object device of the given
  7303. - * pool type from a given MC bus
  7304. + * fsl_mc_object_allocate - Allocates an fsl-mc object of the given
  7305. + * pool type from a given fsl-mc bus instance
  7306. *
  7307. - * @mc_dev: MC device for which the MC object device is to be allocated
  7308. - * @pool_type: MC bus resource pool type
  7309. - * @new_mc_dev: Pointer to area where the pointer to the allocated
  7310. - * MC object device is to be returned
  7311. + * @mc_dev: fsl-mc device which is used in conjunction with the
  7312. + * allocated object
  7313. + * @pool_type: pool type
  7314. + * @new_mc_dev: pointer to area where the pointer to the allocated device
  7315. + * is to be returned
  7316. *
  7317. - * This function allocates a MC object device from the device's parent DPRC,
  7318. - * from the corresponding MC bus' pool of allocatable MC object devices of
  7319. - * the given resource type. mc_dev cannot be a DPRC itself.
  7320. + * Allocatable objects are always used in conjunction with some functional
  7321. + * device. This function allocates an object of the specified type from
  7322. + * the DPRC containing the functional device.
  7323. *
  7324. * NOTE: pool_type must be different from FSL_MC_POOL_MCP, since MC
  7325. * portals are allocated using fsl_mc_portal_allocate(), instead of
  7326. @@ -312,10 +310,9 @@ error:
  7327. EXPORT_SYMBOL_GPL(fsl_mc_object_allocate);
  7328. /**
  7329. - * fsl_mc_object_free - Returns an allocatable MC object device to the
  7330. - * corresponding resource pool of a given MC bus.
  7331. - *
  7332. - * @mc_adev: Pointer to the MC object device
  7333. + * fsl_mc_object_free - Returns an fsl-mc object to the resource
  7334. + * pool where it came from.
  7335. + * @mc_adev: Pointer to the fsl-mc device
  7336. */
  7337. void fsl_mc_object_free(struct fsl_mc_device *mc_adev)
  7338. {
  7339. @@ -332,8 +329,14 @@ void fsl_mc_object_free(struct fsl_mc_de
  7340. EXPORT_SYMBOL_GPL(fsl_mc_object_free);
  7341. /*
  7342. - * Initialize the interrupt pool associated with a MC bus.
  7343. - * It allocates a block of IRQs from the GIC-ITS
  7344. + * A DPRC and the devices in the DPRC all share the same GIC-ITS device
  7345. + * ID. A block of IRQs is pre-allocated and maintained in a pool
  7346. + * from which devices can allocate them when needed.
  7347. + */
  7348. +
  7349. +/*
  7350. + * Initialize the interrupt pool associated with an fsl-mc bus.
  7351. + * It allocates a block of IRQs from the GIC-ITS.
  7352. */
  7353. int fsl_mc_populate_irq_pool(struct fsl_mc_bus *mc_bus,
  7354. unsigned int irq_count)
  7355. @@ -395,7 +398,7 @@ cleanup_msi_irqs:
  7356. EXPORT_SYMBOL_GPL(fsl_mc_populate_irq_pool);
  7357. /**
  7358. - * Teardown the interrupt pool associated with an MC bus.
  7359. + * Teardown the interrupt pool associated with an fsl-mc bus.
  7360. * It frees the IRQs that were allocated to the pool, back to the GIC-ITS.
  7361. */
  7362. void fsl_mc_cleanup_irq_pool(struct fsl_mc_bus *mc_bus)
  7363. @@ -422,11 +425,7 @@ void fsl_mc_cleanup_irq_pool(struct fsl_
  7364. EXPORT_SYMBOL_GPL(fsl_mc_cleanup_irq_pool);
  7365. /**
  7366. - * It allocates the IRQs required by a given MC object device. The
  7367. - * IRQs are allocated from the interrupt pool associated with the
  7368. - * MC bus that contains the device, if the device is not a DPRC device.
  7369. - * Otherwise, the IRQs are allocated from the interrupt pool associated
  7370. - * with the MC bus that represents the DPRC device itself.
  7371. + * Allocate the IRQs required by a given fsl-mc device.
  7372. */
  7373. int __must_check fsl_mc_allocate_irqs(struct fsl_mc_device *mc_dev)
  7374. {
  7375. @@ -495,8 +494,7 @@ error_resource_alloc:
  7376. EXPORT_SYMBOL_GPL(fsl_mc_allocate_irqs);
  7377. /*
  7378. - * It frees the IRQs that were allocated for a MC object device, by
  7379. - * returning them to the corresponding interrupt pool.
  7380. + * Frees the IRQs that were allocated for an fsl-mc device.
  7381. */
  7382. void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev)
  7383. {
  7384. @@ -605,7 +603,7 @@ static int fsl_mc_allocator_probe(struct
  7385. return error;
  7386. dev_dbg(&mc_dev->dev,
  7387. - "Allocatable MC object device bound to fsl_mc_allocator driver");
  7388. + "Allocatable fsl-mc device bound to fsl_mc_allocator driver");
  7389. return 0;
  7390. }
  7391. @@ -627,7 +625,7 @@ static int fsl_mc_allocator_remove(struc
  7392. }
  7393. dev_dbg(&mc_dev->dev,
  7394. - "Allocatable MC object device unbound from fsl_mc_allocator driver");
  7395. + "Allocatable fsl-mc device unbound from fsl_mc_allocator driver");
  7396. return 0;
  7397. }
  7398. --- a/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
  7399. +++ b/drivers/staging/fsl-mc/bus/fsl-mc-bus.c
  7400. @@ -1,7 +1,7 @@
  7401. /*
  7402. * Freescale Management Complex (MC) bus driver
  7403. *
  7404. - * Copyright (C) 2014 Freescale Semiconductor, Inc.
  7405. + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  7406. * Author: German Rivera <[email protected]>
  7407. *
  7408. * This file is licensed under the terms of the GNU General Public
  7409. @@ -9,6 +9,8 @@
  7410. * warranty of any kind, whether express or implied.
  7411. */
  7412. +#define pr_fmt(fmt) "fsl-mc: " fmt
  7413. +
  7414. #include <linux/module.h>
  7415. #include <linux/of_device.h>
  7416. #include <linux/of_address.h>
  7417. @@ -25,8 +27,6 @@
  7418. #include "fsl-mc-private.h"
  7419. #include "dprc-cmd.h"
  7420. -static struct kmem_cache *mc_dev_cache;
  7421. -
  7422. /**
  7423. * Default DMA mask for devices on a fsl-mc bus
  7424. */
  7425. @@ -34,7 +34,7 @@ static struct kmem_cache *mc_dev_cache;
  7426. /**
  7427. * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
  7428. - * @root_mc_bus_dev: MC object device representing the root DPRC
  7429. + * @root_mc_bus_dev: fsl-mc device representing the root DPRC
  7430. * @num_translation_ranges: number of entries in addr_translation_ranges
  7431. * @translation_ranges: array of bus to system address translation ranges
  7432. */
  7433. @@ -62,8 +62,8 @@ struct fsl_mc_addr_translation_range {
  7434. /**
  7435. * fsl_mc_bus_match - device to driver matching callback
  7436. - * @dev: the MC object device structure to match against
  7437. - * @drv: the device driver to search for matching MC object device id
  7438. + * @dev: the fsl-mc device to match against
  7439. + * @drv: the device driver to search for matching fsl-mc object type
  7440. * structures
  7441. *
  7442. * Returns 1 on success, 0 otherwise.
  7443. @@ -75,8 +75,11 @@ static int fsl_mc_bus_match(struct devic
  7444. struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv);
  7445. bool found = false;
  7446. - if (WARN_ON(!fsl_mc_bus_exists()))
  7447. + /* When driver_override is set, only bind to the matching driver */
  7448. + if (mc_dev->driver_override) {
  7449. + found = !strcmp(mc_dev->driver_override, mc_drv->driver.name);
  7450. goto out;
  7451. + }
  7452. if (!mc_drv->match_id_table)
  7453. goto out;
  7454. @@ -91,7 +94,7 @@ static int fsl_mc_bus_match(struct devic
  7455. /*
  7456. * Traverse the match_id table of the given driver, trying to find
  7457. - * a matching for the given MC object device.
  7458. + * a matching for the given device.
  7459. */
  7460. for (id = mc_drv->match_id_table; id->vendor != 0x0; id++) {
  7461. if (id->vendor == mc_dev->obj_desc.vendor &&
  7462. @@ -132,23 +135,141 @@ static ssize_t modalias_show(struct devi
  7463. }
  7464. static DEVICE_ATTR_RO(modalias);
  7465. +static ssize_t rescan_store(struct device *dev,
  7466. + struct device_attribute *attr,
  7467. + const char *buf, size_t count)
  7468. +{
  7469. + unsigned long val;
  7470. + unsigned int irq_count;
  7471. + struct fsl_mc_device *root_mc_dev;
  7472. + struct fsl_mc_bus *root_mc_bus;
  7473. +
  7474. + if (!fsl_mc_is_root_dprc(dev))
  7475. + return -EINVAL;
  7476. +
  7477. + root_mc_dev = to_fsl_mc_device(dev);
  7478. + root_mc_bus = to_fsl_mc_bus(root_mc_dev);
  7479. +
  7480. + if (kstrtoul(buf, 0, &val) < 0)
  7481. + return -EINVAL;
  7482. +
  7483. + if (val) {
  7484. + mutex_lock(&root_mc_bus->scan_mutex);
  7485. + dprc_scan_objects(root_mc_dev, NULL, &irq_count);
  7486. + mutex_unlock(&root_mc_bus->scan_mutex);
  7487. + }
  7488. +
  7489. + return count;
  7490. +}
  7491. +static DEVICE_ATTR_WO(rescan);
  7492. +
  7493. +static ssize_t driver_override_store(struct device *dev,
  7494. + struct device_attribute *attr,
  7495. + const char *buf, size_t count)
  7496. +{
  7497. + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
  7498. + const char *driver_override, *old = mc_dev->driver_override;
  7499. + char *cp;
  7500. +
  7501. + if (WARN_ON(dev->bus != &fsl_mc_bus_type))
  7502. + return -EINVAL;
  7503. +
  7504. + if (count >= (PAGE_SIZE - 1))
  7505. + return -EINVAL;
  7506. +
  7507. + driver_override = kstrndup(buf, count, GFP_KERNEL);
  7508. + if (!driver_override)
  7509. + return -ENOMEM;
  7510. +
  7511. + cp = strchr(driver_override, '\n');
  7512. + if (cp)
  7513. + *cp = '\0';
  7514. +
  7515. + if (strlen(driver_override)) {
  7516. + mc_dev->driver_override = driver_override;
  7517. + } else {
  7518. + kfree(driver_override);
  7519. + mc_dev->driver_override = NULL;
  7520. + }
  7521. +
  7522. + kfree(old);
  7523. +
  7524. + return count;
  7525. +}
  7526. +
  7527. +static ssize_t driver_override_show(struct device *dev,
  7528. + struct device_attribute *attr, char *buf)
  7529. +{
  7530. + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
  7531. +
  7532. + return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override);
  7533. +}
  7534. +static DEVICE_ATTR_RW(driver_override);
  7535. +
  7536. static struct attribute *fsl_mc_dev_attrs[] = {
  7537. &dev_attr_modalias.attr,
  7538. + &dev_attr_rescan.attr,
  7539. + &dev_attr_driver_override.attr,
  7540. NULL,
  7541. };
  7542. ATTRIBUTE_GROUPS(fsl_mc_dev);
  7543. +static int scan_fsl_mc_bus(struct device *dev, void *data)
  7544. +{
  7545. + unsigned int irq_count;
  7546. + struct fsl_mc_device *root_mc_dev;
  7547. + struct fsl_mc_bus *root_mc_bus;
  7548. +
  7549. + if (fsl_mc_is_root_dprc(dev)) {
  7550. + root_mc_dev = to_fsl_mc_device(dev);
  7551. + root_mc_bus = to_fsl_mc_bus(root_mc_dev);
  7552. + mutex_lock(&root_mc_bus->scan_mutex);
  7553. + dprc_scan_objects(root_mc_dev, NULL, &irq_count);
  7554. + mutex_unlock(&root_mc_bus->scan_mutex);
  7555. + }
  7556. +
  7557. + return 0;
  7558. +}
  7559. +
  7560. +static ssize_t bus_rescan_store(struct bus_type *bus,
  7561. + const char *buf, size_t count)
  7562. +{
  7563. + unsigned long val;
  7564. +
  7565. + if (kstrtoul(buf, 0, &val) < 0)
  7566. + return -EINVAL;
  7567. +
  7568. + if (val)
  7569. + bus_for_each_dev(bus, NULL, NULL, scan_fsl_mc_bus);
  7570. +
  7571. + return count;
  7572. +}
  7573. +static BUS_ATTR(rescan, (S_IWUSR | S_IWGRP), NULL, bus_rescan_store);
  7574. +
  7575. +static struct attribute *fsl_mc_bus_attrs[] = {
  7576. + &bus_attr_rescan.attr,
  7577. + NULL,
  7578. +};
  7579. +
  7580. +static const struct attribute_group fsl_mc_bus_group = {
  7581. + .attrs = fsl_mc_bus_attrs,
  7582. +};
  7583. +
  7584. +static const struct attribute_group *fsl_mc_bus_groups[] = {
  7585. + &fsl_mc_bus_group,
  7586. + NULL,
  7587. +};
  7588. +
  7589. struct bus_type fsl_mc_bus_type = {
  7590. .name = "fsl-mc",
  7591. .match = fsl_mc_bus_match,
  7592. .uevent = fsl_mc_bus_uevent,
  7593. .dev_groups = fsl_mc_dev_groups,
  7594. + .bus_groups = fsl_mc_bus_groups,
  7595. };
  7596. EXPORT_SYMBOL_GPL(fsl_mc_bus_type);
  7597. -static atomic_t root_dprc_count = ATOMIC_INIT(0);
  7598. -
  7599. static int fsl_mc_driver_probe(struct device *dev)
  7600. {
  7601. struct fsl_mc_driver *mc_drv;
  7602. @@ -164,8 +285,7 @@ static int fsl_mc_driver_probe(struct de
  7603. error = mc_drv->probe(mc_dev);
  7604. if (error < 0) {
  7605. - dev_err(dev, "MC object device probe callback failed: %d\n",
  7606. - error);
  7607. + dev_err(dev, "%s failed: %d\n", __func__, error);
  7608. return error;
  7609. }
  7610. @@ -183,9 +303,7 @@ static int fsl_mc_driver_remove(struct d
  7611. error = mc_drv->remove(mc_dev);
  7612. if (error < 0) {
  7613. - dev_err(dev,
  7614. - "MC object device remove callback failed: %d\n",
  7615. - error);
  7616. + dev_err(dev, "%s failed: %d\n", __func__, error);
  7617. return error;
  7618. }
  7619. @@ -232,8 +350,6 @@ int __fsl_mc_driver_register(struct fsl_
  7620. return error;
  7621. }
  7622. - pr_info("MC object device driver %s registered\n",
  7623. - mc_driver->driver.name);
  7624. return 0;
  7625. }
  7626. EXPORT_SYMBOL_GPL(__fsl_mc_driver_register);
  7627. @@ -249,15 +365,6 @@ void fsl_mc_driver_unregister(struct fsl
  7628. EXPORT_SYMBOL_GPL(fsl_mc_driver_unregister);
  7629. /**
  7630. - * fsl_mc_bus_exists - check if a root dprc exists
  7631. - */
  7632. -bool fsl_mc_bus_exists(void)
  7633. -{
  7634. - return atomic_read(&root_dprc_count) > 0;
  7635. -}
  7636. -EXPORT_SYMBOL_GPL(fsl_mc_bus_exists);
  7637. -
  7638. -/**
  7639. * fsl_mc_get_root_dprc - function to traverse to the root dprc
  7640. */
  7641. void fsl_mc_get_root_dprc(struct device *dev,
  7642. @@ -315,21 +422,6 @@ static int get_dprc_icid(struct fsl_mc_i
  7643. return error;
  7644. }
  7645. -static int get_dprc_version(struct fsl_mc_io *mc_io,
  7646. - int container_id, u16 *major, u16 *minor)
  7647. -{
  7648. - struct dprc_attributes attr;
  7649. - int error;
  7650. -
  7651. - error = get_dprc_attr(mc_io, container_id, &attr);
  7652. - if (error == 0) {
  7653. - *major = attr.version.major;
  7654. - *minor = attr.version.minor;
  7655. - }
  7656. -
  7657. - return error;
  7658. -}
  7659. -
  7660. static int translate_mc_addr(struct fsl_mc_device *mc_dev,
  7661. enum dprc_region_type mc_region_type,
  7662. u64 mc_offset, phys_addr_t *phys_addr)
  7663. @@ -451,18 +543,37 @@ bool fsl_mc_is_root_dprc(struct device *
  7664. return dev == root_dprc_dev;
  7665. }
  7666. +static void fsl_mc_device_release(struct device *dev)
  7667. +{
  7668. + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
  7669. + struct fsl_mc_bus *mc_bus = NULL;
  7670. +
  7671. + kfree(mc_dev->regions);
  7672. +
  7673. + if (strcmp(mc_dev->obj_desc.type, "dprc") == 0)
  7674. + mc_bus = to_fsl_mc_bus(mc_dev);
  7675. +
  7676. + if (mc_bus)
  7677. + kfree(mc_bus);
  7678. + else
  7679. + kfree(mc_dev);
  7680. +}
  7681. +
  7682. /**
  7683. - * Add a newly discovered MC object device to be visible in Linux
  7684. + * Add a newly discovered fsl-mc device to be visible in Linux
  7685. */
  7686. int fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
  7687. struct fsl_mc_io *mc_io,
  7688. struct device *parent_dev,
  7689. + const char *driver_override,
  7690. struct fsl_mc_device **new_mc_dev)
  7691. {
  7692. int error;
  7693. struct fsl_mc_device *mc_dev = NULL;
  7694. struct fsl_mc_bus *mc_bus = NULL;
  7695. struct fsl_mc_device *parent_mc_dev;
  7696. + struct device *fsl_mc_platform_dev;
  7697. + struct device_node *fsl_mc_platform_node;
  7698. if (dev_is_fsl_mc(parent_dev))
  7699. parent_mc_dev = to_fsl_mc_device(parent_dev);
  7700. @@ -473,7 +584,7 @@ int fsl_mc_device_add(struct dprc_obj_de
  7701. /*
  7702. * Allocate an MC bus device object:
  7703. */
  7704. - mc_bus = devm_kzalloc(parent_dev, sizeof(*mc_bus), GFP_KERNEL);
  7705. + mc_bus = kzalloc(sizeof(*mc_bus), GFP_KERNEL);
  7706. if (!mc_bus)
  7707. return -ENOMEM;
  7708. @@ -482,16 +593,30 @@ int fsl_mc_device_add(struct dprc_obj_de
  7709. /*
  7710. * Allocate a regular fsl_mc_device object:
  7711. */
  7712. - mc_dev = kmem_cache_zalloc(mc_dev_cache, GFP_KERNEL);
  7713. + mc_dev = kzalloc(sizeof(*mc_dev), GFP_KERNEL);
  7714. if (!mc_dev)
  7715. return -ENOMEM;
  7716. }
  7717. mc_dev->obj_desc = *obj_desc;
  7718. mc_dev->mc_io = mc_io;
  7719. +
  7720. + if (driver_override) {
  7721. + /*
  7722. + * We trust driver_override, so we don't need to use
  7723. + * kstrndup() here
  7724. + */
  7725. + mc_dev->driver_override = kstrdup(driver_override, GFP_KERNEL);
  7726. + if (!mc_dev->driver_override) {
  7727. + error = -ENOMEM;
  7728. + goto error_cleanup_dev;
  7729. + }
  7730. + }
  7731. +
  7732. device_initialize(&mc_dev->dev);
  7733. mc_dev->dev.parent = parent_dev;
  7734. mc_dev->dev.bus = &fsl_mc_bus_type;
  7735. + mc_dev->dev.release = fsl_mc_device_release;
  7736. dev_set_name(&mc_dev->dev, "%s.%d", obj_desc->type, obj_desc->id);
  7737. if (strcmp(obj_desc->type, "dprc") == 0) {
  7738. @@ -524,8 +649,6 @@ int fsl_mc_device_add(struct dprc_obj_de
  7739. }
  7740. mc_io2 = mc_io;
  7741. -
  7742. - atomic_inc(&root_dprc_count);
  7743. }
  7744. error = get_dprc_icid(mc_io2, obj_desc->id, &mc_dev->icid);
  7745. @@ -533,8 +656,8 @@ int fsl_mc_device_add(struct dprc_obj_de
  7746. goto error_cleanup_dev;
  7747. } else {
  7748. /*
  7749. - * A non-DPRC MC object device has to be a child of another
  7750. - * MC object (specifically a DPRC object)
  7751. + * A non-DPRC object has to be a child of a DPRC, use the
  7752. + * parent's ICID and interrupt domain.
  7753. */
  7754. mc_dev->icid = parent_mc_dev->icid;
  7755. mc_dev->dma_mask = FSL_MC_DEFAULT_DMA_MASK;
  7756. @@ -556,9 +679,14 @@ int fsl_mc_device_add(struct dprc_obj_de
  7757. goto error_cleanup_dev;
  7758. }
  7759. - /* Objects are coherent, unless 'no shareability' flag set. */
  7760. - if (!(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY))
  7761. - arch_setup_dma_ops(&mc_dev->dev, 0, 0, NULL, true);
  7762. + fsl_mc_platform_dev = &mc_dev->dev;
  7763. + while (dev_is_fsl_mc(fsl_mc_platform_dev))
  7764. + fsl_mc_platform_dev = fsl_mc_platform_dev->parent;
  7765. + fsl_mc_platform_node = fsl_mc_platform_dev->of_node;
  7766. +
  7767. + /* Set up the iommu configuration for the devices. */
  7768. + fsl_mc_dma_configure(mc_dev, fsl_mc_platform_node,
  7769. + !(obj_desc->flags & DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY));
  7770. /*
  7771. * The device-specific probe callback will get invoked by device_add()
  7772. @@ -571,9 +699,7 @@ int fsl_mc_device_add(struct dprc_obj_de
  7773. goto error_cleanup_dev;
  7774. }
  7775. - (void)get_device(&mc_dev->dev);
  7776. - dev_dbg(parent_dev, "Added MC object device %s\n",
  7777. - dev_name(&mc_dev->dev));
  7778. + dev_dbg(parent_dev, "added %s\n", dev_name(&mc_dev->dev));
  7779. *new_mc_dev = mc_dev;
  7780. return 0;
  7781. @@ -581,47 +707,34 @@ int fsl_mc_device_add(struct dprc_obj_de
  7782. error_cleanup_dev:
  7783. kfree(mc_dev->regions);
  7784. if (mc_bus)
  7785. - devm_kfree(parent_dev, mc_bus);
  7786. + kfree(mc_bus);
  7787. else
  7788. - kmem_cache_free(mc_dev_cache, mc_dev);
  7789. + kfree(mc_dev);
  7790. return error;
  7791. }
  7792. EXPORT_SYMBOL_GPL(fsl_mc_device_add);
  7793. /**
  7794. - * fsl_mc_device_remove - Remove a MC object device from being visible to
  7795. + * fsl_mc_device_remove - Remove an fsl-mc device from being visible to
  7796. * Linux
  7797. *
  7798. - * @mc_dev: Pointer to a MC object device object
  7799. + * @mc_dev: Pointer to an fsl-mc device
  7800. */
  7801. void fsl_mc_device_remove(struct fsl_mc_device *mc_dev)
  7802. {
  7803. - struct fsl_mc_bus *mc_bus = NULL;
  7804. -
  7805. - kfree(mc_dev->regions);
  7806. + kfree(mc_dev->driver_override);
  7807. + mc_dev->driver_override = NULL;
  7808. /*
  7809. * The device-specific remove callback will get invoked by device_del()
  7810. */
  7811. device_del(&mc_dev->dev);
  7812. - put_device(&mc_dev->dev);
  7813. - if (strcmp(mc_dev->obj_desc.type, "dprc") == 0) {
  7814. - mc_bus = to_fsl_mc_bus(mc_dev);
  7815. -
  7816. - if (fsl_mc_is_root_dprc(&mc_dev->dev)) {
  7817. - if (atomic_read(&root_dprc_count) > 0)
  7818. - atomic_dec(&root_dprc_count);
  7819. - else
  7820. - WARN_ON(1);
  7821. - }
  7822. - }
  7823. + if (strcmp(mc_dev->obj_desc.type, "dprc") != 0)
  7824. + mc_dev->dev.iommu_fwspec = NULL;
  7825. - if (mc_bus)
  7826. - devm_kfree(mc_dev->dev.parent, mc_bus);
  7827. - else
  7828. - kmem_cache_free(mc_dev_cache, mc_dev);
  7829. + put_device(&mc_dev->dev);
  7830. }
  7831. EXPORT_SYMBOL_GPL(fsl_mc_device_remove);
  7832. @@ -629,8 +742,7 @@ static int parse_mc_ranges(struct device
  7833. int *paddr_cells,
  7834. int *mc_addr_cells,
  7835. int *mc_size_cells,
  7836. - const __be32 **ranges_start,
  7837. - u8 *num_ranges)
  7838. + const __be32 **ranges_start)
  7839. {
  7840. const __be32 *prop;
  7841. int range_tuple_cell_count;
  7842. @@ -643,8 +755,6 @@ static int parse_mc_ranges(struct device
  7843. dev_warn(dev,
  7844. "missing or empty ranges property for device tree node '%s'\n",
  7845. mc_node->name);
  7846. -
  7847. - *num_ranges = 0;
  7848. return 0;
  7849. }
  7850. @@ -671,8 +781,7 @@ static int parse_mc_ranges(struct device
  7851. return -EINVAL;
  7852. }
  7853. - *num_ranges = ranges_len / tuple_len;
  7854. - return 0;
  7855. + return ranges_len / tuple_len;
  7856. }
  7857. static int get_mc_addr_translation_ranges(struct device *dev,
  7858. @@ -680,7 +789,7 @@ static int get_mc_addr_translation_range
  7859. **ranges,
  7860. u8 *num_ranges)
  7861. {
  7862. - int error;
  7863. + int ret;
  7864. int paddr_cells;
  7865. int mc_addr_cells;
  7866. int mc_size_cells;
  7867. @@ -688,16 +797,16 @@ static int get_mc_addr_translation_range
  7868. const __be32 *ranges_start;
  7869. const __be32 *cell;
  7870. - error = parse_mc_ranges(dev,
  7871. + ret = parse_mc_ranges(dev,
  7872. &paddr_cells,
  7873. &mc_addr_cells,
  7874. &mc_size_cells,
  7875. - &ranges_start,
  7876. - num_ranges);
  7877. - if (error < 0)
  7878. - return error;
  7879. + &ranges_start);
  7880. + if (ret < 0)
  7881. + return ret;
  7882. - if (!(*num_ranges)) {
  7883. + *num_ranges = ret;
  7884. + if (!ret) {
  7885. /*
  7886. * Missing or empty ranges property ("ranges;") for the
  7887. * 'fsl,qoriq-mc' node. In this case, identity mapping
  7888. @@ -749,8 +858,6 @@ static int fsl_mc_bus_probe(struct platf
  7889. struct mc_version mc_version;
  7890. struct resource res;
  7891. - dev_info(&pdev->dev, "Root MC bus device probed");
  7892. -
  7893. mc = devm_kzalloc(&pdev->dev, sizeof(*mc), GFP_KERNEL);
  7894. if (!mc)
  7895. return -ENOMEM;
  7896. @@ -783,8 +890,7 @@ static int fsl_mc_bus_probe(struct platf
  7897. goto error_cleanup_mc_io;
  7898. }
  7899. - dev_info(&pdev->dev,
  7900. - "Freescale Management Complex Firmware version: %u.%u.%u\n",
  7901. + dev_info(&pdev->dev, "MC firmware version: %u.%u.%u\n",
  7902. mc_version.major, mc_version.minor, mc_version.revision);
  7903. error = get_mc_addr_translation_ranges(&pdev->dev,
  7904. @@ -793,16 +899,17 @@ static int fsl_mc_bus_probe(struct platf
  7905. if (error < 0)
  7906. goto error_cleanup_mc_io;
  7907. - error = dpmng_get_container_id(mc_io, 0, &container_id);
  7908. + error = dprc_get_container_id(mc_io, 0, &container_id);
  7909. if (error < 0) {
  7910. dev_err(&pdev->dev,
  7911. - "dpmng_get_container_id() failed: %d\n", error);
  7912. + "dprc_get_container_id() failed: %d\n", error);
  7913. goto error_cleanup_mc_io;
  7914. }
  7915. memset(&obj_desc, 0, sizeof(struct dprc_obj_desc));
  7916. - error = get_dprc_version(mc_io, container_id,
  7917. - &obj_desc.ver_major, &obj_desc.ver_minor);
  7918. + error = dprc_get_api_version(mc_io, 0,
  7919. + &obj_desc.ver_major,
  7920. + &obj_desc.ver_minor);
  7921. if (error < 0)
  7922. goto error_cleanup_mc_io;
  7923. @@ -812,7 +919,8 @@ static int fsl_mc_bus_probe(struct platf
  7924. obj_desc.irq_count = 1;
  7925. obj_desc.region_count = 0;
  7926. - error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, &mc_bus_dev);
  7927. + error = fsl_mc_device_add(&obj_desc, mc_io, &pdev->dev, NULL,
  7928. + &mc_bus_dev);
  7929. if (error < 0)
  7930. goto error_cleanup_mc_io;
  7931. @@ -840,7 +948,6 @@ static int fsl_mc_bus_remove(struct plat
  7932. fsl_destroy_mc_io(mc->root_mc_bus_dev->mc_io);
  7933. mc->root_mc_bus_dev->mc_io = NULL;
  7934. - dev_info(&pdev->dev, "Root MC bus device removed");
  7935. return 0;
  7936. }
  7937. @@ -865,22 +972,12 @@ static int __init fsl_mc_bus_driver_init
  7938. {
  7939. int error;
  7940. - mc_dev_cache = kmem_cache_create("fsl_mc_device",
  7941. - sizeof(struct fsl_mc_device), 0, 0,
  7942. - NULL);
  7943. - if (!mc_dev_cache) {
  7944. - pr_err("Could not create fsl_mc_device cache\n");
  7945. - return -ENOMEM;
  7946. - }
  7947. -
  7948. error = bus_register(&fsl_mc_bus_type);
  7949. if (error < 0) {
  7950. - pr_err("fsl-mc bus type registration failed: %d\n", error);
  7951. + pr_err("bus type registration failed: %d\n", error);
  7952. goto error_cleanup_cache;
  7953. }
  7954. - pr_info("fsl-mc bus type registered\n");
  7955. -
  7956. error = platform_driver_register(&fsl_mc_bus_driver);
  7957. if (error < 0) {
  7958. pr_err("platform_driver_register() failed: %d\n", error);
  7959. @@ -914,7 +1011,6 @@ error_cleanup_bus:
  7960. bus_unregister(&fsl_mc_bus_type);
  7961. error_cleanup_cache:
  7962. - kmem_cache_destroy(mc_dev_cache);
  7963. return error;
  7964. }
  7965. postcore_initcall(fsl_mc_bus_driver_init);
  7966. --- /dev/null
  7967. +++ b/drivers/staging/fsl-mc/bus/fsl-mc-iommu.c
  7968. @@ -0,0 +1,104 @@
  7969. +/*
  7970. + * Copyright 2016-17 NXP
  7971. + * Author: Nipun Gupta <[email protected]>
  7972. + *
  7973. + * This file is licensed under the terms of the GNU General Public
  7974. + * License version 2. This program is licensed "as is" without any
  7975. + * warranty of any kind, whether express or implied.
  7976. + */
  7977. +
  7978. +#include <linux/iommu.h>
  7979. +#include <linux/of.h>
  7980. +#include <linux/of_iommu.h>
  7981. +#include "../include/mc.h"
  7982. +
  7983. +/* Setup the IOMMU for the DPRC container */
  7984. +static const struct iommu_ops
  7985. +*fsl_mc_iommu_configure(struct fsl_mc_device *mc_dev,
  7986. + struct device_node *fsl_mc_platform_node)
  7987. +{
  7988. + struct of_phandle_args iommu_spec;
  7989. + const struct iommu_ops *ops;
  7990. + u32 iommu_phandle;
  7991. + struct device_node *iommu_node;
  7992. + const __be32 *map = NULL;
  7993. + int iommu_cells, map_len, ret;
  7994. +
  7995. + map = of_get_property(fsl_mc_platform_node, "iommu-map", &map_len);
  7996. + if (!map)
  7997. + return NULL;
  7998. +
  7999. + ops = mc_dev->dev.bus->iommu_ops;
  8000. + if (!ops || !ops->of_xlate)
  8001. + return NULL;
  8002. +
  8003. + iommu_phandle = be32_to_cpup(map + 1);
  8004. + iommu_node = of_find_node_by_phandle(iommu_phandle);
  8005. +
  8006. + if (of_property_read_u32(iommu_node, "#iommu-cells", &iommu_cells)) {
  8007. + pr_err("%s: missing #iommu-cells property\n", iommu_node->name);
  8008. + return NULL;
  8009. + }
  8010. +
  8011. + /* Initialize the fwspec */
  8012. + ret = iommu_fwspec_init(&mc_dev->dev, &iommu_node->fwnode, ops);
  8013. + if (ret)
  8014. + return NULL;
  8015. +
  8016. + /*
  8017. + * Fill in the required stream-id before calling the iommu's
  8018. + * ops->xlate callback.
  8019. + */
  8020. + iommu_spec.np = iommu_node;
  8021. + iommu_spec.args[0] = mc_dev->icid;
  8022. + iommu_spec.args_count = 1;
  8023. +
  8024. + ret = ops->of_xlate(&mc_dev->dev, &iommu_spec);
  8025. + if (ret)
  8026. + return NULL;
  8027. +
  8028. + of_node_put(iommu_spec.np);
  8029. +
  8030. + return ops;
  8031. +}
  8032. +
  8033. +/* Set up DMA configuration for fsl-mc devices */
  8034. +void fsl_mc_dma_configure(struct fsl_mc_device *mc_dev,
  8035. + struct device_node *fsl_mc_platform_node, int coherent)
  8036. +{
  8037. + const struct iommu_ops *ops;
  8038. +
  8039. + ops = fsl_mc_iommu_configure(mc_dev, fsl_mc_platform_node);
  8040. +
  8041. + mc_dev->dev.coherent_dma_mask = DMA_BIT_MASK(48);
  8042. + mc_dev->dev.dma_mask = &mc_dev->dev.coherent_dma_mask;
  8043. + arch_setup_dma_ops(&mc_dev->dev, 0,
  8044. + mc_dev->dev.coherent_dma_mask + 1, ops, coherent);
  8045. +}
  8046. +
  8047. +/* Macro to get the container device of a MC device */
  8048. +#define fsl_mc_cont_dev(_dev) ((to_fsl_mc_device(_dev)->flags & \
  8049. + FSL_MC_IS_DPRC) ? (_dev) : ((_dev)->parent))
  8050. +
  8051. +/* Macro to check if a device is a container device */
  8052. +#define is_cont_dev(_dev) (to_fsl_mc_device(_dev)->flags & FSL_MC_IS_DPRC)
  8053. +
  8054. +/* Get the IOMMU group for device on fsl-mc bus */
  8055. +struct iommu_group *fsl_mc_device_group(struct device *dev)
  8056. +{
  8057. + struct device *cont_dev = fsl_mc_cont_dev(dev);
  8058. + struct iommu_group *group;
  8059. +
  8060. + /* Container device is responsible for creating the iommu group */
  8061. + if (is_cont_dev(dev)) {
  8062. + group = iommu_group_alloc();
  8063. + if (IS_ERR(group))
  8064. + return NULL;
  8065. + } else {
  8066. + get_device(cont_dev);
  8067. + group = iommu_group_get(cont_dev);
  8068. + put_device(cont_dev);
  8069. + }
  8070. +
  8071. + return group;
  8072. +}
  8073. --- a/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
  8074. +++ b/drivers/staging/fsl-mc/bus/fsl-mc-msi.c
  8075. @@ -1,7 +1,7 @@
  8076. /*
  8077. * Freescale Management Complex (MC) bus driver MSI support
  8078. *
  8079. - * Copyright (C) 2015 Freescale Semiconductor, Inc.
  8080. + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
  8081. * Author: German Rivera <[email protected]>
  8082. *
  8083. * This file is licensed under the terms of the GNU General Public
  8084. --- a/drivers/staging/fsl-mc/bus/fsl-mc-private.h
  8085. +++ b/drivers/staging/fsl-mc/bus/fsl-mc-private.h
  8086. @@ -10,13 +10,15 @@
  8087. #ifndef _FSL_MC_PRIVATE_H_
  8088. #define _FSL_MC_PRIVATE_H_
  8089. +#include "../include/mc.h"
  8090. +#include "../include/mc-bus.h"
  8091. +
  8092. int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
  8093. struct fsl_mc_io *mc_io,
  8094. struct device *parent_dev,
  8095. + const char *driver_override,
  8096. struct fsl_mc_device **new_mc_dev);
  8097. -void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
  8098. -
  8099. int __init dprc_driver_init(void);
  8100. void dprc_driver_exit(void);
  8101. --- a/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
  8102. +++ b/drivers/staging/fsl-mc/bus/irq-gic-v3-its-fsl-mc-msi.c
  8103. @@ -1,7 +1,7 @@
  8104. /*
  8105. * Freescale Management Complex (MC) bus driver MSI support
  8106. *
  8107. - * Copyright (C) 2015 Freescale Semiconductor, Inc.
  8108. + * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
  8109. * Author: German Rivera <[email protected]>
  8110. *
  8111. * This file is licensed under the terms of the GNU General Public
  8112. @@ -20,7 +20,7 @@
  8113. #include "fsl-mc-private.h"
  8114. static struct irq_chip its_msi_irq_chip = {
  8115. - .name = "fsl-mc-bus-msi",
  8116. + .name = "ITS-fMSI",
  8117. .irq_mask = irq_chip_mask_parent,
  8118. .irq_unmask = irq_chip_unmask_parent,
  8119. .irq_eoi = irq_chip_eoi_parent,
  8120. @@ -52,7 +52,7 @@ static int its_fsl_mc_msi_prepare(struct
  8121. return msi_info->ops->msi_prepare(msi_domain->parent, dev, nvec, info);
  8122. }
  8123. -static struct msi_domain_ops its_fsl_mc_msi_ops = {
  8124. +static struct msi_domain_ops its_fsl_mc_msi_ops __ro_after_init = {
  8125. .msi_prepare = its_fsl_mc_msi_prepare,
  8126. };
  8127. @@ -97,8 +97,8 @@ int __init its_fsl_mc_msi_init(void)
  8128. continue;
  8129. }
  8130. - WARN_ON(mc_msi_domain->
  8131. - host_data != &its_fsl_mc_msi_domain_info);
  8132. + WARN_ON(mc_msi_domain->host_data !=
  8133. + &its_fsl_mc_msi_domain_info);
  8134. pr_info("fsl-mc MSI: %s domain created\n", np->full_name);
  8135. }
  8136. --- a/drivers/staging/fsl-mc/bus/mc-io.c
  8137. +++ b/drivers/staging/fsl-mc/bus/mc-io.c
  8138. @@ -1,4 +1,5 @@
  8139. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  8140. +/*
  8141. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  8142. *
  8143. * Redistribution and use in source and binary forms, with or without
  8144. * modification, are permitted provided that the following conditions are met:
  8145. @@ -11,7 +12,6 @@
  8146. * names of any contributors may be used to endorse or promote products
  8147. * derived from this software without specific prior written permission.
  8148. *
  8149. - *
  8150. * ALTERNATIVELY, this software may be distributed under the terms of the
  8151. * GNU General Public License ("GPL") as published by the Free Software
  8152. * Foundation, either version 2 of that License or (at your option) any
  8153. --- /dev/null
  8154. +++ b/drivers/staging/fsl-mc/bus/mc-ioctl.h
  8155. @@ -0,0 +1,22 @@
  8156. +/*
  8157. + * Freescale Management Complex (MC) ioclt interface
  8158. + *
  8159. + * Copyright (C) 2014 Freescale Semiconductor, Inc.
  8160. + * Author: Lijun Pan <[email protected]>
  8161. + *
  8162. + * This file is licensed under the terms of the GNU General Public
  8163. + * License version 2. This program is licensed "as is" without any
  8164. + * warranty of any kind, whether express or implied.
  8165. + */
  8166. +#ifndef _FSL_MC_IOCTL_H_
  8167. +#define _FSL_MC_IOCTL_H_
  8168. +
  8169. +#include <linux/ioctl.h>
  8170. +#include "../include/mc-sys.h"
  8171. +
  8172. +#define RESTOOL_IOCTL_TYPE 'R'
  8173. +
  8174. +#define RESTOOL_SEND_MC_COMMAND \
  8175. + _IOWR(RESTOOL_IOCTL_TYPE, 0xE0, struct mc_command)
  8176. +
  8177. +#endif /* _FSL_MC_IOCTL_H_ */
  8178. --- /dev/null
  8179. +++ b/drivers/staging/fsl-mc/bus/mc-restool.c
  8180. @@ -0,0 +1,405 @@
  8181. +/*
  8182. + * Freescale Management Complex (MC) restool driver
  8183. + *
  8184. + * Copyright (C) 2014 Freescale Semiconductor, Inc.
  8185. + * Author: Lijun Pan <[email protected]>
  8186. + *
  8187. + * This file is licensed under the terms of the GNU General Public
  8188. + * License version 2. This program is licensed "as is" without any
  8189. + * warranty of any kind, whether express or implied.
  8190. + */
  8191. +
  8192. +#include "../include/mc.h"
  8193. +#include <linux/module.h>
  8194. +#include <linux/fs.h>
  8195. +#include <linux/miscdevice.h>
  8196. +#include <linux/mm.h>
  8197. +#include <linux/slab.h>
  8198. +#include <linux/uaccess.h>
  8199. +#include <linux/mutex.h>
  8200. +#include <linux/platform_device.h>
  8201. +#include "mc-ioctl.h"
  8202. +#include "../include/mc-sys.h"
  8203. +#include "../include/mc-bus.h"
  8204. +#include "../include/mc-cmd.h"
  8205. +#include "../include/dpmng.h"
  8206. +
  8207. +/**
  8208. + * Maximum number of DPRCs that can be opened at the same time
  8209. + */
  8210. +#define MAX_DPRC_HANDLES 64
  8211. +
  8212. +/**
  8213. + * restool_misc - information associated with the newly added miscdevice
  8214. + * @misc: newly created miscdevice associated with root dprc
  8215. + * @miscdevt: device id of this miscdevice
  8216. + * @list: a linked list node representing this miscdevcie
  8217. + * @static_mc_io: pointer to the static MC I/O object used by the restool
  8218. + * @dynamic_instance_count: number of dynamically created instances
  8219. + * @static_instance_in_use: static instance is in use or not
  8220. + * @mutex: mutex lock to serialze the open/release operations
  8221. + * @dev: root dprc associated with this miscdevice
  8222. + */
  8223. +struct restool_misc {
  8224. + struct miscdevice misc;
  8225. + dev_t miscdevt;
  8226. + struct list_head list;
  8227. + struct fsl_mc_io *static_mc_io;
  8228. + u32 dynamic_instance_count;
  8229. + bool static_instance_in_use;
  8230. + struct mutex mutex; /* serialze the open/release operations */
  8231. + struct device *dev;
  8232. +};
  8233. +
  8234. +/**
  8235. + * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
  8236. + * @root_mc_bus_dev: fsl-mc device representing the root DPRC
  8237. + * @num_translation_ranges: number of entries in addr_translation_ranges
  8238. + * @translation_ranges: array of bus to system address translation ranges
  8239. + */
  8240. +struct fsl_mc {
  8241. + struct fsl_mc_device *root_mc_bus_dev;
  8242. + u8 num_translation_ranges;
  8243. + struct fsl_mc_addr_translation_range *translation_ranges;
  8244. +};
  8245. +
  8246. +/*
  8247. + * initialize a global list to link all
  8248. + * the miscdevice nodes (struct restool_misc)
  8249. + */
  8250. +static LIST_HEAD(misc_list);
  8251. +static DEFINE_MUTEX(misc_list_mutex);
  8252. +
  8253. +static int fsl_mc_restool_dev_open(struct inode *inode, struct file *filep)
  8254. +{
  8255. + struct fsl_mc_device *root_mc_dev;
  8256. + int error;
  8257. + struct fsl_mc_io *dynamic_mc_io = NULL;
  8258. + struct restool_misc *restool_misc = NULL;
  8259. + struct restool_misc *restool_misc_cursor;
  8260. +
  8261. + mutex_lock(&misc_list_mutex);
  8262. +
  8263. + list_for_each_entry(restool_misc_cursor, &misc_list, list) {
  8264. + if (restool_misc_cursor->miscdevt == inode->i_rdev) {
  8265. + restool_misc = restool_misc_cursor;
  8266. + break;
  8267. + }
  8268. + }
  8269. +
  8270. + mutex_unlock(&misc_list_mutex);
  8271. +
  8272. + if (!restool_misc)
  8273. + return -EINVAL;
  8274. +
  8275. + if (WARN_ON(!restool_misc->dev))
  8276. + return -EINVAL;
  8277. +
  8278. + mutex_lock(&restool_misc->mutex);
  8279. +
  8280. + if (!restool_misc->static_instance_in_use) {
  8281. + restool_misc->static_instance_in_use = true;
  8282. + filep->private_data = restool_misc->static_mc_io;
  8283. + } else {
  8284. + dynamic_mc_io = kzalloc(sizeof(*dynamic_mc_io), GFP_KERNEL);
  8285. + if (!dynamic_mc_io) {
  8286. + error = -ENOMEM;
  8287. + goto err_unlock;
  8288. + }
  8289. +
  8290. + root_mc_dev = to_fsl_mc_device(restool_misc->dev);
  8291. + error = fsl_mc_portal_allocate(root_mc_dev, 0, &dynamic_mc_io);
  8292. + if (error < 0) {
  8293. + pr_err("Not able to allocate MC portal\n");
  8294. + goto free_dynamic_mc_io;
  8295. + }
  8296. + ++restool_misc->dynamic_instance_count;
  8297. + filep->private_data = dynamic_mc_io;
  8298. + }
  8299. +
  8300. + mutex_unlock(&restool_misc->mutex);
  8301. +
  8302. + return 0;
  8303. +
  8304. +free_dynamic_mc_io:
  8305. + kfree(dynamic_mc_io);
  8306. +err_unlock:
  8307. + mutex_unlock(&restool_misc->mutex);
  8308. +
  8309. + return error;
  8310. +}
  8311. +
  8312. +static int fsl_mc_restool_dev_release(struct inode *inode, struct file *filep)
  8313. +{
  8314. + struct fsl_mc_io *local_mc_io = filep->private_data;
  8315. + struct restool_misc *restool_misc = NULL;
  8316. + struct restool_misc *restool_misc_cursor;
  8317. +
  8318. + if (WARN_ON(!filep->private_data))
  8319. + return -EINVAL;
  8320. +
  8321. + mutex_lock(&misc_list_mutex);
  8322. +
  8323. + list_for_each_entry(restool_misc_cursor, &misc_list, list) {
  8324. + if (restool_misc_cursor->miscdevt == inode->i_rdev) {
  8325. + restool_misc = restool_misc_cursor;
  8326. + break;
  8327. + }
  8328. + }
  8329. +
  8330. + mutex_unlock(&misc_list_mutex);
  8331. +
  8332. + if (!restool_misc)
  8333. + return -EINVAL;
  8334. +
  8335. + mutex_lock(&restool_misc->mutex);
  8336. +
  8337. + if (WARN_ON(restool_misc->dynamic_instance_count == 0 &&
  8338. + !restool_misc->static_instance_in_use)) {
  8339. + mutex_unlock(&restool_misc->mutex);
  8340. + return -EINVAL;
  8341. + }
  8342. +
  8343. + /* Globally clean up opened/untracked handles */
  8344. + fsl_mc_portal_reset(local_mc_io);
  8345. +
  8346. + /*
  8347. + * must check
  8348. + * whether local_mc_io is dynamic or static instance
  8349. + * Otherwise it will free up the reserved portal by accident
  8350. + * or even not free up the dynamic allocated portal
  8351. + * if 2 or more instances running concurrently
  8352. + */
  8353. + if (local_mc_io == restool_misc->static_mc_io) {
  8354. + restool_misc->static_instance_in_use = false;
  8355. + } else {
  8356. + fsl_mc_portal_free(local_mc_io);
  8357. + kfree(filep->private_data);
  8358. + --restool_misc->dynamic_instance_count;
  8359. + }
  8360. +
  8361. + filep->private_data = NULL;
  8362. + mutex_unlock(&restool_misc->mutex);
  8363. +
  8364. + return 0;
  8365. +}
  8366. +
  8367. +static int restool_send_mc_command(unsigned long arg,
  8368. + struct fsl_mc_io *local_mc_io)
  8369. +{
  8370. + int error;
  8371. + struct mc_command mc_cmd;
  8372. +
  8373. + if (copy_from_user(&mc_cmd, (void __user *)arg, sizeof(mc_cmd)))
  8374. + return -EFAULT;
  8375. +
  8376. + /*
  8377. + * Send MC command to the MC:
  8378. + */
  8379. + error = mc_send_command(local_mc_io, &mc_cmd);
  8380. + if (error < 0)
  8381. + return error;
  8382. +
  8383. + if (copy_to_user((void __user *)arg, &mc_cmd, sizeof(mc_cmd)))
  8384. + return -EFAULT;
  8385. +
  8386. + return 0;
  8387. +}
  8388. +
  8389. +static long
  8390. +fsl_mc_restool_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  8391. +{
  8392. + int error;
  8393. +
  8394. + switch (cmd) {
  8395. + case RESTOOL_SEND_MC_COMMAND:
  8396. + error = restool_send_mc_command(arg, file->private_data);
  8397. + break;
  8398. + default:
  8399. + pr_err("%s: unexpected ioctl call number\n", __func__);
  8400. + error = -EINVAL;
  8401. + }
  8402. +
  8403. + return error;
  8404. +}
  8405. +
  8406. +static const struct file_operations fsl_mc_restool_dev_fops = {
  8407. + .owner = THIS_MODULE,
  8408. + .open = fsl_mc_restool_dev_open,
  8409. + .release = fsl_mc_restool_dev_release,
  8410. + .unlocked_ioctl = fsl_mc_restool_dev_ioctl,
  8411. +};
  8412. +
  8413. +static int restool_add_device_file(struct device *dev)
  8414. +{
  8415. + u32 name1 = 0;
  8416. + char name2[20] = {0};
  8417. + int error;
  8418. + struct fsl_mc_device *root_mc_dev;
  8419. + struct restool_misc *restool_misc;
  8420. +
  8421. + if (dev->bus == &platform_bus_type && dev->driver_data) {
  8422. + if (sscanf(dev_name(dev), "%x.%s", &name1, name2) != 2)
  8423. + return -EINVAL;
  8424. +
  8425. + if (strcmp(name2, "fsl-mc") == 0)
  8426. + pr_debug("platform's root dprc name is: %s\n",
  8427. + dev_name(&(((struct fsl_mc *)
  8428. + (dev->driver_data))->root_mc_bus_dev->dev)));
  8429. + }
  8430. +
  8431. + if (!fsl_mc_is_root_dprc(dev))
  8432. + return 0;
  8433. +
  8434. + restool_misc = kzalloc(sizeof(*restool_misc), GFP_KERNEL);
  8435. + if (!restool_misc)
  8436. + return -ENOMEM;
  8437. +
  8438. + restool_misc->dev = dev;
  8439. + root_mc_dev = to_fsl_mc_device(dev);
  8440. + error = fsl_mc_portal_allocate(root_mc_dev, 0,
  8441. + &restool_misc->static_mc_io);
  8442. + if (error < 0) {
  8443. + pr_err("Not able to allocate MC portal\n");
  8444. + goto free_restool_misc;
  8445. + }
  8446. +
  8447. + restool_misc->misc.minor = MISC_DYNAMIC_MINOR;
  8448. + restool_misc->misc.name = dev_name(dev);
  8449. + restool_misc->misc.fops = &fsl_mc_restool_dev_fops;
  8450. +
  8451. + error = misc_register(&restool_misc->misc);
  8452. + if (error < 0) {
  8453. + pr_err("misc_register() failed: %d\n", error);
  8454. + goto free_portal;
  8455. + }
  8456. +
  8457. + restool_misc->miscdevt = restool_misc->misc.this_device->devt;
  8458. + mutex_init(&restool_misc->mutex);
  8459. + mutex_lock(&misc_list_mutex);
  8460. + list_add(&restool_misc->list, &misc_list);
  8461. + mutex_unlock(&misc_list_mutex);
  8462. +
  8463. + pr_info("/dev/%s driver registered\n", dev_name(dev));
  8464. +
  8465. + return 0;
  8466. +
  8467. +free_portal:
  8468. + fsl_mc_portal_free(restool_misc->static_mc_io);
  8469. +free_restool_misc:
  8470. + kfree(restool_misc);
  8471. +
  8472. + return error;
  8473. +}
  8474. +
  8475. +static int restool_bus_notifier(struct notifier_block *nb,
  8476. + unsigned long action, void *data)
  8477. +{
  8478. + int error;
  8479. + struct device *dev = data;
  8480. +
  8481. + switch (action) {
  8482. + case BUS_NOTIFY_ADD_DEVICE:
  8483. + error = restool_add_device_file(dev);
  8484. + if (error)
  8485. + return error;
  8486. + break;
  8487. + case BUS_NOTIFY_DEL_DEVICE:
  8488. + case BUS_NOTIFY_REMOVED_DEVICE:
  8489. + case BUS_NOTIFY_BIND_DRIVER:
  8490. + case BUS_NOTIFY_BOUND_DRIVER:
  8491. + case BUS_NOTIFY_UNBIND_DRIVER:
  8492. + case BUS_NOTIFY_UNBOUND_DRIVER:
  8493. + break;
  8494. + default:
  8495. + pr_err("%s: unrecognized device action from %s\n", __func__,
  8496. + dev_name(dev));
  8497. + return -EINVAL;
  8498. + }
  8499. +
  8500. + return 0;
  8501. +}
  8502. +
  8503. +static int add_to_restool(struct device *dev, void *data)
  8504. +{
  8505. + return restool_add_device_file(dev);
  8506. +}
  8507. +
  8508. +static int __init fsl_mc_restool_driver_init(void)
  8509. +{
  8510. + int error;
  8511. + struct notifier_block *nb;
  8512. +
  8513. + nb = kzalloc(sizeof(*nb), GFP_KERNEL);
  8514. + if (!nb)
  8515. + return -ENOMEM;
  8516. +
  8517. + nb->notifier_call = restool_bus_notifier;
  8518. + error = bus_register_notifier(&fsl_mc_bus_type, nb);
  8519. + if (error)
  8520. + goto free_nb;
  8521. +
  8522. + /*
  8523. + * This driver runs after fsl-mc bus driver runs.
  8524. + * Hence, many of the root dprcs are already attached to fsl-mc bus
  8525. + * In order to make sure we find all the root dprcs,
  8526. + * we need to scan the fsl_mc_bus_type.
  8527. + */
  8528. + error = bus_for_each_dev(&fsl_mc_bus_type, NULL, NULL, add_to_restool);
  8529. + if (error) {
  8530. + bus_unregister_notifier(&fsl_mc_bus_type, nb);
  8531. + kfree(nb);
  8532. + pr_err("restool driver registration failure\n");
  8533. + return error;
  8534. + }
  8535. +
  8536. + return 0;
  8537. +
  8538. +free_nb:
  8539. + kfree(nb);
  8540. + return error;
  8541. +}
  8542. +
  8543. +module_init(fsl_mc_restool_driver_init);
  8544. +
  8545. +static void __exit fsl_mc_restool_driver_exit(void)
  8546. +{
  8547. + struct restool_misc *restool_misc;
  8548. + struct restool_misc *restool_misc_tmp;
  8549. + char name1[20] = {0};
  8550. + u32 name2 = 0;
  8551. +
  8552. + list_for_each_entry_safe(restool_misc, restool_misc_tmp,
  8553. + &misc_list, list) {
  8554. + if (sscanf(restool_misc->misc.name, "%4s.%u", name1, &name2)
  8555. + != 2)
  8556. + continue;
  8557. +
  8558. + pr_debug("name1=%s,name2=%u\n", name1, name2);
  8559. + pr_debug("misc-device: %s\n", restool_misc->misc.name);
  8560. + if (strcmp(name1, "dprc") != 0)
  8561. + continue;
  8562. +
  8563. + if (WARN_ON(!restool_misc->static_mc_io))
  8564. + return;
  8565. +
  8566. + if (WARN_ON(restool_misc->dynamic_instance_count != 0))
  8567. + return;
  8568. +
  8569. + if (WARN_ON(restool_misc->static_instance_in_use))
  8570. + return;
  8571. +
  8572. + misc_deregister(&restool_misc->misc);
  8573. + pr_info("/dev/%s driver unregistered\n",
  8574. + restool_misc->misc.name);
  8575. + fsl_mc_portal_free(restool_misc->static_mc_io);
  8576. + list_del(&restool_misc->list);
  8577. + kfree(restool_misc);
  8578. + }
  8579. +}
  8580. +
  8581. +module_exit(fsl_mc_restool_driver_exit);
  8582. +
  8583. +MODULE_AUTHOR("Freescale Semiconductor Inc.");
  8584. +MODULE_DESCRIPTION("Freescale's MC restool driver");
  8585. +MODULE_LICENSE("GPL");
  8586. --- a/drivers/staging/fsl-mc/bus/mc-sys.c
  8587. +++ b/drivers/staging/fsl-mc/bus/mc-sys.c
  8588. @@ -1,4 +1,5 @@
  8589. -/* Copyright 2013-2014 Freescale Semiconductor Inc.
  8590. +/*
  8591. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  8592. *
  8593. * I/O services to send MC commands to the MC hardware
  8594. *
  8595. @@ -13,7 +14,6 @@
  8596. * names of any contributors may be used to endorse or promote products
  8597. * derived from this software without specific prior written permission.
  8598. *
  8599. - *
  8600. * ALTERNATIVELY, this software may be distributed under the terms of the
  8601. * GNU General Public License ("GPL") as published by the Free Software
  8602. * Foundation, either version 2 of that License or (at your option) any
  8603. @@ -46,7 +46,7 @@
  8604. /**
  8605. * Timeout in milliseconds to wait for the completion of an MC command
  8606. */
  8607. -#define MC_CMD_COMPLETION_TIMEOUT_MS 500
  8608. +#define MC_CMD_COMPLETION_TIMEOUT_MS 15000
  8609. /*
  8610. * usleep_range() min and max values used to throttle down polling
  8611. @@ -67,7 +67,7 @@ static u16 mc_cmd_hdr_read_cmdid(struct
  8612. struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
  8613. u16 cmd_id = le16_to_cpu(hdr->cmd_id);
  8614. - return (cmd_id & MC_CMD_HDR_CMDID_MASK) >> MC_CMD_HDR_CMDID_SHIFT;
  8615. + return cmd_id;
  8616. }
  8617. static int mc_status_to_error(enum mc_cmd_status status)
  8618. @@ -200,7 +200,7 @@ static int mc_polling_wait_preemptible(s
  8619. if (time_after_eq(jiffies, jiffies_until_timeout)) {
  8620. dev_dbg(mc_io->dev,
  8621. - "MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
  8622. + "MC command timed out (portal: %#llx, dprc handle: %#x, command: %#x)\n",
  8623. mc_io->portal_phys_addr,
  8624. (unsigned int)mc_cmd_hdr_read_token(cmd),
  8625. (unsigned int)mc_cmd_hdr_read_cmdid(cmd));
  8626. @@ -240,7 +240,7 @@ static int mc_polling_wait_atomic(struct
  8627. timeout_usecs -= MC_CMD_COMPLETION_POLLING_MAX_SLEEP_USECS;
  8628. if (timeout_usecs == 0) {
  8629. dev_dbg(mc_io->dev,
  8630. - "MC command timed out (portal: %#llx, obj handle: %#x, command: %#x)\n",
  8631. + "MC command timed out (portal: %#llx, dprc handle: %#x, command: %#x)\n",
  8632. mc_io->portal_phys_addr,
  8633. (unsigned int)mc_cmd_hdr_read_token(cmd),
  8634. (unsigned int)mc_cmd_hdr_read_cmdid(cmd));
  8635. @@ -294,7 +294,7 @@ int mc_send_command(struct fsl_mc_io *mc
  8636. if (status != MC_CMD_STATUS_OK) {
  8637. dev_dbg(mc_io->dev,
  8638. - "MC command failed: portal: %#llx, obj handle: %#x, command: %#x, status: %s (%#x)\n",
  8639. + "MC command failed: portal: %#llx, dprc handle: %#x, command: %#x, status: %s (%#x)\n",
  8640. mc_io->portal_phys_addr,
  8641. (unsigned int)mc_cmd_hdr_read_token(cmd),
  8642. (unsigned int)mc_cmd_hdr_read_cmdid(cmd),
  8643. --- /dev/null
  8644. +++ b/drivers/staging/fsl-mc/include/dpaa2-fd.h
  8645. @@ -0,0 +1,706 @@
  8646. +/*
  8647. + * Copyright 2014-2016 Freescale Semiconductor Inc.
  8648. + * Copyright 2016 NXP
  8649. + *
  8650. + * Redistribution and use in source and binary forms, with or without
  8651. + * modification, are permitted provided that the following conditions are met:
  8652. + * * Redistributions of source code must retain the above copyright
  8653. + * notice, this list of conditions and the following disclaimer.
  8654. + * * Redistributions in binary form must reproduce the above copyright
  8655. + * notice, this list of conditions and the following disclaimer in the
  8656. + * documentation and/or other materials provided with the distribution.
  8657. + * * Neither the name of Freescale Semiconductor nor the
  8658. + * names of its contributors may be used to endorse or promote products
  8659. + * derived from this software without specific prior written permission.
  8660. + *
  8661. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8662. + * GNU General Public License ("GPL") as published by the Free Software
  8663. + * Foundation, either version 2 of that License or (at your option) any
  8664. + * later version.
  8665. + *
  8666. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  8667. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  8668. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  8669. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  8670. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  8671. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  8672. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  8673. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  8674. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8675. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8676. + */
  8677. +#ifndef __FSL_DPAA2_FD_H
  8678. +#define __FSL_DPAA2_FD_H
  8679. +
  8680. +#include <linux/kernel.h>
  8681. +
  8682. +/**
  8683. + * DOC: DPAA2 FD - Frame Descriptor APIs for DPAA2
  8684. + *
  8685. + * Frame Descriptors (FDs) are used to describe frame data in the DPAA2.
  8686. + * Frames can be enqueued and dequeued to Frame Queues (FQs) which are consumed
  8687. + * by the various DPAA accelerators (WRIOP, SEC, PME, DCE)
  8688. + *
  8689. + * There are three types of frames: single, scatter gather, and frame lists.
  8690. + *
  8691. + * The set of APIs in this file must be used to create, manipulate and
  8692. + * query Frame Descriptors.
  8693. + */
  8694. +
  8695. +/**
  8696. + * struct dpaa2_fd - Struct describing FDs
  8697. + * @words: for easier/faster copying the whole FD structure
  8698. + * @addr: address in the FD
  8699. + * @len: length in the FD
  8700. + * @bpid: buffer pool ID
  8701. + * @format_offset: format, offset, and short-length fields
  8702. + * @frc: frame context
  8703. + * @ctrl: control bits...including dd, sc, va, err, etc
  8704. + * @flc: flow context address
  8705. + *
  8706. + * This structure represents the basic Frame Descriptor used in the system.
  8707. + */
  8708. +struct dpaa2_fd {
  8709. + union {
  8710. + u32 words[8];
  8711. + struct dpaa2_fd_simple {
  8712. + __le64 addr;
  8713. + __le32 len;
  8714. + __le16 bpid;
  8715. + __le16 format_offset;
  8716. + __le32 frc;
  8717. + __le32 ctrl;
  8718. + __le64 flc;
  8719. + } simple;
  8720. + };
  8721. +};
  8722. +
  8723. +#define FD_SHORT_LEN_FLAG_MASK 0x1
  8724. +#define FD_SHORT_LEN_FLAG_SHIFT 14
  8725. +#define FD_SHORT_LEN_MASK 0x3FFFF
  8726. +#define FD_OFFSET_MASK 0x0FFF
  8727. +#define FD_FORMAT_MASK 0x3
  8728. +#define FD_FORMAT_SHIFT 12
  8729. +#define FD_BPID_MASK 0x3FFF
  8730. +#define SG_SHORT_LEN_FLAG_MASK 0x1
  8731. +#define SG_SHORT_LEN_FLAG_SHIFT 14
  8732. +#define SG_SHORT_LEN_MASK 0x1FFFF
  8733. +#define SG_OFFSET_MASK 0x0FFF
  8734. +#define SG_FORMAT_MASK 0x3
  8735. +#define SG_FORMAT_SHIFT 12
  8736. +#define SG_BPID_MASK 0x3FFF
  8737. +#define SG_FINAL_FLAG_MASK 0x1
  8738. +#define SG_FINAL_FLAG_SHIFT 15
  8739. +#define FL_SHORT_LEN_FLAG_MASK 0x1
  8740. +#define FL_SHORT_LEN_FLAG_SHIFT 14
  8741. +#define FL_SHORT_LEN_MASK 0x3FFFF
  8742. +#define FL_OFFSET_MASK 0x0FFF
  8743. +#define FL_FORMAT_MASK 0x3
  8744. +#define FL_FORMAT_SHIFT 12
  8745. +#define FL_BPID_MASK 0x3FFF
  8746. +#define FL_FINAL_FLAG_MASK 0x1
  8747. +#define FL_FINAL_FLAG_SHIFT 15
  8748. +
  8749. +/* Error bits in FD CTRL */
  8750. +#define FD_CTRL_ERR_MASK 0x000000FF
  8751. +#define FD_CTRL_UFD 0x00000004
  8752. +#define FD_CTRL_SBE 0x00000008
  8753. +#define FD_CTRL_FLC 0x00000010
  8754. +#define FD_CTRL_FSE 0x00000020
  8755. +#define FD_CTRL_FAERR 0x00000040
  8756. +
  8757. +/* Annotation bits in FD CTRL */
  8758. +#define FD_CTRL_PTA 0x00800000
  8759. +#define FD_CTRL_PTV1 0x00400000
  8760. +
  8761. +enum dpaa2_fd_format {
  8762. + dpaa2_fd_single = 0,
  8763. + dpaa2_fd_list,
  8764. + dpaa2_fd_sg
  8765. +};
  8766. +
  8767. +/**
  8768. + * dpaa2_fd_get_addr() - get the addr field of frame descriptor
  8769. + * @fd: the given frame descriptor
  8770. + *
  8771. + * Return the address in the frame descriptor.
  8772. + */
  8773. +static inline dma_addr_t dpaa2_fd_get_addr(const struct dpaa2_fd *fd)
  8774. +{
  8775. + return (dma_addr_t)le64_to_cpu(fd->simple.addr);
  8776. +}
  8777. +
  8778. +/**
  8779. + * dpaa2_fd_set_addr() - Set the addr field of frame descriptor
  8780. + * @fd: the given frame descriptor
  8781. + * @addr: the address needs to be set in frame descriptor
  8782. + */
  8783. +static inline void dpaa2_fd_set_addr(struct dpaa2_fd *fd, dma_addr_t addr)
  8784. +{
  8785. + fd->simple.addr = cpu_to_le64(addr);
  8786. +}
  8787. +
  8788. +/**
  8789. + * dpaa2_fd_get_frc() - Get the frame context in the frame descriptor
  8790. + * @fd: the given frame descriptor
  8791. + *
  8792. + * Return the frame context field in the frame descriptor.
  8793. + */
  8794. +static inline u32 dpaa2_fd_get_frc(const struct dpaa2_fd *fd)
  8795. +{
  8796. + return le32_to_cpu(fd->simple.frc);
  8797. +}
  8798. +
  8799. +/**
  8800. + * dpaa2_fd_set_frc() - Set the frame context in the frame descriptor
  8801. + * @fd: the given frame descriptor
  8802. + * @frc: the frame context needs to be set in frame descriptor
  8803. + */
  8804. +static inline void dpaa2_fd_set_frc(struct dpaa2_fd *fd, u32 frc)
  8805. +{
  8806. + fd->simple.frc = cpu_to_le32(frc);
  8807. +}
  8808. +
  8809. +/**
  8810. + * dpaa2_fd_get_ctrl() - Get the control bits in the frame descriptor
  8811. + * @fd: the given frame descriptor
  8812. + *
  8813. + * Return the control bits field in the frame descriptor.
  8814. + */
  8815. +static inline u32 dpaa2_fd_get_ctrl(const struct dpaa2_fd *fd)
  8816. +{
  8817. + return le32_to_cpu(fd->simple.ctrl);
  8818. +}
  8819. +
  8820. +/**
  8821. + * dpaa2_fd_set_ctrl() - Set the control bits in the frame descriptor
  8822. + * @fd: the given frame descriptor
  8823. + * @ctrl: the control bits to be set in the frame descriptor
  8824. + */
  8825. +static inline void dpaa2_fd_set_ctrl(struct dpaa2_fd *fd, u32 ctrl)
  8826. +{
  8827. + fd->simple.ctrl = cpu_to_le32(ctrl);
  8828. +}
  8829. +
  8830. +/**
  8831. + * dpaa2_fd_get_flc() - Get the flow context in the frame descriptor
  8832. + * @fd: the given frame descriptor
  8833. + *
  8834. + * Return the flow context in the frame descriptor.
  8835. + */
  8836. +static inline dma_addr_t dpaa2_fd_get_flc(const struct dpaa2_fd *fd)
  8837. +{
  8838. + return (dma_addr_t)le64_to_cpu(fd->simple.flc);
  8839. +}
  8840. +
  8841. +/**
  8842. + * dpaa2_fd_set_flc() - Set the flow context field of frame descriptor
  8843. + * @fd: the given frame descriptor
  8844. + * @flc_addr: the flow context needs to be set in frame descriptor
  8845. + */
  8846. +static inline void dpaa2_fd_set_flc(struct dpaa2_fd *fd, dma_addr_t flc_addr)
  8847. +{
  8848. + fd->simple.flc = cpu_to_le64(flc_addr);
  8849. +}
  8850. +
  8851. +static inline bool dpaa2_fd_short_len(const struct dpaa2_fd *fd)
  8852. +{
  8853. + return !!((le16_to_cpu(fd->simple.format_offset) >>
  8854. + FD_SHORT_LEN_FLAG_SHIFT) & FD_SHORT_LEN_FLAG_MASK);
  8855. +}
  8856. +
  8857. +/**
  8858. + * dpaa2_fd_get_len() - Get the length in the frame descriptor
  8859. + * @fd: the given frame descriptor
  8860. + *
  8861. + * Return the length field in the frame descriptor.
  8862. + */
  8863. +static inline u32 dpaa2_fd_get_len(const struct dpaa2_fd *fd)
  8864. +{
  8865. + if (dpaa2_fd_short_len(fd))
  8866. + return le32_to_cpu(fd->simple.len) & FD_SHORT_LEN_MASK;
  8867. +
  8868. + return le32_to_cpu(fd->simple.len);
  8869. +}
  8870. +
  8871. +/**
  8872. + * dpaa2_fd_set_len() - Set the length field of frame descriptor
  8873. + * @fd: the given frame descriptor
  8874. + * @len: the length needs to be set in frame descriptor
  8875. + */
  8876. +static inline void dpaa2_fd_set_len(struct dpaa2_fd *fd, u32 len)
  8877. +{
  8878. + fd->simple.len = cpu_to_le32(len);
  8879. +}
  8880. +
  8881. +/**
  8882. + * dpaa2_fd_get_offset() - Get the offset field in the frame descriptor
  8883. + * @fd: the given frame descriptor
  8884. + *
  8885. + * Return the offset.
  8886. + */
  8887. +static inline uint16_t dpaa2_fd_get_offset(const struct dpaa2_fd *fd)
  8888. +{
  8889. + return le16_to_cpu(fd->simple.format_offset) & FD_OFFSET_MASK;
  8890. +}
  8891. +
  8892. +/**
  8893. + * dpaa2_fd_set_offset() - Set the offset field of frame descriptor
  8894. + * @fd: the given frame descriptor
  8895. + * @offset: the offset needs to be set in frame descriptor
  8896. + */
  8897. +static inline void dpaa2_fd_set_offset(struct dpaa2_fd *fd, uint16_t offset)
  8898. +{
  8899. + fd->simple.format_offset &= cpu_to_le16(~FD_OFFSET_MASK);
  8900. + fd->simple.format_offset |= cpu_to_le16(offset);
  8901. +}
  8902. +
  8903. +/**
  8904. + * dpaa2_fd_get_format() - Get the format field in the frame descriptor
  8905. + * @fd: the given frame descriptor
  8906. + *
  8907. + * Return the format.
  8908. + */
  8909. +static inline enum dpaa2_fd_format dpaa2_fd_get_format(
  8910. + const struct dpaa2_fd *fd)
  8911. +{
  8912. + return (enum dpaa2_fd_format)((le16_to_cpu(fd->simple.format_offset)
  8913. + >> FD_FORMAT_SHIFT) & FD_FORMAT_MASK);
  8914. +}
  8915. +
  8916. +/**
  8917. + * dpaa2_fd_set_format() - Set the format field of frame descriptor
  8918. + * @fd: the given frame descriptor
  8919. + * @format: the format needs to be set in frame descriptor
  8920. + */
  8921. +static inline void dpaa2_fd_set_format(struct dpaa2_fd *fd,
  8922. + enum dpaa2_fd_format format)
  8923. +{
  8924. + fd->simple.format_offset &=
  8925. + cpu_to_le16(~(FD_FORMAT_MASK << FD_FORMAT_SHIFT));
  8926. + fd->simple.format_offset |= cpu_to_le16(format << FD_FORMAT_SHIFT);
  8927. +}
  8928. +
  8929. +/**
  8930. + * dpaa2_fd_get_bpid() - Get the bpid field in the frame descriptor
  8931. + * @fd: the given frame descriptor
  8932. + *
  8933. + * Return the buffer pool id.
  8934. + */
  8935. +static inline uint16_t dpaa2_fd_get_bpid(const struct dpaa2_fd *fd)
  8936. +{
  8937. + return le16_to_cpu(fd->simple.bpid) & FD_BPID_MASK;
  8938. +}
  8939. +
  8940. +/**
  8941. + * dpaa2_fd_set_bpid() - Set the bpid field of frame descriptor
  8942. + * @fd: the given frame descriptor
  8943. + * @bpid: buffer pool id to be set
  8944. + */
  8945. +static inline void dpaa2_fd_set_bpid(struct dpaa2_fd *fd, uint16_t bpid)
  8946. +{
  8947. + fd->simple.bpid &= cpu_to_le16(~(FD_BPID_MASK));
  8948. + fd->simple.bpid |= cpu_to_le16(bpid);
  8949. +}
  8950. +
  8951. +/**
  8952. + * struct dpaa2_sg_entry - the scatter-gathering structure
  8953. + * @addr: address of the sg entry
  8954. + * @len: length in this sg entry
  8955. + * @bpid: buffer pool id
  8956. + * @format_offset: format and offset fields
  8957. + */
  8958. +struct dpaa2_sg_entry {
  8959. + __le64 addr;
  8960. + __le32 len;
  8961. + __le16 bpid;
  8962. + __le16 format_offset;
  8963. +};
  8964. +
  8965. +enum dpaa2_sg_format {
  8966. + dpaa2_sg_single = 0,
  8967. + dpaa2_sg_frame_data,
  8968. + dpaa2_sg_sgt_ext
  8969. +};
  8970. +
  8971. +/* Accessors for SG entry fields */
  8972. +
  8973. +/**
  8974. + * dpaa2_sg_get_addr() - Get the address from SG entry
  8975. + * @sg: the given scatter-gathering object
  8976. + *
  8977. + * Return the address.
  8978. + */
  8979. +static inline dma_addr_t dpaa2_sg_get_addr(const struct dpaa2_sg_entry *sg)
  8980. +{
  8981. + return le64_to_cpu((dma_addr_t)sg->addr);
  8982. +}
  8983. +
  8984. +/**
  8985. + * dpaa2_sg_set_addr() - Set the address in SG entry
  8986. + * @sg: the given scatter-gathering object
  8987. + * @addr: the address to be set
  8988. + */
  8989. +static inline void dpaa2_sg_set_addr(struct dpaa2_sg_entry *sg, dma_addr_t addr)
  8990. +{
  8991. + sg->addr = cpu_to_le64(addr);
  8992. +}
  8993. +
  8994. +static inline bool dpaa2_sg_short_len(const struct dpaa2_sg_entry *sg)
  8995. +{
  8996. + return !!((le16_to_cpu(sg->format_offset) >> SG_SHORT_LEN_FLAG_SHIFT)
  8997. + & SG_SHORT_LEN_FLAG_MASK);
  8998. +}
  8999. +
  9000. +/**
  9001. + * dpaa2_sg_get_len() - Get the length in SG entry
  9002. + * @sg: the given scatter-gathering object
  9003. + *
  9004. + * Return the length.
  9005. + */
  9006. +static inline u32 dpaa2_sg_get_len(const struct dpaa2_sg_entry *sg)
  9007. +{
  9008. + if (dpaa2_sg_short_len(sg))
  9009. + return le32_to_cpu(sg->len) & SG_SHORT_LEN_MASK;
  9010. +
  9011. + return le32_to_cpu(sg->len);
  9012. +}
  9013. +
  9014. +/**
  9015. + * dpaa2_sg_set_len() - Set the length in SG entry
  9016. + * @sg: the given scatter-gathering object
  9017. + * @len: the length to be set
  9018. + */
  9019. +static inline void dpaa2_sg_set_len(struct dpaa2_sg_entry *sg, u32 len)
  9020. +{
  9021. + sg->len = cpu_to_le32(len);
  9022. +}
  9023. +
  9024. +/**
  9025. + * dpaa2_sg_get_offset() - Get the offset in SG entry
  9026. + * @sg: the given scatter-gathering object
  9027. + *
  9028. + * Return the offset.
  9029. + */
  9030. +static inline u16 dpaa2_sg_get_offset(const struct dpaa2_sg_entry *sg)
  9031. +{
  9032. + return le16_to_cpu(sg->format_offset) & SG_OFFSET_MASK;
  9033. +}
  9034. +
  9035. +/**
  9036. + * dpaa2_sg_set_offset() - Set the offset in SG entry
  9037. + * @sg: the given scatter-gathering object
  9038. + * @offset: the offset to be set
  9039. + */
  9040. +static inline void dpaa2_sg_set_offset(struct dpaa2_sg_entry *sg,
  9041. + u16 offset)
  9042. +{
  9043. + sg->format_offset &= cpu_to_le16(~SG_OFFSET_MASK);
  9044. + sg->format_offset |= cpu_to_le16(offset);
  9045. +}
  9046. +
  9047. +/**
  9048. + * dpaa2_sg_get_format() - Get the SG format in SG entry
  9049. + * @sg: the given scatter-gathering object
  9050. + *
  9051. + * Return the format.
  9052. + */
  9053. +static inline enum dpaa2_sg_format
  9054. + dpaa2_sg_get_format(const struct dpaa2_sg_entry *sg)
  9055. +{
  9056. + return (enum dpaa2_sg_format)((le16_to_cpu(sg->format_offset)
  9057. + >> SG_FORMAT_SHIFT) & SG_FORMAT_MASK);
  9058. +}
  9059. +
  9060. +/**
  9061. + * dpaa2_sg_set_format() - Set the SG format in SG entry
  9062. + * @sg: the given scatter-gathering object
  9063. + * @format: the format to be set
  9064. + */
  9065. +static inline void dpaa2_sg_set_format(struct dpaa2_sg_entry *sg,
  9066. + enum dpaa2_sg_format format)
  9067. +{
  9068. + sg->format_offset &= cpu_to_le16(~(SG_FORMAT_MASK << SG_FORMAT_SHIFT));
  9069. + sg->format_offset |= cpu_to_le16(format << SG_FORMAT_SHIFT);
  9070. +}
  9071. +
  9072. +/**
  9073. + * dpaa2_sg_get_bpid() - Get the buffer pool id in SG entry
  9074. + * @sg: the given scatter-gathering object
  9075. + *
  9076. + * Return the bpid.
  9077. + */
  9078. +static inline u16 dpaa2_sg_get_bpid(const struct dpaa2_sg_entry *sg)
  9079. +{
  9080. + return le16_to_cpu(sg->bpid) & SG_BPID_MASK;
  9081. +}
  9082. +
  9083. +/**
  9084. + * dpaa2_sg_set_bpid() - Set the buffer pool id in SG entry
  9085. + * @sg: the given scatter-gathering object
  9086. + * @bpid: the bpid to be set
  9087. + */
  9088. +static inline void dpaa2_sg_set_bpid(struct dpaa2_sg_entry *sg, u16 bpid)
  9089. +{
  9090. + sg->bpid &= cpu_to_le16(~(SG_BPID_MASK));
  9091. + sg->bpid |= cpu_to_le16(bpid);
  9092. +}
  9093. +
  9094. +/**
  9095. + * dpaa2_sg_is_final() - Check final bit in SG entry
  9096. + * @sg: the given scatter-gathering object
  9097. + *
  9098. + * Return bool.
  9099. + */
  9100. +static inline bool dpaa2_sg_is_final(const struct dpaa2_sg_entry *sg)
  9101. +{
  9102. + return !!(le16_to_cpu(sg->format_offset) >> SG_FINAL_FLAG_SHIFT);
  9103. +}
  9104. +
  9105. +/**
  9106. + * dpaa2_sg_set_final() - Set the final bit in SG entry
  9107. + * @sg: the given scatter-gathering object
  9108. + * @final: the final boolean to be set
  9109. + */
  9110. +static inline void dpaa2_sg_set_final(struct dpaa2_sg_entry *sg, bool final)
  9111. +{
  9112. + sg->format_offset &= cpu_to_le16(~(SG_FINAL_FLAG_MASK
  9113. + << SG_FINAL_FLAG_SHIFT));
  9114. + sg->format_offset |= cpu_to_le16(final << SG_FINAL_FLAG_SHIFT);
  9115. +}
  9116. +
  9117. +/**
  9118. + * struct dpaa2_fl_entry - structure for frame list entry.
  9119. + * @addr: address in the FLE
  9120. + * @len: length in the FLE
  9121. + * @bpid: buffer pool ID
  9122. + * @format_offset: format, offset, and short-length fields
  9123. + * @frc: frame context
  9124. + * @ctrl: control bits...including pta, pvt1, pvt2, err, etc
  9125. + * @flc: flow context address
  9126. + */
  9127. +struct dpaa2_fl_entry {
  9128. + __le64 addr;
  9129. + __le32 len;
  9130. + __le16 bpid;
  9131. + __le16 format_offset;
  9132. + __le32 frc;
  9133. + __le32 ctrl;
  9134. + __le64 flc;
  9135. +};
  9136. +
  9137. +enum dpaa2_fl_format {
  9138. + dpaa2_fl_single = 0,
  9139. + dpaa2_fl_res,
  9140. + dpaa2_fl_sg
  9141. +};
  9142. +
  9143. +/**
  9144. + * dpaa2_fl_get_addr() - get the addr field of FLE
  9145. + * @fle: the given frame list entry
  9146. + *
  9147. + * Return the address in the frame list entry.
  9148. + */
  9149. +static inline dma_addr_t dpaa2_fl_get_addr(const struct dpaa2_fl_entry *fle)
  9150. +{
  9151. + return (dma_addr_t)le64_to_cpu(fle->addr);
  9152. +}
  9153. +
  9154. +/**
  9155. + * dpaa2_fl_set_addr() - Set the addr field of FLE
  9156. + * @fle: the given frame list entry
  9157. + * @addr: the address needs to be set in frame list entry
  9158. + */
  9159. +static inline void dpaa2_fl_set_addr(struct dpaa2_fl_entry *fle,
  9160. + dma_addr_t addr)
  9161. +{
  9162. + fle->addr = cpu_to_le64(addr);
  9163. +}
  9164. +
  9165. +/**
  9166. + * dpaa2_fl_get_frc() - Get the frame context in the FLE
  9167. + * @fle: the given frame list entry
  9168. + *
  9169. + * Return the frame context field in the frame lsit entry.
  9170. + */
  9171. +static inline u32 dpaa2_fl_get_frc(const struct dpaa2_fl_entry *fle)
  9172. +{
  9173. + return le32_to_cpu(fle->frc);
  9174. +}
  9175. +
  9176. +/**
  9177. + * dpaa2_fl_set_frc() - Set the frame context in the FLE
  9178. + * @fle: the given frame list entry
  9179. + * @frc: the frame context needs to be set in frame list entry
  9180. + */
  9181. +static inline void dpaa2_fl_set_frc(struct dpaa2_fl_entry *fle, u32 frc)
  9182. +{
  9183. + fle->frc = cpu_to_le32(frc);
  9184. +}
  9185. +
  9186. +/**
  9187. + * dpaa2_fl_get_ctrl() - Get the control bits in the FLE
  9188. + * @fle: the given frame list entry
  9189. + *
  9190. + * Return the control bits field in the frame list entry.
  9191. + */
  9192. +static inline u32 dpaa2_fl_get_ctrl(const struct dpaa2_fl_entry *fle)
  9193. +{
  9194. + return le32_to_cpu(fle->ctrl);
  9195. +}
  9196. +
  9197. +/**
  9198. + * dpaa2_fl_set_ctrl() - Set the control bits in the FLE
  9199. + * @fle: the given frame list entry
  9200. + * @ctrl: the control bits to be set in the frame list entry
  9201. + */
  9202. +static inline void dpaa2_fl_set_ctrl(struct dpaa2_fl_entry *fle, u32 ctrl)
  9203. +{
  9204. + fle->ctrl = cpu_to_le32(ctrl);
  9205. +}
  9206. +
  9207. +/**
  9208. + * dpaa2_fl_get_flc() - Get the flow context in the FLE
  9209. + * @fle: the given frame list entry
  9210. + *
  9211. + * Return the flow context in the frame list entry.
  9212. + */
  9213. +static inline dma_addr_t dpaa2_fl_get_flc(const struct dpaa2_fl_entry *fle)
  9214. +{
  9215. + return (dma_addr_t)le64_to_cpu(fle->flc);
  9216. +}
  9217. +
  9218. +/**
  9219. + * dpaa2_fl_set_flc() - Set the flow context field of FLE
  9220. + * @fle: the given frame list entry
  9221. + * @flc_addr: the flow context needs to be set in frame list entry
  9222. + */
  9223. +static inline void dpaa2_fl_set_flc(struct dpaa2_fl_entry *fle,
  9224. + dma_addr_t flc_addr)
  9225. +{
  9226. + fle->flc = cpu_to_le64(flc_addr);
  9227. +}
  9228. +
  9229. +static inline bool dpaa2_fl_short_len(const struct dpaa2_fl_entry *fle)
  9230. +{
  9231. + return !!((le16_to_cpu(fle->format_offset) >>
  9232. + FL_SHORT_LEN_FLAG_SHIFT) & FL_SHORT_LEN_FLAG_MASK);
  9233. +}
  9234. +
  9235. +/**
  9236. + * dpaa2_fl_get_len() - Get the length in the FLE
  9237. + * @fle: the given frame list entry
  9238. + *
  9239. + * Return the length field in the frame list entry.
  9240. + */
  9241. +static inline u32 dpaa2_fl_get_len(const struct dpaa2_fl_entry *fle)
  9242. +{
  9243. + if (dpaa2_fl_short_len(fle))
  9244. + return le32_to_cpu(fle->len) & FL_SHORT_LEN_MASK;
  9245. +
  9246. + return le32_to_cpu(fle->len);
  9247. +}
  9248. +
  9249. +/**
  9250. + * dpaa2_fl_set_len() - Set the length field of FLE
  9251. + * @fle: the given frame list entry
  9252. + * @len: the length needs to be set in frame list entry
  9253. + */
  9254. +static inline void dpaa2_fl_set_len(struct dpaa2_fl_entry *fle, u32 len)
  9255. +{
  9256. + fle->len = cpu_to_le32(len);
  9257. +}
  9258. +
  9259. +/**
  9260. + * dpaa2_fl_get_offset() - Get the offset field in the frame list entry
  9261. + * @fle: the given frame list entry
  9262. + *
  9263. + * Return the offset.
  9264. + */
  9265. +static inline u16 dpaa2_fl_get_offset(const struct dpaa2_fl_entry *fle)
  9266. +{
  9267. + return le16_to_cpu(fle->format_offset) & FL_OFFSET_MASK;
  9268. +}
  9269. +
  9270. +/**
  9271. + * dpaa2_fl_set_offset() - Set the offset field of FLE
  9272. + * @fle: the given frame list entry
  9273. + * @offset: the offset needs to be set in frame list entry
  9274. + */
  9275. +static inline void dpaa2_fl_set_offset(struct dpaa2_fl_entry *fle, u16 offset)
  9276. +{
  9277. + fle->format_offset &= cpu_to_le16(~FL_OFFSET_MASK);
  9278. + fle->format_offset |= cpu_to_le16(offset);
  9279. +}
  9280. +
  9281. +/**
  9282. + * dpaa2_fl_get_format() - Get the format field in the FLE
  9283. + * @fle: the given frame list entry
  9284. + *
  9285. + * Return the format.
  9286. + */
  9287. +static inline enum dpaa2_fl_format dpaa2_fl_get_format(
  9288. + const struct dpaa2_fl_entry *fle)
  9289. +{
  9290. + return (enum dpaa2_fl_format)((le16_to_cpu(fle->format_offset) >>
  9291. + FL_FORMAT_SHIFT) & FL_FORMAT_MASK);
  9292. +}
  9293. +
  9294. +/**
  9295. + * dpaa2_fl_set_format() - Set the format field of FLE
  9296. + * @fle: the given frame list entry
  9297. + * @format: the format needs to be set in frame list entry
  9298. + */
  9299. +static inline void dpaa2_fl_set_format(struct dpaa2_fl_entry *fle,
  9300. + enum dpaa2_fl_format format)
  9301. +{
  9302. + fle->format_offset &= cpu_to_le16(~(FL_FORMAT_MASK << FL_FORMAT_SHIFT));
  9303. + fle->format_offset |= cpu_to_le16(format << FL_FORMAT_SHIFT);
  9304. +}
  9305. +
  9306. +/**
  9307. + * dpaa2_fl_get_bpid() - Get the bpid field in the FLE
  9308. + * @fle: the given frame list entry
  9309. + *
  9310. + * Return the buffer pool id.
  9311. + */
  9312. +static inline u16 dpaa2_fl_get_bpid(const struct dpaa2_fl_entry *fle)
  9313. +{
  9314. + return le16_to_cpu(fle->bpid) & FL_BPID_MASK;
  9315. +}
  9316. +
  9317. +/**
  9318. + * dpaa2_fl_set_bpid() - Set the bpid field of FLE
  9319. + * @fle: the given frame list entry
  9320. + * @bpid: buffer pool id to be set
  9321. + */
  9322. +static inline void dpaa2_fl_set_bpid(struct dpaa2_fl_entry *fle, u16 bpid)
  9323. +{
  9324. + fle->bpid &= cpu_to_le16(~(FL_BPID_MASK));
  9325. + fle->bpid |= cpu_to_le16(bpid);
  9326. +}
  9327. +
  9328. +/**
  9329. + * dpaa2_fl_is_final() - Check final bit in FLE
  9330. + * @fle: the given frame list entry
  9331. + *
  9332. + * Return bool.
  9333. + */
  9334. +static inline bool dpaa2_fl_is_final(const struct dpaa2_fl_entry *fle)
  9335. +{
  9336. + return !!(le16_to_cpu(fle->format_offset) >> FL_FINAL_FLAG_SHIFT);
  9337. +}
  9338. +
  9339. +/**
  9340. + * dpaa2_fl_set_final() - Set the final bit in FLE
  9341. + * @fle: the given frame list entry
  9342. + * @final: the final boolean to be set
  9343. + */
  9344. +static inline void dpaa2_fl_set_final(struct dpaa2_fl_entry *fle, bool final)
  9345. +{
  9346. + fle->format_offset &= cpu_to_le16(~(FL_FINAL_FLAG_MASK <<
  9347. + FL_FINAL_FLAG_SHIFT));
  9348. + fle->format_offset |= cpu_to_le16(final << FL_FINAL_FLAG_SHIFT);
  9349. +}
  9350. +
  9351. +#endif /* __FSL_DPAA2_FD_H */
  9352. --- /dev/null
  9353. +++ b/drivers/staging/fsl-mc/include/dpaa2-global.h
  9354. @@ -0,0 +1,202 @@
  9355. +/*
  9356. + * Copyright 2014-2016 Freescale Semiconductor Inc.
  9357. + * Copyright 2016 NXP
  9358. + *
  9359. + * Redistribution and use in source and binary forms, with or without
  9360. + * modification, are permitted provided that the following conditions are met:
  9361. + * * Redistributions of source code must retain the above copyright
  9362. + * notice, this list of conditions and the following disclaimer.
  9363. + * * Redistributions in binary form must reproduce the above copyright
  9364. + * notice, this list of conditions and the following disclaimer in the
  9365. + * documentation and/or other materials provided with the distribution.
  9366. + * * Neither the name of Freescale Semiconductor nor the
  9367. + * names of its contributors may be used to endorse or promote products
  9368. + * derived from this software without specific prior written permission.
  9369. + *
  9370. + * ALTERNATIVELY, this software may be distributed under the terms of the
  9371. + * GNU General Public License ("GPL") as published by the Free Software
  9372. + * Foundation, either version 2 of that License or (at your option) any
  9373. + * later version.
  9374. + *
  9375. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  9376. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  9377. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  9378. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  9379. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  9380. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  9381. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  9382. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9383. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  9384. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9385. + */
  9386. +#ifndef __FSL_DPAA2_GLOBAL_H
  9387. +#define __FSL_DPAA2_GLOBAL_H
  9388. +
  9389. +#include <linux/types.h>
  9390. +#include <linux/cpumask.h>
  9391. +#include "dpaa2-fd.h"
  9392. +
  9393. +struct dpaa2_dq {
  9394. + union {
  9395. + struct common {
  9396. + u8 verb;
  9397. + u8 reserved[63];
  9398. + } common;
  9399. + struct dq {
  9400. + u8 verb;
  9401. + u8 stat;
  9402. + __le16 seqnum;
  9403. + __le16 oprid;
  9404. + u8 reserved;
  9405. + u8 tok;
  9406. + __le32 fqid;
  9407. + u32 reserved2;
  9408. + __le32 fq_byte_cnt;
  9409. + __le32 fq_frm_cnt;
  9410. + __le64 fqd_ctx;
  9411. + u8 fd[32];
  9412. + } dq;
  9413. + struct scn {
  9414. + u8 verb;
  9415. + u8 stat;
  9416. + u8 state;
  9417. + u8 reserved;
  9418. + __le32 rid_tok;
  9419. + __le64 ctx;
  9420. + } scn;
  9421. + };
  9422. +};
  9423. +
  9424. +/* Parsing frame dequeue results */
  9425. +/* FQ empty */
  9426. +#define DPAA2_DQ_STAT_FQEMPTY 0x80
  9427. +/* FQ held active */
  9428. +#define DPAA2_DQ_STAT_HELDACTIVE 0x40
  9429. +/* FQ force eligible */
  9430. +#define DPAA2_DQ_STAT_FORCEELIGIBLE 0x20
  9431. +/* valid frame */
  9432. +#define DPAA2_DQ_STAT_VALIDFRAME 0x10
  9433. +/* FQ ODP enable */
  9434. +#define DPAA2_DQ_STAT_ODPVALID 0x04
  9435. +/* volatile dequeue */
  9436. +#define DPAA2_DQ_STAT_VOLATILE 0x02
  9437. +/* volatile dequeue command is expired */
  9438. +#define DPAA2_DQ_STAT_EXPIRED 0x01
  9439. +
  9440. +#define DQ_FQID_MASK 0x00FFFFFF
  9441. +#define DQ_FRAME_COUNT_MASK 0x00FFFFFF
  9442. +
  9443. +/**
  9444. + * dpaa2_dq_flags() - Get the stat field of dequeue response
  9445. + * @dq: the dequeue result.
  9446. + */
  9447. +static inline u32 dpaa2_dq_flags(const struct dpaa2_dq *dq)
  9448. +{
  9449. + return dq->dq.stat;
  9450. +}
  9451. +
  9452. +/**
  9453. + * dpaa2_dq_is_pull() - Check whether the dq response is from a pull
  9454. + * command.
  9455. + * @dq: the dequeue result
  9456. + *
  9457. + * Return 1 for volatile(pull) dequeue, 0 for static dequeue.
  9458. + */
  9459. +static inline int dpaa2_dq_is_pull(const struct dpaa2_dq *dq)
  9460. +{
  9461. + return (int)(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_VOLATILE);
  9462. +}
  9463. +
  9464. +/**
  9465. + * dpaa2_dq_is_pull_complete() - Check whether the pull command is completed.
  9466. + * @dq: the dequeue result
  9467. + *
  9468. + * Return boolean.
  9469. + */
  9470. +static inline bool dpaa2_dq_is_pull_complete(const struct dpaa2_dq *dq)
  9471. +{
  9472. + return !!(dpaa2_dq_flags(dq) & DPAA2_DQ_STAT_EXPIRED);
  9473. +}
  9474. +
  9475. +/**
  9476. + * dpaa2_dq_seqnum() - Get the seqnum field in dequeue response
  9477. + * @dq: the dequeue result
  9478. + *
  9479. + * seqnum is valid only if VALIDFRAME flag is TRUE
  9480. + *
  9481. + * Return seqnum.
  9482. + */
  9483. +static inline u16 dpaa2_dq_seqnum(const struct dpaa2_dq *dq)
  9484. +{
  9485. + return le16_to_cpu(dq->dq.seqnum);
  9486. +}
  9487. +
  9488. +/**
  9489. + * dpaa2_dq_odpid() - Get the odpid field in dequeue response
  9490. + * @dq: the dequeue result
  9491. + *
  9492. + * odpid is valid only if ODPVALID flag is TRUE.
  9493. + *
  9494. + * Return odpid.
  9495. + */
  9496. +static inline u16 dpaa2_dq_odpid(const struct dpaa2_dq *dq)
  9497. +{
  9498. + return le16_to_cpu(dq->dq.oprid);
  9499. +}
  9500. +
  9501. +/**
  9502. + * dpaa2_dq_fqid() - Get the fqid in dequeue response
  9503. + * @dq: the dequeue result
  9504. + *
  9505. + * Return fqid.
  9506. + */
  9507. +static inline u32 dpaa2_dq_fqid(const struct dpaa2_dq *dq)
  9508. +{
  9509. + return le32_to_cpu(dq->dq.fqid) & DQ_FQID_MASK;
  9510. +}
  9511. +
  9512. +/**
  9513. + * dpaa2_dq_byte_count() - Get the byte count in dequeue response
  9514. + * @dq: the dequeue result
  9515. + *
  9516. + * Return the byte count remaining in the FQ.
  9517. + */
  9518. +static inline u32 dpaa2_dq_byte_count(const struct dpaa2_dq *dq)
  9519. +{
  9520. + return le32_to_cpu(dq->dq.fq_byte_cnt);
  9521. +}
  9522. +
  9523. +/**
  9524. + * dpaa2_dq_frame_count() - Get the frame count in dequeue response
  9525. + * @dq: the dequeue result
  9526. + *
  9527. + * Return the frame count remaining in the FQ.
  9528. + */
  9529. +static inline u32 dpaa2_dq_frame_count(const struct dpaa2_dq *dq)
  9530. +{
  9531. + return le32_to_cpu(dq->dq.fq_frm_cnt) & DQ_FRAME_COUNT_MASK;
  9532. +}
  9533. +
  9534. +/**
  9535. + * dpaa2_dq_fd_ctx() - Get the frame queue context in dequeue response
  9536. + * @dq: the dequeue result
  9537. + *
  9538. + * Return the frame queue context.
  9539. + */
  9540. +static inline u64 dpaa2_dq_fqd_ctx(const struct dpaa2_dq *dq)
  9541. +{
  9542. + return le64_to_cpu(dq->dq.fqd_ctx);
  9543. +}
  9544. +
  9545. +/**
  9546. + * dpaa2_dq_fd() - Get the frame descriptor in dequeue response
  9547. + * @dq: the dequeue result
  9548. + *
  9549. + * Return the frame descriptor.
  9550. + */
  9551. +static inline const struct dpaa2_fd *dpaa2_dq_fd(const struct dpaa2_dq *dq)
  9552. +{
  9553. + return (const struct dpaa2_fd *)&dq->dq.fd[0];
  9554. +}
  9555. +
  9556. +#endif /* __FSL_DPAA2_GLOBAL_H */
  9557. --- /dev/null
  9558. +++ b/drivers/staging/fsl-mc/include/dpaa2-io.h
  9559. @@ -0,0 +1,190 @@
  9560. +/*
  9561. + * Copyright 2014-2016 Freescale Semiconductor Inc.
  9562. + * Copyright 2017 NXP
  9563. + *
  9564. + * Redistribution and use in source and binary forms, with or without
  9565. + * modification, are permitted provided that the following conditions are met:
  9566. + * * Redistributions of source code must retain the above copyright
  9567. + * notice, this list of conditions and the following disclaimer.
  9568. + * * Redistributions in binary form must reproduce the above copyright
  9569. + * notice, this list of conditions and the following disclaimer in the
  9570. + * documentation and/or other materials provided with the distribution.
  9571. + * * Neither the name of Freescale Semiconductor nor the
  9572. + * names of its contributors may be used to endorse or promote products
  9573. + * derived from this software without specific prior written permission.
  9574. + *
  9575. + * ALTERNATIVELY, this software may be distributed under the terms of the
  9576. + * GNU General Public License ("GPL") as published by the Free Software
  9577. + * Foundation, either version 2 of that License or (at your option) any
  9578. + * later version.
  9579. + *
  9580. + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  9581. + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  9582. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  9583. + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  9584. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  9585. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  9586. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  9587. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  9588. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  9589. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9590. + */
  9591. +#ifndef __FSL_DPAA2_IO_H
  9592. +#define __FSL_DPAA2_IO_H
  9593. +
  9594. +#include <linux/types.h>
  9595. +#include <linux/cpumask.h>
  9596. +
  9597. +#include "dpaa2-fd.h"
  9598. +#include "dpaa2-global.h"
  9599. +
  9600. +struct dpaa2_io;
  9601. +struct dpaa2_io_store;
  9602. +struct device;
  9603. +
  9604. +/**
  9605. + * DOC: DPIO Service
  9606. + *
  9607. + * The DPIO service provides APIs for users to interact with the datapath
  9608. + * by enqueueing and dequeing frame descriptors.
  9609. + *
  9610. + * The following set of APIs can be used to enqueue and dequeue frames
  9611. + * as well as producing notification callbacks when data is available
  9612. + * for dequeue.
  9613. + */
  9614. +
  9615. +/**
  9616. + * struct dpaa2_io_desc - The DPIO descriptor
  9617. + * @receives_notifications: Use notificaton mode. Non-zero if the DPIO
  9618. + * has a channel.
  9619. + * @has_8prio: Set to non-zero for channel with 8 priority WQs. Ignored
  9620. + * unless receives_notification is TRUE.
  9621. + * @cpu: The cpu index that at least interrupt handlers will
  9622. + * execute on.
  9623. + * @stash_affinity: The stash affinity for this portal favour 'cpu'
  9624. + * @regs_cena: The cache enabled regs.
  9625. + * @regs_cinh: The cache inhibited regs
  9626. + * @dpio_id: The dpio index
  9627. + * @qman_version: The qman version
  9628. + *
  9629. + * Describes the attributes and features of the DPIO object.
  9630. + */
  9631. +struct dpaa2_io_desc {
  9632. + int receives_notifications;
  9633. + int has_8prio;
  9634. + int cpu;
  9635. + void *regs_cena;
  9636. + void *regs_cinh;
  9637. + int dpio_id;
  9638. + u32 qman_version;
  9639. +};
  9640. +
  9641. +struct dpaa2_io *dpaa2_io_create(const struct dpaa2_io_desc *desc);
  9642. +
  9643. +void dpaa2_io_down(struct dpaa2_io *d);
  9644. +
  9645. +irqreturn_t dpaa2_io_irq(struct dpaa2_io *obj);
  9646. +
  9647. +/**
  9648. + * struct dpaa2_io_notification_ctx - The DPIO notification context structure
  9649. + * @cb: The callback to be invoked when the notification arrives
  9650. + * @is_cdan: Zero for FQDAN, non-zero for CDAN
  9651. + * @id: FQID or channel ID, needed for rearm
  9652. + * @desired_cpu: The cpu on which the notifications will show up. -1 means
  9653. + * any CPU.
  9654. + * @dpio_id: The dpio index
  9655. + * @qman64: The 64-bit context value shows up in the FQDAN/CDAN.
  9656. + * @node: The list node
  9657. + * @dpio_private: The dpio object internal to dpio_service
  9658. + *
  9659. + * Used when a FQDAN/CDAN registration is made by drivers.
  9660. + */
  9661. +struct dpaa2_io_notification_ctx {
  9662. + void (*cb)(struct dpaa2_io_notification_ctx *);
  9663. + int is_cdan;
  9664. + u32 id;
  9665. + int desired_cpu;
  9666. + int dpio_id;
  9667. + u64 qman64;
  9668. + struct list_head node;
  9669. + void *dpio_private;
  9670. +};
  9671. +
  9672. +int dpaa2_io_service_register(struct dpaa2_io *service,
  9673. + struct dpaa2_io_notification_ctx *ctx);
  9674. +void dpaa2_io_service_deregister(struct dpaa2_io *service,
  9675. + struct dpaa2_io_notification_ctx *ctx);
  9676. +int dpaa2_io_service_rearm(struct dpaa2_io *service,
  9677. + struct dpaa2_io_notification_ctx *ctx);
  9678. +
  9679. +int dpaa2_io_service_pull_fq(struct dpaa2_io *d, u32 fqid,
  9680. + struct dpaa2_io_store *s);
  9681. +int dpaa2_io_service_pull_channel(struct dpaa2_io *d, u32 channelid,
  9682. + struct dpaa2_io_store *s);
  9683. +
  9684. +int dpaa2_io_service_enqueue_fq(struct dpaa2_io *d, u32 fqid,
  9685. + const struct dpaa2_fd *fd);
  9686. +int dpaa2_io_service_enqueue_qd(struct dpaa2_io *d, u32 qdid, u8 prio,
  9687. + u16 qdbin, const struct dpaa2_fd *fd);
  9688. +int dpaa2_io_service_release(struct dpaa2_io *d, u32 bpid,
  9689. + const u64 *buffers, unsigned int num_buffers);
  9690. +int dpaa2_io_service_acquire(struct dpaa2_io *d, u32 bpid,
  9691. + u64 *buffers, unsigned int num_buffers);
  9692. +
  9693. +struct dpaa2_io_store *dpaa2_io_store_create(unsigned int max_frames,
  9694. + struct device *dev);
  9695. +void dpaa2_io_store_destroy(struct dpaa2_io_store *s);
  9696. +struct dpaa2_dq *dpaa2_io_store_next(struct dpaa2_io_store *s, int *is_last);
  9697. +
  9698. +#ifdef CONFIG_FSL_QBMAN_DEBUG
  9699. +int dpaa2_io_query_fq_count(struct dpaa2_io *d, uint32_t fqid,
  9700. + uint32_t *fcnt, uint32_t *bcnt);
  9701. +int dpaa2_io_query_bp_count(struct dpaa2_io *d, uint32_t bpid,
  9702. + uint32_t *num);
  9703. +#endif
  9704. +
  9705. +
  9706. +/***************/
  9707. +/* CSCN */
  9708. +/***************/
  9709. +
  9710. +/**
  9711. + * struct dpaa2_cscn - The CSCN message format
  9712. + * @verb: identifies the type of message (should be 0x27).
  9713. + * @stat: status bits related to dequeuing response (not used)
  9714. + * @state: bit 0 = 0/1 if CG is no/is congested
  9715. + * @reserved: reserved byte
  9716. + * @cgid: congest grp ID - the first 16 bits
  9717. + * @ctx: context data
  9718. + *
  9719. + * Congestion management can be implemented in software through
  9720. + * the use of Congestion State Change Notifications (CSCN). These
  9721. + * are messages written by DPAA2 hardware to memory whenever the
  9722. + * instantaneous count (I_CNT field in the CG) exceeds the
  9723. + * Congestion State (CS) entrance threshold, signifying congestion
  9724. + * entrance, or when the instantaneous count returns below exit
  9725. + * threshold, signifying congestion exit. The format of the message
  9726. + * is given by the dpaa2_cscn structure. Bit 0 of the state field
  9727. + * represents congestion state written by the hardware.
  9728. + */
  9729. +struct dpaa2_cscn {
  9730. + u8 verb;
  9731. + u8 stat;
  9732. + u8 state;
  9733. + u8 reserved;
  9734. + __le32 cgid;
  9735. + __le64 ctx;
  9736. +};
  9737. +
  9738. +#define DPAA2_CSCN_SIZE 64
  9739. +#define DPAA2_CSCN_ALIGN 16
  9740. +
  9741. +#define DPAA2_CSCN_STATE_MASK 0x1
  9742. +#define DPAA2_CSCN_CONGESTED 1
  9743. +
  9744. +static inline bool dpaa2_cscn_state_congested(struct dpaa2_cscn *cscn)
  9745. +{
  9746. + return ((cscn->state & DPAA2_CSCN_STATE_MASK) == DPAA2_CSCN_CONGESTED);
  9747. +}
  9748. +
  9749. +#endif /* __FSL_DPAA2_IO_H */
  9750. --- a/drivers/staging/fsl-mc/include/dpbp-cmd.h
  9751. +++ /dev/null
  9752. @@ -1,185 +0,0 @@
  9753. -/* Copyright 2013-2016 Freescale Semiconductor Inc.
  9754. - *
  9755. - * Redistribution and use in source and binary forms, with or without
  9756. - * modification, are permitted provided that the following conditions are met:
  9757. - * * Redistributions of source code must retain the above copyright
  9758. - * notice, this list of conditions and the following disclaimer.
  9759. - * * Redistributions in binary form must reproduce the above copyright
  9760. - * notice, this list of conditions and the following disclaimer in the
  9761. - * documentation and/or other materials provided with the distribution.
  9762. - * * Neither the name of the above-listed copyright holders nor the
  9763. - * names of any contributors may be used to endorse or promote products
  9764. - * derived from this software without specific prior written permission.
  9765. - *
  9766. - *
  9767. - * ALTERNATIVELY, this software may be distributed under the terms of the
  9768. - * GNU General Public License ("GPL") as published by the Free Software
  9769. - * Foundation, either version 2 of that License or (at your option) any
  9770. - * later version.
  9771. - *
  9772. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  9773. - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  9774. - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  9775. - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  9776. - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  9777. - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  9778. - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  9779. - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  9780. - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  9781. - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  9782. - * POSSIBILITY OF SUCH DAMAGE.
  9783. - */
  9784. -#ifndef _FSL_DPBP_CMD_H
  9785. -#define _FSL_DPBP_CMD_H
  9786. -
  9787. -/* DPBP Version */
  9788. -#define DPBP_VER_MAJOR 2
  9789. -#define DPBP_VER_MINOR 2
  9790. -
  9791. -/* Command IDs */
  9792. -#define DPBP_CMDID_CLOSE 0x800
  9793. -#define DPBP_CMDID_OPEN 0x804
  9794. -#define DPBP_CMDID_CREATE 0x904
  9795. -#define DPBP_CMDID_DESTROY 0x900
  9796. -
  9797. -#define DPBP_CMDID_ENABLE 0x002
  9798. -#define DPBP_CMDID_DISABLE 0x003
  9799. -#define DPBP_CMDID_GET_ATTR 0x004
  9800. -#define DPBP_CMDID_RESET 0x005
  9801. -#define DPBP_CMDID_IS_ENABLED 0x006
  9802. -
  9803. -#define DPBP_CMDID_SET_IRQ 0x010
  9804. -#define DPBP_CMDID_GET_IRQ 0x011
  9805. -#define DPBP_CMDID_SET_IRQ_ENABLE 0x012
  9806. -#define DPBP_CMDID_GET_IRQ_ENABLE 0x013
  9807. -#define DPBP_CMDID_SET_IRQ_MASK 0x014
  9808. -#define DPBP_CMDID_GET_IRQ_MASK 0x015
  9809. -#define DPBP_CMDID_GET_IRQ_STATUS 0x016
  9810. -#define DPBP_CMDID_CLEAR_IRQ_STATUS 0x017
  9811. -
  9812. -#define DPBP_CMDID_SET_NOTIFICATIONS 0x01b0
  9813. -#define DPBP_CMDID_GET_NOTIFICATIONS 0x01b1
  9814. -
  9815. -struct dpbp_cmd_open {
  9816. - __le32 dpbp_id;
  9817. -};
  9818. -
  9819. -#define DPBP_ENABLE 0x1
  9820. -
  9821. -struct dpbp_rsp_is_enabled {
  9822. - u8 enabled;
  9823. -};
  9824. -
  9825. -struct dpbp_cmd_set_irq {
  9826. - /* cmd word 0 */
  9827. - u8 irq_index;
  9828. - u8 pad[3];
  9829. - __le32 irq_val;
  9830. - /* cmd word 1 */
  9831. - __le64 irq_addr;
  9832. - /* cmd word 2 */
  9833. - __le32 irq_num;
  9834. -};
  9835. -
  9836. -struct dpbp_cmd_get_irq {
  9837. - __le32 pad;
  9838. - u8 irq_index;
  9839. -};
  9840. -
  9841. -struct dpbp_rsp_get_irq {
  9842. - /* response word 0 */
  9843. - __le32 irq_val;
  9844. - __le32 pad;
  9845. - /* response word 1 */
  9846. - __le64 irq_addr;
  9847. - /* response word 2 */
  9848. - __le32 irq_num;
  9849. - __le32 type;
  9850. -};
  9851. -
  9852. -struct dpbp_cmd_set_irq_enable {
  9853. - u8 enable;
  9854. - u8 pad[3];
  9855. - u8 irq_index;
  9856. -};
  9857. -
  9858. -struct dpbp_cmd_get_irq_enable {
  9859. - __le32 pad;
  9860. - u8 irq_index;
  9861. -};
  9862. -
  9863. -struct dpbp_rsp_get_irq_enable {
  9864. - u8 enabled;
  9865. -};
  9866. -
  9867. -struct dpbp_cmd_set_irq_mask {
  9868. - __le32 mask;
  9869. - u8 irq_index;
  9870. -};
  9871. -
  9872. -struct dpbp_cmd_get_irq_mask {
  9873. - __le32 pad;
  9874. - u8 irq_index;
  9875. -};
  9876. -
  9877. -struct dpbp_rsp_get_irq_mask {
  9878. - __le32 mask;
  9879. -};
  9880. -
  9881. -struct dpbp_cmd_get_irq_status {
  9882. - __le32 status;
  9883. - u8 irq_index;
  9884. -};
  9885. -
  9886. -struct dpbp_rsp_get_irq_status {
  9887. - __le32 status;
  9888. -};
  9889. -
  9890. -struct dpbp_cmd_clear_irq_status {
  9891. - __le32 status;
  9892. - u8 irq_index;
  9893. -};
  9894. -
  9895. -struct dpbp_rsp_get_attributes {
  9896. - /* response word 0 */
  9897. - __le16 pad;
  9898. - __le16 bpid;
  9899. - __le32 id;
  9900. - /* response word 1 */
  9901. - __le16 version_major;
  9902. - __le16 version_minor;
  9903. -};
  9904. -
  9905. -struct dpbp_cmd_set_notifications {
  9906. - /* cmd word 0 */
  9907. - __le32 depletion_entry;
  9908. - __le32 depletion_exit;
  9909. - /* cmd word 1 */
  9910. - __le32 surplus_entry;
  9911. - __le32 surplus_exit;
  9912. - /* cmd word 2 */
  9913. - __le16 options;
  9914. - __le16 pad[3];
  9915. - /* cmd word 3 */
  9916. - __le64 message_ctx;
  9917. - /* cmd word 4 */
  9918. - __le64 message_iova;
  9919. -};
  9920. -
  9921. -struct dpbp_rsp_get_notifications {
  9922. - /* response word 0 */
  9923. - __le32 depletion_entry;
  9924. - __le32 depletion_exit;
  9925. - /* response word 1 */
  9926. - __le32 surplus_entry;
  9927. - __le32 surplus_exit;
  9928. - /* response word 2 */
  9929. - __le16 options;
  9930. - __le16 pad[3];
  9931. - /* response word 3 */
  9932. - __le64 message_ctx;
  9933. - /* response word 4 */
  9934. - __le64 message_iova;
  9935. -};
  9936. -
  9937. -#endif /* _FSL_DPBP_CMD_H */
  9938. --- a/drivers/staging/fsl-mc/include/dpbp.h
  9939. +++ b/drivers/staging/fsl-mc/include/dpbp.h
  9940. @@ -1,4 +1,5 @@
  9941. -/* Copyright 2013-2015 Freescale Semiconductor Inc.
  9942. +/*
  9943. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  9944. *
  9945. * Redistribution and use in source and binary forms, with or without
  9946. * modification, are permitted provided that the following conditions are met:
  9947. @@ -32,7 +33,8 @@
  9948. #ifndef __FSL_DPBP_H
  9949. #define __FSL_DPBP_H
  9950. -/* Data Path Buffer Pool API
  9951. +/*
  9952. + * Data Path Buffer Pool API
  9953. * Contains initialization APIs and runtime control APIs for DPBP
  9954. */
  9955. @@ -44,25 +46,8 @@ int dpbp_open(struct fsl_mc_io *mc_io,
  9956. u16 *token);
  9957. int dpbp_close(struct fsl_mc_io *mc_io,
  9958. - u32 cmd_flags,
  9959. - u16 token);
  9960. -
  9961. -/**
  9962. - * struct dpbp_cfg - Structure representing DPBP configuration
  9963. - * @options: place holder
  9964. - */
  9965. -struct dpbp_cfg {
  9966. - u32 options;
  9967. -};
  9968. -
  9969. -int dpbp_create(struct fsl_mc_io *mc_io,
  9970. - u32 cmd_flags,
  9971. - const struct dpbp_cfg *cfg,
  9972. - u16 *token);
  9973. -
  9974. -int dpbp_destroy(struct fsl_mc_io *mc_io,
  9975. - u32 cmd_flags,
  9976. - u16 token);
  9977. + u32 cmd_flags,
  9978. + u16 token);
  9979. int dpbp_enable(struct fsl_mc_io *mc_io,
  9980. u32 cmd_flags,
  9981. @@ -82,139 +67,24 @@ int dpbp_reset(struct fsl_mc_io *mc_io,
  9982. u16 token);
  9983. /**
  9984. - * struct dpbp_irq_cfg - IRQ configuration
  9985. - * @addr: Address that must be written to signal a message-based interrupt
  9986. - * @val: Value to write into irq_addr address
  9987. - * @irq_num: A user defined number associated with this IRQ
  9988. - */
  9989. -struct dpbp_irq_cfg {
  9990. - u64 addr;
  9991. - u32 val;
  9992. - int irq_num;
  9993. -};
  9994. -
  9995. -int dpbp_set_irq(struct fsl_mc_io *mc_io,
  9996. - u32 cmd_flags,
  9997. - u16 token,
  9998. - u8 irq_index,
  9999. - struct dpbp_irq_cfg *irq_cfg);
  10000. -
  10001. -int dpbp_get_irq(struct fsl_mc_io *mc_io,
  10002. - u32 cmd_flags,
  10003. - u16 token,
  10004. - u8 irq_index,
  10005. - int *type,
  10006. - struct dpbp_irq_cfg *irq_cfg);
  10007. -
  10008. -int dpbp_set_irq_enable(struct fsl_mc_io *mc_io,
  10009. - u32 cmd_flags,
  10010. - u16 token,
  10011. - u8 irq_index,
  10012. - u8 en);
  10013. -
  10014. -int dpbp_get_irq_enable(struct fsl_mc_io *mc_io,
  10015. - u32 cmd_flags,
  10016. - u16 token,
  10017. - u8 irq_index,
  10018. - u8 *en);
  10019. -
  10020. -int dpbp_set_irq_mask(struct fsl_mc_io *mc_io,
  10021. - u32 cmd_flags,
  10022. - u16 token,
  10023. - u8 irq_index,
  10024. - u32 mask);
  10025. -
  10026. -int dpbp_get_irq_mask(struct fsl_mc_io *mc_io,
  10027. - u32 cmd_flags,
  10028. - u16 token,
  10029. - u8 irq_index,
  10030. - u32 *mask);
  10031. -
  10032. -int dpbp_get_irq_status(struct fsl_mc_io *mc_io,
  10033. - u32 cmd_flags,
  10034. - u16 token,
  10035. - u8 irq_index,
  10036. - u32 *status);
  10037. -
  10038. -int dpbp_clear_irq_status(struct fsl_mc_io *mc_io,
  10039. - u32 cmd_flags,
  10040. - u16 token,
  10041. - u8 irq_index,
  10042. - u32 status);
  10043. -
  10044. -/**
  10045. * struct dpbp_attr - Structure representing DPBP attributes
  10046. * @id: DPBP object ID
  10047. - * @version: DPBP version
  10048. * @bpid: Hardware buffer pool ID; should be used as an argument in
  10049. * acquire/release operations on buffers
  10050. */
  10051. struct dpbp_attr {
  10052. int id;
  10053. - /**
  10054. - * struct version - Structure representing DPBP version
  10055. - * @major: DPBP major version
  10056. - * @minor: DPBP minor version
  10057. - */
  10058. - struct {
  10059. - u16 major;
  10060. - u16 minor;
  10061. - } version;
  10062. u16 bpid;
  10063. };
  10064. -int dpbp_get_attributes(struct fsl_mc_io *mc_io,
  10065. - u32 cmd_flags,
  10066. - u16 token,
  10067. - struct dpbp_attr *attr);
  10068. -
  10069. -/**
  10070. - * DPBP notifications options
  10071. - */
  10072. -
  10073. -/**
  10074. - * BPSCN write will attempt to allocate into a cache (coherent write)
  10075. - */
  10076. -#define DPBP_NOTIF_OPT_COHERENT_WRITE 0x00000001
  10077. -
  10078. -/**
  10079. - * struct dpbp_notification_cfg - Structure representing DPBP notifications
  10080. - * towards software
  10081. - * @depletion_entry: below this threshold the pool is "depleted";
  10082. - * set it to '0' to disable it
  10083. - * @depletion_exit: greater than or equal to this threshold the pool exit its
  10084. - * "depleted" state
  10085. - * @surplus_entry: above this threshold the pool is in "surplus" state;
  10086. - * set it to '0' to disable it
  10087. - * @surplus_exit: less than or equal to this threshold the pool exit its
  10088. - * "surplus" state
  10089. - * @message_iova: MUST be given if either 'depletion_entry' or 'surplus_entry'
  10090. - * is not '0' (enable); I/O virtual address (must be in DMA-able memory),
  10091. - * must be 16B aligned.
  10092. - * @message_ctx: The context that will be part of the BPSCN message and will
  10093. - * be written to 'message_iova'
  10094. - * @options: Mask of available options; use 'DPBP_NOTIF_OPT_<X>' values
  10095. - */
  10096. -struct dpbp_notification_cfg {
  10097. - u32 depletion_entry;
  10098. - u32 depletion_exit;
  10099. - u32 surplus_entry;
  10100. - u32 surplus_exit;
  10101. - u64 message_iova;
  10102. - u64 message_ctx;
  10103. - u16 options;
  10104. -};
  10105. -
  10106. -int dpbp_set_notifications(struct fsl_mc_io *mc_io,
  10107. - u32 cmd_flags,
  10108. - u16 token,
  10109. - struct dpbp_notification_cfg *cfg);
  10110. -
  10111. -int dpbp_get_notifications(struct fsl_mc_io *mc_io,
  10112. - u32 cmd_flags,
  10113. - u16 token,
  10114. - struct dpbp_notification_cfg *cfg);
  10115. -
  10116. -/** @} */
  10117. +int dpbp_get_attributes(struct fsl_mc_io *mc_io,
  10118. + u32 cmd_flags,
  10119. + u16 token,
  10120. + struct dpbp_attr *attr);
  10121. +
  10122. +int dpbp_get_api_version(struct fsl_mc_io *mc_io,
  10123. + u32 cmd_flags,
  10124. + u16 *major_ver,
  10125. + u16 *minor_ver);
  10126. #endif /* __FSL_DPBP_H */
  10127. --- /dev/null
  10128. +++ b/drivers/staging/fsl-mc/include/dpcon.h
  10129. @@ -0,0 +1,115 @@
  10130. +/* Copyright 2013-2016 Freescale Semiconductor Inc.
  10131. + *
  10132. + * Redistribution and use in source and binary forms, with or without
  10133. + * modification, are permitted provided that the following conditions are met:
  10134. + * * Redistributions of source code must retain the above copyright
  10135. + * notice, this list of conditions and the following disclaimer.
  10136. + * * Redistributions in binary form must reproduce the above copyright
  10137. + * notice, this list of conditions and the following disclaimer in the
  10138. + * documentation and/or other materials provided with the distribution.
  10139. + * * Neither the name of the above-listed copyright holders nor the
  10140. + * names of any contributors may be used to endorse or promote products
  10141. + * derived from this software without specific prior written permission.
  10142. + *
  10143. + *
  10144. + * ALTERNATIVELY, this software may be distributed under the terms of the
  10145. + * GNU General Public License ("GPL") as published by the Free Software
  10146. + * Foundation, either version 2 of that License or (at your option) any
  10147. + * later version.
  10148. + *
  10149. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  10150. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  10151. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  10152. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  10153. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  10154. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  10155. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  10156. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  10157. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  10158. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  10159. + * POSSIBILITY OF SUCH DAMAGE.
  10160. + */
  10161. +#ifndef __FSL_DPCON_H
  10162. +#define __FSL_DPCON_H
  10163. +
  10164. +/* Data Path Concentrator API
  10165. + * Contains initialization APIs and runtime control APIs for DPCON
  10166. + */
  10167. +
  10168. +struct fsl_mc_io;
  10169. +
  10170. +/** General DPCON macros */
  10171. +
  10172. +/**
  10173. + * Use it to disable notifications; see dpcon_set_notification()
  10174. + */
  10175. +#define DPCON_INVALID_DPIO_ID (int)(-1)
  10176. +
  10177. +int dpcon_open(struct fsl_mc_io *mc_io,
  10178. + u32 cmd_flags,
  10179. + int dpcon_id,
  10180. + u16 *token);
  10181. +
  10182. +int dpcon_close(struct fsl_mc_io *mc_io,
  10183. + u32 cmd_flags,
  10184. + u16 token);
  10185. +
  10186. +int dpcon_enable(struct fsl_mc_io *mc_io,
  10187. + u32 cmd_flags,
  10188. + u16 token);
  10189. +
  10190. +int dpcon_disable(struct fsl_mc_io *mc_io,
  10191. + u32 cmd_flags,
  10192. + u16 token);
  10193. +
  10194. +int dpcon_is_enabled(struct fsl_mc_io *mc_io,
  10195. + u32 cmd_flags,
  10196. + u16 token,
  10197. + int *en);
  10198. +
  10199. +int dpcon_reset(struct fsl_mc_io *mc_io,
  10200. + u32 cmd_flags,
  10201. + u16 token);
  10202. +
  10203. +/**
  10204. + * struct dpcon_attr - Structure representing DPCON attributes
  10205. + * @id: DPCON object ID
  10206. + * @qbman_ch_id: Channel ID to be used by dequeue operation
  10207. + * @num_priorities: Number of priorities for the DPCON channel (1-8)
  10208. + */
  10209. +struct dpcon_attr {
  10210. + int id;
  10211. + u16 qbman_ch_id;
  10212. + u8 num_priorities;
  10213. +};
  10214. +
  10215. +int dpcon_get_attributes(struct fsl_mc_io *mc_io,
  10216. + u32 cmd_flags,
  10217. + u16 token,
  10218. + struct dpcon_attr *attr);
  10219. +
  10220. +/**
  10221. + * struct dpcon_notification_cfg - Structure representing notification params
  10222. + * @dpio_id: DPIO object ID; must be configured with a notification channel;
  10223. + * to disable notifications set it to 'DPCON_INVALID_DPIO_ID';
  10224. + * @priority: Priority selection within the DPIO channel; valid values
  10225. + * are 0-7, depending on the number of priorities in that channel
  10226. + * @user_ctx: User context value provided with each CDAN message
  10227. + */
  10228. +struct dpcon_notification_cfg {
  10229. + int dpio_id;
  10230. + u8 priority;
  10231. + u64 user_ctx;
  10232. +};
  10233. +
  10234. +int dpcon_set_notification(struct fsl_mc_io *mc_io,
  10235. + u32 cmd_flags,
  10236. + u16 token,
  10237. + struct dpcon_notification_cfg *cfg);
  10238. +
  10239. +int dpcon_get_api_version(struct fsl_mc_io *mc_io,
  10240. + u32 cmd_flags,
  10241. + u16 *major_ver,
  10242. + u16 *minor_ver);
  10243. +
  10244. +#endif /* __FSL_DPCON_H */
  10245. --- a/drivers/staging/fsl-mc/include/dpmng.h
  10246. +++ b/drivers/staging/fsl-mc/include/dpmng.h
  10247. @@ -1,4 +1,5 @@
  10248. -/* Copyright 2013-2015 Freescale Semiconductor Inc.
  10249. +/*
  10250. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  10251. *
  10252. * Redistribution and use in source and binary forms, with or without
  10253. * modification, are permitted provided that the following conditions are met:
  10254. @@ -32,7 +33,8 @@
  10255. #ifndef __FSL_DPMNG_H
  10256. #define __FSL_DPMNG_H
  10257. -/* Management Complex General API
  10258. +/*
  10259. + * Management Complex General API
  10260. * Contains general API for the Management Complex firmware
  10261. */
  10262. @@ -58,12 +60,8 @@ struct mc_version {
  10263. u32 revision;
  10264. };
  10265. -int mc_get_version(struct fsl_mc_io *mc_io,
  10266. - u32 cmd_flags,
  10267. - struct mc_version *mc_ver_info);
  10268. -
  10269. -int dpmng_get_container_id(struct fsl_mc_io *mc_io,
  10270. - u32 cmd_flags,
  10271. - int *container_id);
  10272. +int mc_get_version(struct fsl_mc_io *mc_io,
  10273. + u32 cmd_flags,
  10274. + struct mc_version *mc_ver_info);
  10275. #endif /* __FSL_DPMNG_H */
  10276. --- /dev/null
  10277. +++ b/drivers/staging/fsl-mc/include/dpopr.h
  10278. @@ -0,0 +1,110 @@
  10279. +/*
  10280. + * Copyright 2017 NXP
  10281. + *
  10282. + * Redistribution and use in source and binary forms, with or without
  10283. + * modification, are permitted provided that the following conditions are met:
  10284. + * * Redistributions of source code must retain the above copyright
  10285. + * notice, this list of conditions and the following disclaimer.
  10286. + * * Redistributions in binary form must reproduce the above copyright
  10287. + * notice, this list of conditions and the following disclaimer in the
  10288. + * documentation and/or other materials provided with the distribution.
  10289. + * * Neither the name of the above-listed copyright holders nor the
  10290. + * names of any contributors may be used to endorse or promote products
  10291. + * derived from this software without specific prior written permission.
  10292. + *
  10293. + *
  10294. + * ALTERNATIVELY, this software may be distributed under the terms of the
  10295. + * GNU General Public License ("GPL") as published by the Free Software
  10296. + * Foundation, either version 2 of that License or (at your option) any
  10297. + * later version.
  10298. + *
  10299. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  10300. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  10301. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  10302. + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  10303. + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  10304. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  10305. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  10306. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  10307. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  10308. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  10309. + * POSSIBILITY OF SUCH DAMAGE.
  10310. + */
  10311. +#ifndef __FSL_DPOPR_H_
  10312. +#define __FSL_DPOPR_H_
  10313. +
  10314. +/* Data Path Order Restoration API
  10315. + * Contains initialization APIs and runtime APIs for the Order Restoration
  10316. + */
  10317. +
  10318. +/** Order Restoration properties */
  10319. +
  10320. +/**
  10321. + * Create a new Order Point Record option
  10322. + */
  10323. +#define OPR_OPT_CREATE 0x1
  10324. +/**
  10325. + * Retire an existing Order Point Record option
  10326. + */
  10327. +#define OPR_OPT_RETIRE 0x2
  10328. +
  10329. +/**
  10330. + * struct opr_cfg - Structure representing OPR configuration
  10331. + * @oprrws: Order point record (OPR) restoration window size (0 to 5)
  10332. + * 0 - Window size is 32 frames.
  10333. + * 1 - Window size is 64 frames.
  10334. + * 2 - Window size is 128 frames.
  10335. + * 3 - Window size is 256 frames.
  10336. + * 4 - Window size is 512 frames.
  10337. + * 5 - Window size is 1024 frames.
  10338. + * @oa: OPR auto advance NESN window size (0 disabled, 1 enabled)
  10339. + * @olws: OPR acceptable late arrival window size (0 to 3)
  10340. + * 0 - Disabled. Late arrivals are always rejected.
  10341. + * 1 - Window size is 32 frames.
  10342. + * 2 - Window size is the same as the OPR restoration
  10343. + * window size configured in the OPRRWS field.
  10344. + * 3 - Window size is 8192 frames. Late arrivals are
  10345. + * always accepted.
  10346. + * @oeane: Order restoration list (ORL) resource exhaustion
  10347. + * advance NESN enable (0 disabled, 1 enabled)
  10348. + * @oloe: OPR loose ordering enable (0 disabled, 1 enabled)
  10349. + */
  10350. +struct opr_cfg {
  10351. + u8 oprrws;
  10352. + u8 oa;
  10353. + u8 olws;
  10354. + u8 oeane;
  10355. + u8 oloe;
  10356. +};
  10357. +
  10358. +/**
  10359. + * struct opr_qry - Structure representing OPR configuration
  10360. + * @enable: Enabled state
  10361. + * @rip: Retirement In Progress
  10362. + * @ndsn: Next dispensed sequence number
  10363. + * @nesn: Next expected sequence number
  10364. + * @ea_hseq: Early arrival head sequence number
  10365. + * @hseq_nlis: HSEQ not last in sequence
  10366. + * @ea_tseq: Early arrival tail sequence number
  10367. + * @tseq_nlis: TSEQ not last in sequence
  10368. + * @ea_tptr: Early arrival tail pointer
  10369. + * @ea_hptr: Early arrival head pointer
  10370. + * @opr_id: Order Point Record ID
  10371. + * @opr_vid: Order Point Record Virtual ID
  10372. + */
  10373. +struct opr_qry {
  10374. + char enable;
  10375. + char rip;
  10376. + u16 ndsn;
  10377. + u16 nesn;
  10378. + u16 ea_hseq;
  10379. + char hseq_nlis;
  10380. + u16 ea_tseq;
  10381. + char tseq_nlis;
  10382. + u16 ea_tptr;
  10383. + u16 ea_hptr;
  10384. + u16 opr_id;
  10385. + u16 opr_vid;
  10386. +};
  10387. +
  10388. +#endif /* __FSL_DPOPR_H_ */
  10389. --- a/drivers/staging/fsl-mc/include/dprc.h
  10390. +++ b/drivers/staging/fsl-mc/include/dprc.h
  10391. @@ -1,4 +1,5 @@
  10392. -/* Copyright 2013-2015 Freescale Semiconductor Inc.
  10393. +/*
  10394. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  10395. *
  10396. * Redistribution and use in source and binary forms, with or without
  10397. * modification, are permitted provided that the following conditions are met:
  10398. @@ -34,26 +35,13 @@
  10399. #include "mc-cmd.h"
  10400. -/* Data Path Resource Container API
  10401. +/*
  10402. + * Data Path Resource Container API
  10403. * Contains DPRC API for managing and querying DPAA resources
  10404. */
  10405. struct fsl_mc_io;
  10406. -/**
  10407. - * Set this value as the icid value in dprc_cfg structure when creating a
  10408. - * container, in case the ICID is not selected by the user and should be
  10409. - * allocated by the DPRC from the pool of ICIDs.
  10410. - */
  10411. -#define DPRC_GET_ICID_FROM_POOL (u16)(~(0))
  10412. -
  10413. -/**
  10414. - * Set this value as the portal_id value in dprc_cfg structure when creating a
  10415. - * container, in case the portal ID is not specifically selected by the
  10416. - * user and should be allocated by the DPRC from the pool of portal ids.
  10417. - */
  10418. -#define DPRC_GET_PORTAL_ID_FROM_POOL (int)(~(0))
  10419. -
  10420. int dprc_open(struct fsl_mc_io *mc_io,
  10421. u32 cmd_flags,
  10422. int container_id,
  10423. @@ -63,75 +51,6 @@ int dprc_close(struct fsl_mc_io *mc_io,
  10424. u32 cmd_flags,
  10425. u16 token);
  10426. -/**
  10427. - * Container general options
  10428. - *
  10429. - * These options may be selected at container creation by the container creator
  10430. - * and can be retrieved using dprc_get_attributes()
  10431. - */
  10432. -
  10433. -/* Spawn Policy Option allowed - Indicates that the new container is allowed
  10434. - * to spawn and have its own child containers.
  10435. - */
  10436. -#define DPRC_CFG_OPT_SPAWN_ALLOWED 0x00000001
  10437. -
  10438. -/* General Container allocation policy - Indicates that the new container is
  10439. - * allowed to allocate requested resources from its parent container; if not
  10440. - * set, the container is only allowed to use resources in its own pools; Note
  10441. - * that this is a container's global policy, but the parent container may
  10442. - * override it and set specific quota per resource type.
  10443. - */
  10444. -#define DPRC_CFG_OPT_ALLOC_ALLOWED 0x00000002
  10445. -
  10446. -/* Object initialization allowed - software context associated with this
  10447. - * container is allowed to invoke object initialization operations.
  10448. - */
  10449. -#define DPRC_CFG_OPT_OBJ_CREATE_ALLOWED 0x00000004
  10450. -
  10451. -/* Topology change allowed - software context associated with this
  10452. - * container is allowed to invoke topology operations, such as attach/detach
  10453. - * of network objects.
  10454. - */
  10455. -#define DPRC_CFG_OPT_TOPOLOGY_CHANGES_ALLOWED 0x00000008
  10456. -
  10457. -/* AIOP - Indicates that container belongs to AIOP. */
  10458. -#define DPRC_CFG_OPT_AIOP 0x00000020
  10459. -
  10460. -/* IRQ Config - Indicates that the container allowed to configure its IRQs. */
  10461. -#define DPRC_CFG_OPT_IRQ_CFG_ALLOWED 0x00000040
  10462. -
  10463. -/**
  10464. - * struct dprc_cfg - Container configuration options
  10465. - * @icid: Container's ICID; if set to 'DPRC_GET_ICID_FROM_POOL', a free
  10466. - * ICID value is allocated by the DPRC
  10467. - * @portal_id: Portal ID; if set to 'DPRC_GET_PORTAL_ID_FROM_POOL', a free
  10468. - * portal ID is allocated by the DPRC
  10469. - * @options: Combination of 'DPRC_CFG_OPT_<X>' options
  10470. - * @label: Object's label
  10471. - */
  10472. -struct dprc_cfg {
  10473. - u16 icid;
  10474. - int portal_id;
  10475. - u64 options;
  10476. - char label[16];
  10477. -};
  10478. -
  10479. -int dprc_create_container(struct fsl_mc_io *mc_io,
  10480. - u32 cmd_flags,
  10481. - u16 token,
  10482. - struct dprc_cfg *cfg,
  10483. - int *child_container_id,
  10484. - u64 *child_portal_offset);
  10485. -
  10486. -int dprc_destroy_container(struct fsl_mc_io *mc_io,
  10487. - u32 cmd_flags,
  10488. - u16 token,
  10489. - int child_container_id);
  10490. -
  10491. -int dprc_reset_container(struct fsl_mc_io *mc_io,
  10492. - u32 cmd_flags,
  10493. - u16 token,
  10494. - int child_container_id);
  10495. /* IRQ */
  10496. @@ -139,7 +58,7 @@ int dprc_reset_container(struct fsl_mc_i
  10497. #define DPRC_IRQ_INDEX 0
  10498. /* Number of dprc's IRQs */
  10499. -#define DPRC_NUM_OF_IRQS 1
  10500. +#define DPRC_NUM_OF_IRQS 1
  10501. /* DPRC IRQ events */
  10502. @@ -151,12 +70,14 @@ int dprc_reset_container(struct fsl_mc_i
  10503. #define DPRC_IRQ_EVENT_RES_ADDED 0x00000004
  10504. /* IRQ event - Indicates that resources removed from the container */
  10505. #define DPRC_IRQ_EVENT_RES_REMOVED 0x00000008
  10506. -/* IRQ event - Indicates that one of the descendant containers that opened by
  10507. +/*
  10508. + * IRQ event - Indicates that one of the descendant containers that opened by
  10509. * this container is destroyed
  10510. */
  10511. #define DPRC_IRQ_EVENT_CONTAINER_DESTROYED 0x00000010
  10512. -/* IRQ event - Indicates that on one of the container's opened object is
  10513. +/*
  10514. + * IRQ event - Indicates that on one of the container's opened object is
  10515. * destroyed
  10516. */
  10517. #define DPRC_IRQ_EVENT_OBJ_DESTROYED 0x00000020
  10518. @@ -171,59 +92,59 @@ int dprc_reset_container(struct fsl_mc_i
  10519. * @irq_num: A user defined number associated with this IRQ
  10520. */
  10521. struct dprc_irq_cfg {
  10522. - phys_addr_t paddr;
  10523. - u32 val;
  10524. - int irq_num;
  10525. -};
  10526. -
  10527. -int dprc_set_irq(struct fsl_mc_io *mc_io,
  10528. - u32 cmd_flags,
  10529. - u16 token,
  10530. - u8 irq_index,
  10531. - struct dprc_irq_cfg *irq_cfg);
  10532. -
  10533. -int dprc_get_irq(struct fsl_mc_io *mc_io,
  10534. - u32 cmd_flags,
  10535. - u16 token,
  10536. - u8 irq_index,
  10537. - int *type,
  10538. - struct dprc_irq_cfg *irq_cfg);
  10539. -
  10540. -int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
  10541. - u32 cmd_flags,
  10542. - u16 token,
  10543. - u8 irq_index,
  10544. - u8 en);
  10545. -
  10546. -int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
  10547. - u32 cmd_flags,
  10548. - u16 token,
  10549. - u8 irq_index,
  10550. - u8 *en);
  10551. -
  10552. -int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
  10553. - u32 cmd_flags,
  10554. - u16 token,
  10555. - u8 irq_index,
  10556. - u32 mask);
  10557. -
  10558. -int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
  10559. - u32 cmd_flags,
  10560. - u16 token,
  10561. - u8 irq_index,
  10562. - u32 *mask);
  10563. -
  10564. -int dprc_get_irq_status(struct fsl_mc_io *mc_io,
  10565. - u32 cmd_flags,
  10566. - u16 token,
  10567. - u8 irq_index,
  10568. - u32 *status);
  10569. -
  10570. -int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
  10571. - u32 cmd_flags,
  10572. - u16 token,
  10573. - u8 irq_index,
  10574. - u32 status);
  10575. + phys_addr_t paddr;
  10576. + u32 val;
  10577. + int irq_num;
  10578. +};
  10579. +
  10580. +int dprc_set_irq(struct fsl_mc_io *mc_io,
  10581. + u32 cmd_flags,
  10582. + u16 token,
  10583. + u8 irq_index,
  10584. + struct dprc_irq_cfg *irq_cfg);
  10585. +
  10586. +int dprc_get_irq(struct fsl_mc_io *mc_io,
  10587. + u32 cmd_flags,
  10588. + u16 token,
  10589. + u8 irq_index,
  10590. + int *type,
  10591. + struct dprc_irq_cfg *irq_cfg);
  10592. +
  10593. +int dprc_set_irq_enable(struct fsl_mc_io *mc_io,
  10594. + u32 cmd_flags,
  10595. + u16 token,
  10596. + u8 irq_index,
  10597. + u8 en);
  10598. +
  10599. +int dprc_get_irq_enable(struct fsl_mc_io *mc_io,
  10600. + u32 cmd_flags,
  10601. + u16 token,
  10602. + u8 irq_index,
  10603. + u8 *en);
  10604. +
  10605. +int dprc_set_irq_mask(struct fsl_mc_io *mc_io,
  10606. + u32 cmd_flags,
  10607. + u16 token,
  10608. + u8 irq_index,
  10609. + u32 mask);
  10610. +
  10611. +int dprc_get_irq_mask(struct fsl_mc_io *mc_io,
  10612. + u32 cmd_flags,
  10613. + u16 token,
  10614. + u8 irq_index,
  10615. + u32 *mask);
  10616. +
  10617. +int dprc_get_irq_status(struct fsl_mc_io *mc_io,
  10618. + u32 cmd_flags,
  10619. + u16 token,
  10620. + u8 irq_index,
  10621. + u32 *status);
  10622. +
  10623. +int dprc_clear_irq_status(struct fsl_mc_io *mc_io,
  10624. + u32 cmd_flags,
  10625. + u16 token,
  10626. + u8 irq_index,
  10627. + u32 status);
  10628. /**
  10629. * struct dprc_attributes - Container attributes
  10630. @@ -231,114 +152,23 @@ int dprc_clear_irq_status(struct fsl_mc_
  10631. * @icid: Container's ICID
  10632. * @portal_id: Container's portal ID
  10633. * @options: Container's options as set at container's creation
  10634. - * @version: DPRC version
  10635. */
  10636. struct dprc_attributes {
  10637. int container_id;
  10638. u16 icid;
  10639. int portal_id;
  10640. u64 options;
  10641. - /**
  10642. - * struct version - DPRC version
  10643. - * @major: DPRC major version
  10644. - * @minor: DPRC minor version
  10645. - */
  10646. - struct {
  10647. - u16 major;
  10648. - u16 minor;
  10649. - } version;
  10650. };
  10651. -int dprc_get_attributes(struct fsl_mc_io *mc_io,
  10652. - u32 cmd_flags,
  10653. - u16 token,
  10654. - struct dprc_attributes *attributes);
  10655. -
  10656. -int dprc_set_res_quota(struct fsl_mc_io *mc_io,
  10657. - u32 cmd_flags,
  10658. - u16 token,
  10659. - int child_container_id,
  10660. - char *type,
  10661. - u16 quota);
  10662. -
  10663. -int dprc_get_res_quota(struct fsl_mc_io *mc_io,
  10664. - u32 cmd_flags,
  10665. - u16 token,
  10666. - int child_container_id,
  10667. - char *type,
  10668. - u16 *quota);
  10669. -
  10670. -/* Resource request options */
  10671. -
  10672. -/* Explicit resource ID request - The requested objects/resources
  10673. - * are explicit and sequential (in case of resources).
  10674. - * The base ID is given at res_req at base_align field
  10675. - */
  10676. -#define DPRC_RES_REQ_OPT_EXPLICIT 0x00000001
  10677. -
  10678. -/* Aligned resources request - Relevant only for resources
  10679. - * request (and not objects). Indicates that resources base ID should be
  10680. - * sequential and aligned to the value given at dprc_res_req base_align field
  10681. - */
  10682. -#define DPRC_RES_REQ_OPT_ALIGNED 0x00000002
  10683. -
  10684. -/* Plugged Flag - Relevant only for object assignment request.
  10685. - * Indicates that after all objects assigned. An interrupt will be invoked at
  10686. - * the relevant GPP. The assigned object will be marked as plugged.
  10687. - * plugged objects can't be assigned from their container
  10688. - */
  10689. -#define DPRC_RES_REQ_OPT_PLUGGED 0x00000004
  10690. -
  10691. -/**
  10692. - * struct dprc_res_req - Resource request descriptor, to be used in assignment
  10693. - * or un-assignment of resources and objects.
  10694. - * @type: Resource/object type: Represent as a NULL terminated string.
  10695. - * This string may received by using dprc_get_pool() to get resource
  10696. - * type and dprc_get_obj() to get object type;
  10697. - * Note: it is not possible to assign/un-assign DPRC objects
  10698. - * @num: Number of resources
  10699. - * @options: Request options: combination of DPRC_RES_REQ_OPT_ options
  10700. - * @id_base_align: In case of explicit assignment (DPRC_RES_REQ_OPT_EXPLICIT
  10701. - * is set at option), this field represents the required base ID
  10702. - * for resource allocation; In case of aligned assignment
  10703. - * (DPRC_RES_REQ_OPT_ALIGNED is set at option), this field
  10704. - * indicates the required alignment for the resource ID(s) -
  10705. - * use 0 if there is no alignment or explicit ID requirements
  10706. - */
  10707. -struct dprc_res_req {
  10708. - char type[16];
  10709. - u32 num;
  10710. - u32 options;
  10711. - int id_base_align;
  10712. -};
  10713. -
  10714. -int dprc_assign(struct fsl_mc_io *mc_io,
  10715. - u32 cmd_flags,
  10716. - u16 token,
  10717. - int container_id,
  10718. - struct dprc_res_req *res_req);
  10719. -
  10720. -int dprc_unassign(struct fsl_mc_io *mc_io,
  10721. - u32 cmd_flags,
  10722. - u16 token,
  10723. - int child_container_id,
  10724. - struct dprc_res_req *res_req);
  10725. -
  10726. -int dprc_get_pool_count(struct fsl_mc_io *mc_io,
  10727. - u32 cmd_flags,
  10728. - u16 token,
  10729. - int *pool_count);
  10730. -
  10731. -int dprc_get_pool(struct fsl_mc_io *mc_io,
  10732. - u32 cmd_flags,
  10733. - u16 token,
  10734. - int pool_index,
  10735. - char *type);
  10736. +int dprc_get_attributes(struct fsl_mc_io *mc_io,
  10737. + u32 cmd_flags,
  10738. + u16 token,
  10739. + struct dprc_attributes *attributes);
  10740. int dprc_get_obj_count(struct fsl_mc_io *mc_io,
  10741. - u32 cmd_flags,
  10742. - u16 token,
  10743. - int *obj_count);
  10744. + u32 cmd_flags,
  10745. + u16 token,
  10746. + int *obj_count);
  10747. /* Objects Attributes Flags */
  10748. @@ -353,7 +183,7 @@ int dprc_get_obj_count(struct fsl_mc_io
  10749. * masters;
  10750. * user is responsible for proper memory handling through IOMMU configuration.
  10751. */
  10752. -#define DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
  10753. +#define DPRC_OBJ_FLAG_NO_MEM_SHAREABILITY 0x0001
  10754. /**
  10755. * struct dprc_obj_desc - Object descriptor, returned from dprc_get_obj()
  10756. @@ -381,41 +211,41 @@ struct dprc_obj_desc {
  10757. u16 flags;
  10758. };
  10759. -int dprc_get_obj(struct fsl_mc_io *mc_io,
  10760. - u32 cmd_flags,
  10761. - u16 token,
  10762. - int obj_index,
  10763. - struct dprc_obj_desc *obj_desc);
  10764. -
  10765. -int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
  10766. - u32 cmd_flags,
  10767. - u16 token,
  10768. - char *obj_type,
  10769. - int obj_id,
  10770. - struct dprc_obj_desc *obj_desc);
  10771. -
  10772. -int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
  10773. - u32 cmd_flags,
  10774. - u16 token,
  10775. - char *obj_type,
  10776. - int obj_id,
  10777. - u8 irq_index,
  10778. - struct dprc_irq_cfg *irq_cfg);
  10779. -
  10780. -int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
  10781. - u32 cmd_flags,
  10782. - u16 token,
  10783. - char *obj_type,
  10784. - int obj_id,
  10785. - u8 irq_index,
  10786. - int *type,
  10787. - struct dprc_irq_cfg *irq_cfg);
  10788. -
  10789. -int dprc_get_res_count(struct fsl_mc_io *mc_io,
  10790. - u32 cmd_flags,
  10791. - u16 token,
  10792. - char *type,
  10793. - int *res_count);
  10794. +int dprc_get_obj(struct fsl_mc_io *mc_io,
  10795. + u32 cmd_flags,
  10796. + u16 token,
  10797. + int obj_index,
  10798. + struct dprc_obj_desc *obj_desc);
  10799. +
  10800. +int dprc_get_obj_desc(struct fsl_mc_io *mc_io,
  10801. + u32 cmd_flags,
  10802. + u16 token,
  10803. + char *obj_type,
  10804. + int obj_id,
  10805. + struct dprc_obj_desc *obj_desc);
  10806. +
  10807. +int dprc_set_obj_irq(struct fsl_mc_io *mc_io,
  10808. + u32 cmd_flags,
  10809. + u16 token,
  10810. + char *obj_type,
  10811. + int obj_id,
  10812. + u8 irq_index,
  10813. + struct dprc_irq_cfg *irq_cfg);
  10814. +
  10815. +int dprc_get_obj_irq(struct fsl_mc_io *mc_io,
  10816. + u32 cmd_flags,
  10817. + u16 token,
  10818. + char *obj_type,
  10819. + int obj_id,
  10820. + u8 irq_index,
  10821. + int *type,
  10822. + struct dprc_irq_cfg *irq_cfg);
  10823. +
  10824. +int dprc_get_res_count(struct fsl_mc_io *mc_io,
  10825. + u32 cmd_flags,
  10826. + u16 token,
  10827. + char *type,
  10828. + int *res_count);
  10829. /**
  10830. * enum dprc_iter_status - Iteration status
  10831. @@ -429,27 +259,6 @@ enum dprc_iter_status {
  10832. DPRC_ITER_STATUS_LAST = 2
  10833. };
  10834. -/**
  10835. - * struct dprc_res_ids_range_desc - Resource ID range descriptor
  10836. - * @base_id: Base resource ID of this range
  10837. - * @last_id: Last resource ID of this range
  10838. - * @iter_status: Iteration status - should be set to DPRC_ITER_STATUS_FIRST at
  10839. - * first iteration; while the returned marker is DPRC_ITER_STATUS_MORE,
  10840. - * additional iterations are needed, until the returned marker is
  10841. - * DPRC_ITER_STATUS_LAST
  10842. - */
  10843. -struct dprc_res_ids_range_desc {
  10844. - int base_id;
  10845. - int last_id;
  10846. - enum dprc_iter_status iter_status;
  10847. -};
  10848. -
  10849. -int dprc_get_res_ids(struct fsl_mc_io *mc_io,
  10850. - u32 cmd_flags,
  10851. - u16 token,
  10852. - char *type,
  10853. - struct dprc_res_ids_range_desc *range_desc);
  10854. -
  10855. /* Region flags */
  10856. /* Cacheable - Indicates that region should be mapped as cacheable */
  10857. #define DPRC_REGION_CACHEABLE 0x00000001
  10858. @@ -481,64 +290,27 @@ struct dprc_region_desc {
  10859. enum dprc_region_type type;
  10860. };
  10861. -int dprc_get_obj_region(struct fsl_mc_io *mc_io,
  10862. - u32 cmd_flags,
  10863. - u16 token,
  10864. - char *obj_type,
  10865. - int obj_id,
  10866. - u8 region_index,
  10867. - struct dprc_region_desc *region_desc);
  10868. -
  10869. -int dprc_set_obj_label(struct fsl_mc_io *mc_io,
  10870. - u32 cmd_flags,
  10871. - u16 token,
  10872. - char *obj_type,
  10873. - int obj_id,
  10874. - char *label);
  10875. +int dprc_get_obj_region(struct fsl_mc_io *mc_io,
  10876. + u32 cmd_flags,
  10877. + u16 token,
  10878. + char *obj_type,
  10879. + int obj_id,
  10880. + u8 region_index,
  10881. + struct dprc_region_desc *region_desc);
  10882. -/**
  10883. - * struct dprc_endpoint - Endpoint description for link connect/disconnect
  10884. - * operations
  10885. - * @type: Endpoint object type: NULL terminated string
  10886. - * @id: Endpoint object ID
  10887. - * @if_id: Interface ID; should be set for endpoints with multiple
  10888. - * interfaces ("dpsw", "dpdmux"); for others, always set to 0
  10889. - */
  10890. -struct dprc_endpoint {
  10891. - char type[16];
  10892. - int id;
  10893. - int if_id;
  10894. -};
  10895. +int dprc_get_api_version(struct fsl_mc_io *mc_io,
  10896. + u32 cmd_flags,
  10897. + u16 *major_ver,
  10898. + u16 *minor_ver);
  10899. -/**
  10900. - * struct dprc_connection_cfg - Connection configuration.
  10901. - * Used for virtual connections only
  10902. - * @committed_rate: Committed rate (Mbits/s)
  10903. - * @max_rate: Maximum rate (Mbits/s)
  10904. - */
  10905. -struct dprc_connection_cfg {
  10906. - u32 committed_rate;
  10907. - u32 max_rate;
  10908. -};
  10909. +int dprc_get_container_id(struct fsl_mc_io *mc_io,
  10910. + u32 cmd_flags,
  10911. + int *container_id);
  10912. -int dprc_connect(struct fsl_mc_io *mc_io,
  10913. - u32 cmd_flags,
  10914. - u16 token,
  10915. - const struct dprc_endpoint *endpoint1,
  10916. - const struct dprc_endpoint *endpoint2,
  10917. - const struct dprc_connection_cfg *cfg);
  10918. -
  10919. -int dprc_disconnect(struct fsl_mc_io *mc_io,
  10920. - u32 cmd_flags,
  10921. - u16 token,
  10922. - const struct dprc_endpoint *endpoint);
  10923. -
  10924. -int dprc_get_connection(struct fsl_mc_io *mc_io,
  10925. - u32 cmd_flags,
  10926. - u16 token,
  10927. - const struct dprc_endpoint *endpoint1,
  10928. - struct dprc_endpoint *endpoint2,
  10929. - int *state);
  10930. +int dprc_reset_container(struct fsl_mc_io *mc_io,
  10931. + u32 cmd_flags,
  10932. + u16 token,
  10933. + int child_container_id);
  10934. #endif /* _FSL_DPRC_H */
  10935. --- a/drivers/staging/fsl-mc/include/mc-bus.h
  10936. +++ b/drivers/staging/fsl-mc/include/mc-bus.h
  10937. @@ -1,7 +1,7 @@
  10938. /*
  10939. * Freescale Management Complex (MC) bus declarations
  10940. *
  10941. - * Copyright (C) 2014 Freescale Semiconductor, Inc.
  10942. + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  10943. * Author: German Rivera <[email protected]>
  10944. *
  10945. * This file is licensed under the terms of the GNU General Public
  10946. @@ -42,8 +42,8 @@ struct msi_domain_info;
  10947. */
  10948. struct fsl_mc_resource_pool {
  10949. enum fsl_mc_pool_type type;
  10950. - int16_t max_count;
  10951. - int16_t free_count;
  10952. + int max_count;
  10953. + int free_count;
  10954. struct mutex mutex; /* serializes access to free_list */
  10955. struct list_head free_list;
  10956. struct fsl_mc_bus *mc_bus;
  10957. @@ -73,6 +73,7 @@ struct fsl_mc_bus {
  10958. int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
  10959. int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev,
  10960. + const char *driver_override,
  10961. unsigned int *total_irq_count);
  10962. int __init dprc_driver_init(void);
  10963. --- a/drivers/staging/fsl-mc/include/mc-cmd.h
  10964. +++ b/drivers/staging/fsl-mc/include/mc-cmd.h
  10965. @@ -1,4 +1,5 @@
  10966. -/* Copyright 2013-2015 Freescale Semiconductor Inc.
  10967. +/*
  10968. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  10969. *
  10970. * Redistribution and use in source and binary forms, with or without
  10971. * modification, are permitted provided that the following conditions are met:
  10972. @@ -48,6 +49,15 @@ struct mc_command {
  10973. u64 params[MC_CMD_NUM_OF_PARAMS];
  10974. };
  10975. +struct mc_rsp_create {
  10976. + __le32 object_id;
  10977. +};
  10978. +
  10979. +struct mc_rsp_api_ver {
  10980. + __le16 major_ver;
  10981. + __le16 minor_ver;
  10982. +};
  10983. +
  10984. enum mc_cmd_status {
  10985. MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
  10986. MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
  10987. @@ -72,11 +82,6 @@ enum mc_cmd_status {
  10988. /* Command completion flag */
  10989. #define MC_CMD_FLAG_INTR_DIS 0x01
  10990. -#define MC_CMD_HDR_CMDID_MASK 0xFFF0
  10991. -#define MC_CMD_HDR_CMDID_SHIFT 4
  10992. -#define MC_CMD_HDR_TOKEN_MASK 0xFFC0
  10993. -#define MC_CMD_HDR_TOKEN_SHIFT 6
  10994. -
  10995. static inline u64 mc_encode_cmd_header(u16 cmd_id,
  10996. u32 cmd_flags,
  10997. u16 token)
  10998. @@ -84,10 +89,8 @@ static inline u64 mc_encode_cmd_header(u
  10999. u64 header = 0;
  11000. struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
  11001. - hdr->cmd_id = cpu_to_le16((cmd_id << MC_CMD_HDR_CMDID_SHIFT) &
  11002. - MC_CMD_HDR_CMDID_MASK);
  11003. - hdr->token = cpu_to_le16((token << MC_CMD_HDR_TOKEN_SHIFT) &
  11004. - MC_CMD_HDR_TOKEN_MASK);
  11005. + hdr->cmd_id = cpu_to_le16(cmd_id);
  11006. + hdr->token = cpu_to_le16(token);
  11007. hdr->status = MC_CMD_STATUS_READY;
  11008. if (cmd_flags & MC_CMD_FLAG_PRI)
  11009. hdr->flags_hw = MC_CMD_FLAG_PRI;
  11010. @@ -102,7 +105,26 @@ static inline u16 mc_cmd_hdr_read_token(
  11011. struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
  11012. u16 token = le16_to_cpu(hdr->token);
  11013. - return (token & MC_CMD_HDR_TOKEN_MASK) >> MC_CMD_HDR_TOKEN_SHIFT;
  11014. + return token;
  11015. +}
  11016. +
  11017. +static inline u32 mc_cmd_read_object_id(struct mc_command *cmd)
  11018. +{
  11019. + struct mc_rsp_create *rsp_params;
  11020. +
  11021. + rsp_params = (struct mc_rsp_create *)cmd->params;
  11022. + return le32_to_cpu(rsp_params->object_id);
  11023. +}
  11024. +
  11025. +static inline void mc_cmd_read_api_version(struct mc_command *cmd,
  11026. + u16 *major_ver,
  11027. + u16 *minor_ver)
  11028. +{
  11029. + struct mc_rsp_api_ver *rsp_params;
  11030. +
  11031. + rsp_params = (struct mc_rsp_api_ver *)cmd->params;
  11032. + *major_ver = le16_to_cpu(rsp_params->major_ver);
  11033. + *minor_ver = le16_to_cpu(rsp_params->minor_ver);
  11034. }
  11035. #endif /* __FSL_MC_CMD_H */
  11036. --- a/drivers/staging/fsl-mc/include/mc-sys.h
  11037. +++ b/drivers/staging/fsl-mc/include/mc-sys.h
  11038. @@ -1,4 +1,5 @@
  11039. -/* Copyright 2013-2014 Freescale Semiconductor Inc.
  11040. +/*
  11041. + * Copyright 2013-2016 Freescale Semiconductor Inc.
  11042. *
  11043. * Interface of the I/O services to send MC commands to the MC hardware
  11044. *
  11045. --- a/drivers/staging/fsl-mc/include/mc.h
  11046. +++ b/drivers/staging/fsl-mc/include/mc.h
  11047. @@ -1,7 +1,7 @@
  11048. /*
  11049. * Freescale Management Complex (MC) bus public interface
  11050. *
  11051. - * Copyright (C) 2014 Freescale Semiconductor, Inc.
  11052. + * Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
  11053. * Author: German Rivera <[email protected]>
  11054. *
  11055. * This file is licensed under the terms of the GNU General Public
  11056. @@ -81,7 +81,7 @@ enum fsl_mc_pool_type {
  11057. */
  11058. struct fsl_mc_resource {
  11059. enum fsl_mc_pool_type type;
  11060. - int32_t id;
  11061. + s32 id;
  11062. void *data;
  11063. struct fsl_mc_resource_pool *parent_pool;
  11064. struct list_head node;
  11065. @@ -122,6 +122,7 @@ struct fsl_mc_device_irq {
  11066. * @regions: pointer to array of MMIO region entries
  11067. * @irqs: pointer to array of pointers to interrupts allocated to this device
  11068. * @resource: generic resource associated with this MC object device, if any.
  11069. + * @driver_override: Driver name to force a match
  11070. *
  11071. * Generic device object for MC object devices that are "attached" to a
  11072. * MC bus.
  11073. @@ -154,6 +155,7 @@ struct fsl_mc_device {
  11074. struct resource *regions;
  11075. struct fsl_mc_device_irq **irqs;
  11076. struct fsl_mc_resource *resource;
  11077. + const char *driver_override;
  11078. };
  11079. #define to_fsl_mc_device(_dev) \
  11080. @@ -175,6 +177,8 @@ struct fsl_mc_device {
  11081. #define fsl_mc_driver_register(drv) \
  11082. __fsl_mc_driver_register(drv, THIS_MODULE)
  11083. +void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
  11084. +
  11085. int __must_check __fsl_mc_driver_register(struct fsl_mc_driver *fsl_mc_driver,
  11086. struct module *owner);
  11087. @@ -198,4 +202,13 @@ int __must_check fsl_mc_allocate_irqs(st
  11088. void fsl_mc_free_irqs(struct fsl_mc_device *mc_dev);
  11089. +void fsl_mc_dma_configure(struct fsl_mc_device *mc_dev,
  11090. + struct device_node *fsl_mc_platform_node, int coherent);
  11091. +
  11092. +#ifdef CONFIG_FSL_MC_BUS
  11093. +struct iommu_group *fsl_mc_device_group(struct device *dev);
  11094. +#else
  11095. +#define fsl_mc_device_group(__dev) NULL
  11096. +#endif
  11097. +
  11098. #endif /* _FSL_MC_H_ */