vxge-config.c 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115
  1. /******************************************************************************
  2. * This software may be used and distributed according to the terms of
  3. * the GNU General Public License (GPL), incorporated herein by reference.
  4. * Drivers based on or derived from this code fall under the GPL and must
  5. * retain the authorship, copyright and license notice. This file is not
  6. * a complete program and may only be used when the entire operating
  7. * system is licensed under the GPL.
  8. * See the file COPYING in this distribution for more information.
  9. *
  10. * vxge-config.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2010 Exar Corp.
  13. ******************************************************************************/
  14. #include <linux/vmalloc.h>
  15. #include <linux/etherdevice.h>
  16. #include <linux/pci.h>
  17. #include <linux/pci_hotplug.h>
  18. #include <linux/slab.h>
  19. #include "vxge-traffic.h"
  20. #include "vxge-config.h"
  21. #include "vxge-main.h"
  22. #define VXGE_HW_VPATH_STATS_PIO_READ(offset) { \
  23. status = __vxge_hw_vpath_stats_access(vpath, \
  24. VXGE_HW_STATS_OP_READ, \
  25. offset, \
  26. &val64); \
  27. if (status != VXGE_HW_OK) \
  28. return status; \
  29. }
  30. static void
  31. vxge_hw_vpath_set_zero_rx_frm_len(struct vxge_hw_vpath_reg __iomem *vp_reg)
  32. {
  33. u64 val64;
  34. val64 = readq(&vp_reg->rxmac_vcfg0);
  35. val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
  36. writeq(val64, &vp_reg->rxmac_vcfg0);
  37. val64 = readq(&vp_reg->rxmac_vcfg0);
  38. }
  39. /*
  40. * vxge_hw_vpath_wait_receive_idle - Wait for Rx to become idle
  41. */
  42. int vxge_hw_vpath_wait_receive_idle(struct __vxge_hw_device *hldev, u32 vp_id)
  43. {
  44. struct vxge_hw_vpath_reg __iomem *vp_reg;
  45. struct __vxge_hw_virtualpath *vpath;
  46. u64 val64, rxd_count, rxd_spat;
  47. int count = 0, total_count = 0;
  48. vpath = &hldev->virtual_paths[vp_id];
  49. vp_reg = vpath->vp_reg;
  50. vxge_hw_vpath_set_zero_rx_frm_len(vp_reg);
  51. /* Check that the ring controller for this vpath has enough free RxDs
  52. * to send frames to the host. This is done by reading the
  53. * PRC_RXD_DOORBELL_VPn register and comparing the read value to the
  54. * RXD_SPAT value for the vpath.
  55. */
  56. val64 = readq(&vp_reg->prc_cfg6);
  57. rxd_spat = VXGE_HW_PRC_CFG6_GET_RXD_SPAT(val64) + 1;
  58. /* Use a factor of 2 when comparing rxd_count against rxd_spat for some
  59. * leg room.
  60. */
  61. rxd_spat *= 2;
  62. do {
  63. mdelay(1);
  64. rxd_count = readq(&vp_reg->prc_rxd_doorbell);
  65. /* Check that the ring controller for this vpath does
  66. * not have any frame in its pipeline.
  67. */
  68. val64 = readq(&vp_reg->frm_in_progress_cnt);
  69. if ((rxd_count <= rxd_spat) || (val64 > 0))
  70. count = 0;
  71. else
  72. count++;
  73. total_count++;
  74. } while ((count < VXGE_HW_MIN_SUCCESSIVE_IDLE_COUNT) &&
  75. (total_count < VXGE_HW_MAX_POLLING_COUNT));
  76. if (total_count >= VXGE_HW_MAX_POLLING_COUNT)
  77. printk(KERN_ALERT "%s: Still Receiving traffic. Abort wait\n",
  78. __func__);
  79. return total_count;
  80. }
  81. /* vxge_hw_device_wait_receive_idle - This function waits until all frames
  82. * stored in the frame buffer for each vpath assigned to the given
  83. * function (hldev) have been sent to the host.
  84. */
  85. void vxge_hw_device_wait_receive_idle(struct __vxge_hw_device *hldev)
  86. {
  87. int i, total_count = 0;
  88. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  89. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  90. continue;
  91. total_count += vxge_hw_vpath_wait_receive_idle(hldev, i);
  92. if (total_count >= VXGE_HW_MAX_POLLING_COUNT)
  93. break;
  94. }
  95. }
  96. /*
  97. * __vxge_hw_device_register_poll
  98. * Will poll certain register for specified amount of time.
  99. * Will poll until masked bit is not cleared.
  100. */
  101. static enum vxge_hw_status
  102. __vxge_hw_device_register_poll(void __iomem *reg, u64 mask, u32 max_millis)
  103. {
  104. u64 val64;
  105. u32 i = 0;
  106. udelay(10);
  107. do {
  108. val64 = readq(reg);
  109. if (!(val64 & mask))
  110. return VXGE_HW_OK;
  111. udelay(100);
  112. } while (++i <= 9);
  113. i = 0;
  114. do {
  115. val64 = readq(reg);
  116. if (!(val64 & mask))
  117. return VXGE_HW_OK;
  118. mdelay(1);
  119. } while (++i <= max_millis);
  120. return VXGE_HW_FAIL;
  121. }
  122. static inline enum vxge_hw_status
  123. __vxge_hw_pio_mem_write64(u64 val64, void __iomem *addr,
  124. u64 mask, u32 max_millis)
  125. {
  126. __vxge_hw_pio_mem_write32_lower((u32)vxge_bVALn(val64, 32, 32), addr);
  127. wmb();
  128. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32), addr);
  129. wmb();
  130. return __vxge_hw_device_register_poll(addr, mask, max_millis);
  131. }
  132. static enum vxge_hw_status
  133. vxge_hw_vpath_fw_api(struct __vxge_hw_virtualpath *vpath, u32 action,
  134. u32 fw_memo, u32 offset, u64 *data0, u64 *data1,
  135. u64 *steer_ctrl)
  136. {
  137. struct vxge_hw_vpath_reg __iomem *vp_reg = vpath->vp_reg;
  138. enum vxge_hw_status status;
  139. u64 val64;
  140. u32 retry = 0, max_retry = 3;
  141. spin_lock(&vpath->lock);
  142. if (!vpath->vp_open) {
  143. spin_unlock(&vpath->lock);
  144. max_retry = 100;
  145. }
  146. writeq(*data0, &vp_reg->rts_access_steer_data0);
  147. writeq(*data1, &vp_reg->rts_access_steer_data1);
  148. wmb();
  149. val64 = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION(action) |
  150. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL(fw_memo) |
  151. VXGE_HW_RTS_ACCESS_STEER_CTRL_OFFSET(offset) |
  152. VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE |
  153. *steer_ctrl;
  154. status = __vxge_hw_pio_mem_write64(val64,
  155. &vp_reg->rts_access_steer_ctrl,
  156. VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE,
  157. VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  158. /* The __vxge_hw_device_register_poll can udelay for a significant
  159. * amount of time, blocking other process from the CPU. If it delays
  160. * for ~5secs, a NMI error can occur. A way around this is to give up
  161. * the processor via msleep, but this is not allowed is under lock.
  162. * So, only allow it to sleep for ~4secs if open. Otherwise, delay for
  163. * 1sec and sleep for 10ms until the firmware operation has completed
  164. * or timed-out.
  165. */
  166. while ((status != VXGE_HW_OK) && retry++ < max_retry) {
  167. if (!vpath->vp_open)
  168. msleep(20);
  169. status = __vxge_hw_device_register_poll(
  170. &vp_reg->rts_access_steer_ctrl,
  171. VXGE_HW_RTS_ACCESS_STEER_CTRL_STROBE,
  172. VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  173. }
  174. if (status != VXGE_HW_OK)
  175. goto out;
  176. val64 = readq(&vp_reg->rts_access_steer_ctrl);
  177. if (val64 & VXGE_HW_RTS_ACCESS_STEER_CTRL_RMACJ_STATUS) {
  178. *data0 = readq(&vp_reg->rts_access_steer_data0);
  179. *data1 = readq(&vp_reg->rts_access_steer_data1);
  180. *steer_ctrl = val64;
  181. } else
  182. status = VXGE_HW_FAIL;
  183. out:
  184. if (vpath->vp_open)
  185. spin_unlock(&vpath->lock);
  186. return status;
  187. }
  188. enum vxge_hw_status
  189. vxge_hw_upgrade_read_version(struct __vxge_hw_device *hldev, u32 *major,
  190. u32 *minor, u32 *build)
  191. {
  192. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  193. struct __vxge_hw_virtualpath *vpath;
  194. enum vxge_hw_status status;
  195. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  196. status = vxge_hw_vpath_fw_api(vpath,
  197. VXGE_HW_FW_UPGRADE_ACTION,
  198. VXGE_HW_FW_UPGRADE_MEMO,
  199. VXGE_HW_FW_UPGRADE_OFFSET_READ,
  200. &data0, &data1, &steer_ctrl);
  201. if (status != VXGE_HW_OK)
  202. return status;
  203. *major = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0);
  204. *minor = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0);
  205. *build = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0);
  206. return status;
  207. }
  208. enum vxge_hw_status vxge_hw_flash_fw(struct __vxge_hw_device *hldev)
  209. {
  210. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  211. struct __vxge_hw_virtualpath *vpath;
  212. enum vxge_hw_status status;
  213. u32 ret;
  214. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  215. status = vxge_hw_vpath_fw_api(vpath,
  216. VXGE_HW_FW_UPGRADE_ACTION,
  217. VXGE_HW_FW_UPGRADE_MEMO,
  218. VXGE_HW_FW_UPGRADE_OFFSET_COMMIT,
  219. &data0, &data1, &steer_ctrl);
  220. if (status != VXGE_HW_OK) {
  221. vxge_debug_init(VXGE_ERR, "%s: FW upgrade failed", __func__);
  222. goto exit;
  223. }
  224. ret = VXGE_HW_RTS_ACCESS_STEER_CTRL_GET_ACTION(steer_ctrl) & 0x7F;
  225. if (ret != 1) {
  226. vxge_debug_init(VXGE_ERR, "%s: FW commit failed with error %d",
  227. __func__, ret);
  228. status = VXGE_HW_FAIL;
  229. }
  230. exit:
  231. return status;
  232. }
  233. enum vxge_hw_status
  234. vxge_update_fw_image(struct __vxge_hw_device *hldev, const u8 *fwdata, int size)
  235. {
  236. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  237. struct __vxge_hw_virtualpath *vpath;
  238. enum vxge_hw_status status;
  239. int ret_code, sec_code;
  240. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  241. /* send upgrade start command */
  242. status = vxge_hw_vpath_fw_api(vpath,
  243. VXGE_HW_FW_UPGRADE_ACTION,
  244. VXGE_HW_FW_UPGRADE_MEMO,
  245. VXGE_HW_FW_UPGRADE_OFFSET_START,
  246. &data0, &data1, &steer_ctrl);
  247. if (status != VXGE_HW_OK) {
  248. vxge_debug_init(VXGE_ERR, " %s: Upgrade start cmd failed",
  249. __func__);
  250. return status;
  251. }
  252. /* Transfer fw image to adapter 16 bytes at a time */
  253. for (; size > 0; size -= VXGE_HW_FW_UPGRADE_BLK_SIZE) {
  254. steer_ctrl = 0;
  255. /* The next 128bits of fwdata to be loaded onto the adapter */
  256. data0 = *((u64 *)fwdata);
  257. data1 = *((u64 *)fwdata + 1);
  258. status = vxge_hw_vpath_fw_api(vpath,
  259. VXGE_HW_FW_UPGRADE_ACTION,
  260. VXGE_HW_FW_UPGRADE_MEMO,
  261. VXGE_HW_FW_UPGRADE_OFFSET_SEND,
  262. &data0, &data1, &steer_ctrl);
  263. if (status != VXGE_HW_OK) {
  264. vxge_debug_init(VXGE_ERR, "%s: Upgrade send failed",
  265. __func__);
  266. goto out;
  267. }
  268. ret_code = VXGE_HW_UPGRADE_GET_RET_ERR_CODE(data0);
  269. switch (ret_code) {
  270. case VXGE_HW_FW_UPGRADE_OK:
  271. /* All OK, send next 16 bytes. */
  272. break;
  273. case VXGE_FW_UPGRADE_BYTES2SKIP:
  274. /* skip bytes in the stream */
  275. fwdata += (data0 >> 8) & 0xFFFFFFFF;
  276. break;
  277. case VXGE_HW_FW_UPGRADE_DONE:
  278. goto out;
  279. case VXGE_HW_FW_UPGRADE_ERR:
  280. sec_code = VXGE_HW_UPGRADE_GET_SEC_ERR_CODE(data0);
  281. switch (sec_code) {
  282. case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_1:
  283. case VXGE_HW_FW_UPGRADE_ERR_CORRUPT_DATA_7:
  284. printk(KERN_ERR
  285. "corrupted data from .ncf file\n");
  286. break;
  287. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_3:
  288. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_4:
  289. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_5:
  290. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_6:
  291. case VXGE_HW_FW_UPGRADE_ERR_INV_NCF_FILE_8:
  292. printk(KERN_ERR "invalid .ncf file\n");
  293. break;
  294. case VXGE_HW_FW_UPGRADE_ERR_BUFFER_OVERFLOW:
  295. printk(KERN_ERR "buffer overflow\n");
  296. break;
  297. case VXGE_HW_FW_UPGRADE_ERR_FAILED_TO_FLASH:
  298. printk(KERN_ERR "failed to flash the image\n");
  299. break;
  300. case VXGE_HW_FW_UPGRADE_ERR_GENERIC_ERROR_UNKNOWN:
  301. printk(KERN_ERR
  302. "generic error. Unknown error type\n");
  303. break;
  304. default:
  305. printk(KERN_ERR "Unknown error of type %d\n",
  306. sec_code);
  307. break;
  308. }
  309. status = VXGE_HW_FAIL;
  310. goto out;
  311. default:
  312. printk(KERN_ERR "Unknown FW error: %d\n", ret_code);
  313. status = VXGE_HW_FAIL;
  314. goto out;
  315. }
  316. /* point to next 16 bytes */
  317. fwdata += VXGE_HW_FW_UPGRADE_BLK_SIZE;
  318. }
  319. out:
  320. return status;
  321. }
  322. enum vxge_hw_status
  323. vxge_hw_vpath_eprom_img_ver_get(struct __vxge_hw_device *hldev,
  324. struct eprom_image *img)
  325. {
  326. u64 data0 = 0, data1 = 0, steer_ctrl = 0;
  327. struct __vxge_hw_virtualpath *vpath;
  328. enum vxge_hw_status status;
  329. int i;
  330. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  331. for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
  332. data0 = VXGE_HW_RTS_ACCESS_STEER_ROM_IMAGE_INDEX(i);
  333. data1 = steer_ctrl = 0;
  334. status = vxge_hw_vpath_fw_api(vpath,
  335. VXGE_HW_FW_API_GET_EPROM_REV,
  336. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  337. 0, &data0, &data1, &steer_ctrl);
  338. if (status != VXGE_HW_OK)
  339. break;
  340. img[i].is_valid = VXGE_HW_GET_EPROM_IMAGE_VALID(data0);
  341. img[i].index = VXGE_HW_GET_EPROM_IMAGE_INDEX(data0);
  342. img[i].type = VXGE_HW_GET_EPROM_IMAGE_TYPE(data0);
  343. img[i].version = VXGE_HW_GET_EPROM_IMAGE_REV(data0);
  344. }
  345. return status;
  346. }
  347. /*
  348. * __vxge_hw_channel_free - Free memory allocated for channel
  349. * This function deallocates memory from the channel and various arrays
  350. * in the channel
  351. */
  352. static void __vxge_hw_channel_free(struct __vxge_hw_channel *channel)
  353. {
  354. kfree(channel->work_arr);
  355. kfree(channel->free_arr);
  356. kfree(channel->reserve_arr);
  357. kfree(channel->orig_arr);
  358. kfree(channel);
  359. }
  360. /*
  361. * __vxge_hw_channel_initialize - Initialize a channel
  362. * This function initializes a channel by properly setting the
  363. * various references
  364. */
  365. static enum vxge_hw_status
  366. __vxge_hw_channel_initialize(struct __vxge_hw_channel *channel)
  367. {
  368. u32 i;
  369. struct __vxge_hw_virtualpath *vpath;
  370. vpath = channel->vph->vpath;
  371. if ((channel->reserve_arr != NULL) && (channel->orig_arr != NULL)) {
  372. for (i = 0; i < channel->length; i++)
  373. channel->orig_arr[i] = channel->reserve_arr[i];
  374. }
  375. switch (channel->type) {
  376. case VXGE_HW_CHANNEL_TYPE_FIFO:
  377. vpath->fifoh = (struct __vxge_hw_fifo *)channel;
  378. channel->stats = &((struct __vxge_hw_fifo *)
  379. channel)->stats->common_stats;
  380. break;
  381. case VXGE_HW_CHANNEL_TYPE_RING:
  382. vpath->ringh = (struct __vxge_hw_ring *)channel;
  383. channel->stats = &((struct __vxge_hw_ring *)
  384. channel)->stats->common_stats;
  385. break;
  386. default:
  387. break;
  388. }
  389. return VXGE_HW_OK;
  390. }
  391. /*
  392. * __vxge_hw_channel_reset - Resets a channel
  393. * This function resets a channel by properly setting the various references
  394. */
  395. static enum vxge_hw_status
  396. __vxge_hw_channel_reset(struct __vxge_hw_channel *channel)
  397. {
  398. u32 i;
  399. for (i = 0; i < channel->length; i++) {
  400. if (channel->reserve_arr != NULL)
  401. channel->reserve_arr[i] = channel->orig_arr[i];
  402. if (channel->free_arr != NULL)
  403. channel->free_arr[i] = NULL;
  404. if (channel->work_arr != NULL)
  405. channel->work_arr[i] = NULL;
  406. }
  407. channel->free_ptr = channel->length;
  408. channel->reserve_ptr = channel->length;
  409. channel->reserve_top = 0;
  410. channel->post_index = 0;
  411. channel->compl_index = 0;
  412. return VXGE_HW_OK;
  413. }
  414. /*
  415. * __vxge_hw_device_pci_e_init
  416. * Initialize certain PCI/PCI-X configuration registers
  417. * with recommended values. Save config space for future hw resets.
  418. */
  419. static void __vxge_hw_device_pci_e_init(struct __vxge_hw_device *hldev)
  420. {
  421. u16 cmd = 0;
  422. /* Set the PErr Repconse bit and SERR in PCI command register. */
  423. pci_read_config_word(hldev->pdev, PCI_COMMAND, &cmd);
  424. cmd |= 0x140;
  425. pci_write_config_word(hldev->pdev, PCI_COMMAND, cmd);
  426. pci_save_state(hldev->pdev);
  427. }
  428. /* __vxge_hw_device_vpath_reset_in_prog_check - Check if vpath reset
  429. * in progress
  430. * This routine checks the vpath reset in progress register is turned zero
  431. */
  432. static enum vxge_hw_status
  433. __vxge_hw_device_vpath_reset_in_prog_check(u64 __iomem *vpath_rst_in_prog)
  434. {
  435. enum vxge_hw_status status;
  436. status = __vxge_hw_device_register_poll(vpath_rst_in_prog,
  437. VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(0x1ffff),
  438. VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  439. return status;
  440. }
  441. /*
  442. * _hw_legacy_swapper_set - Set the swapper bits for the legacy secion.
  443. * Set the swapper bits appropriately for the lagacy section.
  444. */
  445. static enum vxge_hw_status
  446. __vxge_hw_legacy_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg)
  447. {
  448. u64 val64;
  449. enum vxge_hw_status status = VXGE_HW_OK;
  450. val64 = readq(&legacy_reg->toc_swapper_fb);
  451. wmb();
  452. switch (val64) {
  453. case VXGE_HW_SWAPPER_INITIAL_VALUE:
  454. return status;
  455. case VXGE_HW_SWAPPER_BYTE_SWAPPED_BIT_FLIPPED:
  456. writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE,
  457. &legacy_reg->pifm_rd_swap_en);
  458. writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE,
  459. &legacy_reg->pifm_rd_flip_en);
  460. writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE,
  461. &legacy_reg->pifm_wr_swap_en);
  462. writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE,
  463. &legacy_reg->pifm_wr_flip_en);
  464. break;
  465. case VXGE_HW_SWAPPER_BYTE_SWAPPED:
  466. writeq(VXGE_HW_SWAPPER_READ_BYTE_SWAP_ENABLE,
  467. &legacy_reg->pifm_rd_swap_en);
  468. writeq(VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE,
  469. &legacy_reg->pifm_wr_swap_en);
  470. break;
  471. case VXGE_HW_SWAPPER_BIT_FLIPPED:
  472. writeq(VXGE_HW_SWAPPER_READ_BIT_FLAP_ENABLE,
  473. &legacy_reg->pifm_rd_flip_en);
  474. writeq(VXGE_HW_SWAPPER_WRITE_BIT_FLAP_ENABLE,
  475. &legacy_reg->pifm_wr_flip_en);
  476. break;
  477. }
  478. wmb();
  479. val64 = readq(&legacy_reg->toc_swapper_fb);
  480. if (val64 != VXGE_HW_SWAPPER_INITIAL_VALUE)
  481. status = VXGE_HW_ERR_SWAPPER_CTRL;
  482. return status;
  483. }
  484. /*
  485. * __vxge_hw_device_toc_get
  486. * This routine sets the swapper and reads the toc pointer and returns the
  487. * memory mapped address of the toc
  488. */
  489. static struct vxge_hw_toc_reg __iomem *
  490. __vxge_hw_device_toc_get(void __iomem *bar0)
  491. {
  492. u64 val64;
  493. struct vxge_hw_toc_reg __iomem *toc = NULL;
  494. enum vxge_hw_status status;
  495. struct vxge_hw_legacy_reg __iomem *legacy_reg =
  496. (struct vxge_hw_legacy_reg __iomem *)bar0;
  497. status = __vxge_hw_legacy_swapper_set(legacy_reg);
  498. if (status != VXGE_HW_OK)
  499. goto exit;
  500. val64 = readq(&legacy_reg->toc_first_pointer);
  501. toc = bar0 + val64;
  502. exit:
  503. return toc;
  504. }
  505. /*
  506. * __vxge_hw_device_reg_addr_get
  507. * This routine sets the swapper and reads the toc pointer and initializes the
  508. * register location pointers in the device object. It waits until the ric is
  509. * completed initializing registers.
  510. */
  511. static enum vxge_hw_status
  512. __vxge_hw_device_reg_addr_get(struct __vxge_hw_device *hldev)
  513. {
  514. u64 val64;
  515. u32 i;
  516. enum vxge_hw_status status = VXGE_HW_OK;
  517. hldev->legacy_reg = hldev->bar0;
  518. hldev->toc_reg = __vxge_hw_device_toc_get(hldev->bar0);
  519. if (hldev->toc_reg == NULL) {
  520. status = VXGE_HW_FAIL;
  521. goto exit;
  522. }
  523. val64 = readq(&hldev->toc_reg->toc_common_pointer);
  524. hldev->common_reg = hldev->bar0 + val64;
  525. val64 = readq(&hldev->toc_reg->toc_mrpcim_pointer);
  526. hldev->mrpcim_reg = hldev->bar0 + val64;
  527. for (i = 0; i < VXGE_HW_TITAN_SRPCIM_REG_SPACES; i++) {
  528. val64 = readq(&hldev->toc_reg->toc_srpcim_pointer[i]);
  529. hldev->srpcim_reg[i] = hldev->bar0 + val64;
  530. }
  531. for (i = 0; i < VXGE_HW_TITAN_VPMGMT_REG_SPACES; i++) {
  532. val64 = readq(&hldev->toc_reg->toc_vpmgmt_pointer[i]);
  533. hldev->vpmgmt_reg[i] = hldev->bar0 + val64;
  534. }
  535. for (i = 0; i < VXGE_HW_TITAN_VPATH_REG_SPACES; i++) {
  536. val64 = readq(&hldev->toc_reg->toc_vpath_pointer[i]);
  537. hldev->vpath_reg[i] = hldev->bar0 + val64;
  538. }
  539. val64 = readq(&hldev->toc_reg->toc_kdfc);
  540. switch (VXGE_HW_TOC_GET_KDFC_INITIAL_BIR(val64)) {
  541. case 0:
  542. hldev->kdfc = hldev->bar0 + VXGE_HW_TOC_GET_KDFC_INITIAL_OFFSET(val64) ;
  543. break;
  544. default:
  545. break;
  546. }
  547. status = __vxge_hw_device_vpath_reset_in_prog_check(
  548. (u64 __iomem *)&hldev->common_reg->vpath_rst_in_prog);
  549. exit:
  550. return status;
  551. }
  552. /*
  553. * __vxge_hw_device_access_rights_get: Get Access Rights of the driver
  554. * This routine returns the Access Rights of the driver
  555. */
  556. static u32
  557. __vxge_hw_device_access_rights_get(u32 host_type, u32 func_id)
  558. {
  559. u32 access_rights = VXGE_HW_DEVICE_ACCESS_RIGHT_VPATH;
  560. switch (host_type) {
  561. case VXGE_HW_NO_MR_NO_SR_NORMAL_FUNCTION:
  562. if (func_id == 0) {
  563. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM |
  564. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  565. }
  566. break;
  567. case VXGE_HW_MR_NO_SR_VH0_BASE_FUNCTION:
  568. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM |
  569. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  570. break;
  571. case VXGE_HW_NO_MR_SR_VH0_FUNCTION0:
  572. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM |
  573. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  574. break;
  575. case VXGE_HW_NO_MR_SR_VH0_VIRTUAL_FUNCTION:
  576. case VXGE_HW_SR_VH_VIRTUAL_FUNCTION:
  577. case VXGE_HW_MR_SR_VH0_INVALID_CONFIG:
  578. break;
  579. case VXGE_HW_SR_VH_FUNCTION0:
  580. case VXGE_HW_VH_NORMAL_FUNCTION:
  581. access_rights |= VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM;
  582. break;
  583. }
  584. return access_rights;
  585. }
  586. /*
  587. * __vxge_hw_device_is_privilaged
  588. * This routine checks if the device function is privilaged or not
  589. */
  590. enum vxge_hw_status
  591. __vxge_hw_device_is_privilaged(u32 host_type, u32 func_id)
  592. {
  593. if (__vxge_hw_device_access_rights_get(host_type,
  594. func_id) &
  595. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)
  596. return VXGE_HW_OK;
  597. else
  598. return VXGE_HW_ERR_PRIVILAGED_OPEARATION;
  599. }
  600. /*
  601. * __vxge_hw_vpath_func_id_get - Get the function id of the vpath.
  602. * Returns the function number of the vpath.
  603. */
  604. static u32
  605. __vxge_hw_vpath_func_id_get(struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg)
  606. {
  607. u64 val64;
  608. val64 = readq(&vpmgmt_reg->vpath_to_func_map_cfg1);
  609. return
  610. (u32)VXGE_HW_VPATH_TO_FUNC_MAP_CFG1_GET_VPATH_TO_FUNC_MAP_CFG1(val64);
  611. }
  612. /*
  613. * __vxge_hw_device_host_info_get
  614. * This routine returns the host type assignments
  615. */
  616. static void __vxge_hw_device_host_info_get(struct __vxge_hw_device *hldev)
  617. {
  618. u64 val64;
  619. u32 i;
  620. val64 = readq(&hldev->common_reg->host_type_assignments);
  621. hldev->host_type =
  622. (u32)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64);
  623. hldev->vpath_assignments = readq(&hldev->common_reg->vpath_assignments);
  624. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  625. if (!(hldev->vpath_assignments & vxge_mBIT(i)))
  626. continue;
  627. hldev->func_id =
  628. __vxge_hw_vpath_func_id_get(hldev->vpmgmt_reg[i]);
  629. hldev->access_rights = __vxge_hw_device_access_rights_get(
  630. hldev->host_type, hldev->func_id);
  631. hldev->virtual_paths[i].vp_open = VXGE_HW_VP_NOT_OPEN;
  632. hldev->virtual_paths[i].vp_reg = hldev->vpath_reg[i];
  633. hldev->first_vp_id = i;
  634. break;
  635. }
  636. }
  637. /*
  638. * __vxge_hw_verify_pci_e_info - Validate the pci-e link parameters such as
  639. * link width and signalling rate.
  640. */
  641. static enum vxge_hw_status
  642. __vxge_hw_verify_pci_e_info(struct __vxge_hw_device *hldev)
  643. {
  644. struct pci_dev *dev = hldev->pdev;
  645. u16 lnk;
  646. /* Get the negotiated link width and speed from PCI config space */
  647. pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnk);
  648. if ((lnk & PCI_EXP_LNKSTA_CLS) != 1)
  649. return VXGE_HW_ERR_INVALID_PCI_INFO;
  650. switch ((lnk & PCI_EXP_LNKSTA_NLW) >> 4) {
  651. case PCIE_LNK_WIDTH_RESRV:
  652. case PCIE_LNK_X1:
  653. case PCIE_LNK_X2:
  654. case PCIE_LNK_X4:
  655. case PCIE_LNK_X8:
  656. break;
  657. default:
  658. return VXGE_HW_ERR_INVALID_PCI_INFO;
  659. }
  660. return VXGE_HW_OK;
  661. }
  662. /*
  663. * __vxge_hw_device_initialize
  664. * Initialize Titan-V hardware.
  665. */
  666. static enum vxge_hw_status
  667. __vxge_hw_device_initialize(struct __vxge_hw_device *hldev)
  668. {
  669. enum vxge_hw_status status = VXGE_HW_OK;
  670. if (VXGE_HW_OK == __vxge_hw_device_is_privilaged(hldev->host_type,
  671. hldev->func_id)) {
  672. /* Validate the pci-e link width and speed */
  673. status = __vxge_hw_verify_pci_e_info(hldev);
  674. if (status != VXGE_HW_OK)
  675. goto exit;
  676. }
  677. exit:
  678. return status;
  679. }
  680. /*
  681. * __vxge_hw_vpath_fw_ver_get - Get the fw version
  682. * Returns FW Version
  683. */
  684. static enum vxge_hw_status
  685. __vxge_hw_vpath_fw_ver_get(struct __vxge_hw_virtualpath *vpath,
  686. struct vxge_hw_device_hw_info *hw_info)
  687. {
  688. struct vxge_hw_device_version *fw_version = &hw_info->fw_version;
  689. struct vxge_hw_device_date *fw_date = &hw_info->fw_date;
  690. struct vxge_hw_device_version *flash_version = &hw_info->flash_version;
  691. struct vxge_hw_device_date *flash_date = &hw_info->flash_date;
  692. u64 data0, data1 = 0, steer_ctrl = 0;
  693. enum vxge_hw_status status;
  694. status = vxge_hw_vpath_fw_api(vpath,
  695. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY,
  696. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  697. 0, &data0, &data1, &steer_ctrl);
  698. if (status != VXGE_HW_OK)
  699. goto exit;
  700. fw_date->day =
  701. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_DAY(data0);
  702. fw_date->month =
  703. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MONTH(data0);
  704. fw_date->year =
  705. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_YEAR(data0);
  706. snprintf(fw_date->date, VXGE_HW_FW_STRLEN, "%2.2d/%2.2d/%4.4d",
  707. fw_date->month, fw_date->day, fw_date->year);
  708. fw_version->major =
  709. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MAJOR(data0);
  710. fw_version->minor =
  711. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_MINOR(data0);
  712. fw_version->build =
  713. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_FW_VER_BUILD(data0);
  714. snprintf(fw_version->version, VXGE_HW_FW_STRLEN, "%d.%d.%d",
  715. fw_version->major, fw_version->minor, fw_version->build);
  716. flash_date->day =
  717. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_DAY(data1);
  718. flash_date->month =
  719. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MONTH(data1);
  720. flash_date->year =
  721. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_YEAR(data1);
  722. snprintf(flash_date->date, VXGE_HW_FW_STRLEN, "%2.2d/%2.2d/%4.4d",
  723. flash_date->month, flash_date->day, flash_date->year);
  724. flash_version->major =
  725. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MAJOR(data1);
  726. flash_version->minor =
  727. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_MINOR(data1);
  728. flash_version->build =
  729. (u32) VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_FLASH_VER_BUILD(data1);
  730. snprintf(flash_version->version, VXGE_HW_FW_STRLEN, "%d.%d.%d",
  731. flash_version->major, flash_version->minor,
  732. flash_version->build);
  733. exit:
  734. return status;
  735. }
  736. /*
  737. * __vxge_hw_vpath_card_info_get - Get the serial numbers,
  738. * part number and product description.
  739. */
  740. static enum vxge_hw_status
  741. __vxge_hw_vpath_card_info_get(struct __vxge_hw_virtualpath *vpath,
  742. struct vxge_hw_device_hw_info *hw_info)
  743. {
  744. enum vxge_hw_status status;
  745. u64 data0, data1 = 0, steer_ctrl = 0;
  746. u8 *serial_number = hw_info->serial_number;
  747. u8 *part_number = hw_info->part_number;
  748. u8 *product_desc = hw_info->product_desc;
  749. u32 i, j = 0;
  750. data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_SERIAL_NUMBER;
  751. status = vxge_hw_vpath_fw_api(vpath,
  752. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY,
  753. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  754. 0, &data0, &data1, &steer_ctrl);
  755. if (status != VXGE_HW_OK)
  756. return status;
  757. ((u64 *)serial_number)[0] = be64_to_cpu(data0);
  758. ((u64 *)serial_number)[1] = be64_to_cpu(data1);
  759. data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_PART_NUMBER;
  760. data1 = steer_ctrl = 0;
  761. status = vxge_hw_vpath_fw_api(vpath,
  762. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY,
  763. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  764. 0, &data0, &data1, &steer_ctrl);
  765. if (status != VXGE_HW_OK)
  766. return status;
  767. ((u64 *)part_number)[0] = be64_to_cpu(data0);
  768. ((u64 *)part_number)[1] = be64_to_cpu(data1);
  769. for (i = VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_0;
  770. i <= VXGE_HW_RTS_ACCESS_STEER_DATA0_MEMO_ITEM_DESC_3; i++) {
  771. data0 = i;
  772. data1 = steer_ctrl = 0;
  773. status = vxge_hw_vpath_fw_api(vpath,
  774. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_MEMO_ENTRY,
  775. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  776. 0, &data0, &data1, &steer_ctrl);
  777. if (status != VXGE_HW_OK)
  778. return status;
  779. ((u64 *)product_desc)[j++] = be64_to_cpu(data0);
  780. ((u64 *)product_desc)[j++] = be64_to_cpu(data1);
  781. }
  782. return status;
  783. }
  784. /*
  785. * __vxge_hw_vpath_pci_func_mode_get - Get the pci mode
  786. * Returns pci function mode
  787. */
  788. static enum vxge_hw_status
  789. __vxge_hw_vpath_pci_func_mode_get(struct __vxge_hw_virtualpath *vpath,
  790. struct vxge_hw_device_hw_info *hw_info)
  791. {
  792. u64 data0, data1 = 0, steer_ctrl = 0;
  793. enum vxge_hw_status status;
  794. data0 = 0;
  795. status = vxge_hw_vpath_fw_api(vpath,
  796. VXGE_HW_FW_API_GET_FUNC_MODE,
  797. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  798. 0, &data0, &data1, &steer_ctrl);
  799. if (status != VXGE_HW_OK)
  800. return status;
  801. hw_info->function_mode = VXGE_HW_GET_FUNC_MODE_VAL(data0);
  802. return status;
  803. }
  804. /*
  805. * __vxge_hw_vpath_addr_get - Get the hw address entry for this vpath
  806. * from MAC address table.
  807. */
  808. static enum vxge_hw_status
  809. __vxge_hw_vpath_addr_get(struct __vxge_hw_virtualpath *vpath,
  810. u8 *macaddr, u8 *macaddr_mask)
  811. {
  812. u64 action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_FIRST_ENTRY,
  813. data0 = 0, data1 = 0, steer_ctrl = 0;
  814. enum vxge_hw_status status;
  815. int i;
  816. do {
  817. status = vxge_hw_vpath_fw_api(vpath, action,
  818. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA,
  819. 0, &data0, &data1, &steer_ctrl);
  820. if (status != VXGE_HW_OK)
  821. goto exit;
  822. data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_DA_MAC_ADDR(data0);
  823. data1 = VXGE_HW_RTS_ACCESS_STEER_DATA1_GET_DA_MAC_ADDR_MASK(
  824. data1);
  825. for (i = ETH_ALEN; i > 0; i--) {
  826. macaddr[i - 1] = (u8) (data0 & 0xFF);
  827. data0 >>= 8;
  828. macaddr_mask[i - 1] = (u8) (data1 & 0xFF);
  829. data1 >>= 8;
  830. }
  831. action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LIST_NEXT_ENTRY;
  832. data0 = 0, data1 = 0, steer_ctrl = 0;
  833. } while (!is_valid_ether_addr(macaddr));
  834. exit:
  835. return status;
  836. }
  837. /**
  838. * vxge_hw_device_hw_info_get - Get the hw information
  839. * Returns the vpath mask that has the bits set for each vpath allocated
  840. * for the driver, FW version information, and the first mac address for
  841. * each vpath
  842. */
  843. enum vxge_hw_status
  844. vxge_hw_device_hw_info_get(void __iomem *bar0,
  845. struct vxge_hw_device_hw_info *hw_info)
  846. {
  847. u32 i;
  848. u64 val64;
  849. struct vxge_hw_toc_reg __iomem *toc;
  850. struct vxge_hw_mrpcim_reg __iomem *mrpcim_reg;
  851. struct vxge_hw_common_reg __iomem *common_reg;
  852. struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg;
  853. enum vxge_hw_status status;
  854. struct __vxge_hw_virtualpath vpath;
  855. memset(hw_info, 0, sizeof(struct vxge_hw_device_hw_info));
  856. toc = __vxge_hw_device_toc_get(bar0);
  857. if (toc == NULL) {
  858. status = VXGE_HW_ERR_CRITICAL;
  859. goto exit;
  860. }
  861. val64 = readq(&toc->toc_common_pointer);
  862. common_reg = bar0 + val64;
  863. status = __vxge_hw_device_vpath_reset_in_prog_check(
  864. (u64 __iomem *)&common_reg->vpath_rst_in_prog);
  865. if (status != VXGE_HW_OK)
  866. goto exit;
  867. hw_info->vpath_mask = readq(&common_reg->vpath_assignments);
  868. val64 = readq(&common_reg->host_type_assignments);
  869. hw_info->host_type =
  870. (u32)VXGE_HW_HOST_TYPE_ASSIGNMENTS_GET_HOST_TYPE_ASSIGNMENTS(val64);
  871. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  872. if (!((hw_info->vpath_mask) & vxge_mBIT(i)))
  873. continue;
  874. val64 = readq(&toc->toc_vpmgmt_pointer[i]);
  875. vpmgmt_reg = bar0 + val64;
  876. hw_info->func_id = __vxge_hw_vpath_func_id_get(vpmgmt_reg);
  877. if (__vxge_hw_device_access_rights_get(hw_info->host_type,
  878. hw_info->func_id) &
  879. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM) {
  880. val64 = readq(&toc->toc_mrpcim_pointer);
  881. mrpcim_reg = bar0 + val64;
  882. writeq(0, &mrpcim_reg->xgmac_gen_fw_memo_mask);
  883. wmb();
  884. }
  885. val64 = readq(&toc->toc_vpath_pointer[i]);
  886. spin_lock_init(&vpath.lock);
  887. vpath.vp_reg = bar0 + val64;
  888. vpath.vp_open = VXGE_HW_VP_NOT_OPEN;
  889. status = __vxge_hw_vpath_pci_func_mode_get(&vpath, hw_info);
  890. if (status != VXGE_HW_OK)
  891. goto exit;
  892. status = __vxge_hw_vpath_fw_ver_get(&vpath, hw_info);
  893. if (status != VXGE_HW_OK)
  894. goto exit;
  895. status = __vxge_hw_vpath_card_info_get(&vpath, hw_info);
  896. if (status != VXGE_HW_OK)
  897. goto exit;
  898. break;
  899. }
  900. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  901. if (!((hw_info->vpath_mask) & vxge_mBIT(i)))
  902. continue;
  903. val64 = readq(&toc->toc_vpath_pointer[i]);
  904. vpath.vp_reg = bar0 + val64;
  905. vpath.vp_open = VXGE_HW_VP_NOT_OPEN;
  906. status = __vxge_hw_vpath_addr_get(&vpath,
  907. hw_info->mac_addrs[i],
  908. hw_info->mac_addr_masks[i]);
  909. if (status != VXGE_HW_OK)
  910. goto exit;
  911. }
  912. exit:
  913. return status;
  914. }
  915. /*
  916. * __vxge_hw_blockpool_destroy - Deallocates the block pool
  917. */
  918. static void __vxge_hw_blockpool_destroy(struct __vxge_hw_blockpool *blockpool)
  919. {
  920. struct __vxge_hw_device *hldev;
  921. struct list_head *p, *n;
  922. u16 ret;
  923. if (blockpool == NULL) {
  924. ret = 1;
  925. goto exit;
  926. }
  927. hldev = blockpool->hldev;
  928. list_for_each_safe(p, n, &blockpool->free_block_list) {
  929. pci_unmap_single(hldev->pdev,
  930. ((struct __vxge_hw_blockpool_entry *)p)->dma_addr,
  931. ((struct __vxge_hw_blockpool_entry *)p)->length,
  932. PCI_DMA_BIDIRECTIONAL);
  933. vxge_os_dma_free(hldev->pdev,
  934. ((struct __vxge_hw_blockpool_entry *)p)->memblock,
  935. &((struct __vxge_hw_blockpool_entry *)p)->acc_handle);
  936. list_del(&((struct __vxge_hw_blockpool_entry *)p)->item);
  937. kfree(p);
  938. blockpool->pool_size--;
  939. }
  940. list_for_each_safe(p, n, &blockpool->free_entry_list) {
  941. list_del(&((struct __vxge_hw_blockpool_entry *)p)->item);
  942. kfree((void *)p);
  943. }
  944. ret = 0;
  945. exit:
  946. return;
  947. }
  948. /*
  949. * __vxge_hw_blockpool_create - Create block pool
  950. */
  951. static enum vxge_hw_status
  952. __vxge_hw_blockpool_create(struct __vxge_hw_device *hldev,
  953. struct __vxge_hw_blockpool *blockpool,
  954. u32 pool_size,
  955. u32 pool_max)
  956. {
  957. u32 i;
  958. struct __vxge_hw_blockpool_entry *entry = NULL;
  959. void *memblock;
  960. dma_addr_t dma_addr;
  961. struct pci_dev *dma_handle;
  962. struct pci_dev *acc_handle;
  963. enum vxge_hw_status status = VXGE_HW_OK;
  964. if (blockpool == NULL) {
  965. status = VXGE_HW_FAIL;
  966. goto blockpool_create_exit;
  967. }
  968. blockpool->hldev = hldev;
  969. blockpool->block_size = VXGE_HW_BLOCK_SIZE;
  970. blockpool->pool_size = 0;
  971. blockpool->pool_max = pool_max;
  972. blockpool->req_out = 0;
  973. INIT_LIST_HEAD(&blockpool->free_block_list);
  974. INIT_LIST_HEAD(&blockpool->free_entry_list);
  975. for (i = 0; i < pool_size + pool_max; i++) {
  976. entry = kzalloc(sizeof(struct __vxge_hw_blockpool_entry),
  977. GFP_KERNEL);
  978. if (entry == NULL) {
  979. __vxge_hw_blockpool_destroy(blockpool);
  980. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  981. goto blockpool_create_exit;
  982. }
  983. list_add(&entry->item, &blockpool->free_entry_list);
  984. }
  985. for (i = 0; i < pool_size; i++) {
  986. memblock = vxge_os_dma_malloc(
  987. hldev->pdev,
  988. VXGE_HW_BLOCK_SIZE,
  989. &dma_handle,
  990. &acc_handle);
  991. if (memblock == NULL) {
  992. __vxge_hw_blockpool_destroy(blockpool);
  993. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  994. goto blockpool_create_exit;
  995. }
  996. dma_addr = pci_map_single(hldev->pdev, memblock,
  997. VXGE_HW_BLOCK_SIZE, PCI_DMA_BIDIRECTIONAL);
  998. if (unlikely(pci_dma_mapping_error(hldev->pdev,
  999. dma_addr))) {
  1000. vxge_os_dma_free(hldev->pdev, memblock, &acc_handle);
  1001. __vxge_hw_blockpool_destroy(blockpool);
  1002. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1003. goto blockpool_create_exit;
  1004. }
  1005. if (!list_empty(&blockpool->free_entry_list))
  1006. entry = (struct __vxge_hw_blockpool_entry *)
  1007. list_first_entry(&blockpool->free_entry_list,
  1008. struct __vxge_hw_blockpool_entry,
  1009. item);
  1010. if (entry == NULL)
  1011. entry =
  1012. kzalloc(sizeof(struct __vxge_hw_blockpool_entry),
  1013. GFP_KERNEL);
  1014. if (entry != NULL) {
  1015. list_del(&entry->item);
  1016. entry->length = VXGE_HW_BLOCK_SIZE;
  1017. entry->memblock = memblock;
  1018. entry->dma_addr = dma_addr;
  1019. entry->acc_handle = acc_handle;
  1020. entry->dma_handle = dma_handle;
  1021. list_add(&entry->item,
  1022. &blockpool->free_block_list);
  1023. blockpool->pool_size++;
  1024. } else {
  1025. __vxge_hw_blockpool_destroy(blockpool);
  1026. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1027. goto blockpool_create_exit;
  1028. }
  1029. }
  1030. blockpool_create_exit:
  1031. return status;
  1032. }
  1033. /*
  1034. * __vxge_hw_device_fifo_config_check - Check fifo configuration.
  1035. * Check the fifo configuration
  1036. */
  1037. static enum vxge_hw_status
  1038. __vxge_hw_device_fifo_config_check(struct vxge_hw_fifo_config *fifo_config)
  1039. {
  1040. if ((fifo_config->fifo_blocks < VXGE_HW_MIN_FIFO_BLOCKS) ||
  1041. (fifo_config->fifo_blocks > VXGE_HW_MAX_FIFO_BLOCKS))
  1042. return VXGE_HW_BADCFG_FIFO_BLOCKS;
  1043. return VXGE_HW_OK;
  1044. }
  1045. /*
  1046. * __vxge_hw_device_vpath_config_check - Check vpath configuration.
  1047. * Check the vpath configuration
  1048. */
  1049. static enum vxge_hw_status
  1050. __vxge_hw_device_vpath_config_check(struct vxge_hw_vp_config *vp_config)
  1051. {
  1052. enum vxge_hw_status status;
  1053. if ((vp_config->min_bandwidth < VXGE_HW_VPATH_BANDWIDTH_MIN) ||
  1054. (vp_config->min_bandwidth > VXGE_HW_VPATH_BANDWIDTH_MAX))
  1055. return VXGE_HW_BADCFG_VPATH_MIN_BANDWIDTH;
  1056. status = __vxge_hw_device_fifo_config_check(&vp_config->fifo);
  1057. if (status != VXGE_HW_OK)
  1058. return status;
  1059. if ((vp_config->mtu != VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU) &&
  1060. ((vp_config->mtu < VXGE_HW_VPATH_MIN_INITIAL_MTU) ||
  1061. (vp_config->mtu > VXGE_HW_VPATH_MAX_INITIAL_MTU)))
  1062. return VXGE_HW_BADCFG_VPATH_MTU;
  1063. if ((vp_config->rpa_strip_vlan_tag !=
  1064. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT) &&
  1065. (vp_config->rpa_strip_vlan_tag !=
  1066. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE) &&
  1067. (vp_config->rpa_strip_vlan_tag !=
  1068. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_DISABLE))
  1069. return VXGE_HW_BADCFG_VPATH_RPA_STRIP_VLAN_TAG;
  1070. return VXGE_HW_OK;
  1071. }
  1072. /*
  1073. * __vxge_hw_device_config_check - Check device configuration.
  1074. * Check the device configuration
  1075. */
  1076. static enum vxge_hw_status
  1077. __vxge_hw_device_config_check(struct vxge_hw_device_config *new_config)
  1078. {
  1079. u32 i;
  1080. enum vxge_hw_status status;
  1081. if ((new_config->intr_mode != VXGE_HW_INTR_MODE_IRQLINE) &&
  1082. (new_config->intr_mode != VXGE_HW_INTR_MODE_MSIX) &&
  1083. (new_config->intr_mode != VXGE_HW_INTR_MODE_MSIX_ONE_SHOT) &&
  1084. (new_config->intr_mode != VXGE_HW_INTR_MODE_DEF))
  1085. return VXGE_HW_BADCFG_INTR_MODE;
  1086. if ((new_config->rts_mac_en != VXGE_HW_RTS_MAC_DISABLE) &&
  1087. (new_config->rts_mac_en != VXGE_HW_RTS_MAC_ENABLE))
  1088. return VXGE_HW_BADCFG_RTS_MAC_EN;
  1089. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1090. status = __vxge_hw_device_vpath_config_check(
  1091. &new_config->vp_config[i]);
  1092. if (status != VXGE_HW_OK)
  1093. return status;
  1094. }
  1095. return VXGE_HW_OK;
  1096. }
  1097. /*
  1098. * vxge_hw_device_initialize - Initialize Titan device.
  1099. * Initialize Titan device. Note that all the arguments of this public API
  1100. * are 'IN', including @hldev. Driver cooperates with
  1101. * OS to find new Titan device, locate its PCI and memory spaces.
  1102. *
  1103. * When done, the driver allocates sizeof(struct __vxge_hw_device) bytes for HW
  1104. * to enable the latter to perform Titan hardware initialization.
  1105. */
  1106. enum vxge_hw_status
  1107. vxge_hw_device_initialize(
  1108. struct __vxge_hw_device **devh,
  1109. struct vxge_hw_device_attr *attr,
  1110. struct vxge_hw_device_config *device_config)
  1111. {
  1112. u32 i;
  1113. u32 nblocks = 0;
  1114. struct __vxge_hw_device *hldev = NULL;
  1115. enum vxge_hw_status status = VXGE_HW_OK;
  1116. status = __vxge_hw_device_config_check(device_config);
  1117. if (status != VXGE_HW_OK)
  1118. goto exit;
  1119. hldev = vzalloc(sizeof(struct __vxge_hw_device));
  1120. if (hldev == NULL) {
  1121. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1122. goto exit;
  1123. }
  1124. hldev->magic = VXGE_HW_DEVICE_MAGIC;
  1125. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_ALL);
  1126. /* apply config */
  1127. memcpy(&hldev->config, device_config,
  1128. sizeof(struct vxge_hw_device_config));
  1129. hldev->bar0 = attr->bar0;
  1130. hldev->pdev = attr->pdev;
  1131. hldev->uld_callbacks = attr->uld_callbacks;
  1132. __vxge_hw_device_pci_e_init(hldev);
  1133. status = __vxge_hw_device_reg_addr_get(hldev);
  1134. if (status != VXGE_HW_OK) {
  1135. vfree(hldev);
  1136. goto exit;
  1137. }
  1138. __vxge_hw_device_host_info_get(hldev);
  1139. /* Incrementing for stats blocks */
  1140. nblocks++;
  1141. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1142. if (!(hldev->vpath_assignments & vxge_mBIT(i)))
  1143. continue;
  1144. if (device_config->vp_config[i].ring.enable ==
  1145. VXGE_HW_RING_ENABLE)
  1146. nblocks += device_config->vp_config[i].ring.ring_blocks;
  1147. if (device_config->vp_config[i].fifo.enable ==
  1148. VXGE_HW_FIFO_ENABLE)
  1149. nblocks += device_config->vp_config[i].fifo.fifo_blocks;
  1150. nblocks++;
  1151. }
  1152. if (__vxge_hw_blockpool_create(hldev,
  1153. &hldev->block_pool,
  1154. device_config->dma_blockpool_initial + nblocks,
  1155. device_config->dma_blockpool_max + nblocks) != VXGE_HW_OK) {
  1156. vxge_hw_device_terminate(hldev);
  1157. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1158. goto exit;
  1159. }
  1160. status = __vxge_hw_device_initialize(hldev);
  1161. if (status != VXGE_HW_OK) {
  1162. vxge_hw_device_terminate(hldev);
  1163. goto exit;
  1164. }
  1165. *devh = hldev;
  1166. exit:
  1167. return status;
  1168. }
  1169. /*
  1170. * vxge_hw_device_terminate - Terminate Titan device.
  1171. * Terminate HW device.
  1172. */
  1173. void
  1174. vxge_hw_device_terminate(struct __vxge_hw_device *hldev)
  1175. {
  1176. vxge_assert(hldev->magic == VXGE_HW_DEVICE_MAGIC);
  1177. hldev->magic = VXGE_HW_DEVICE_DEAD;
  1178. __vxge_hw_blockpool_destroy(&hldev->block_pool);
  1179. vfree(hldev);
  1180. }
  1181. /*
  1182. * __vxge_hw_vpath_stats_access - Get the statistics from the given location
  1183. * and offset and perform an operation
  1184. */
  1185. static enum vxge_hw_status
  1186. __vxge_hw_vpath_stats_access(struct __vxge_hw_virtualpath *vpath,
  1187. u32 operation, u32 offset, u64 *stat)
  1188. {
  1189. u64 val64;
  1190. enum vxge_hw_status status = VXGE_HW_OK;
  1191. struct vxge_hw_vpath_reg __iomem *vp_reg;
  1192. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1193. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1194. goto vpath_stats_access_exit;
  1195. }
  1196. vp_reg = vpath->vp_reg;
  1197. val64 = VXGE_HW_XMAC_STATS_ACCESS_CMD_OP(operation) |
  1198. VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE |
  1199. VXGE_HW_XMAC_STATS_ACCESS_CMD_OFFSET_SEL(offset);
  1200. status = __vxge_hw_pio_mem_write64(val64,
  1201. &vp_reg->xmac_stats_access_cmd,
  1202. VXGE_HW_XMAC_STATS_ACCESS_CMD_STROBE,
  1203. vpath->hldev->config.device_poll_millis);
  1204. if ((status == VXGE_HW_OK) && (operation == VXGE_HW_STATS_OP_READ))
  1205. *stat = readq(&vp_reg->xmac_stats_access_data);
  1206. else
  1207. *stat = 0;
  1208. vpath_stats_access_exit:
  1209. return status;
  1210. }
  1211. /*
  1212. * __vxge_hw_vpath_xmac_tx_stats_get - Get the TX Statistics of a vpath
  1213. */
  1214. static enum vxge_hw_status
  1215. __vxge_hw_vpath_xmac_tx_stats_get(struct __vxge_hw_virtualpath *vpath,
  1216. struct vxge_hw_xmac_vpath_tx_stats *vpath_tx_stats)
  1217. {
  1218. u64 *val64;
  1219. int i;
  1220. u32 offset = VXGE_HW_STATS_VPATH_TX_OFFSET;
  1221. enum vxge_hw_status status = VXGE_HW_OK;
  1222. val64 = (u64 *)vpath_tx_stats;
  1223. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1224. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1225. goto exit;
  1226. }
  1227. for (i = 0; i < sizeof(struct vxge_hw_xmac_vpath_tx_stats) / 8; i++) {
  1228. status = __vxge_hw_vpath_stats_access(vpath,
  1229. VXGE_HW_STATS_OP_READ,
  1230. offset, val64);
  1231. if (status != VXGE_HW_OK)
  1232. goto exit;
  1233. offset++;
  1234. val64++;
  1235. }
  1236. exit:
  1237. return status;
  1238. }
  1239. /*
  1240. * __vxge_hw_vpath_xmac_rx_stats_get - Get the RX Statistics of a vpath
  1241. */
  1242. static enum vxge_hw_status
  1243. __vxge_hw_vpath_xmac_rx_stats_get(struct __vxge_hw_virtualpath *vpath,
  1244. struct vxge_hw_xmac_vpath_rx_stats *vpath_rx_stats)
  1245. {
  1246. u64 *val64;
  1247. enum vxge_hw_status status = VXGE_HW_OK;
  1248. int i;
  1249. u32 offset = VXGE_HW_STATS_VPATH_RX_OFFSET;
  1250. val64 = (u64 *) vpath_rx_stats;
  1251. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1252. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1253. goto exit;
  1254. }
  1255. for (i = 0; i < sizeof(struct vxge_hw_xmac_vpath_rx_stats) / 8; i++) {
  1256. status = __vxge_hw_vpath_stats_access(vpath,
  1257. VXGE_HW_STATS_OP_READ,
  1258. offset >> 3, val64);
  1259. if (status != VXGE_HW_OK)
  1260. goto exit;
  1261. offset += 8;
  1262. val64++;
  1263. }
  1264. exit:
  1265. return status;
  1266. }
  1267. /*
  1268. * __vxge_hw_vpath_stats_get - Get the vpath hw statistics.
  1269. */
  1270. static enum vxge_hw_status
  1271. __vxge_hw_vpath_stats_get(struct __vxge_hw_virtualpath *vpath,
  1272. struct vxge_hw_vpath_stats_hw_info *hw_stats)
  1273. {
  1274. u64 val64;
  1275. enum vxge_hw_status status = VXGE_HW_OK;
  1276. struct vxge_hw_vpath_reg __iomem *vp_reg;
  1277. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  1278. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  1279. goto exit;
  1280. }
  1281. vp_reg = vpath->vp_reg;
  1282. val64 = readq(&vp_reg->vpath_debug_stats0);
  1283. hw_stats->ini_num_mwr_sent =
  1284. (u32)VXGE_HW_VPATH_DEBUG_STATS0_GET_INI_NUM_MWR_SENT(val64);
  1285. val64 = readq(&vp_reg->vpath_debug_stats1);
  1286. hw_stats->ini_num_mrd_sent =
  1287. (u32)VXGE_HW_VPATH_DEBUG_STATS1_GET_INI_NUM_MRD_SENT(val64);
  1288. val64 = readq(&vp_reg->vpath_debug_stats2);
  1289. hw_stats->ini_num_cpl_rcvd =
  1290. (u32)VXGE_HW_VPATH_DEBUG_STATS2_GET_INI_NUM_CPL_RCVD(val64);
  1291. val64 = readq(&vp_reg->vpath_debug_stats3);
  1292. hw_stats->ini_num_mwr_byte_sent =
  1293. VXGE_HW_VPATH_DEBUG_STATS3_GET_INI_NUM_MWR_BYTE_SENT(val64);
  1294. val64 = readq(&vp_reg->vpath_debug_stats4);
  1295. hw_stats->ini_num_cpl_byte_rcvd =
  1296. VXGE_HW_VPATH_DEBUG_STATS4_GET_INI_NUM_CPL_BYTE_RCVD(val64);
  1297. val64 = readq(&vp_reg->vpath_debug_stats5);
  1298. hw_stats->wrcrdtarb_xoff =
  1299. (u32)VXGE_HW_VPATH_DEBUG_STATS5_GET_WRCRDTARB_XOFF(val64);
  1300. val64 = readq(&vp_reg->vpath_debug_stats6);
  1301. hw_stats->rdcrdtarb_xoff =
  1302. (u32)VXGE_HW_VPATH_DEBUG_STATS6_GET_RDCRDTARB_XOFF(val64);
  1303. val64 = readq(&vp_reg->vpath_genstats_count01);
  1304. hw_stats->vpath_genstats_count0 =
  1305. (u32)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT0(
  1306. val64);
  1307. val64 = readq(&vp_reg->vpath_genstats_count01);
  1308. hw_stats->vpath_genstats_count1 =
  1309. (u32)VXGE_HW_VPATH_GENSTATS_COUNT01_GET_PPIF_VPATH_GENSTATS_COUNT1(
  1310. val64);
  1311. val64 = readq(&vp_reg->vpath_genstats_count23);
  1312. hw_stats->vpath_genstats_count2 =
  1313. (u32)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT2(
  1314. val64);
  1315. val64 = readq(&vp_reg->vpath_genstats_count01);
  1316. hw_stats->vpath_genstats_count3 =
  1317. (u32)VXGE_HW_VPATH_GENSTATS_COUNT23_GET_PPIF_VPATH_GENSTATS_COUNT3(
  1318. val64);
  1319. val64 = readq(&vp_reg->vpath_genstats_count4);
  1320. hw_stats->vpath_genstats_count4 =
  1321. (u32)VXGE_HW_VPATH_GENSTATS_COUNT4_GET_PPIF_VPATH_GENSTATS_COUNT4(
  1322. val64);
  1323. val64 = readq(&vp_reg->vpath_genstats_count5);
  1324. hw_stats->vpath_genstats_count5 =
  1325. (u32)VXGE_HW_VPATH_GENSTATS_COUNT5_GET_PPIF_VPATH_GENSTATS_COUNT5(
  1326. val64);
  1327. status = __vxge_hw_vpath_xmac_tx_stats_get(vpath, &hw_stats->tx_stats);
  1328. if (status != VXGE_HW_OK)
  1329. goto exit;
  1330. status = __vxge_hw_vpath_xmac_rx_stats_get(vpath, &hw_stats->rx_stats);
  1331. if (status != VXGE_HW_OK)
  1332. goto exit;
  1333. VXGE_HW_VPATH_STATS_PIO_READ(
  1334. VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM0_OFFSET);
  1335. hw_stats->prog_event_vnum0 =
  1336. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM0(val64);
  1337. hw_stats->prog_event_vnum1 =
  1338. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM1(val64);
  1339. VXGE_HW_VPATH_STATS_PIO_READ(
  1340. VXGE_HW_STATS_VPATH_PROG_EVENT_VNUM2_OFFSET);
  1341. hw_stats->prog_event_vnum2 =
  1342. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM2(val64);
  1343. hw_stats->prog_event_vnum3 =
  1344. (u32)VXGE_HW_STATS_GET_VPATH_PROG_EVENT_VNUM3(val64);
  1345. val64 = readq(&vp_reg->rx_multi_cast_stats);
  1346. hw_stats->rx_multi_cast_frame_discard =
  1347. (u16)VXGE_HW_RX_MULTI_CAST_STATS_GET_FRAME_DISCARD(val64);
  1348. val64 = readq(&vp_reg->rx_frm_transferred);
  1349. hw_stats->rx_frm_transferred =
  1350. (u32)VXGE_HW_RX_FRM_TRANSFERRED_GET_RX_FRM_TRANSFERRED(val64);
  1351. val64 = readq(&vp_reg->rxd_returned);
  1352. hw_stats->rxd_returned =
  1353. (u16)VXGE_HW_RXD_RETURNED_GET_RXD_RETURNED(val64);
  1354. val64 = readq(&vp_reg->dbg_stats_rx_mpa);
  1355. hw_stats->rx_mpa_len_fail_frms =
  1356. (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_LEN_FAIL_FRMS(val64);
  1357. hw_stats->rx_mpa_mrk_fail_frms =
  1358. (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_MRK_FAIL_FRMS(val64);
  1359. hw_stats->rx_mpa_crc_fail_frms =
  1360. (u16)VXGE_HW_DBG_STATS_GET_RX_MPA_CRC_FAIL_FRMS(val64);
  1361. val64 = readq(&vp_reg->dbg_stats_rx_fau);
  1362. hw_stats->rx_permitted_frms =
  1363. (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_PERMITTED_FRMS(val64);
  1364. hw_stats->rx_vp_reset_discarded_frms =
  1365. (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_VP_RESET_DISCARDED_FRMS(val64);
  1366. hw_stats->rx_wol_frms =
  1367. (u16)VXGE_HW_DBG_STATS_GET_RX_FAU_RX_WOL_FRMS(val64);
  1368. val64 = readq(&vp_reg->tx_vp_reset_discarded_frms);
  1369. hw_stats->tx_vp_reset_discarded_frms =
  1370. (u16)VXGE_HW_TX_VP_RESET_DISCARDED_FRMS_GET_TX_VP_RESET_DISCARDED_FRMS(
  1371. val64);
  1372. exit:
  1373. return status;
  1374. }
  1375. /*
  1376. * vxge_hw_device_stats_get - Get the device hw statistics.
  1377. * Returns the vpath h/w stats for the device.
  1378. */
  1379. enum vxge_hw_status
  1380. vxge_hw_device_stats_get(struct __vxge_hw_device *hldev,
  1381. struct vxge_hw_device_stats_hw_info *hw_stats)
  1382. {
  1383. u32 i;
  1384. enum vxge_hw_status status = VXGE_HW_OK;
  1385. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1386. if (!(hldev->vpaths_deployed & vxge_mBIT(i)) ||
  1387. (hldev->virtual_paths[i].vp_open ==
  1388. VXGE_HW_VP_NOT_OPEN))
  1389. continue;
  1390. memcpy(hldev->virtual_paths[i].hw_stats_sav,
  1391. hldev->virtual_paths[i].hw_stats,
  1392. sizeof(struct vxge_hw_vpath_stats_hw_info));
  1393. status = __vxge_hw_vpath_stats_get(
  1394. &hldev->virtual_paths[i],
  1395. hldev->virtual_paths[i].hw_stats);
  1396. }
  1397. memcpy(hw_stats, &hldev->stats.hw_dev_info_stats,
  1398. sizeof(struct vxge_hw_device_stats_hw_info));
  1399. return status;
  1400. }
  1401. /*
  1402. * vxge_hw_driver_stats_get - Get the device sw statistics.
  1403. * Returns the vpath s/w stats for the device.
  1404. */
  1405. enum vxge_hw_status vxge_hw_driver_stats_get(
  1406. struct __vxge_hw_device *hldev,
  1407. struct vxge_hw_device_stats_sw_info *sw_stats)
  1408. {
  1409. memcpy(sw_stats, &hldev->stats.sw_dev_info_stats,
  1410. sizeof(struct vxge_hw_device_stats_sw_info));
  1411. return VXGE_HW_OK;
  1412. }
  1413. /*
  1414. * vxge_hw_mrpcim_stats_access - Access the statistics from the given location
  1415. * and offset and perform an operation
  1416. * Get the statistics from the given location and offset.
  1417. */
  1418. enum vxge_hw_status
  1419. vxge_hw_mrpcim_stats_access(struct __vxge_hw_device *hldev,
  1420. u32 operation, u32 location, u32 offset, u64 *stat)
  1421. {
  1422. u64 val64;
  1423. enum vxge_hw_status status = VXGE_HW_OK;
  1424. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1425. hldev->func_id);
  1426. if (status != VXGE_HW_OK)
  1427. goto exit;
  1428. val64 = VXGE_HW_XMAC_STATS_SYS_CMD_OP(operation) |
  1429. VXGE_HW_XMAC_STATS_SYS_CMD_STROBE |
  1430. VXGE_HW_XMAC_STATS_SYS_CMD_LOC_SEL(location) |
  1431. VXGE_HW_XMAC_STATS_SYS_CMD_OFFSET_SEL(offset);
  1432. status = __vxge_hw_pio_mem_write64(val64,
  1433. &hldev->mrpcim_reg->xmac_stats_sys_cmd,
  1434. VXGE_HW_XMAC_STATS_SYS_CMD_STROBE,
  1435. hldev->config.device_poll_millis);
  1436. if ((status == VXGE_HW_OK) && (operation == VXGE_HW_STATS_OP_READ))
  1437. *stat = readq(&hldev->mrpcim_reg->xmac_stats_sys_data);
  1438. else
  1439. *stat = 0;
  1440. exit:
  1441. return status;
  1442. }
  1443. /*
  1444. * vxge_hw_device_xmac_aggr_stats_get - Get the Statistics on aggregate port
  1445. * Get the Statistics on aggregate port
  1446. */
  1447. static enum vxge_hw_status
  1448. vxge_hw_device_xmac_aggr_stats_get(struct __vxge_hw_device *hldev, u32 port,
  1449. struct vxge_hw_xmac_aggr_stats *aggr_stats)
  1450. {
  1451. u64 *val64;
  1452. int i;
  1453. u32 offset = VXGE_HW_STATS_AGGRn_OFFSET;
  1454. enum vxge_hw_status status = VXGE_HW_OK;
  1455. val64 = (u64 *)aggr_stats;
  1456. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1457. hldev->func_id);
  1458. if (status != VXGE_HW_OK)
  1459. goto exit;
  1460. for (i = 0; i < sizeof(struct vxge_hw_xmac_aggr_stats) / 8; i++) {
  1461. status = vxge_hw_mrpcim_stats_access(hldev,
  1462. VXGE_HW_STATS_OP_READ,
  1463. VXGE_HW_STATS_LOC_AGGR,
  1464. ((offset + (104 * port)) >> 3), val64);
  1465. if (status != VXGE_HW_OK)
  1466. goto exit;
  1467. offset += 8;
  1468. val64++;
  1469. }
  1470. exit:
  1471. return status;
  1472. }
  1473. /*
  1474. * vxge_hw_device_xmac_port_stats_get - Get the Statistics on a port
  1475. * Get the Statistics on port
  1476. */
  1477. static enum vxge_hw_status
  1478. vxge_hw_device_xmac_port_stats_get(struct __vxge_hw_device *hldev, u32 port,
  1479. struct vxge_hw_xmac_port_stats *port_stats)
  1480. {
  1481. u64 *val64;
  1482. enum vxge_hw_status status = VXGE_HW_OK;
  1483. int i;
  1484. u32 offset = 0x0;
  1485. val64 = (u64 *) port_stats;
  1486. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1487. hldev->func_id);
  1488. if (status != VXGE_HW_OK)
  1489. goto exit;
  1490. for (i = 0; i < sizeof(struct vxge_hw_xmac_port_stats) / 8; i++) {
  1491. status = vxge_hw_mrpcim_stats_access(hldev,
  1492. VXGE_HW_STATS_OP_READ,
  1493. VXGE_HW_STATS_LOC_AGGR,
  1494. ((offset + (608 * port)) >> 3), val64);
  1495. if (status != VXGE_HW_OK)
  1496. goto exit;
  1497. offset += 8;
  1498. val64++;
  1499. }
  1500. exit:
  1501. return status;
  1502. }
  1503. /*
  1504. * vxge_hw_device_xmac_stats_get - Get the XMAC Statistics
  1505. * Get the XMAC Statistics
  1506. */
  1507. enum vxge_hw_status
  1508. vxge_hw_device_xmac_stats_get(struct __vxge_hw_device *hldev,
  1509. struct vxge_hw_xmac_stats *xmac_stats)
  1510. {
  1511. enum vxge_hw_status status = VXGE_HW_OK;
  1512. u32 i;
  1513. status = vxge_hw_device_xmac_aggr_stats_get(hldev,
  1514. 0, &xmac_stats->aggr_stats[0]);
  1515. if (status != VXGE_HW_OK)
  1516. goto exit;
  1517. status = vxge_hw_device_xmac_aggr_stats_get(hldev,
  1518. 1, &xmac_stats->aggr_stats[1]);
  1519. if (status != VXGE_HW_OK)
  1520. goto exit;
  1521. for (i = 0; i <= VXGE_HW_MAC_MAX_MAC_PORT_ID; i++) {
  1522. status = vxge_hw_device_xmac_port_stats_get(hldev,
  1523. i, &xmac_stats->port_stats[i]);
  1524. if (status != VXGE_HW_OK)
  1525. goto exit;
  1526. }
  1527. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  1528. if (!(hldev->vpaths_deployed & vxge_mBIT(i)))
  1529. continue;
  1530. status = __vxge_hw_vpath_xmac_tx_stats_get(
  1531. &hldev->virtual_paths[i],
  1532. &xmac_stats->vpath_tx_stats[i]);
  1533. if (status != VXGE_HW_OK)
  1534. goto exit;
  1535. status = __vxge_hw_vpath_xmac_rx_stats_get(
  1536. &hldev->virtual_paths[i],
  1537. &xmac_stats->vpath_rx_stats[i]);
  1538. if (status != VXGE_HW_OK)
  1539. goto exit;
  1540. }
  1541. exit:
  1542. return status;
  1543. }
  1544. /*
  1545. * vxge_hw_device_debug_set - Set the debug module, level and timestamp
  1546. * This routine is used to dynamically change the debug output
  1547. */
  1548. void vxge_hw_device_debug_set(struct __vxge_hw_device *hldev,
  1549. enum vxge_debug_level level, u32 mask)
  1550. {
  1551. if (hldev == NULL)
  1552. return;
  1553. #if defined(VXGE_DEBUG_TRACE_MASK) || \
  1554. defined(VXGE_DEBUG_ERR_MASK)
  1555. hldev->debug_module_mask = mask;
  1556. hldev->debug_level = level;
  1557. #endif
  1558. #if defined(VXGE_DEBUG_ERR_MASK)
  1559. hldev->level_err = level & VXGE_ERR;
  1560. #endif
  1561. #if defined(VXGE_DEBUG_TRACE_MASK)
  1562. hldev->level_trace = level & VXGE_TRACE;
  1563. #endif
  1564. }
  1565. /*
  1566. * vxge_hw_device_error_level_get - Get the error level
  1567. * This routine returns the current error level set
  1568. */
  1569. u32 vxge_hw_device_error_level_get(struct __vxge_hw_device *hldev)
  1570. {
  1571. #if defined(VXGE_DEBUG_ERR_MASK)
  1572. if (hldev == NULL)
  1573. return VXGE_ERR;
  1574. else
  1575. return hldev->level_err;
  1576. #else
  1577. return 0;
  1578. #endif
  1579. }
  1580. /*
  1581. * vxge_hw_device_trace_level_get - Get the trace level
  1582. * This routine returns the current trace level set
  1583. */
  1584. u32 vxge_hw_device_trace_level_get(struct __vxge_hw_device *hldev)
  1585. {
  1586. #if defined(VXGE_DEBUG_TRACE_MASK)
  1587. if (hldev == NULL)
  1588. return VXGE_TRACE;
  1589. else
  1590. return hldev->level_trace;
  1591. #else
  1592. return 0;
  1593. #endif
  1594. }
  1595. /*
  1596. * vxge_hw_getpause_data -Pause frame frame generation and reception.
  1597. * Returns the Pause frame generation and reception capability of the NIC.
  1598. */
  1599. enum vxge_hw_status vxge_hw_device_getpause_data(struct __vxge_hw_device *hldev,
  1600. u32 port, u32 *tx, u32 *rx)
  1601. {
  1602. u64 val64;
  1603. enum vxge_hw_status status = VXGE_HW_OK;
  1604. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  1605. status = VXGE_HW_ERR_INVALID_DEVICE;
  1606. goto exit;
  1607. }
  1608. if (port > VXGE_HW_MAC_MAX_MAC_PORT_ID) {
  1609. status = VXGE_HW_ERR_INVALID_PORT;
  1610. goto exit;
  1611. }
  1612. if (!(hldev->access_rights & VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) {
  1613. status = VXGE_HW_ERR_PRIVILAGED_OPEARATION;
  1614. goto exit;
  1615. }
  1616. val64 = readq(&hldev->mrpcim_reg->rxmac_pause_cfg_port[port]);
  1617. if (val64 & VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN)
  1618. *tx = 1;
  1619. if (val64 & VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN)
  1620. *rx = 1;
  1621. exit:
  1622. return status;
  1623. }
  1624. /*
  1625. * vxge_hw_device_setpause_data - set/reset pause frame generation.
  1626. * It can be used to set or reset Pause frame generation or reception
  1627. * support of the NIC.
  1628. */
  1629. enum vxge_hw_status vxge_hw_device_setpause_data(struct __vxge_hw_device *hldev,
  1630. u32 port, u32 tx, u32 rx)
  1631. {
  1632. u64 val64;
  1633. enum vxge_hw_status status = VXGE_HW_OK;
  1634. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  1635. status = VXGE_HW_ERR_INVALID_DEVICE;
  1636. goto exit;
  1637. }
  1638. if (port > VXGE_HW_MAC_MAX_MAC_PORT_ID) {
  1639. status = VXGE_HW_ERR_INVALID_PORT;
  1640. goto exit;
  1641. }
  1642. status = __vxge_hw_device_is_privilaged(hldev->host_type,
  1643. hldev->func_id);
  1644. if (status != VXGE_HW_OK)
  1645. goto exit;
  1646. val64 = readq(&hldev->mrpcim_reg->rxmac_pause_cfg_port[port]);
  1647. if (tx)
  1648. val64 |= VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN;
  1649. else
  1650. val64 &= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_GEN_EN;
  1651. if (rx)
  1652. val64 |= VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN;
  1653. else
  1654. val64 &= ~VXGE_HW_RXMAC_PAUSE_CFG_PORT_RCV_EN;
  1655. writeq(val64, &hldev->mrpcim_reg->rxmac_pause_cfg_port[port]);
  1656. exit:
  1657. return status;
  1658. }
  1659. u16 vxge_hw_device_link_width_get(struct __vxge_hw_device *hldev)
  1660. {
  1661. struct pci_dev *dev = hldev->pdev;
  1662. u16 lnk;
  1663. pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnk);
  1664. return (lnk & VXGE_HW_PCI_EXP_LNKCAP_LNK_WIDTH) >> 4;
  1665. }
  1666. /*
  1667. * __vxge_hw_ring_block_memblock_idx - Return the memblock index
  1668. * This function returns the index of memory block
  1669. */
  1670. static inline u32
  1671. __vxge_hw_ring_block_memblock_idx(u8 *block)
  1672. {
  1673. return (u32)*((u64 *)(block + VXGE_HW_RING_MEMBLOCK_IDX_OFFSET));
  1674. }
  1675. /*
  1676. * __vxge_hw_ring_block_memblock_idx_set - Sets the memblock index
  1677. * This function sets index to a memory block
  1678. */
  1679. static inline void
  1680. __vxge_hw_ring_block_memblock_idx_set(u8 *block, u32 memblock_idx)
  1681. {
  1682. *((u64 *)(block + VXGE_HW_RING_MEMBLOCK_IDX_OFFSET)) = memblock_idx;
  1683. }
  1684. /*
  1685. * __vxge_hw_ring_block_next_pointer_set - Sets the next block pointer
  1686. * in RxD block
  1687. * Sets the next block pointer in RxD block
  1688. */
  1689. static inline void
  1690. __vxge_hw_ring_block_next_pointer_set(u8 *block, dma_addr_t dma_next)
  1691. {
  1692. *((u64 *)(block + VXGE_HW_RING_NEXT_BLOCK_POINTER_OFFSET)) = dma_next;
  1693. }
  1694. /*
  1695. * __vxge_hw_ring_first_block_address_get - Returns the dma address of the
  1696. * first block
  1697. * Returns the dma address of the first RxD block
  1698. */
  1699. static u64 __vxge_hw_ring_first_block_address_get(struct __vxge_hw_ring *ring)
  1700. {
  1701. struct vxge_hw_mempool_dma *dma_object;
  1702. dma_object = ring->mempool->memblocks_dma_arr;
  1703. vxge_assert(dma_object != NULL);
  1704. return dma_object->addr;
  1705. }
  1706. /*
  1707. * __vxge_hw_ring_item_dma_addr - Return the dma address of an item
  1708. * This function returns the dma address of a given item
  1709. */
  1710. static dma_addr_t __vxge_hw_ring_item_dma_addr(struct vxge_hw_mempool *mempoolh,
  1711. void *item)
  1712. {
  1713. u32 memblock_idx;
  1714. void *memblock;
  1715. struct vxge_hw_mempool_dma *memblock_dma_object;
  1716. ptrdiff_t dma_item_offset;
  1717. /* get owner memblock index */
  1718. memblock_idx = __vxge_hw_ring_block_memblock_idx(item);
  1719. /* get owner memblock by memblock index */
  1720. memblock = mempoolh->memblocks_arr[memblock_idx];
  1721. /* get memblock DMA object by memblock index */
  1722. memblock_dma_object = mempoolh->memblocks_dma_arr + memblock_idx;
  1723. /* calculate offset in the memblock of this item */
  1724. dma_item_offset = (u8 *)item - (u8 *)memblock;
  1725. return memblock_dma_object->addr + dma_item_offset;
  1726. }
  1727. /*
  1728. * __vxge_hw_ring_rxdblock_link - Link the RxD blocks
  1729. * This function returns the dma address of a given item
  1730. */
  1731. static void __vxge_hw_ring_rxdblock_link(struct vxge_hw_mempool *mempoolh,
  1732. struct __vxge_hw_ring *ring, u32 from,
  1733. u32 to)
  1734. {
  1735. u8 *to_item , *from_item;
  1736. dma_addr_t to_dma;
  1737. /* get "from" RxD block */
  1738. from_item = mempoolh->items_arr[from];
  1739. vxge_assert(from_item);
  1740. /* get "to" RxD block */
  1741. to_item = mempoolh->items_arr[to];
  1742. vxge_assert(to_item);
  1743. /* return address of the beginning of previous RxD block */
  1744. to_dma = __vxge_hw_ring_item_dma_addr(mempoolh, to_item);
  1745. /* set next pointer for this RxD block to point on
  1746. * previous item's DMA start address */
  1747. __vxge_hw_ring_block_next_pointer_set(from_item, to_dma);
  1748. }
  1749. /*
  1750. * __vxge_hw_ring_mempool_item_alloc - Allocate List blocks for RxD
  1751. * block callback
  1752. * This function is callback passed to __vxge_hw_mempool_create to create memory
  1753. * pool for RxD block
  1754. */
  1755. static void
  1756. __vxge_hw_ring_mempool_item_alloc(struct vxge_hw_mempool *mempoolh,
  1757. u32 memblock_index,
  1758. struct vxge_hw_mempool_dma *dma_object,
  1759. u32 index, u32 is_last)
  1760. {
  1761. u32 i;
  1762. void *item = mempoolh->items_arr[index];
  1763. struct __vxge_hw_ring *ring =
  1764. (struct __vxge_hw_ring *)mempoolh->userdata;
  1765. /* format rxds array */
  1766. for (i = 0; i < ring->rxds_per_block; i++) {
  1767. void *rxdblock_priv;
  1768. void *uld_priv;
  1769. struct vxge_hw_ring_rxd_1 *rxdp;
  1770. u32 reserve_index = ring->channel.reserve_ptr -
  1771. (index * ring->rxds_per_block + i + 1);
  1772. u32 memblock_item_idx;
  1773. ring->channel.reserve_arr[reserve_index] = ((u8 *)item) +
  1774. i * ring->rxd_size;
  1775. /* Note: memblock_item_idx is index of the item within
  1776. * the memblock. For instance, in case of three RxD-blocks
  1777. * per memblock this value can be 0, 1 or 2. */
  1778. rxdblock_priv = __vxge_hw_mempool_item_priv(mempoolh,
  1779. memblock_index, item,
  1780. &memblock_item_idx);
  1781. rxdp = ring->channel.reserve_arr[reserve_index];
  1782. uld_priv = ((u8 *)rxdblock_priv + ring->rxd_priv_size * i);
  1783. /* pre-format Host_Control */
  1784. rxdp->host_control = (u64)(size_t)uld_priv;
  1785. }
  1786. __vxge_hw_ring_block_memblock_idx_set(item, memblock_index);
  1787. if (is_last) {
  1788. /* link last one with first one */
  1789. __vxge_hw_ring_rxdblock_link(mempoolh, ring, index, 0);
  1790. }
  1791. if (index > 0) {
  1792. /* link this RxD block with previous one */
  1793. __vxge_hw_ring_rxdblock_link(mempoolh, ring, index - 1, index);
  1794. }
  1795. }
  1796. /*
  1797. * __vxge_hw_ring_replenish - Initial replenish of RxDs
  1798. * This function replenishes the RxDs from reserve array to work array
  1799. */
  1800. static enum vxge_hw_status
  1801. vxge_hw_ring_replenish(struct __vxge_hw_ring *ring)
  1802. {
  1803. void *rxd;
  1804. struct __vxge_hw_channel *channel;
  1805. enum vxge_hw_status status = VXGE_HW_OK;
  1806. channel = &ring->channel;
  1807. while (vxge_hw_channel_dtr_count(channel) > 0) {
  1808. status = vxge_hw_ring_rxd_reserve(ring, &rxd);
  1809. vxge_assert(status == VXGE_HW_OK);
  1810. if (ring->rxd_init) {
  1811. status = ring->rxd_init(rxd, channel->userdata);
  1812. if (status != VXGE_HW_OK) {
  1813. vxge_hw_ring_rxd_free(ring, rxd);
  1814. goto exit;
  1815. }
  1816. }
  1817. vxge_hw_ring_rxd_post(ring, rxd);
  1818. }
  1819. status = VXGE_HW_OK;
  1820. exit:
  1821. return status;
  1822. }
  1823. /*
  1824. * __vxge_hw_channel_allocate - Allocate memory for channel
  1825. * This function allocates required memory for the channel and various arrays
  1826. * in the channel
  1827. */
  1828. static struct __vxge_hw_channel *
  1829. __vxge_hw_channel_allocate(struct __vxge_hw_vpath_handle *vph,
  1830. enum __vxge_hw_channel_type type,
  1831. u32 length, u32 per_dtr_space,
  1832. void *userdata)
  1833. {
  1834. struct __vxge_hw_channel *channel;
  1835. struct __vxge_hw_device *hldev;
  1836. int size = 0;
  1837. u32 vp_id;
  1838. hldev = vph->vpath->hldev;
  1839. vp_id = vph->vpath->vp_id;
  1840. switch (type) {
  1841. case VXGE_HW_CHANNEL_TYPE_FIFO:
  1842. size = sizeof(struct __vxge_hw_fifo);
  1843. break;
  1844. case VXGE_HW_CHANNEL_TYPE_RING:
  1845. size = sizeof(struct __vxge_hw_ring);
  1846. break;
  1847. default:
  1848. break;
  1849. }
  1850. channel = kzalloc(size, GFP_KERNEL);
  1851. if (channel == NULL)
  1852. goto exit0;
  1853. INIT_LIST_HEAD(&channel->item);
  1854. channel->common_reg = hldev->common_reg;
  1855. channel->first_vp_id = hldev->first_vp_id;
  1856. channel->type = type;
  1857. channel->devh = hldev;
  1858. channel->vph = vph;
  1859. channel->userdata = userdata;
  1860. channel->per_dtr_space = per_dtr_space;
  1861. channel->length = length;
  1862. channel->vp_id = vp_id;
  1863. channel->work_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL);
  1864. if (channel->work_arr == NULL)
  1865. goto exit1;
  1866. channel->free_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL);
  1867. if (channel->free_arr == NULL)
  1868. goto exit1;
  1869. channel->free_ptr = length;
  1870. channel->reserve_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL);
  1871. if (channel->reserve_arr == NULL)
  1872. goto exit1;
  1873. channel->reserve_ptr = length;
  1874. channel->reserve_top = 0;
  1875. channel->orig_arr = kzalloc(sizeof(void *)*length, GFP_KERNEL);
  1876. if (channel->orig_arr == NULL)
  1877. goto exit1;
  1878. return channel;
  1879. exit1:
  1880. __vxge_hw_channel_free(channel);
  1881. exit0:
  1882. return NULL;
  1883. }
  1884. /*
  1885. * vxge_hw_blockpool_block_add - callback for vxge_os_dma_malloc_async
  1886. * Adds a block to block pool
  1887. */
  1888. static void vxge_hw_blockpool_block_add(struct __vxge_hw_device *devh,
  1889. void *block_addr,
  1890. u32 length,
  1891. struct pci_dev *dma_h,
  1892. struct pci_dev *acc_handle)
  1893. {
  1894. struct __vxge_hw_blockpool *blockpool;
  1895. struct __vxge_hw_blockpool_entry *entry = NULL;
  1896. dma_addr_t dma_addr;
  1897. enum vxge_hw_status status = VXGE_HW_OK;
  1898. u32 req_out;
  1899. blockpool = &devh->block_pool;
  1900. if (block_addr == NULL) {
  1901. blockpool->req_out--;
  1902. status = VXGE_HW_FAIL;
  1903. goto exit;
  1904. }
  1905. dma_addr = pci_map_single(devh->pdev, block_addr, length,
  1906. PCI_DMA_BIDIRECTIONAL);
  1907. if (unlikely(pci_dma_mapping_error(devh->pdev, dma_addr))) {
  1908. vxge_os_dma_free(devh->pdev, block_addr, &acc_handle);
  1909. blockpool->req_out--;
  1910. status = VXGE_HW_FAIL;
  1911. goto exit;
  1912. }
  1913. if (!list_empty(&blockpool->free_entry_list))
  1914. entry = (struct __vxge_hw_blockpool_entry *)
  1915. list_first_entry(&blockpool->free_entry_list,
  1916. struct __vxge_hw_blockpool_entry,
  1917. item);
  1918. if (entry == NULL)
  1919. entry = vmalloc(sizeof(struct __vxge_hw_blockpool_entry));
  1920. else
  1921. list_del(&entry->item);
  1922. if (entry != NULL) {
  1923. entry->length = length;
  1924. entry->memblock = block_addr;
  1925. entry->dma_addr = dma_addr;
  1926. entry->acc_handle = acc_handle;
  1927. entry->dma_handle = dma_h;
  1928. list_add(&entry->item, &blockpool->free_block_list);
  1929. blockpool->pool_size++;
  1930. status = VXGE_HW_OK;
  1931. } else
  1932. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1933. blockpool->req_out--;
  1934. req_out = blockpool->req_out;
  1935. exit:
  1936. return;
  1937. }
  1938. static inline void
  1939. vxge_os_dma_malloc_async(struct pci_dev *pdev, void *devh, unsigned long size)
  1940. {
  1941. gfp_t flags;
  1942. void *vaddr;
  1943. if (in_interrupt())
  1944. flags = GFP_ATOMIC | GFP_DMA;
  1945. else
  1946. flags = GFP_KERNEL | GFP_DMA;
  1947. vaddr = kmalloc((size), flags);
  1948. vxge_hw_blockpool_block_add(devh, vaddr, size, pdev, pdev);
  1949. }
  1950. /*
  1951. * __vxge_hw_blockpool_blocks_add - Request additional blocks
  1952. */
  1953. static
  1954. void __vxge_hw_blockpool_blocks_add(struct __vxge_hw_blockpool *blockpool)
  1955. {
  1956. u32 nreq = 0, i;
  1957. if ((blockpool->pool_size + blockpool->req_out) <
  1958. VXGE_HW_MIN_DMA_BLOCK_POOL_SIZE) {
  1959. nreq = VXGE_HW_INCR_DMA_BLOCK_POOL_SIZE;
  1960. blockpool->req_out += nreq;
  1961. }
  1962. for (i = 0; i < nreq; i++)
  1963. vxge_os_dma_malloc_async(
  1964. (blockpool->hldev)->pdev,
  1965. blockpool->hldev, VXGE_HW_BLOCK_SIZE);
  1966. }
  1967. /*
  1968. * __vxge_hw_blockpool_malloc - Allocate a memory block from pool
  1969. * Allocates a block of memory of given size, either from block pool
  1970. * or by calling vxge_os_dma_malloc()
  1971. */
  1972. static void *__vxge_hw_blockpool_malloc(struct __vxge_hw_device *devh, u32 size,
  1973. struct vxge_hw_mempool_dma *dma_object)
  1974. {
  1975. struct __vxge_hw_blockpool_entry *entry = NULL;
  1976. struct __vxge_hw_blockpool *blockpool;
  1977. void *memblock = NULL;
  1978. enum vxge_hw_status status = VXGE_HW_OK;
  1979. blockpool = &devh->block_pool;
  1980. if (size != blockpool->block_size) {
  1981. memblock = vxge_os_dma_malloc(devh->pdev, size,
  1982. &dma_object->handle,
  1983. &dma_object->acc_handle);
  1984. if (memblock == NULL) {
  1985. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1986. goto exit;
  1987. }
  1988. dma_object->addr = pci_map_single(devh->pdev, memblock, size,
  1989. PCI_DMA_BIDIRECTIONAL);
  1990. if (unlikely(pci_dma_mapping_error(devh->pdev,
  1991. dma_object->addr))) {
  1992. vxge_os_dma_free(devh->pdev, memblock,
  1993. &dma_object->acc_handle);
  1994. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  1995. goto exit;
  1996. }
  1997. } else {
  1998. if (!list_empty(&blockpool->free_block_list))
  1999. entry = (struct __vxge_hw_blockpool_entry *)
  2000. list_first_entry(&blockpool->free_block_list,
  2001. struct __vxge_hw_blockpool_entry,
  2002. item);
  2003. if (entry != NULL) {
  2004. list_del(&entry->item);
  2005. dma_object->addr = entry->dma_addr;
  2006. dma_object->handle = entry->dma_handle;
  2007. dma_object->acc_handle = entry->acc_handle;
  2008. memblock = entry->memblock;
  2009. list_add(&entry->item,
  2010. &blockpool->free_entry_list);
  2011. blockpool->pool_size--;
  2012. }
  2013. if (memblock != NULL)
  2014. __vxge_hw_blockpool_blocks_add(blockpool);
  2015. }
  2016. exit:
  2017. return memblock;
  2018. }
  2019. /*
  2020. * __vxge_hw_blockpool_blocks_remove - Free additional blocks
  2021. */
  2022. static void
  2023. __vxge_hw_blockpool_blocks_remove(struct __vxge_hw_blockpool *blockpool)
  2024. {
  2025. struct list_head *p, *n;
  2026. list_for_each_safe(p, n, &blockpool->free_block_list) {
  2027. if (blockpool->pool_size < blockpool->pool_max)
  2028. break;
  2029. pci_unmap_single(
  2030. (blockpool->hldev)->pdev,
  2031. ((struct __vxge_hw_blockpool_entry *)p)->dma_addr,
  2032. ((struct __vxge_hw_blockpool_entry *)p)->length,
  2033. PCI_DMA_BIDIRECTIONAL);
  2034. vxge_os_dma_free(
  2035. (blockpool->hldev)->pdev,
  2036. ((struct __vxge_hw_blockpool_entry *)p)->memblock,
  2037. &((struct __vxge_hw_blockpool_entry *)p)->acc_handle);
  2038. list_del(&((struct __vxge_hw_blockpool_entry *)p)->item);
  2039. list_add(p, &blockpool->free_entry_list);
  2040. blockpool->pool_size--;
  2041. }
  2042. }
  2043. /*
  2044. * __vxge_hw_blockpool_free - Frees the memory allcoated with
  2045. * __vxge_hw_blockpool_malloc
  2046. */
  2047. static void __vxge_hw_blockpool_free(struct __vxge_hw_device *devh,
  2048. void *memblock, u32 size,
  2049. struct vxge_hw_mempool_dma *dma_object)
  2050. {
  2051. struct __vxge_hw_blockpool_entry *entry = NULL;
  2052. struct __vxge_hw_blockpool *blockpool;
  2053. enum vxge_hw_status status = VXGE_HW_OK;
  2054. blockpool = &devh->block_pool;
  2055. if (size != blockpool->block_size) {
  2056. pci_unmap_single(devh->pdev, dma_object->addr, size,
  2057. PCI_DMA_BIDIRECTIONAL);
  2058. vxge_os_dma_free(devh->pdev, memblock, &dma_object->acc_handle);
  2059. } else {
  2060. if (!list_empty(&blockpool->free_entry_list))
  2061. entry = (struct __vxge_hw_blockpool_entry *)
  2062. list_first_entry(&blockpool->free_entry_list,
  2063. struct __vxge_hw_blockpool_entry,
  2064. item);
  2065. if (entry == NULL)
  2066. entry = vmalloc(sizeof(
  2067. struct __vxge_hw_blockpool_entry));
  2068. else
  2069. list_del(&entry->item);
  2070. if (entry != NULL) {
  2071. entry->length = size;
  2072. entry->memblock = memblock;
  2073. entry->dma_addr = dma_object->addr;
  2074. entry->acc_handle = dma_object->acc_handle;
  2075. entry->dma_handle = dma_object->handle;
  2076. list_add(&entry->item,
  2077. &blockpool->free_block_list);
  2078. blockpool->pool_size++;
  2079. status = VXGE_HW_OK;
  2080. } else
  2081. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2082. if (status == VXGE_HW_OK)
  2083. __vxge_hw_blockpool_blocks_remove(blockpool);
  2084. }
  2085. }
  2086. /*
  2087. * vxge_hw_mempool_destroy
  2088. */
  2089. static void __vxge_hw_mempool_destroy(struct vxge_hw_mempool *mempool)
  2090. {
  2091. u32 i, j;
  2092. struct __vxge_hw_device *devh = mempool->devh;
  2093. for (i = 0; i < mempool->memblocks_allocated; i++) {
  2094. struct vxge_hw_mempool_dma *dma_object;
  2095. vxge_assert(mempool->memblocks_arr[i]);
  2096. vxge_assert(mempool->memblocks_dma_arr + i);
  2097. dma_object = mempool->memblocks_dma_arr + i;
  2098. for (j = 0; j < mempool->items_per_memblock; j++) {
  2099. u32 index = i * mempool->items_per_memblock + j;
  2100. /* to skip last partially filled(if any) memblock */
  2101. if (index >= mempool->items_current)
  2102. break;
  2103. }
  2104. vfree(mempool->memblocks_priv_arr[i]);
  2105. __vxge_hw_blockpool_free(devh, mempool->memblocks_arr[i],
  2106. mempool->memblock_size, dma_object);
  2107. }
  2108. vfree(mempool->items_arr);
  2109. vfree(mempool->memblocks_dma_arr);
  2110. vfree(mempool->memblocks_priv_arr);
  2111. vfree(mempool->memblocks_arr);
  2112. vfree(mempool);
  2113. }
  2114. /*
  2115. * __vxge_hw_mempool_grow
  2116. * Will resize mempool up to %num_allocate value.
  2117. */
  2118. static enum vxge_hw_status
  2119. __vxge_hw_mempool_grow(struct vxge_hw_mempool *mempool, u32 num_allocate,
  2120. u32 *num_allocated)
  2121. {
  2122. u32 i, first_time = mempool->memblocks_allocated == 0 ? 1 : 0;
  2123. u32 n_items = mempool->items_per_memblock;
  2124. u32 start_block_idx = mempool->memblocks_allocated;
  2125. u32 end_block_idx = mempool->memblocks_allocated + num_allocate;
  2126. enum vxge_hw_status status = VXGE_HW_OK;
  2127. *num_allocated = 0;
  2128. if (end_block_idx > mempool->memblocks_max) {
  2129. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2130. goto exit;
  2131. }
  2132. for (i = start_block_idx; i < end_block_idx; i++) {
  2133. u32 j;
  2134. u32 is_last = ((end_block_idx - 1) == i);
  2135. struct vxge_hw_mempool_dma *dma_object =
  2136. mempool->memblocks_dma_arr + i;
  2137. void *the_memblock;
  2138. /* allocate memblock's private part. Each DMA memblock
  2139. * has a space allocated for item's private usage upon
  2140. * mempool's user request. Each time mempool grows, it will
  2141. * allocate new memblock and its private part at once.
  2142. * This helps to minimize memory usage a lot. */
  2143. mempool->memblocks_priv_arr[i] =
  2144. vzalloc(mempool->items_priv_size * n_items);
  2145. if (mempool->memblocks_priv_arr[i] == NULL) {
  2146. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2147. goto exit;
  2148. }
  2149. /* allocate DMA-capable memblock */
  2150. mempool->memblocks_arr[i] =
  2151. __vxge_hw_blockpool_malloc(mempool->devh,
  2152. mempool->memblock_size, dma_object);
  2153. if (mempool->memblocks_arr[i] == NULL) {
  2154. vfree(mempool->memblocks_priv_arr[i]);
  2155. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2156. goto exit;
  2157. }
  2158. (*num_allocated)++;
  2159. mempool->memblocks_allocated++;
  2160. memset(mempool->memblocks_arr[i], 0, mempool->memblock_size);
  2161. the_memblock = mempool->memblocks_arr[i];
  2162. /* fill the items hash array */
  2163. for (j = 0; j < n_items; j++) {
  2164. u32 index = i * n_items + j;
  2165. if (first_time && index >= mempool->items_initial)
  2166. break;
  2167. mempool->items_arr[index] =
  2168. ((char *)the_memblock + j*mempool->item_size);
  2169. /* let caller to do more job on each item */
  2170. if (mempool->item_func_alloc != NULL)
  2171. mempool->item_func_alloc(mempool, i,
  2172. dma_object, index, is_last);
  2173. mempool->items_current = index + 1;
  2174. }
  2175. if (first_time && mempool->items_current ==
  2176. mempool->items_initial)
  2177. break;
  2178. }
  2179. exit:
  2180. return status;
  2181. }
  2182. /*
  2183. * vxge_hw_mempool_create
  2184. * This function will create memory pool object. Pool may grow but will
  2185. * never shrink. Pool consists of number of dynamically allocated blocks
  2186. * with size enough to hold %items_initial number of items. Memory is
  2187. * DMA-able but client must map/unmap before interoperating with the device.
  2188. */
  2189. static struct vxge_hw_mempool *
  2190. __vxge_hw_mempool_create(struct __vxge_hw_device *devh,
  2191. u32 memblock_size,
  2192. u32 item_size,
  2193. u32 items_priv_size,
  2194. u32 items_initial,
  2195. u32 items_max,
  2196. const struct vxge_hw_mempool_cbs *mp_callback,
  2197. void *userdata)
  2198. {
  2199. enum vxge_hw_status status = VXGE_HW_OK;
  2200. u32 memblocks_to_allocate;
  2201. struct vxge_hw_mempool *mempool = NULL;
  2202. u32 allocated;
  2203. if (memblock_size < item_size) {
  2204. status = VXGE_HW_FAIL;
  2205. goto exit;
  2206. }
  2207. mempool = vzalloc(sizeof(struct vxge_hw_mempool));
  2208. if (mempool == NULL) {
  2209. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2210. goto exit;
  2211. }
  2212. mempool->devh = devh;
  2213. mempool->memblock_size = memblock_size;
  2214. mempool->items_max = items_max;
  2215. mempool->items_initial = items_initial;
  2216. mempool->item_size = item_size;
  2217. mempool->items_priv_size = items_priv_size;
  2218. mempool->item_func_alloc = mp_callback->item_func_alloc;
  2219. mempool->userdata = userdata;
  2220. mempool->memblocks_allocated = 0;
  2221. mempool->items_per_memblock = memblock_size / item_size;
  2222. mempool->memblocks_max = (items_max + mempool->items_per_memblock - 1) /
  2223. mempool->items_per_memblock;
  2224. /* allocate array of memblocks */
  2225. mempool->memblocks_arr =
  2226. vzalloc(sizeof(void *) * mempool->memblocks_max);
  2227. if (mempool->memblocks_arr == NULL) {
  2228. __vxge_hw_mempool_destroy(mempool);
  2229. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2230. mempool = NULL;
  2231. goto exit;
  2232. }
  2233. /* allocate array of private parts of items per memblocks */
  2234. mempool->memblocks_priv_arr =
  2235. vzalloc(sizeof(void *) * mempool->memblocks_max);
  2236. if (mempool->memblocks_priv_arr == NULL) {
  2237. __vxge_hw_mempool_destroy(mempool);
  2238. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2239. mempool = NULL;
  2240. goto exit;
  2241. }
  2242. /* allocate array of memblocks DMA objects */
  2243. mempool->memblocks_dma_arr =
  2244. vzalloc(sizeof(struct vxge_hw_mempool_dma) *
  2245. mempool->memblocks_max);
  2246. if (mempool->memblocks_dma_arr == NULL) {
  2247. __vxge_hw_mempool_destroy(mempool);
  2248. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2249. mempool = NULL;
  2250. goto exit;
  2251. }
  2252. /* allocate hash array of items */
  2253. mempool->items_arr = vzalloc(sizeof(void *) * mempool->items_max);
  2254. if (mempool->items_arr == NULL) {
  2255. __vxge_hw_mempool_destroy(mempool);
  2256. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2257. mempool = NULL;
  2258. goto exit;
  2259. }
  2260. /* calculate initial number of memblocks */
  2261. memblocks_to_allocate = (mempool->items_initial +
  2262. mempool->items_per_memblock - 1) /
  2263. mempool->items_per_memblock;
  2264. /* pre-allocate the mempool */
  2265. status = __vxge_hw_mempool_grow(mempool, memblocks_to_allocate,
  2266. &allocated);
  2267. if (status != VXGE_HW_OK) {
  2268. __vxge_hw_mempool_destroy(mempool);
  2269. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2270. mempool = NULL;
  2271. goto exit;
  2272. }
  2273. exit:
  2274. return mempool;
  2275. }
  2276. /*
  2277. * __vxge_hw_ring_abort - Returns the RxD
  2278. * This function terminates the RxDs of ring
  2279. */
  2280. static enum vxge_hw_status __vxge_hw_ring_abort(struct __vxge_hw_ring *ring)
  2281. {
  2282. void *rxdh;
  2283. struct __vxge_hw_channel *channel;
  2284. channel = &ring->channel;
  2285. for (;;) {
  2286. vxge_hw_channel_dtr_try_complete(channel, &rxdh);
  2287. if (rxdh == NULL)
  2288. break;
  2289. vxge_hw_channel_dtr_complete(channel);
  2290. if (ring->rxd_term)
  2291. ring->rxd_term(rxdh, VXGE_HW_RXD_STATE_POSTED,
  2292. channel->userdata);
  2293. vxge_hw_channel_dtr_free(channel, rxdh);
  2294. }
  2295. return VXGE_HW_OK;
  2296. }
  2297. /*
  2298. * __vxge_hw_ring_reset - Resets the ring
  2299. * This function resets the ring during vpath reset operation
  2300. */
  2301. static enum vxge_hw_status __vxge_hw_ring_reset(struct __vxge_hw_ring *ring)
  2302. {
  2303. enum vxge_hw_status status = VXGE_HW_OK;
  2304. struct __vxge_hw_channel *channel;
  2305. channel = &ring->channel;
  2306. __vxge_hw_ring_abort(ring);
  2307. status = __vxge_hw_channel_reset(channel);
  2308. if (status != VXGE_HW_OK)
  2309. goto exit;
  2310. if (ring->rxd_init) {
  2311. status = vxge_hw_ring_replenish(ring);
  2312. if (status != VXGE_HW_OK)
  2313. goto exit;
  2314. }
  2315. exit:
  2316. return status;
  2317. }
  2318. /*
  2319. * __vxge_hw_ring_delete - Removes the ring
  2320. * This function freeup the memory pool and removes the ring
  2321. */
  2322. static enum vxge_hw_status
  2323. __vxge_hw_ring_delete(struct __vxge_hw_vpath_handle *vp)
  2324. {
  2325. struct __vxge_hw_ring *ring = vp->vpath->ringh;
  2326. __vxge_hw_ring_abort(ring);
  2327. if (ring->mempool)
  2328. __vxge_hw_mempool_destroy(ring->mempool);
  2329. vp->vpath->ringh = NULL;
  2330. __vxge_hw_channel_free(&ring->channel);
  2331. return VXGE_HW_OK;
  2332. }
  2333. /*
  2334. * __vxge_hw_ring_create - Create a Ring
  2335. * This function creates Ring and initializes it.
  2336. */
  2337. static enum vxge_hw_status
  2338. __vxge_hw_ring_create(struct __vxge_hw_vpath_handle *vp,
  2339. struct vxge_hw_ring_attr *attr)
  2340. {
  2341. enum vxge_hw_status status = VXGE_HW_OK;
  2342. struct __vxge_hw_ring *ring;
  2343. u32 ring_length;
  2344. struct vxge_hw_ring_config *config;
  2345. struct __vxge_hw_device *hldev;
  2346. u32 vp_id;
  2347. static const struct vxge_hw_mempool_cbs ring_mp_callback = {
  2348. .item_func_alloc = __vxge_hw_ring_mempool_item_alloc,
  2349. };
  2350. if ((vp == NULL) || (attr == NULL)) {
  2351. status = VXGE_HW_FAIL;
  2352. goto exit;
  2353. }
  2354. hldev = vp->vpath->hldev;
  2355. vp_id = vp->vpath->vp_id;
  2356. config = &hldev->config.vp_config[vp_id].ring;
  2357. ring_length = config->ring_blocks *
  2358. vxge_hw_ring_rxds_per_block_get(config->buffer_mode);
  2359. ring = (struct __vxge_hw_ring *)__vxge_hw_channel_allocate(vp,
  2360. VXGE_HW_CHANNEL_TYPE_RING,
  2361. ring_length,
  2362. attr->per_rxd_space,
  2363. attr->userdata);
  2364. if (ring == NULL) {
  2365. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2366. goto exit;
  2367. }
  2368. vp->vpath->ringh = ring;
  2369. ring->vp_id = vp_id;
  2370. ring->vp_reg = vp->vpath->vp_reg;
  2371. ring->common_reg = hldev->common_reg;
  2372. ring->stats = &vp->vpath->sw_stats->ring_stats;
  2373. ring->config = config;
  2374. ring->callback = attr->callback;
  2375. ring->rxd_init = attr->rxd_init;
  2376. ring->rxd_term = attr->rxd_term;
  2377. ring->buffer_mode = config->buffer_mode;
  2378. ring->tim_rti_cfg1_saved = vp->vpath->tim_rti_cfg1_saved;
  2379. ring->tim_rti_cfg3_saved = vp->vpath->tim_rti_cfg3_saved;
  2380. ring->rxds_limit = config->rxds_limit;
  2381. ring->rxd_size = vxge_hw_ring_rxd_size_get(config->buffer_mode);
  2382. ring->rxd_priv_size =
  2383. sizeof(struct __vxge_hw_ring_rxd_priv) + attr->per_rxd_space;
  2384. ring->per_rxd_space = attr->per_rxd_space;
  2385. ring->rxd_priv_size =
  2386. ((ring->rxd_priv_size + VXGE_CACHE_LINE_SIZE - 1) /
  2387. VXGE_CACHE_LINE_SIZE) * VXGE_CACHE_LINE_SIZE;
  2388. /* how many RxDs can fit into one block. Depends on configured
  2389. * buffer_mode. */
  2390. ring->rxds_per_block =
  2391. vxge_hw_ring_rxds_per_block_get(config->buffer_mode);
  2392. /* calculate actual RxD block private size */
  2393. ring->rxdblock_priv_size = ring->rxd_priv_size * ring->rxds_per_block;
  2394. ring->mempool = __vxge_hw_mempool_create(hldev,
  2395. VXGE_HW_BLOCK_SIZE,
  2396. VXGE_HW_BLOCK_SIZE,
  2397. ring->rxdblock_priv_size,
  2398. ring->config->ring_blocks,
  2399. ring->config->ring_blocks,
  2400. &ring_mp_callback,
  2401. ring);
  2402. if (ring->mempool == NULL) {
  2403. __vxge_hw_ring_delete(vp);
  2404. return VXGE_HW_ERR_OUT_OF_MEMORY;
  2405. }
  2406. status = __vxge_hw_channel_initialize(&ring->channel);
  2407. if (status != VXGE_HW_OK) {
  2408. __vxge_hw_ring_delete(vp);
  2409. goto exit;
  2410. }
  2411. /* Note:
  2412. * Specifying rxd_init callback means two things:
  2413. * 1) rxds need to be initialized by driver at channel-open time;
  2414. * 2) rxds need to be posted at channel-open time
  2415. * (that's what the initial_replenish() below does)
  2416. * Currently we don't have a case when the 1) is done without the 2).
  2417. */
  2418. if (ring->rxd_init) {
  2419. status = vxge_hw_ring_replenish(ring);
  2420. if (status != VXGE_HW_OK) {
  2421. __vxge_hw_ring_delete(vp);
  2422. goto exit;
  2423. }
  2424. }
  2425. /* initial replenish will increment the counter in its post() routine,
  2426. * we have to reset it */
  2427. ring->stats->common_stats.usage_cnt = 0;
  2428. exit:
  2429. return status;
  2430. }
  2431. /*
  2432. * vxge_hw_device_config_default_get - Initialize device config with defaults.
  2433. * Initialize Titan device config with default values.
  2434. */
  2435. enum vxge_hw_status
  2436. vxge_hw_device_config_default_get(struct vxge_hw_device_config *device_config)
  2437. {
  2438. u32 i;
  2439. device_config->dma_blockpool_initial =
  2440. VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
  2441. device_config->dma_blockpool_max = VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
  2442. device_config->intr_mode = VXGE_HW_INTR_MODE_DEF;
  2443. device_config->rth_en = VXGE_HW_RTH_DEFAULT;
  2444. device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_DEFAULT;
  2445. device_config->device_poll_millis = VXGE_HW_DEF_DEVICE_POLL_MILLIS;
  2446. device_config->rts_mac_en = VXGE_HW_RTS_MAC_DEFAULT;
  2447. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  2448. device_config->vp_config[i].vp_id = i;
  2449. device_config->vp_config[i].min_bandwidth =
  2450. VXGE_HW_VPATH_BANDWIDTH_DEFAULT;
  2451. device_config->vp_config[i].ring.enable = VXGE_HW_RING_DEFAULT;
  2452. device_config->vp_config[i].ring.ring_blocks =
  2453. VXGE_HW_DEF_RING_BLOCKS;
  2454. device_config->vp_config[i].ring.buffer_mode =
  2455. VXGE_HW_RING_RXD_BUFFER_MODE_DEFAULT;
  2456. device_config->vp_config[i].ring.scatter_mode =
  2457. VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT;
  2458. device_config->vp_config[i].ring.rxds_limit =
  2459. VXGE_HW_DEF_RING_RXDS_LIMIT;
  2460. device_config->vp_config[i].fifo.enable = VXGE_HW_FIFO_ENABLE;
  2461. device_config->vp_config[i].fifo.fifo_blocks =
  2462. VXGE_HW_MIN_FIFO_BLOCKS;
  2463. device_config->vp_config[i].fifo.max_frags =
  2464. VXGE_HW_MAX_FIFO_FRAGS;
  2465. device_config->vp_config[i].fifo.memblock_size =
  2466. VXGE_HW_DEF_FIFO_MEMBLOCK_SIZE;
  2467. device_config->vp_config[i].fifo.alignment_size =
  2468. VXGE_HW_DEF_FIFO_ALIGNMENT_SIZE;
  2469. device_config->vp_config[i].fifo.intr =
  2470. VXGE_HW_FIFO_QUEUE_INTR_DEFAULT;
  2471. device_config->vp_config[i].fifo.no_snoop_bits =
  2472. VXGE_HW_FIFO_NO_SNOOP_DEFAULT;
  2473. device_config->vp_config[i].tti.intr_enable =
  2474. VXGE_HW_TIM_INTR_DEFAULT;
  2475. device_config->vp_config[i].tti.btimer_val =
  2476. VXGE_HW_USE_FLASH_DEFAULT;
  2477. device_config->vp_config[i].tti.timer_ac_en =
  2478. VXGE_HW_USE_FLASH_DEFAULT;
  2479. device_config->vp_config[i].tti.timer_ci_en =
  2480. VXGE_HW_USE_FLASH_DEFAULT;
  2481. device_config->vp_config[i].tti.timer_ri_en =
  2482. VXGE_HW_USE_FLASH_DEFAULT;
  2483. device_config->vp_config[i].tti.rtimer_val =
  2484. VXGE_HW_USE_FLASH_DEFAULT;
  2485. device_config->vp_config[i].tti.util_sel =
  2486. VXGE_HW_USE_FLASH_DEFAULT;
  2487. device_config->vp_config[i].tti.ltimer_val =
  2488. VXGE_HW_USE_FLASH_DEFAULT;
  2489. device_config->vp_config[i].tti.urange_a =
  2490. VXGE_HW_USE_FLASH_DEFAULT;
  2491. device_config->vp_config[i].tti.uec_a =
  2492. VXGE_HW_USE_FLASH_DEFAULT;
  2493. device_config->vp_config[i].tti.urange_b =
  2494. VXGE_HW_USE_FLASH_DEFAULT;
  2495. device_config->vp_config[i].tti.uec_b =
  2496. VXGE_HW_USE_FLASH_DEFAULT;
  2497. device_config->vp_config[i].tti.urange_c =
  2498. VXGE_HW_USE_FLASH_DEFAULT;
  2499. device_config->vp_config[i].tti.uec_c =
  2500. VXGE_HW_USE_FLASH_DEFAULT;
  2501. device_config->vp_config[i].tti.uec_d =
  2502. VXGE_HW_USE_FLASH_DEFAULT;
  2503. device_config->vp_config[i].rti.intr_enable =
  2504. VXGE_HW_TIM_INTR_DEFAULT;
  2505. device_config->vp_config[i].rti.btimer_val =
  2506. VXGE_HW_USE_FLASH_DEFAULT;
  2507. device_config->vp_config[i].rti.timer_ac_en =
  2508. VXGE_HW_USE_FLASH_DEFAULT;
  2509. device_config->vp_config[i].rti.timer_ci_en =
  2510. VXGE_HW_USE_FLASH_DEFAULT;
  2511. device_config->vp_config[i].rti.timer_ri_en =
  2512. VXGE_HW_USE_FLASH_DEFAULT;
  2513. device_config->vp_config[i].rti.rtimer_val =
  2514. VXGE_HW_USE_FLASH_DEFAULT;
  2515. device_config->vp_config[i].rti.util_sel =
  2516. VXGE_HW_USE_FLASH_DEFAULT;
  2517. device_config->vp_config[i].rti.ltimer_val =
  2518. VXGE_HW_USE_FLASH_DEFAULT;
  2519. device_config->vp_config[i].rti.urange_a =
  2520. VXGE_HW_USE_FLASH_DEFAULT;
  2521. device_config->vp_config[i].rti.uec_a =
  2522. VXGE_HW_USE_FLASH_DEFAULT;
  2523. device_config->vp_config[i].rti.urange_b =
  2524. VXGE_HW_USE_FLASH_DEFAULT;
  2525. device_config->vp_config[i].rti.uec_b =
  2526. VXGE_HW_USE_FLASH_DEFAULT;
  2527. device_config->vp_config[i].rti.urange_c =
  2528. VXGE_HW_USE_FLASH_DEFAULT;
  2529. device_config->vp_config[i].rti.uec_c =
  2530. VXGE_HW_USE_FLASH_DEFAULT;
  2531. device_config->vp_config[i].rti.uec_d =
  2532. VXGE_HW_USE_FLASH_DEFAULT;
  2533. device_config->vp_config[i].mtu =
  2534. VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU;
  2535. device_config->vp_config[i].rpa_strip_vlan_tag =
  2536. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT;
  2537. }
  2538. return VXGE_HW_OK;
  2539. }
  2540. /*
  2541. * __vxge_hw_vpath_swapper_set - Set the swapper bits for the vpath.
  2542. * Set the swapper bits appropriately for the vpath.
  2543. */
  2544. static enum vxge_hw_status
  2545. __vxge_hw_vpath_swapper_set(struct vxge_hw_vpath_reg __iomem *vpath_reg)
  2546. {
  2547. #ifndef __BIG_ENDIAN
  2548. u64 val64;
  2549. val64 = readq(&vpath_reg->vpath_general_cfg1);
  2550. wmb();
  2551. val64 |= VXGE_HW_VPATH_GENERAL_CFG1_CTL_BYTE_SWAPEN;
  2552. writeq(val64, &vpath_reg->vpath_general_cfg1);
  2553. wmb();
  2554. #endif
  2555. return VXGE_HW_OK;
  2556. }
  2557. /*
  2558. * __vxge_hw_kdfc_swapper_set - Set the swapper bits for the kdfc.
  2559. * Set the swapper bits appropriately for the vpath.
  2560. */
  2561. static enum vxge_hw_status
  2562. __vxge_hw_kdfc_swapper_set(struct vxge_hw_legacy_reg __iomem *legacy_reg,
  2563. struct vxge_hw_vpath_reg __iomem *vpath_reg)
  2564. {
  2565. u64 val64;
  2566. val64 = readq(&legacy_reg->pifm_wr_swap_en);
  2567. if (val64 == VXGE_HW_SWAPPER_WRITE_BYTE_SWAP_ENABLE) {
  2568. val64 = readq(&vpath_reg->kdfcctl_cfg0);
  2569. wmb();
  2570. val64 |= VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO0 |
  2571. VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO1 |
  2572. VXGE_HW_KDFCCTL_CFG0_BYTE_SWAPEN_FIFO2;
  2573. writeq(val64, &vpath_reg->kdfcctl_cfg0);
  2574. wmb();
  2575. }
  2576. return VXGE_HW_OK;
  2577. }
  2578. /*
  2579. * vxge_hw_mgmt_reg_read - Read Titan register.
  2580. */
  2581. enum vxge_hw_status
  2582. vxge_hw_mgmt_reg_read(struct __vxge_hw_device *hldev,
  2583. enum vxge_hw_mgmt_reg_type type,
  2584. u32 index, u32 offset, u64 *value)
  2585. {
  2586. enum vxge_hw_status status = VXGE_HW_OK;
  2587. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  2588. status = VXGE_HW_ERR_INVALID_DEVICE;
  2589. goto exit;
  2590. }
  2591. switch (type) {
  2592. case vxge_hw_mgmt_reg_type_legacy:
  2593. if (offset > sizeof(struct vxge_hw_legacy_reg) - 8) {
  2594. status = VXGE_HW_ERR_INVALID_OFFSET;
  2595. break;
  2596. }
  2597. *value = readq((void __iomem *)hldev->legacy_reg + offset);
  2598. break;
  2599. case vxge_hw_mgmt_reg_type_toc:
  2600. if (offset > sizeof(struct vxge_hw_toc_reg) - 8) {
  2601. status = VXGE_HW_ERR_INVALID_OFFSET;
  2602. break;
  2603. }
  2604. *value = readq((void __iomem *)hldev->toc_reg + offset);
  2605. break;
  2606. case vxge_hw_mgmt_reg_type_common:
  2607. if (offset > sizeof(struct vxge_hw_common_reg) - 8) {
  2608. status = VXGE_HW_ERR_INVALID_OFFSET;
  2609. break;
  2610. }
  2611. *value = readq((void __iomem *)hldev->common_reg + offset);
  2612. break;
  2613. case vxge_hw_mgmt_reg_type_mrpcim:
  2614. if (!(hldev->access_rights &
  2615. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) {
  2616. status = VXGE_HW_ERR_PRIVILAGED_OPEARATION;
  2617. break;
  2618. }
  2619. if (offset > sizeof(struct vxge_hw_mrpcim_reg) - 8) {
  2620. status = VXGE_HW_ERR_INVALID_OFFSET;
  2621. break;
  2622. }
  2623. *value = readq((void __iomem *)hldev->mrpcim_reg + offset);
  2624. break;
  2625. case vxge_hw_mgmt_reg_type_srpcim:
  2626. if (!(hldev->access_rights &
  2627. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM)) {
  2628. status = VXGE_HW_ERR_PRIVILAGED_OPEARATION;
  2629. break;
  2630. }
  2631. if (index > VXGE_HW_TITAN_SRPCIM_REG_SPACES - 1) {
  2632. status = VXGE_HW_ERR_INVALID_INDEX;
  2633. break;
  2634. }
  2635. if (offset > sizeof(struct vxge_hw_srpcim_reg) - 8) {
  2636. status = VXGE_HW_ERR_INVALID_OFFSET;
  2637. break;
  2638. }
  2639. *value = readq((void __iomem *)hldev->srpcim_reg[index] +
  2640. offset);
  2641. break;
  2642. case vxge_hw_mgmt_reg_type_vpmgmt:
  2643. if ((index > VXGE_HW_TITAN_VPMGMT_REG_SPACES - 1) ||
  2644. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2645. status = VXGE_HW_ERR_INVALID_INDEX;
  2646. break;
  2647. }
  2648. if (offset > sizeof(struct vxge_hw_vpmgmt_reg) - 8) {
  2649. status = VXGE_HW_ERR_INVALID_OFFSET;
  2650. break;
  2651. }
  2652. *value = readq((void __iomem *)hldev->vpmgmt_reg[index] +
  2653. offset);
  2654. break;
  2655. case vxge_hw_mgmt_reg_type_vpath:
  2656. if ((index > VXGE_HW_TITAN_VPATH_REG_SPACES - 1) ||
  2657. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2658. status = VXGE_HW_ERR_INVALID_INDEX;
  2659. break;
  2660. }
  2661. if (index > VXGE_HW_TITAN_VPATH_REG_SPACES - 1) {
  2662. status = VXGE_HW_ERR_INVALID_INDEX;
  2663. break;
  2664. }
  2665. if (offset > sizeof(struct vxge_hw_vpath_reg) - 8) {
  2666. status = VXGE_HW_ERR_INVALID_OFFSET;
  2667. break;
  2668. }
  2669. *value = readq((void __iomem *)hldev->vpath_reg[index] +
  2670. offset);
  2671. break;
  2672. default:
  2673. status = VXGE_HW_ERR_INVALID_TYPE;
  2674. break;
  2675. }
  2676. exit:
  2677. return status;
  2678. }
  2679. /*
  2680. * vxge_hw_vpath_strip_fcs_check - Check for FCS strip.
  2681. */
  2682. enum vxge_hw_status
  2683. vxge_hw_vpath_strip_fcs_check(struct __vxge_hw_device *hldev, u64 vpath_mask)
  2684. {
  2685. struct vxge_hw_vpmgmt_reg __iomem *vpmgmt_reg;
  2686. int i = 0, j = 0;
  2687. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  2688. if (!((vpath_mask) & vxge_mBIT(i)))
  2689. continue;
  2690. vpmgmt_reg = hldev->vpmgmt_reg[i];
  2691. for (j = 0; j < VXGE_HW_MAC_MAX_MAC_PORT_ID; j++) {
  2692. if (readq(&vpmgmt_reg->rxmac_cfg0_port_vpmgmt_clone[j])
  2693. & VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_STRIP_FCS)
  2694. return VXGE_HW_FAIL;
  2695. }
  2696. }
  2697. return VXGE_HW_OK;
  2698. }
  2699. /*
  2700. * vxge_hw_mgmt_reg_Write - Write Titan register.
  2701. */
  2702. enum vxge_hw_status
  2703. vxge_hw_mgmt_reg_write(struct __vxge_hw_device *hldev,
  2704. enum vxge_hw_mgmt_reg_type type,
  2705. u32 index, u32 offset, u64 value)
  2706. {
  2707. enum vxge_hw_status status = VXGE_HW_OK;
  2708. if ((hldev == NULL) || (hldev->magic != VXGE_HW_DEVICE_MAGIC)) {
  2709. status = VXGE_HW_ERR_INVALID_DEVICE;
  2710. goto exit;
  2711. }
  2712. switch (type) {
  2713. case vxge_hw_mgmt_reg_type_legacy:
  2714. if (offset > sizeof(struct vxge_hw_legacy_reg) - 8) {
  2715. status = VXGE_HW_ERR_INVALID_OFFSET;
  2716. break;
  2717. }
  2718. writeq(value, (void __iomem *)hldev->legacy_reg + offset);
  2719. break;
  2720. case vxge_hw_mgmt_reg_type_toc:
  2721. if (offset > sizeof(struct vxge_hw_toc_reg) - 8) {
  2722. status = VXGE_HW_ERR_INVALID_OFFSET;
  2723. break;
  2724. }
  2725. writeq(value, (void __iomem *)hldev->toc_reg + offset);
  2726. break;
  2727. case vxge_hw_mgmt_reg_type_common:
  2728. if (offset > sizeof(struct vxge_hw_common_reg) - 8) {
  2729. status = VXGE_HW_ERR_INVALID_OFFSET;
  2730. break;
  2731. }
  2732. writeq(value, (void __iomem *)hldev->common_reg + offset);
  2733. break;
  2734. case vxge_hw_mgmt_reg_type_mrpcim:
  2735. if (!(hldev->access_rights &
  2736. VXGE_HW_DEVICE_ACCESS_RIGHT_MRPCIM)) {
  2737. status = VXGE_HW_ERR_PRIVILAGED_OPEARATION;
  2738. break;
  2739. }
  2740. if (offset > sizeof(struct vxge_hw_mrpcim_reg) - 8) {
  2741. status = VXGE_HW_ERR_INVALID_OFFSET;
  2742. break;
  2743. }
  2744. writeq(value, (void __iomem *)hldev->mrpcim_reg + offset);
  2745. break;
  2746. case vxge_hw_mgmt_reg_type_srpcim:
  2747. if (!(hldev->access_rights &
  2748. VXGE_HW_DEVICE_ACCESS_RIGHT_SRPCIM)) {
  2749. status = VXGE_HW_ERR_PRIVILAGED_OPEARATION;
  2750. break;
  2751. }
  2752. if (index > VXGE_HW_TITAN_SRPCIM_REG_SPACES - 1) {
  2753. status = VXGE_HW_ERR_INVALID_INDEX;
  2754. break;
  2755. }
  2756. if (offset > sizeof(struct vxge_hw_srpcim_reg) - 8) {
  2757. status = VXGE_HW_ERR_INVALID_OFFSET;
  2758. break;
  2759. }
  2760. writeq(value, (void __iomem *)hldev->srpcim_reg[index] +
  2761. offset);
  2762. break;
  2763. case vxge_hw_mgmt_reg_type_vpmgmt:
  2764. if ((index > VXGE_HW_TITAN_VPMGMT_REG_SPACES - 1) ||
  2765. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2766. status = VXGE_HW_ERR_INVALID_INDEX;
  2767. break;
  2768. }
  2769. if (offset > sizeof(struct vxge_hw_vpmgmt_reg) - 8) {
  2770. status = VXGE_HW_ERR_INVALID_OFFSET;
  2771. break;
  2772. }
  2773. writeq(value, (void __iomem *)hldev->vpmgmt_reg[index] +
  2774. offset);
  2775. break;
  2776. case vxge_hw_mgmt_reg_type_vpath:
  2777. if ((index > VXGE_HW_TITAN_VPATH_REG_SPACES-1) ||
  2778. (!(hldev->vpath_assignments & vxge_mBIT(index)))) {
  2779. status = VXGE_HW_ERR_INVALID_INDEX;
  2780. break;
  2781. }
  2782. if (offset > sizeof(struct vxge_hw_vpath_reg) - 8) {
  2783. status = VXGE_HW_ERR_INVALID_OFFSET;
  2784. break;
  2785. }
  2786. writeq(value, (void __iomem *)hldev->vpath_reg[index] +
  2787. offset);
  2788. break;
  2789. default:
  2790. status = VXGE_HW_ERR_INVALID_TYPE;
  2791. break;
  2792. }
  2793. exit:
  2794. return status;
  2795. }
  2796. /*
  2797. * __vxge_hw_fifo_abort - Returns the TxD
  2798. * This function terminates the TxDs of fifo
  2799. */
  2800. static enum vxge_hw_status __vxge_hw_fifo_abort(struct __vxge_hw_fifo *fifo)
  2801. {
  2802. void *txdlh;
  2803. for (;;) {
  2804. vxge_hw_channel_dtr_try_complete(&fifo->channel, &txdlh);
  2805. if (txdlh == NULL)
  2806. break;
  2807. vxge_hw_channel_dtr_complete(&fifo->channel);
  2808. if (fifo->txdl_term) {
  2809. fifo->txdl_term(txdlh,
  2810. VXGE_HW_TXDL_STATE_POSTED,
  2811. fifo->channel.userdata);
  2812. }
  2813. vxge_hw_channel_dtr_free(&fifo->channel, txdlh);
  2814. }
  2815. return VXGE_HW_OK;
  2816. }
  2817. /*
  2818. * __vxge_hw_fifo_reset - Resets the fifo
  2819. * This function resets the fifo during vpath reset operation
  2820. */
  2821. static enum vxge_hw_status __vxge_hw_fifo_reset(struct __vxge_hw_fifo *fifo)
  2822. {
  2823. enum vxge_hw_status status = VXGE_HW_OK;
  2824. __vxge_hw_fifo_abort(fifo);
  2825. status = __vxge_hw_channel_reset(&fifo->channel);
  2826. return status;
  2827. }
  2828. /*
  2829. * __vxge_hw_fifo_delete - Removes the FIFO
  2830. * This function freeup the memory pool and removes the FIFO
  2831. */
  2832. static enum vxge_hw_status
  2833. __vxge_hw_fifo_delete(struct __vxge_hw_vpath_handle *vp)
  2834. {
  2835. struct __vxge_hw_fifo *fifo = vp->vpath->fifoh;
  2836. __vxge_hw_fifo_abort(fifo);
  2837. if (fifo->mempool)
  2838. __vxge_hw_mempool_destroy(fifo->mempool);
  2839. vp->vpath->fifoh = NULL;
  2840. __vxge_hw_channel_free(&fifo->channel);
  2841. return VXGE_HW_OK;
  2842. }
  2843. /*
  2844. * __vxge_hw_fifo_mempool_item_alloc - Allocate List blocks for TxD
  2845. * list callback
  2846. * This function is callback passed to __vxge_hw_mempool_create to create memory
  2847. * pool for TxD list
  2848. */
  2849. static void
  2850. __vxge_hw_fifo_mempool_item_alloc(
  2851. struct vxge_hw_mempool *mempoolh,
  2852. u32 memblock_index, struct vxge_hw_mempool_dma *dma_object,
  2853. u32 index, u32 is_last)
  2854. {
  2855. u32 memblock_item_idx;
  2856. struct __vxge_hw_fifo_txdl_priv *txdl_priv;
  2857. struct vxge_hw_fifo_txd *txdp =
  2858. (struct vxge_hw_fifo_txd *)mempoolh->items_arr[index];
  2859. struct __vxge_hw_fifo *fifo =
  2860. (struct __vxge_hw_fifo *)mempoolh->userdata;
  2861. void *memblock = mempoolh->memblocks_arr[memblock_index];
  2862. vxge_assert(txdp);
  2863. txdp->host_control = (u64) (size_t)
  2864. __vxge_hw_mempool_item_priv(mempoolh, memblock_index, txdp,
  2865. &memblock_item_idx);
  2866. txdl_priv = __vxge_hw_fifo_txdl_priv(fifo, txdp);
  2867. vxge_assert(txdl_priv);
  2868. fifo->channel.reserve_arr[fifo->channel.reserve_ptr - 1 - index] = txdp;
  2869. /* pre-format HW's TxDL's private */
  2870. txdl_priv->dma_offset = (char *)txdp - (char *)memblock;
  2871. txdl_priv->dma_addr = dma_object->addr + txdl_priv->dma_offset;
  2872. txdl_priv->dma_handle = dma_object->handle;
  2873. txdl_priv->memblock = memblock;
  2874. txdl_priv->first_txdp = txdp;
  2875. txdl_priv->next_txdl_priv = NULL;
  2876. txdl_priv->alloc_frags = 0;
  2877. }
  2878. /*
  2879. * __vxge_hw_fifo_create - Create a FIFO
  2880. * This function creates FIFO and initializes it.
  2881. */
  2882. static enum vxge_hw_status
  2883. __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
  2884. struct vxge_hw_fifo_attr *attr)
  2885. {
  2886. enum vxge_hw_status status = VXGE_HW_OK;
  2887. struct __vxge_hw_fifo *fifo;
  2888. struct vxge_hw_fifo_config *config;
  2889. u32 txdl_size, txdl_per_memblock;
  2890. struct vxge_hw_mempool_cbs fifo_mp_callback;
  2891. struct __vxge_hw_virtualpath *vpath;
  2892. if ((vp == NULL) || (attr == NULL)) {
  2893. status = VXGE_HW_ERR_INVALID_HANDLE;
  2894. goto exit;
  2895. }
  2896. vpath = vp->vpath;
  2897. config = &vpath->hldev->config.vp_config[vpath->vp_id].fifo;
  2898. txdl_size = config->max_frags * sizeof(struct vxge_hw_fifo_txd);
  2899. txdl_per_memblock = config->memblock_size / txdl_size;
  2900. fifo = (struct __vxge_hw_fifo *)__vxge_hw_channel_allocate(vp,
  2901. VXGE_HW_CHANNEL_TYPE_FIFO,
  2902. config->fifo_blocks * txdl_per_memblock,
  2903. attr->per_txdl_space, attr->userdata);
  2904. if (fifo == NULL) {
  2905. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2906. goto exit;
  2907. }
  2908. vpath->fifoh = fifo;
  2909. fifo->nofl_db = vpath->nofl_db;
  2910. fifo->vp_id = vpath->vp_id;
  2911. fifo->vp_reg = vpath->vp_reg;
  2912. fifo->stats = &vpath->sw_stats->fifo_stats;
  2913. fifo->config = config;
  2914. /* apply "interrupts per txdl" attribute */
  2915. fifo->interrupt_type = VXGE_HW_FIFO_TXD_INT_TYPE_UTILZ;
  2916. fifo->tim_tti_cfg1_saved = vpath->tim_tti_cfg1_saved;
  2917. fifo->tim_tti_cfg3_saved = vpath->tim_tti_cfg3_saved;
  2918. if (fifo->config->intr)
  2919. fifo->interrupt_type = VXGE_HW_FIFO_TXD_INT_TYPE_PER_LIST;
  2920. fifo->no_snoop_bits = config->no_snoop_bits;
  2921. /*
  2922. * FIFO memory management strategy:
  2923. *
  2924. * TxDL split into three independent parts:
  2925. * - set of TxD's
  2926. * - TxD HW private part
  2927. * - driver private part
  2928. *
  2929. * Adaptative memory allocation used. i.e. Memory allocated on
  2930. * demand with the size which will fit into one memory block.
  2931. * One memory block may contain more than one TxDL.
  2932. *
  2933. * During "reserve" operations more memory can be allocated on demand
  2934. * for example due to FIFO full condition.
  2935. *
  2936. * Pool of memory memblocks never shrinks except in __vxge_hw_fifo_close
  2937. * routine which will essentially stop the channel and free resources.
  2938. */
  2939. /* TxDL common private size == TxDL private + driver private */
  2940. fifo->priv_size =
  2941. sizeof(struct __vxge_hw_fifo_txdl_priv) + attr->per_txdl_space;
  2942. fifo->priv_size = ((fifo->priv_size + VXGE_CACHE_LINE_SIZE - 1) /
  2943. VXGE_CACHE_LINE_SIZE) * VXGE_CACHE_LINE_SIZE;
  2944. fifo->per_txdl_space = attr->per_txdl_space;
  2945. /* recompute txdl size to be cacheline aligned */
  2946. fifo->txdl_size = txdl_size;
  2947. fifo->txdl_per_memblock = txdl_per_memblock;
  2948. fifo->txdl_term = attr->txdl_term;
  2949. fifo->callback = attr->callback;
  2950. if (fifo->txdl_per_memblock == 0) {
  2951. __vxge_hw_fifo_delete(vp);
  2952. status = VXGE_HW_ERR_INVALID_BLOCK_SIZE;
  2953. goto exit;
  2954. }
  2955. fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
  2956. fifo->mempool =
  2957. __vxge_hw_mempool_create(vpath->hldev,
  2958. fifo->config->memblock_size,
  2959. fifo->txdl_size,
  2960. fifo->priv_size,
  2961. (fifo->config->fifo_blocks * fifo->txdl_per_memblock),
  2962. (fifo->config->fifo_blocks * fifo->txdl_per_memblock),
  2963. &fifo_mp_callback,
  2964. fifo);
  2965. if (fifo->mempool == NULL) {
  2966. __vxge_hw_fifo_delete(vp);
  2967. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  2968. goto exit;
  2969. }
  2970. status = __vxge_hw_channel_initialize(&fifo->channel);
  2971. if (status != VXGE_HW_OK) {
  2972. __vxge_hw_fifo_delete(vp);
  2973. goto exit;
  2974. }
  2975. vxge_assert(fifo->channel.reserve_ptr);
  2976. exit:
  2977. return status;
  2978. }
  2979. /*
  2980. * __vxge_hw_vpath_pci_read - Read the content of given address
  2981. * in pci config space.
  2982. * Read from the vpath pci config space.
  2983. */
  2984. static enum vxge_hw_status
  2985. __vxge_hw_vpath_pci_read(struct __vxge_hw_virtualpath *vpath,
  2986. u32 phy_func_0, u32 offset, u32 *val)
  2987. {
  2988. u64 val64;
  2989. enum vxge_hw_status status = VXGE_HW_OK;
  2990. struct vxge_hw_vpath_reg __iomem *vp_reg = vpath->vp_reg;
  2991. val64 = VXGE_HW_PCI_CONFIG_ACCESS_CFG1_ADDRESS(offset);
  2992. if (phy_func_0)
  2993. val64 |= VXGE_HW_PCI_CONFIG_ACCESS_CFG1_SEL_FUNC0;
  2994. writeq(val64, &vp_reg->pci_config_access_cfg1);
  2995. wmb();
  2996. writeq(VXGE_HW_PCI_CONFIG_ACCESS_CFG2_REQ,
  2997. &vp_reg->pci_config_access_cfg2);
  2998. wmb();
  2999. status = __vxge_hw_device_register_poll(
  3000. &vp_reg->pci_config_access_cfg2,
  3001. VXGE_HW_INTR_MASK_ALL, VXGE_HW_DEF_DEVICE_POLL_MILLIS);
  3002. if (status != VXGE_HW_OK)
  3003. goto exit;
  3004. val64 = readq(&vp_reg->pci_config_access_status);
  3005. if (val64 & VXGE_HW_PCI_CONFIG_ACCESS_STATUS_ACCESS_ERR) {
  3006. status = VXGE_HW_FAIL;
  3007. *val = 0;
  3008. } else
  3009. *val = (u32)vxge_bVALn(val64, 32, 32);
  3010. exit:
  3011. return status;
  3012. }
  3013. /**
  3014. * vxge_hw_device_flick_link_led - Flick (blink) link LED.
  3015. * @hldev: HW device.
  3016. * @on_off: TRUE if flickering to be on, FALSE to be off
  3017. *
  3018. * Flicker the link LED.
  3019. */
  3020. enum vxge_hw_status
  3021. vxge_hw_device_flick_link_led(struct __vxge_hw_device *hldev, u64 on_off)
  3022. {
  3023. struct __vxge_hw_virtualpath *vpath;
  3024. u64 data0, data1 = 0, steer_ctrl = 0;
  3025. enum vxge_hw_status status;
  3026. if (hldev == NULL) {
  3027. status = VXGE_HW_ERR_INVALID_DEVICE;
  3028. goto exit;
  3029. }
  3030. vpath = &hldev->virtual_paths[hldev->first_vp_id];
  3031. data0 = on_off;
  3032. status = vxge_hw_vpath_fw_api(vpath,
  3033. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_LED_CONTROL,
  3034. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_FW_MEMO,
  3035. 0, &data0, &data1, &steer_ctrl);
  3036. exit:
  3037. return status;
  3038. }
  3039. /*
  3040. * __vxge_hw_vpath_rts_table_get - Get the entries from RTS access tables
  3041. */
  3042. enum vxge_hw_status
  3043. __vxge_hw_vpath_rts_table_get(struct __vxge_hw_vpath_handle *vp,
  3044. u32 action, u32 rts_table, u32 offset,
  3045. u64 *data0, u64 *data1)
  3046. {
  3047. enum vxge_hw_status status;
  3048. u64 steer_ctrl = 0;
  3049. if (vp == NULL) {
  3050. status = VXGE_HW_ERR_INVALID_HANDLE;
  3051. goto exit;
  3052. }
  3053. if ((rts_table ==
  3054. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT) ||
  3055. (rts_table ==
  3056. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT) ||
  3057. (rts_table ==
  3058. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MASK) ||
  3059. (rts_table ==
  3060. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_KEY)) {
  3061. steer_ctrl = VXGE_HW_RTS_ACCESS_STEER_CTRL_TABLE_SEL;
  3062. }
  3063. status = vxge_hw_vpath_fw_api(vp->vpath, action, rts_table, offset,
  3064. data0, data1, &steer_ctrl);
  3065. if (status != VXGE_HW_OK)
  3066. goto exit;
  3067. if ((rts_table != VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA) &&
  3068. (rts_table !=
  3069. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT))
  3070. *data1 = 0;
  3071. exit:
  3072. return status;
  3073. }
  3074. /*
  3075. * __vxge_hw_vpath_rts_table_set - Set the entries of RTS access tables
  3076. */
  3077. enum vxge_hw_status
  3078. __vxge_hw_vpath_rts_table_set(struct __vxge_hw_vpath_handle *vp, u32 action,
  3079. u32 rts_table, u32 offset, u64 steer_data0,
  3080. u64 steer_data1)
  3081. {
  3082. u64 data0, data1 = 0, steer_ctrl = 0;
  3083. enum vxge_hw_status status;
  3084. if (vp == NULL) {
  3085. status = VXGE_HW_ERR_INVALID_HANDLE;
  3086. goto exit;
  3087. }
  3088. data0 = steer_data0;
  3089. if ((rts_table == VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_DA) ||
  3090. (rts_table ==
  3091. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT))
  3092. data1 = steer_data1;
  3093. status = vxge_hw_vpath_fw_api(vp->vpath, action, rts_table, offset,
  3094. &data0, &data1, &steer_ctrl);
  3095. exit:
  3096. return status;
  3097. }
  3098. /*
  3099. * vxge_hw_vpath_rts_rth_set - Set/configure RTS hashing.
  3100. */
  3101. enum vxge_hw_status vxge_hw_vpath_rts_rth_set(
  3102. struct __vxge_hw_vpath_handle *vp,
  3103. enum vxge_hw_rth_algoritms algorithm,
  3104. struct vxge_hw_rth_hash_types *hash_type,
  3105. u16 bucket_size)
  3106. {
  3107. u64 data0, data1;
  3108. enum vxge_hw_status status = VXGE_HW_OK;
  3109. if (vp == NULL) {
  3110. status = VXGE_HW_ERR_INVALID_HANDLE;
  3111. goto exit;
  3112. }
  3113. status = __vxge_hw_vpath_rts_table_get(vp,
  3114. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_READ_ENTRY,
  3115. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG,
  3116. 0, &data0, &data1);
  3117. if (status != VXGE_HW_OK)
  3118. goto exit;
  3119. data0 &= ~(VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(0xf) |
  3120. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(0x3));
  3121. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_EN |
  3122. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_BUCKET_SIZE(bucket_size) |
  3123. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ALG_SEL(algorithm);
  3124. if (hash_type->hash_type_tcpipv4_en)
  3125. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV4_EN;
  3126. if (hash_type->hash_type_ipv4_en)
  3127. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV4_EN;
  3128. if (hash_type->hash_type_tcpipv6_en)
  3129. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EN;
  3130. if (hash_type->hash_type_ipv6_en)
  3131. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EN;
  3132. if (hash_type->hash_type_tcpipv6ex_en)
  3133. data0 |=
  3134. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_TCP_IPV6_EX_EN;
  3135. if (hash_type->hash_type_ipv6ex_en)
  3136. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_RTH_IPV6_EX_EN;
  3137. if (VXGE_HW_RTS_ACCESS_STEER_DATA0_GET_RTH_GEN_ACTIVE_TABLE(data0))
  3138. data0 &= ~VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE;
  3139. else
  3140. data0 |= VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_GEN_ACTIVE_TABLE;
  3141. status = __vxge_hw_vpath_rts_table_set(vp,
  3142. VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY,
  3143. VXGE_HW_RTS_ACCESS_STEER_CTRL_DATA_STRUCT_SEL_RTH_GEN_CFG,
  3144. 0, data0, 0);
  3145. exit:
  3146. return status;
  3147. }
  3148. static void
  3149. vxge_hw_rts_rth_data0_data1_get(u32 j, u64 *data0, u64 *data1,
  3150. u16 flag, u8 *itable)
  3151. {
  3152. switch (flag) {
  3153. case 1:
  3154. *data0 = VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_NUM(j)|
  3155. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_ENTRY_EN |
  3156. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM0_BUCKET_DATA(
  3157. itable[j]);
  3158. case 2:
  3159. *data0 |=
  3160. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_NUM(j)|
  3161. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_ENTRY_EN |
  3162. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_ITEM1_BUCKET_DATA(
  3163. itable[j]);
  3164. case 3:
  3165. *data1 = VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_NUM(j)|
  3166. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_ENTRY_EN |
  3167. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM0_BUCKET_DATA(
  3168. itable[j]);
  3169. case 4:
  3170. *data1 |=
  3171. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_NUM(j)|
  3172. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_ENTRY_EN |
  3173. VXGE_HW_RTS_ACCESS_STEER_DATA1_RTH_ITEM1_BUCKET_DATA(
  3174. itable[j]);
  3175. default:
  3176. return;
  3177. }
  3178. }
  3179. /*
  3180. * vxge_hw_vpath_rts_rth_itable_set - Set/configure indirection table (IT).
  3181. */
  3182. enum vxge_hw_status vxge_hw_vpath_rts_rth_itable_set(
  3183. struct __vxge_hw_vpath_handle **vpath_handles,
  3184. u32 vpath_count,
  3185. u8 *mtable,
  3186. u8 *itable,
  3187. u32 itable_size)
  3188. {
  3189. u32 i, j, action, rts_table;
  3190. u64 data0;
  3191. u64 data1;
  3192. u32 max_entries;
  3193. enum vxge_hw_status status = VXGE_HW_OK;
  3194. struct __vxge_hw_vpath_handle *vp = vpath_handles[0];
  3195. if (vp == NULL) {
  3196. status = VXGE_HW_ERR_INVALID_HANDLE;
  3197. goto exit;
  3198. }
  3199. max_entries = (((u32)1) << itable_size);
  3200. if (vp->vpath->hldev->config.rth_it_type
  3201. == VXGE_HW_RTH_IT_TYPE_SOLO_IT) {
  3202. action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY;
  3203. rts_table =
  3204. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_SOLO_IT;
  3205. for (j = 0; j < max_entries; j++) {
  3206. data1 = 0;
  3207. data0 =
  3208. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA(
  3209. itable[j]);
  3210. status = __vxge_hw_vpath_rts_table_set(vpath_handles[0],
  3211. action, rts_table, j, data0, data1);
  3212. if (status != VXGE_HW_OK)
  3213. goto exit;
  3214. }
  3215. for (j = 0; j < max_entries; j++) {
  3216. data1 = 0;
  3217. data0 =
  3218. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_ENTRY_EN |
  3219. VXGE_HW_RTS_ACCESS_STEER_DATA0_RTH_SOLO_IT_BUCKET_DATA(
  3220. itable[j]);
  3221. status = __vxge_hw_vpath_rts_table_set(
  3222. vpath_handles[mtable[itable[j]]], action,
  3223. rts_table, j, data0, data1);
  3224. if (status != VXGE_HW_OK)
  3225. goto exit;
  3226. }
  3227. } else {
  3228. action = VXGE_HW_RTS_ACCESS_STEER_CTRL_ACTION_WRITE_ENTRY;
  3229. rts_table =
  3230. VXGE_HW_RTS_ACS_STEER_CTRL_DATA_STRUCT_SEL_RTH_MULTI_IT;
  3231. for (i = 0; i < vpath_count; i++) {
  3232. for (j = 0; j < max_entries;) {
  3233. data0 = 0;
  3234. data1 = 0;
  3235. while (j < max_entries) {
  3236. if (mtable[itable[j]] != i) {
  3237. j++;
  3238. continue;
  3239. }
  3240. vxge_hw_rts_rth_data0_data1_get(j,
  3241. &data0, &data1, 1, itable);
  3242. j++;
  3243. break;
  3244. }
  3245. while (j < max_entries) {
  3246. if (mtable[itable[j]] != i) {
  3247. j++;
  3248. continue;
  3249. }
  3250. vxge_hw_rts_rth_data0_data1_get(j,
  3251. &data0, &data1, 2, itable);
  3252. j++;
  3253. break;
  3254. }
  3255. while (j < max_entries) {
  3256. if (mtable[itable[j]] != i) {
  3257. j++;
  3258. continue;
  3259. }
  3260. vxge_hw_rts_rth_data0_data1_get(j,
  3261. &data0, &data1, 3, itable);
  3262. j++;
  3263. break;
  3264. }
  3265. while (j < max_entries) {
  3266. if (mtable[itable[j]] != i) {
  3267. j++;
  3268. continue;
  3269. }
  3270. vxge_hw_rts_rth_data0_data1_get(j,
  3271. &data0, &data1, 4, itable);
  3272. j++;
  3273. break;
  3274. }
  3275. if (data0 != 0) {
  3276. status = __vxge_hw_vpath_rts_table_set(
  3277. vpath_handles[i],
  3278. action, rts_table,
  3279. 0, data0, data1);
  3280. if (status != VXGE_HW_OK)
  3281. goto exit;
  3282. }
  3283. }
  3284. }
  3285. }
  3286. exit:
  3287. return status;
  3288. }
  3289. /**
  3290. * vxge_hw_vpath_check_leak - Check for memory leak
  3291. * @ringh: Handle to the ring object used for receive
  3292. *
  3293. * If PRC_RXD_DOORBELL_VPn.NEW_QW_CNT is larger or equal to
  3294. * PRC_CFG6_VPn.RXD_SPAT then a leak has occurred.
  3295. * Returns: VXGE_HW_FAIL, if leak has occurred.
  3296. *
  3297. */
  3298. enum vxge_hw_status
  3299. vxge_hw_vpath_check_leak(struct __vxge_hw_ring *ring)
  3300. {
  3301. enum vxge_hw_status status = VXGE_HW_OK;
  3302. u64 rxd_new_count, rxd_spat;
  3303. if (ring == NULL)
  3304. return status;
  3305. rxd_new_count = readl(&ring->vp_reg->prc_rxd_doorbell);
  3306. rxd_spat = readq(&ring->vp_reg->prc_cfg6);
  3307. rxd_spat = VXGE_HW_PRC_CFG6_RXD_SPAT(rxd_spat);
  3308. if (rxd_new_count >= rxd_spat)
  3309. status = VXGE_HW_FAIL;
  3310. return status;
  3311. }
  3312. /*
  3313. * __vxge_hw_vpath_mgmt_read
  3314. * This routine reads the vpath_mgmt registers
  3315. */
  3316. static enum vxge_hw_status
  3317. __vxge_hw_vpath_mgmt_read(
  3318. struct __vxge_hw_device *hldev,
  3319. struct __vxge_hw_virtualpath *vpath)
  3320. {
  3321. u32 i, mtu = 0, max_pyld = 0;
  3322. u64 val64;
  3323. for (i = 0; i < VXGE_HW_MAC_MAX_MAC_PORT_ID; i++) {
  3324. val64 = readq(&vpath->vpmgmt_reg->
  3325. rxmac_cfg0_port_vpmgmt_clone[i]);
  3326. max_pyld =
  3327. (u32)
  3328. VXGE_HW_RXMAC_CFG0_PORT_VPMGMT_CLONE_GET_MAX_PYLD_LEN
  3329. (val64);
  3330. if (mtu < max_pyld)
  3331. mtu = max_pyld;
  3332. }
  3333. vpath->max_mtu = mtu + VXGE_HW_MAC_HEADER_MAX_SIZE;
  3334. val64 = readq(&vpath->vpmgmt_reg->xmac_vsport_choices_vp);
  3335. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3336. if (val64 & vxge_mBIT(i))
  3337. vpath->vsport_number = i;
  3338. }
  3339. val64 = readq(&vpath->vpmgmt_reg->xgmac_gen_status_vpmgmt_clone);
  3340. if (val64 & VXGE_HW_XGMAC_GEN_STATUS_VPMGMT_CLONE_XMACJ_NTWK_OK)
  3341. VXGE_HW_DEVICE_LINK_STATE_SET(vpath->hldev, VXGE_HW_LINK_UP);
  3342. else
  3343. VXGE_HW_DEVICE_LINK_STATE_SET(vpath->hldev, VXGE_HW_LINK_DOWN);
  3344. return VXGE_HW_OK;
  3345. }
  3346. /*
  3347. * __vxge_hw_vpath_reset_check - Check if resetting the vpath completed
  3348. * This routine checks the vpath_rst_in_prog register to see if
  3349. * adapter completed the reset process for the vpath
  3350. */
  3351. static enum vxge_hw_status
  3352. __vxge_hw_vpath_reset_check(struct __vxge_hw_virtualpath *vpath)
  3353. {
  3354. enum vxge_hw_status status;
  3355. status = __vxge_hw_device_register_poll(
  3356. &vpath->hldev->common_reg->vpath_rst_in_prog,
  3357. VXGE_HW_VPATH_RST_IN_PROG_VPATH_RST_IN_PROG(
  3358. 1 << (16 - vpath->vp_id)),
  3359. vpath->hldev->config.device_poll_millis);
  3360. return status;
  3361. }
  3362. /*
  3363. * __vxge_hw_vpath_reset
  3364. * This routine resets the vpath on the device
  3365. */
  3366. static enum vxge_hw_status
  3367. __vxge_hw_vpath_reset(struct __vxge_hw_device *hldev, u32 vp_id)
  3368. {
  3369. u64 val64;
  3370. val64 = VXGE_HW_CMN_RSTHDLR_CFG0_SW_RESET_VPATH(1 << (16 - vp_id));
  3371. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32),
  3372. &hldev->common_reg->cmn_rsthdlr_cfg0);
  3373. return VXGE_HW_OK;
  3374. }
  3375. /*
  3376. * __vxge_hw_vpath_sw_reset
  3377. * This routine resets the vpath structures
  3378. */
  3379. static enum vxge_hw_status
  3380. __vxge_hw_vpath_sw_reset(struct __vxge_hw_device *hldev, u32 vp_id)
  3381. {
  3382. enum vxge_hw_status status = VXGE_HW_OK;
  3383. struct __vxge_hw_virtualpath *vpath;
  3384. vpath = &hldev->virtual_paths[vp_id];
  3385. if (vpath->ringh) {
  3386. status = __vxge_hw_ring_reset(vpath->ringh);
  3387. if (status != VXGE_HW_OK)
  3388. goto exit;
  3389. }
  3390. if (vpath->fifoh)
  3391. status = __vxge_hw_fifo_reset(vpath->fifoh);
  3392. exit:
  3393. return status;
  3394. }
  3395. /*
  3396. * __vxge_hw_vpath_prc_configure
  3397. * This routine configures the prc registers of virtual path using the config
  3398. * passed
  3399. */
  3400. static void
  3401. __vxge_hw_vpath_prc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3402. {
  3403. u64 val64;
  3404. struct __vxge_hw_virtualpath *vpath;
  3405. struct vxge_hw_vp_config *vp_config;
  3406. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3407. vpath = &hldev->virtual_paths[vp_id];
  3408. vp_reg = vpath->vp_reg;
  3409. vp_config = vpath->vp_config;
  3410. if (vp_config->ring.enable == VXGE_HW_RING_DISABLE)
  3411. return;
  3412. val64 = readq(&vp_reg->prc_cfg1);
  3413. val64 |= VXGE_HW_PRC_CFG1_RTI_TINT_DISABLE;
  3414. writeq(val64, &vp_reg->prc_cfg1);
  3415. val64 = readq(&vpath->vp_reg->prc_cfg6);
  3416. val64 |= VXGE_HW_PRC_CFG6_DOORBELL_MODE_EN;
  3417. writeq(val64, &vpath->vp_reg->prc_cfg6);
  3418. val64 = readq(&vp_reg->prc_cfg7);
  3419. if (vpath->vp_config->ring.scatter_mode !=
  3420. VXGE_HW_RING_SCATTER_MODE_USE_FLASH_DEFAULT) {
  3421. val64 &= ~VXGE_HW_PRC_CFG7_SCATTER_MODE(0x3);
  3422. switch (vpath->vp_config->ring.scatter_mode) {
  3423. case VXGE_HW_RING_SCATTER_MODE_A:
  3424. val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE(
  3425. VXGE_HW_PRC_CFG7_SCATTER_MODE_A);
  3426. break;
  3427. case VXGE_HW_RING_SCATTER_MODE_B:
  3428. val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE(
  3429. VXGE_HW_PRC_CFG7_SCATTER_MODE_B);
  3430. break;
  3431. case VXGE_HW_RING_SCATTER_MODE_C:
  3432. val64 |= VXGE_HW_PRC_CFG7_SCATTER_MODE(
  3433. VXGE_HW_PRC_CFG7_SCATTER_MODE_C);
  3434. break;
  3435. }
  3436. }
  3437. writeq(val64, &vp_reg->prc_cfg7);
  3438. writeq(VXGE_HW_PRC_CFG5_RXD0_ADD(
  3439. __vxge_hw_ring_first_block_address_get(
  3440. vpath->ringh) >> 3), &vp_reg->prc_cfg5);
  3441. val64 = readq(&vp_reg->prc_cfg4);
  3442. val64 |= VXGE_HW_PRC_CFG4_IN_SVC;
  3443. val64 &= ~VXGE_HW_PRC_CFG4_RING_MODE(0x3);
  3444. val64 |= VXGE_HW_PRC_CFG4_RING_MODE(
  3445. VXGE_HW_PRC_CFG4_RING_MODE_ONE_BUFFER);
  3446. if (hldev->config.rth_en == VXGE_HW_RTH_DISABLE)
  3447. val64 |= VXGE_HW_PRC_CFG4_RTH_DISABLE;
  3448. else
  3449. val64 &= ~VXGE_HW_PRC_CFG4_RTH_DISABLE;
  3450. writeq(val64, &vp_reg->prc_cfg4);
  3451. }
  3452. /*
  3453. * __vxge_hw_vpath_kdfc_configure
  3454. * This routine configures the kdfc registers of virtual path using the
  3455. * config passed
  3456. */
  3457. static enum vxge_hw_status
  3458. __vxge_hw_vpath_kdfc_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3459. {
  3460. u64 val64;
  3461. u64 vpath_stride;
  3462. enum vxge_hw_status status = VXGE_HW_OK;
  3463. struct __vxge_hw_virtualpath *vpath;
  3464. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3465. vpath = &hldev->virtual_paths[vp_id];
  3466. vp_reg = vpath->vp_reg;
  3467. status = __vxge_hw_kdfc_swapper_set(hldev->legacy_reg, vp_reg);
  3468. if (status != VXGE_HW_OK)
  3469. goto exit;
  3470. val64 = readq(&vp_reg->kdfc_drbl_triplet_total);
  3471. vpath->max_kdfc_db =
  3472. (u32)VXGE_HW_KDFC_DRBL_TRIPLET_TOTAL_GET_KDFC_MAX_SIZE(
  3473. val64+1)/2;
  3474. if (vpath->vp_config->fifo.enable == VXGE_HW_FIFO_ENABLE) {
  3475. vpath->max_nofl_db = vpath->max_kdfc_db;
  3476. if (vpath->max_nofl_db <
  3477. ((vpath->vp_config->fifo.memblock_size /
  3478. (vpath->vp_config->fifo.max_frags *
  3479. sizeof(struct vxge_hw_fifo_txd))) *
  3480. vpath->vp_config->fifo.fifo_blocks)) {
  3481. return VXGE_HW_BADCFG_FIFO_BLOCKS;
  3482. }
  3483. val64 = VXGE_HW_KDFC_FIFO_TRPL_PARTITION_LENGTH_0(
  3484. (vpath->max_nofl_db*2)-1);
  3485. }
  3486. writeq(val64, &vp_reg->kdfc_fifo_trpl_partition);
  3487. writeq(VXGE_HW_KDFC_FIFO_TRPL_CTRL_TRIPLET_ENABLE,
  3488. &vp_reg->kdfc_fifo_trpl_ctrl);
  3489. val64 = readq(&vp_reg->kdfc_trpl_fifo_0_ctrl);
  3490. val64 &= ~(VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(0x3) |
  3491. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0xFF));
  3492. val64 |= VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE(
  3493. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_MODE_NON_OFFLOAD_ONLY) |
  3494. #ifndef __BIG_ENDIAN
  3495. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SWAP_EN |
  3496. #endif
  3497. VXGE_HW_KDFC_TRPL_FIFO_0_CTRL_SELECT(0);
  3498. writeq(val64, &vp_reg->kdfc_trpl_fifo_0_ctrl);
  3499. writeq((u64)0, &vp_reg->kdfc_trpl_fifo_0_wb_address);
  3500. wmb();
  3501. vpath_stride = readq(&hldev->toc_reg->toc_kdfc_vpath_stride);
  3502. vpath->nofl_db =
  3503. (struct __vxge_hw_non_offload_db_wrapper __iomem *)
  3504. (hldev->kdfc + (vp_id *
  3505. VXGE_HW_TOC_KDFC_VPATH_STRIDE_GET_TOC_KDFC_VPATH_STRIDE(
  3506. vpath_stride)));
  3507. exit:
  3508. return status;
  3509. }
  3510. /*
  3511. * __vxge_hw_vpath_mac_configure
  3512. * This routine configures the mac of virtual path using the config passed
  3513. */
  3514. static enum vxge_hw_status
  3515. __vxge_hw_vpath_mac_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3516. {
  3517. u64 val64;
  3518. struct __vxge_hw_virtualpath *vpath;
  3519. struct vxge_hw_vp_config *vp_config;
  3520. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3521. vpath = &hldev->virtual_paths[vp_id];
  3522. vp_reg = vpath->vp_reg;
  3523. vp_config = vpath->vp_config;
  3524. writeq(VXGE_HW_XMAC_VSPORT_CHOICE_VSPORT_NUMBER(
  3525. vpath->vsport_number), &vp_reg->xmac_vsport_choice);
  3526. if (vp_config->ring.enable == VXGE_HW_RING_ENABLE) {
  3527. val64 = readq(&vp_reg->xmac_rpa_vcfg);
  3528. if (vp_config->rpa_strip_vlan_tag !=
  3529. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_USE_FLASH_DEFAULT) {
  3530. if (vp_config->rpa_strip_vlan_tag)
  3531. val64 |= VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG;
  3532. else
  3533. val64 &= ~VXGE_HW_XMAC_RPA_VCFG_STRIP_VLAN_TAG;
  3534. }
  3535. writeq(val64, &vp_reg->xmac_rpa_vcfg);
  3536. val64 = readq(&vp_reg->rxmac_vcfg0);
  3537. if (vp_config->mtu !=
  3538. VXGE_HW_VPATH_USE_FLASH_DEFAULT_INITIAL_MTU) {
  3539. val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
  3540. if ((vp_config->mtu +
  3541. VXGE_HW_MAC_HEADER_MAX_SIZE) < vpath->max_mtu)
  3542. val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(
  3543. vp_config->mtu +
  3544. VXGE_HW_MAC_HEADER_MAX_SIZE);
  3545. else
  3546. val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(
  3547. vpath->max_mtu);
  3548. }
  3549. writeq(val64, &vp_reg->rxmac_vcfg0);
  3550. val64 = readq(&vp_reg->rxmac_vcfg1);
  3551. val64 &= ~(VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(0x3) |
  3552. VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE);
  3553. if (hldev->config.rth_it_type ==
  3554. VXGE_HW_RTH_IT_TYPE_MULTI_IT) {
  3555. val64 |= VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_BD_MODE(
  3556. 0x2) |
  3557. VXGE_HW_RXMAC_VCFG1_RTS_RTH_MULTI_IT_EN_MODE;
  3558. }
  3559. writeq(val64, &vp_reg->rxmac_vcfg1);
  3560. }
  3561. return VXGE_HW_OK;
  3562. }
  3563. /*
  3564. * __vxge_hw_vpath_tim_configure
  3565. * This routine configures the tim registers of virtual path using the config
  3566. * passed
  3567. */
  3568. static enum vxge_hw_status
  3569. __vxge_hw_vpath_tim_configure(struct __vxge_hw_device *hldev, u32 vp_id)
  3570. {
  3571. u64 val64;
  3572. struct __vxge_hw_virtualpath *vpath;
  3573. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3574. struct vxge_hw_vp_config *config;
  3575. vpath = &hldev->virtual_paths[vp_id];
  3576. vp_reg = vpath->vp_reg;
  3577. config = vpath->vp_config;
  3578. writeq(0, &vp_reg->tim_dest_addr);
  3579. writeq(0, &vp_reg->tim_vpath_map);
  3580. writeq(0, &vp_reg->tim_bitmap);
  3581. writeq(0, &vp_reg->tim_remap);
  3582. if (config->ring.enable == VXGE_HW_RING_ENABLE)
  3583. writeq(VXGE_HW_TIM_RING_ASSN_INT_NUM(
  3584. (vp_id * VXGE_HW_MAX_INTR_PER_VP) +
  3585. VXGE_HW_VPATH_INTR_RX), &vp_reg->tim_ring_assn);
  3586. val64 = readq(&vp_reg->tim_pci_cfg);
  3587. val64 |= VXGE_HW_TIM_PCI_CFG_ADD_PAD;
  3588. writeq(val64, &vp_reg->tim_pci_cfg);
  3589. if (config->fifo.enable == VXGE_HW_FIFO_ENABLE) {
  3590. val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]);
  3591. if (config->tti.btimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3592. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3593. 0x3ffffff);
  3594. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3595. config->tti.btimer_val);
  3596. }
  3597. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN;
  3598. if (config->tti.timer_ac_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3599. if (config->tti.timer_ac_en)
  3600. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3601. else
  3602. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3603. }
  3604. if (config->tti.timer_ci_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3605. if (config->tti.timer_ci_en)
  3606. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3607. else
  3608. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3609. }
  3610. if (config->tti.urange_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3611. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f);
  3612. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(
  3613. config->tti.urange_a);
  3614. }
  3615. if (config->tti.urange_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3616. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f);
  3617. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(
  3618. config->tti.urange_b);
  3619. }
  3620. if (config->tti.urange_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3621. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f);
  3622. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(
  3623. config->tti.urange_c);
  3624. }
  3625. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_TX]);
  3626. vpath->tim_tti_cfg1_saved = val64;
  3627. val64 = readq(&vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_TX]);
  3628. if (config->tti.uec_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3629. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff);
  3630. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(
  3631. config->tti.uec_a);
  3632. }
  3633. if (config->tti.uec_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3634. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff);
  3635. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(
  3636. config->tti.uec_b);
  3637. }
  3638. if (config->tti.uec_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3639. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff);
  3640. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(
  3641. config->tti.uec_c);
  3642. }
  3643. if (config->tti.uec_d != VXGE_HW_USE_FLASH_DEFAULT) {
  3644. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff);
  3645. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(
  3646. config->tti.uec_d);
  3647. }
  3648. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_TX]);
  3649. val64 = readq(&vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]);
  3650. if (config->tti.timer_ri_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3651. if (config->tti.timer_ri_en)
  3652. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3653. else
  3654. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3655. }
  3656. if (config->tti.rtimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3657. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3658. 0x3ffffff);
  3659. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3660. config->tti.rtimer_val);
  3661. }
  3662. if (config->tti.util_sel != VXGE_HW_USE_FLASH_DEFAULT) {
  3663. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f);
  3664. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(vp_id);
  3665. }
  3666. if (config->tti.ltimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3667. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3668. 0x3ffffff);
  3669. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3670. config->tti.ltimer_val);
  3671. }
  3672. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_TX]);
  3673. vpath->tim_tti_cfg3_saved = val64;
  3674. }
  3675. if (config->ring.enable == VXGE_HW_RING_ENABLE) {
  3676. val64 = readq(&vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]);
  3677. if (config->rti.btimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3678. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3679. 0x3ffffff);
  3680. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_BTIMER_VAL(
  3681. config->rti.btimer_val);
  3682. }
  3683. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_BITMP_EN;
  3684. if (config->rti.timer_ac_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3685. if (config->rti.timer_ac_en)
  3686. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3687. else
  3688. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_AC;
  3689. }
  3690. if (config->rti.timer_ci_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3691. if (config->rti.timer_ci_en)
  3692. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3693. else
  3694. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_TIMER_CI;
  3695. }
  3696. if (config->rti.urange_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3697. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(0x3f);
  3698. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_A(
  3699. config->rti.urange_a);
  3700. }
  3701. if (config->rti.urange_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3702. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(0x3f);
  3703. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_B(
  3704. config->rti.urange_b);
  3705. }
  3706. if (config->rti.urange_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3707. val64 &= ~VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(0x3f);
  3708. val64 |= VXGE_HW_TIM_CFG1_INT_NUM_URNG_C(
  3709. config->rti.urange_c);
  3710. }
  3711. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_RX]);
  3712. vpath->tim_rti_cfg1_saved = val64;
  3713. val64 = readq(&vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_RX]);
  3714. if (config->rti.uec_a != VXGE_HW_USE_FLASH_DEFAULT) {
  3715. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(0xffff);
  3716. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_A(
  3717. config->rti.uec_a);
  3718. }
  3719. if (config->rti.uec_b != VXGE_HW_USE_FLASH_DEFAULT) {
  3720. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(0xffff);
  3721. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_B(
  3722. config->rti.uec_b);
  3723. }
  3724. if (config->rti.uec_c != VXGE_HW_USE_FLASH_DEFAULT) {
  3725. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(0xffff);
  3726. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_C(
  3727. config->rti.uec_c);
  3728. }
  3729. if (config->rti.uec_d != VXGE_HW_USE_FLASH_DEFAULT) {
  3730. val64 &= ~VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(0xffff);
  3731. val64 |= VXGE_HW_TIM_CFG2_INT_NUM_UEC_D(
  3732. config->rti.uec_d);
  3733. }
  3734. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_RX]);
  3735. val64 = readq(&vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]);
  3736. if (config->rti.timer_ri_en != VXGE_HW_USE_FLASH_DEFAULT) {
  3737. if (config->rti.timer_ri_en)
  3738. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3739. else
  3740. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_TIMER_RI;
  3741. }
  3742. if (config->rti.rtimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3743. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3744. 0x3ffffff);
  3745. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_RTIMER_VAL(
  3746. config->rti.rtimer_val);
  3747. }
  3748. if (config->rti.util_sel != VXGE_HW_USE_FLASH_DEFAULT) {
  3749. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(0x3f);
  3750. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_UTIL_SEL(vp_id);
  3751. }
  3752. if (config->rti.ltimer_val != VXGE_HW_USE_FLASH_DEFAULT) {
  3753. val64 &= ~VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3754. 0x3ffffff);
  3755. val64 |= VXGE_HW_TIM_CFG3_INT_NUM_LTIMER_VAL(
  3756. config->rti.ltimer_val);
  3757. }
  3758. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_RX]);
  3759. vpath->tim_rti_cfg3_saved = val64;
  3760. }
  3761. val64 = 0;
  3762. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_EINTA]);
  3763. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_EINTA]);
  3764. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_EINTA]);
  3765. writeq(val64, &vp_reg->tim_cfg1_int_num[VXGE_HW_VPATH_INTR_BMAP]);
  3766. writeq(val64, &vp_reg->tim_cfg2_int_num[VXGE_HW_VPATH_INTR_BMAP]);
  3767. writeq(val64, &vp_reg->tim_cfg3_int_num[VXGE_HW_VPATH_INTR_BMAP]);
  3768. val64 = VXGE_HW_TIM_WRKLD_CLC_WRKLD_EVAL_PRD(150);
  3769. val64 |= VXGE_HW_TIM_WRKLD_CLC_WRKLD_EVAL_DIV(0);
  3770. val64 |= VXGE_HW_TIM_WRKLD_CLC_CNT_RX_TX(3);
  3771. writeq(val64, &vp_reg->tim_wrkld_clc);
  3772. return VXGE_HW_OK;
  3773. }
  3774. /*
  3775. * __vxge_hw_vpath_initialize
  3776. * This routine is the final phase of init which initializes the
  3777. * registers of the vpath using the configuration passed.
  3778. */
  3779. static enum vxge_hw_status
  3780. __vxge_hw_vpath_initialize(struct __vxge_hw_device *hldev, u32 vp_id)
  3781. {
  3782. u64 val64;
  3783. u32 val32;
  3784. enum vxge_hw_status status = VXGE_HW_OK;
  3785. struct __vxge_hw_virtualpath *vpath;
  3786. struct vxge_hw_vpath_reg __iomem *vp_reg;
  3787. vpath = &hldev->virtual_paths[vp_id];
  3788. if (!(hldev->vpath_assignments & vxge_mBIT(vp_id))) {
  3789. status = VXGE_HW_ERR_VPATH_NOT_AVAILABLE;
  3790. goto exit;
  3791. }
  3792. vp_reg = vpath->vp_reg;
  3793. status = __vxge_hw_vpath_swapper_set(vpath->vp_reg);
  3794. if (status != VXGE_HW_OK)
  3795. goto exit;
  3796. status = __vxge_hw_vpath_mac_configure(hldev, vp_id);
  3797. if (status != VXGE_HW_OK)
  3798. goto exit;
  3799. status = __vxge_hw_vpath_kdfc_configure(hldev, vp_id);
  3800. if (status != VXGE_HW_OK)
  3801. goto exit;
  3802. status = __vxge_hw_vpath_tim_configure(hldev, vp_id);
  3803. if (status != VXGE_HW_OK)
  3804. goto exit;
  3805. val64 = readq(&vp_reg->rtdma_rd_optimization_ctrl);
  3806. /* Get MRRS value from device control */
  3807. status = __vxge_hw_vpath_pci_read(vpath, 1, 0x78, &val32);
  3808. if (status == VXGE_HW_OK) {
  3809. val32 = (val32 & VXGE_HW_PCI_EXP_DEVCTL_READRQ) >> 12;
  3810. val64 &=
  3811. ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(7));
  3812. val64 |=
  3813. VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_FILL_THRESH(val32);
  3814. val64 |= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_WAIT_FOR_SPACE;
  3815. }
  3816. val64 &= ~(VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(7));
  3817. val64 |=
  3818. VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY(
  3819. VXGE_HW_MAX_PAYLOAD_SIZE_512);
  3820. val64 |= VXGE_HW_RTDMA_RD_OPTIMIZATION_CTRL_FB_ADDR_BDRY_EN;
  3821. writeq(val64, &vp_reg->rtdma_rd_optimization_ctrl);
  3822. exit:
  3823. return status;
  3824. }
  3825. /*
  3826. * __vxge_hw_vp_terminate - Terminate Virtual Path structure
  3827. * This routine closes all channels it opened and freeup memory
  3828. */
  3829. static void __vxge_hw_vp_terminate(struct __vxge_hw_device *hldev, u32 vp_id)
  3830. {
  3831. struct __vxge_hw_virtualpath *vpath;
  3832. vpath = &hldev->virtual_paths[vp_id];
  3833. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN)
  3834. goto exit;
  3835. VXGE_HW_DEVICE_TIM_INT_MASK_RESET(vpath->hldev->tim_int_mask0,
  3836. vpath->hldev->tim_int_mask1, vpath->vp_id);
  3837. hldev->stats.hw_dev_info_stats.vpath_info[vpath->vp_id] = NULL;
  3838. /* If the whole struct __vxge_hw_virtualpath is zeroed, nothing will
  3839. * work after the interface is brought down.
  3840. */
  3841. spin_lock(&vpath->lock);
  3842. vpath->vp_open = VXGE_HW_VP_NOT_OPEN;
  3843. spin_unlock(&vpath->lock);
  3844. vpath->vpmgmt_reg = NULL;
  3845. vpath->nofl_db = NULL;
  3846. vpath->max_mtu = 0;
  3847. vpath->vsport_number = 0;
  3848. vpath->max_kdfc_db = 0;
  3849. vpath->max_nofl_db = 0;
  3850. vpath->ringh = NULL;
  3851. vpath->fifoh = NULL;
  3852. memset(&vpath->vpath_handles, 0, sizeof(struct list_head));
  3853. vpath->stats_block = NULL;
  3854. vpath->hw_stats = NULL;
  3855. vpath->hw_stats_sav = NULL;
  3856. vpath->sw_stats = NULL;
  3857. exit:
  3858. return;
  3859. }
  3860. /*
  3861. * __vxge_hw_vp_initialize - Initialize Virtual Path structure
  3862. * This routine is the initial phase of init which resets the vpath and
  3863. * initializes the software support structures.
  3864. */
  3865. static enum vxge_hw_status
  3866. __vxge_hw_vp_initialize(struct __vxge_hw_device *hldev, u32 vp_id,
  3867. struct vxge_hw_vp_config *config)
  3868. {
  3869. struct __vxge_hw_virtualpath *vpath;
  3870. enum vxge_hw_status status = VXGE_HW_OK;
  3871. if (!(hldev->vpath_assignments & vxge_mBIT(vp_id))) {
  3872. status = VXGE_HW_ERR_VPATH_NOT_AVAILABLE;
  3873. goto exit;
  3874. }
  3875. vpath = &hldev->virtual_paths[vp_id];
  3876. spin_lock_init(&vpath->lock);
  3877. vpath->vp_id = vp_id;
  3878. vpath->vp_open = VXGE_HW_VP_OPEN;
  3879. vpath->hldev = hldev;
  3880. vpath->vp_config = config;
  3881. vpath->vp_reg = hldev->vpath_reg[vp_id];
  3882. vpath->vpmgmt_reg = hldev->vpmgmt_reg[vp_id];
  3883. __vxge_hw_vpath_reset(hldev, vp_id);
  3884. status = __vxge_hw_vpath_reset_check(vpath);
  3885. if (status != VXGE_HW_OK) {
  3886. memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath));
  3887. goto exit;
  3888. }
  3889. status = __vxge_hw_vpath_mgmt_read(hldev, vpath);
  3890. if (status != VXGE_HW_OK) {
  3891. memset(vpath, 0, sizeof(struct __vxge_hw_virtualpath));
  3892. goto exit;
  3893. }
  3894. INIT_LIST_HEAD(&vpath->vpath_handles);
  3895. vpath->sw_stats = &hldev->stats.sw_dev_info_stats.vpath_info[vp_id];
  3896. VXGE_HW_DEVICE_TIM_INT_MASK_SET(hldev->tim_int_mask0,
  3897. hldev->tim_int_mask1, vp_id);
  3898. status = __vxge_hw_vpath_initialize(hldev, vp_id);
  3899. if (status != VXGE_HW_OK)
  3900. __vxge_hw_vp_terminate(hldev, vp_id);
  3901. exit:
  3902. return status;
  3903. }
  3904. /*
  3905. * vxge_hw_vpath_mtu_set - Set MTU.
  3906. * Set new MTU value. Example, to use jumbo frames:
  3907. * vxge_hw_vpath_mtu_set(my_device, 9600);
  3908. */
  3909. enum vxge_hw_status
  3910. vxge_hw_vpath_mtu_set(struct __vxge_hw_vpath_handle *vp, u32 new_mtu)
  3911. {
  3912. u64 val64;
  3913. enum vxge_hw_status status = VXGE_HW_OK;
  3914. struct __vxge_hw_virtualpath *vpath;
  3915. if (vp == NULL) {
  3916. status = VXGE_HW_ERR_INVALID_HANDLE;
  3917. goto exit;
  3918. }
  3919. vpath = vp->vpath;
  3920. new_mtu += VXGE_HW_MAC_HEADER_MAX_SIZE;
  3921. if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > vpath->max_mtu))
  3922. status = VXGE_HW_ERR_INVALID_MTU_SIZE;
  3923. val64 = readq(&vpath->vp_reg->rxmac_vcfg0);
  3924. val64 &= ~VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(0x3fff);
  3925. val64 |= VXGE_HW_RXMAC_VCFG0_RTS_MAX_FRM_LEN(new_mtu);
  3926. writeq(val64, &vpath->vp_reg->rxmac_vcfg0);
  3927. vpath->vp_config->mtu = new_mtu - VXGE_HW_MAC_HEADER_MAX_SIZE;
  3928. exit:
  3929. return status;
  3930. }
  3931. /*
  3932. * vxge_hw_vpath_stats_enable - Enable vpath h/wstatistics.
  3933. * Enable the DMA vpath statistics. The function is to be called to re-enable
  3934. * the adapter to update stats into the host memory
  3935. */
  3936. static enum vxge_hw_status
  3937. vxge_hw_vpath_stats_enable(struct __vxge_hw_vpath_handle *vp)
  3938. {
  3939. enum vxge_hw_status status = VXGE_HW_OK;
  3940. struct __vxge_hw_virtualpath *vpath;
  3941. vpath = vp->vpath;
  3942. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  3943. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  3944. goto exit;
  3945. }
  3946. memcpy(vpath->hw_stats_sav, vpath->hw_stats,
  3947. sizeof(struct vxge_hw_vpath_stats_hw_info));
  3948. status = __vxge_hw_vpath_stats_get(vpath, vpath->hw_stats);
  3949. exit:
  3950. return status;
  3951. }
  3952. /*
  3953. * __vxge_hw_blockpool_block_allocate - Allocates a block from block pool
  3954. * This function allocates a block from block pool or from the system
  3955. */
  3956. static struct __vxge_hw_blockpool_entry *
  3957. __vxge_hw_blockpool_block_allocate(struct __vxge_hw_device *devh, u32 size)
  3958. {
  3959. struct __vxge_hw_blockpool_entry *entry = NULL;
  3960. struct __vxge_hw_blockpool *blockpool;
  3961. blockpool = &devh->block_pool;
  3962. if (size == blockpool->block_size) {
  3963. if (!list_empty(&blockpool->free_block_list))
  3964. entry = (struct __vxge_hw_blockpool_entry *)
  3965. list_first_entry(&blockpool->free_block_list,
  3966. struct __vxge_hw_blockpool_entry,
  3967. item);
  3968. if (entry != NULL) {
  3969. list_del(&entry->item);
  3970. blockpool->pool_size--;
  3971. }
  3972. }
  3973. if (entry != NULL)
  3974. __vxge_hw_blockpool_blocks_add(blockpool);
  3975. return entry;
  3976. }
  3977. /*
  3978. * vxge_hw_vpath_open - Open a virtual path on a given adapter
  3979. * This function is used to open access to virtual path of an
  3980. * adapter for offload, GRO operations. This function returns
  3981. * synchronously.
  3982. */
  3983. enum vxge_hw_status
  3984. vxge_hw_vpath_open(struct __vxge_hw_device *hldev,
  3985. struct vxge_hw_vpath_attr *attr,
  3986. struct __vxge_hw_vpath_handle **vpath_handle)
  3987. {
  3988. struct __vxge_hw_virtualpath *vpath;
  3989. struct __vxge_hw_vpath_handle *vp;
  3990. enum vxge_hw_status status;
  3991. vpath = &hldev->virtual_paths[attr->vp_id];
  3992. if (vpath->vp_open == VXGE_HW_VP_OPEN) {
  3993. status = VXGE_HW_ERR_INVALID_STATE;
  3994. goto vpath_open_exit1;
  3995. }
  3996. status = __vxge_hw_vp_initialize(hldev, attr->vp_id,
  3997. &hldev->config.vp_config[attr->vp_id]);
  3998. if (status != VXGE_HW_OK)
  3999. goto vpath_open_exit1;
  4000. vp = vzalloc(sizeof(struct __vxge_hw_vpath_handle));
  4001. if (vp == NULL) {
  4002. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  4003. goto vpath_open_exit2;
  4004. }
  4005. vp->vpath = vpath;
  4006. if (vpath->vp_config->fifo.enable == VXGE_HW_FIFO_ENABLE) {
  4007. status = __vxge_hw_fifo_create(vp, &attr->fifo_attr);
  4008. if (status != VXGE_HW_OK)
  4009. goto vpath_open_exit6;
  4010. }
  4011. if (vpath->vp_config->ring.enable == VXGE_HW_RING_ENABLE) {
  4012. status = __vxge_hw_ring_create(vp, &attr->ring_attr);
  4013. if (status != VXGE_HW_OK)
  4014. goto vpath_open_exit7;
  4015. __vxge_hw_vpath_prc_configure(hldev, attr->vp_id);
  4016. }
  4017. vpath->fifoh->tx_intr_num =
  4018. (attr->vp_id * VXGE_HW_MAX_INTR_PER_VP) +
  4019. VXGE_HW_VPATH_INTR_TX;
  4020. vpath->stats_block = __vxge_hw_blockpool_block_allocate(hldev,
  4021. VXGE_HW_BLOCK_SIZE);
  4022. if (vpath->stats_block == NULL) {
  4023. status = VXGE_HW_ERR_OUT_OF_MEMORY;
  4024. goto vpath_open_exit8;
  4025. }
  4026. vpath->hw_stats = vpath->stats_block->memblock;
  4027. memset(vpath->hw_stats, 0,
  4028. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4029. hldev->stats.hw_dev_info_stats.vpath_info[attr->vp_id] =
  4030. vpath->hw_stats;
  4031. vpath->hw_stats_sav =
  4032. &hldev->stats.hw_dev_info_stats.vpath_info_sav[attr->vp_id];
  4033. memset(vpath->hw_stats_sav, 0,
  4034. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4035. writeq(vpath->stats_block->dma_addr, &vpath->vp_reg->stats_cfg);
  4036. status = vxge_hw_vpath_stats_enable(vp);
  4037. if (status != VXGE_HW_OK)
  4038. goto vpath_open_exit8;
  4039. list_add(&vp->item, &vpath->vpath_handles);
  4040. hldev->vpaths_deployed |= vxge_mBIT(vpath->vp_id);
  4041. *vpath_handle = vp;
  4042. attr->fifo_attr.userdata = vpath->fifoh;
  4043. attr->ring_attr.userdata = vpath->ringh;
  4044. return VXGE_HW_OK;
  4045. vpath_open_exit8:
  4046. if (vpath->ringh != NULL)
  4047. __vxge_hw_ring_delete(vp);
  4048. vpath_open_exit7:
  4049. if (vpath->fifoh != NULL)
  4050. __vxge_hw_fifo_delete(vp);
  4051. vpath_open_exit6:
  4052. vfree(vp);
  4053. vpath_open_exit2:
  4054. __vxge_hw_vp_terminate(hldev, attr->vp_id);
  4055. vpath_open_exit1:
  4056. return status;
  4057. }
  4058. /**
  4059. * vxge_hw_vpath_rx_doorbell_post - Close the handle got from previous vpath
  4060. * (vpath) open
  4061. * @vp: Handle got from previous vpath open
  4062. *
  4063. * This function is used to close access to virtual path opened
  4064. * earlier.
  4065. */
  4066. void vxge_hw_vpath_rx_doorbell_init(struct __vxge_hw_vpath_handle *vp)
  4067. {
  4068. struct __vxge_hw_virtualpath *vpath = vp->vpath;
  4069. struct __vxge_hw_ring *ring = vpath->ringh;
  4070. struct vxgedev *vdev = netdev_priv(vpath->hldev->ndev);
  4071. u64 new_count, val64, val164;
  4072. if (vdev->titan1) {
  4073. new_count = readq(&vpath->vp_reg->rxdmem_size);
  4074. new_count &= 0x1fff;
  4075. } else
  4076. new_count = ring->config->ring_blocks * VXGE_HW_BLOCK_SIZE / 8;
  4077. val164 = VXGE_HW_RXDMEM_SIZE_PRC_RXDMEM_SIZE(new_count);
  4078. writeq(VXGE_HW_PRC_RXD_DOORBELL_NEW_QW_CNT(val164),
  4079. &vpath->vp_reg->prc_rxd_doorbell);
  4080. readl(&vpath->vp_reg->prc_rxd_doorbell);
  4081. val164 /= 2;
  4082. val64 = readq(&vpath->vp_reg->prc_cfg6);
  4083. val64 = VXGE_HW_PRC_CFG6_RXD_SPAT(val64);
  4084. val64 &= 0x1ff;
  4085. /*
  4086. * Each RxD is of 4 qwords
  4087. */
  4088. new_count -= (val64 + 1);
  4089. val64 = min(val164, new_count) / 4;
  4090. ring->rxds_limit = min(ring->rxds_limit, val64);
  4091. if (ring->rxds_limit < 4)
  4092. ring->rxds_limit = 4;
  4093. }
  4094. /*
  4095. * __vxge_hw_blockpool_block_free - Frees a block from block pool
  4096. * @devh: Hal device
  4097. * @entry: Entry of block to be freed
  4098. *
  4099. * This function frees a block from block pool
  4100. */
  4101. static void
  4102. __vxge_hw_blockpool_block_free(struct __vxge_hw_device *devh,
  4103. struct __vxge_hw_blockpool_entry *entry)
  4104. {
  4105. struct __vxge_hw_blockpool *blockpool;
  4106. blockpool = &devh->block_pool;
  4107. if (entry->length == blockpool->block_size) {
  4108. list_add(&entry->item, &blockpool->free_block_list);
  4109. blockpool->pool_size++;
  4110. }
  4111. __vxge_hw_blockpool_blocks_remove(blockpool);
  4112. }
  4113. /*
  4114. * vxge_hw_vpath_close - Close the handle got from previous vpath (vpath) open
  4115. * This function is used to close access to virtual path opened
  4116. * earlier.
  4117. */
  4118. enum vxge_hw_status vxge_hw_vpath_close(struct __vxge_hw_vpath_handle *vp)
  4119. {
  4120. struct __vxge_hw_virtualpath *vpath = NULL;
  4121. struct __vxge_hw_device *devh = NULL;
  4122. u32 vp_id = vp->vpath->vp_id;
  4123. u32 is_empty = TRUE;
  4124. enum vxge_hw_status status = VXGE_HW_OK;
  4125. vpath = vp->vpath;
  4126. devh = vpath->hldev;
  4127. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  4128. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  4129. goto vpath_close_exit;
  4130. }
  4131. list_del(&vp->item);
  4132. if (!list_empty(&vpath->vpath_handles)) {
  4133. list_add(&vp->item, &vpath->vpath_handles);
  4134. is_empty = FALSE;
  4135. }
  4136. if (!is_empty) {
  4137. status = VXGE_HW_FAIL;
  4138. goto vpath_close_exit;
  4139. }
  4140. devh->vpaths_deployed &= ~vxge_mBIT(vp_id);
  4141. if (vpath->ringh != NULL)
  4142. __vxge_hw_ring_delete(vp);
  4143. if (vpath->fifoh != NULL)
  4144. __vxge_hw_fifo_delete(vp);
  4145. if (vpath->stats_block != NULL)
  4146. __vxge_hw_blockpool_block_free(devh, vpath->stats_block);
  4147. vfree(vp);
  4148. __vxge_hw_vp_terminate(devh, vp_id);
  4149. vpath_close_exit:
  4150. return status;
  4151. }
  4152. /*
  4153. * vxge_hw_vpath_reset - Resets vpath
  4154. * This function is used to request a reset of vpath
  4155. */
  4156. enum vxge_hw_status vxge_hw_vpath_reset(struct __vxge_hw_vpath_handle *vp)
  4157. {
  4158. enum vxge_hw_status status;
  4159. u32 vp_id;
  4160. struct __vxge_hw_virtualpath *vpath = vp->vpath;
  4161. vp_id = vpath->vp_id;
  4162. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  4163. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  4164. goto exit;
  4165. }
  4166. status = __vxge_hw_vpath_reset(vpath->hldev, vp_id);
  4167. if (status == VXGE_HW_OK)
  4168. vpath->sw_stats->soft_reset_cnt++;
  4169. exit:
  4170. return status;
  4171. }
  4172. /*
  4173. * vxge_hw_vpath_recover_from_reset - Poll for reset complete and re-initialize.
  4174. * This function poll's for the vpath reset completion and re initializes
  4175. * the vpath.
  4176. */
  4177. enum vxge_hw_status
  4178. vxge_hw_vpath_recover_from_reset(struct __vxge_hw_vpath_handle *vp)
  4179. {
  4180. struct __vxge_hw_virtualpath *vpath = NULL;
  4181. enum vxge_hw_status status;
  4182. struct __vxge_hw_device *hldev;
  4183. u32 vp_id;
  4184. vp_id = vp->vpath->vp_id;
  4185. vpath = vp->vpath;
  4186. hldev = vpath->hldev;
  4187. if (vpath->vp_open == VXGE_HW_VP_NOT_OPEN) {
  4188. status = VXGE_HW_ERR_VPATH_NOT_OPEN;
  4189. goto exit;
  4190. }
  4191. status = __vxge_hw_vpath_reset_check(vpath);
  4192. if (status != VXGE_HW_OK)
  4193. goto exit;
  4194. status = __vxge_hw_vpath_sw_reset(hldev, vp_id);
  4195. if (status != VXGE_HW_OK)
  4196. goto exit;
  4197. status = __vxge_hw_vpath_initialize(hldev, vp_id);
  4198. if (status != VXGE_HW_OK)
  4199. goto exit;
  4200. if (vpath->ringh != NULL)
  4201. __vxge_hw_vpath_prc_configure(hldev, vp_id);
  4202. memset(vpath->hw_stats, 0,
  4203. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4204. memset(vpath->hw_stats_sav, 0,
  4205. sizeof(struct vxge_hw_vpath_stats_hw_info));
  4206. writeq(vpath->stats_block->dma_addr,
  4207. &vpath->vp_reg->stats_cfg);
  4208. status = vxge_hw_vpath_stats_enable(vp);
  4209. exit:
  4210. return status;
  4211. }
  4212. /*
  4213. * vxge_hw_vpath_enable - Enable vpath.
  4214. * This routine clears the vpath reset thereby enabling a vpath
  4215. * to start forwarding frames and generating interrupts.
  4216. */
  4217. void
  4218. vxge_hw_vpath_enable(struct __vxge_hw_vpath_handle *vp)
  4219. {
  4220. struct __vxge_hw_device *hldev;
  4221. u64 val64;
  4222. hldev = vp->vpath->hldev;
  4223. val64 = VXGE_HW_CMN_RSTHDLR_CFG1_CLR_VPATH_RESET(
  4224. 1 << (16 - vp->vpath->vp_id));
  4225. __vxge_hw_pio_mem_write32_upper((u32)vxge_bVALn(val64, 0, 32),
  4226. &hldev->common_reg->cmn_rsthdlr_cfg1);
  4227. }