vxge-config.c 134 KB

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