i40iw_ctrl.c 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenFabrics.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. *
  33. *******************************************************************************/
  34. #include "i40iw_osdep.h"
  35. #include "i40iw_register.h"
  36. #include "i40iw_status.h"
  37. #include "i40iw_hmc.h"
  38. #include "i40iw_d.h"
  39. #include "i40iw_type.h"
  40. #include "i40iw_p.h"
  41. #include "i40iw_vf.h"
  42. #include "i40iw_virtchnl.h"
  43. /**
  44. * i40iw_insert_wqe_hdr - write wqe header
  45. * @wqe: cqp wqe for header
  46. * @header: header for the cqp wqe
  47. */
  48. static inline void i40iw_insert_wqe_hdr(u64 *wqe, u64 header)
  49. {
  50. wmb(); /* make sure WQE is populated before polarity is set */
  51. set_64bit_val(wqe, 24, header);
  52. }
  53. /**
  54. * i40iw_get_cqp_reg_info - get head and tail for cqp using registers
  55. * @cqp: struct for cqp hw
  56. * @val: cqp tail register value
  57. * @tail:wqtail register value
  58. * @error: cqp processing err
  59. */
  60. static inline void i40iw_get_cqp_reg_info(struct i40iw_sc_cqp *cqp,
  61. u32 *val,
  62. u32 *tail,
  63. u32 *error)
  64. {
  65. if (cqp->dev->is_pf) {
  66. *val = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPTAIL);
  67. *tail = RS_32(*val, I40E_PFPE_CQPTAIL_WQTAIL);
  68. *error = RS_32(*val, I40E_PFPE_CQPTAIL_CQP_OP_ERR);
  69. } else {
  70. *val = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPTAIL1);
  71. *tail = RS_32(*val, I40E_VFPE_CQPTAIL_WQTAIL);
  72. *error = RS_32(*val, I40E_VFPE_CQPTAIL_CQP_OP_ERR);
  73. }
  74. }
  75. /**
  76. * i40iw_cqp_poll_registers - poll cqp registers
  77. * @cqp: struct for cqp hw
  78. * @tail:wqtail register value
  79. * @count: how many times to try for completion
  80. */
  81. static enum i40iw_status_code i40iw_cqp_poll_registers(
  82. struct i40iw_sc_cqp *cqp,
  83. u32 tail,
  84. u32 count)
  85. {
  86. u32 i = 0;
  87. u32 newtail, error, val;
  88. while (i < count) {
  89. i++;
  90. i40iw_get_cqp_reg_info(cqp, &val, &newtail, &error);
  91. if (error) {
  92. error = (cqp->dev->is_pf) ?
  93. i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPERRCODES) :
  94. i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPERRCODES1);
  95. return I40IW_ERR_CQP_COMPL_ERROR;
  96. }
  97. if (newtail != tail) {
  98. /* SUCCESS */
  99. I40IW_RING_MOVE_TAIL(cqp->sq_ring);
  100. return 0;
  101. }
  102. udelay(I40IW_SLEEP_COUNT);
  103. }
  104. return I40IW_ERR_TIMEOUT;
  105. }
  106. /**
  107. * i40iw_sc_parse_fpm_commit_buf - parse fpm commit buffer
  108. * @buf: ptr to fpm commit buffer
  109. * @info: ptr to i40iw_hmc_obj_info struct
  110. * @sd: number of SDs for HMC objects
  111. *
  112. * parses fpm commit info and copy base value
  113. * of hmc objects in hmc_info
  114. */
  115. static enum i40iw_status_code i40iw_sc_parse_fpm_commit_buf(
  116. u64 *buf,
  117. struct i40iw_hmc_obj_info *info,
  118. u32 *sd)
  119. {
  120. u64 temp;
  121. u64 size;
  122. u64 base = 0;
  123. u32 i, j;
  124. u32 k = 0;
  125. u32 low;
  126. /* copy base values in obj_info */
  127. for (i = I40IW_HMC_IW_QP, j = 0;
  128. i <= I40IW_HMC_IW_PBLE; i++, j += 8) {
  129. get_64bit_val(buf, j, &temp);
  130. info[i].base = RS_64_1(temp, 32) * 512;
  131. if (info[i].base > base) {
  132. base = info[i].base;
  133. k = i;
  134. }
  135. low = (u32)(temp);
  136. if (low)
  137. info[i].cnt = low;
  138. }
  139. size = info[k].cnt * info[k].size + info[k].base;
  140. if (size & 0x1FFFFF)
  141. *sd = (u32)((size >> 21) + 1); /* add 1 for remainder */
  142. else
  143. *sd = (u32)(size >> 21);
  144. return 0;
  145. }
  146. /**
  147. * i40iw_sc_parse_fpm_query_buf() - parses fpm query buffer
  148. * @buf: ptr to fpm query buffer
  149. * @info: ptr to i40iw_hmc_obj_info struct
  150. * @hmc_fpm_misc: ptr to fpm data
  151. *
  152. * parses fpm query buffer and copy max_cnt and
  153. * size value of hmc objects in hmc_info
  154. */
  155. static enum i40iw_status_code i40iw_sc_parse_fpm_query_buf(
  156. u64 *buf,
  157. struct i40iw_hmc_info *hmc_info,
  158. struct i40iw_hmc_fpm_misc *hmc_fpm_misc)
  159. {
  160. u64 temp;
  161. struct i40iw_hmc_obj_info *obj_info;
  162. u32 i, j, size;
  163. u16 max_pe_sds;
  164. obj_info = hmc_info->hmc_obj;
  165. get_64bit_val(buf, 0, &temp);
  166. hmc_info->first_sd_index = (u16)RS_64(temp, I40IW_QUERY_FPM_FIRST_PE_SD_INDEX);
  167. max_pe_sds = (u16)RS_64(temp, I40IW_QUERY_FPM_MAX_PE_SDS);
  168. /* Reduce SD count for VFs by 1 to account for PBLE backing page rounding */
  169. if (hmc_info->hmc_fn_id >= I40IW_FIRST_VF_FPM_ID)
  170. max_pe_sds--;
  171. hmc_fpm_misc->max_sds = max_pe_sds;
  172. hmc_info->sd_table.sd_cnt = max_pe_sds + hmc_info->first_sd_index;
  173. for (i = I40IW_HMC_IW_QP, j = 8;
  174. i <= I40IW_HMC_IW_ARP; i++, j += 8) {
  175. get_64bit_val(buf, j, &temp);
  176. if (i == I40IW_HMC_IW_QP)
  177. obj_info[i].max_cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_QPS);
  178. else if (i == I40IW_HMC_IW_CQ)
  179. obj_info[i].max_cnt = (u32)RS_64(temp, I40IW_QUERY_FPM_MAX_CQS);
  180. else
  181. obj_info[i].max_cnt = (u32)temp;
  182. size = (u32)RS_64_1(temp, 32);
  183. obj_info[i].size = ((u64)1 << size);
  184. }
  185. for (i = I40IW_HMC_IW_MR, j = 48;
  186. i <= I40IW_HMC_IW_PBLE; i++, j += 8) {
  187. get_64bit_val(buf, j, &temp);
  188. obj_info[i].max_cnt = (u32)temp;
  189. size = (u32)RS_64_1(temp, 32);
  190. obj_info[i].size = LS_64_1(1, size);
  191. }
  192. get_64bit_val(buf, 120, &temp);
  193. hmc_fpm_misc->max_ceqs = (u8)RS_64(temp, I40IW_QUERY_FPM_MAX_CEQS);
  194. get_64bit_val(buf, 120, &temp);
  195. hmc_fpm_misc->ht_multiplier = RS_64(temp, I40IW_QUERY_FPM_HTMULTIPLIER);
  196. get_64bit_val(buf, 120, &temp);
  197. hmc_fpm_misc->timer_bucket = RS_64(temp, I40IW_QUERY_FPM_TIMERBUCKET);
  198. get_64bit_val(buf, 64, &temp);
  199. hmc_fpm_misc->xf_block_size = RS_64(temp, I40IW_QUERY_FPM_XFBLOCKSIZE);
  200. if (!hmc_fpm_misc->xf_block_size)
  201. return I40IW_ERR_INVALID_SIZE;
  202. get_64bit_val(buf, 80, &temp);
  203. hmc_fpm_misc->q1_block_size = RS_64(temp, I40IW_QUERY_FPM_Q1BLOCKSIZE);
  204. if (!hmc_fpm_misc->q1_block_size)
  205. return I40IW_ERR_INVALID_SIZE;
  206. return 0;
  207. }
  208. /**
  209. * i40iw_sc_pd_init - initialize sc pd struct
  210. * @dev: sc device struct
  211. * @pd: sc pd ptr
  212. * @pd_id: pd_id for allocated pd
  213. */
  214. static void i40iw_sc_pd_init(struct i40iw_sc_dev *dev,
  215. struct i40iw_sc_pd *pd,
  216. u16 pd_id)
  217. {
  218. pd->size = sizeof(*pd);
  219. pd->pd_id = pd_id;
  220. pd->dev = dev;
  221. }
  222. /**
  223. * i40iw_get_encoded_wqe_size - given wq size, returns hardware encoded size
  224. * @wqsize: size of the wq (sq, rq, srq) to encoded_size
  225. * @cqpsq: encoded size for sq for cqp as its encoded size is 1+ other wq's
  226. */
  227. u8 i40iw_get_encoded_wqe_size(u32 wqsize, bool cqpsq)
  228. {
  229. u8 encoded_size = 0;
  230. /* cqp sq's hw coded value starts from 1 for size of 4
  231. * while it starts from 0 for qp' wq's.
  232. */
  233. if (cqpsq)
  234. encoded_size = 1;
  235. wqsize >>= 2;
  236. while (wqsize >>= 1)
  237. encoded_size++;
  238. return encoded_size;
  239. }
  240. /**
  241. * i40iw_sc_cqp_init - Initialize buffers for a control Queue Pair
  242. * @cqp: IWARP control queue pair pointer
  243. * @info: IWARP control queue pair init info pointer
  244. *
  245. * Initializes the object and context buffers for a control Queue Pair.
  246. */
  247. static enum i40iw_status_code i40iw_sc_cqp_init(struct i40iw_sc_cqp *cqp,
  248. struct i40iw_cqp_init_info *info)
  249. {
  250. u8 hw_sq_size;
  251. if ((info->sq_size > I40IW_CQP_SW_SQSIZE_2048) ||
  252. (info->sq_size < I40IW_CQP_SW_SQSIZE_4) ||
  253. ((info->sq_size & (info->sq_size - 1))))
  254. return I40IW_ERR_INVALID_SIZE;
  255. hw_sq_size = i40iw_get_encoded_wqe_size(info->sq_size, true);
  256. cqp->size = sizeof(*cqp);
  257. cqp->sq_size = info->sq_size;
  258. cqp->hw_sq_size = hw_sq_size;
  259. cqp->sq_base = info->sq;
  260. cqp->host_ctx = info->host_ctx;
  261. cqp->sq_pa = info->sq_pa;
  262. cqp->host_ctx_pa = info->host_ctx_pa;
  263. cqp->dev = info->dev;
  264. cqp->struct_ver = info->struct_ver;
  265. cqp->scratch_array = info->scratch_array;
  266. cqp->polarity = 0;
  267. cqp->en_datacenter_tcp = info->en_datacenter_tcp;
  268. cqp->enabled_vf_count = info->enabled_vf_count;
  269. cqp->hmc_profile = info->hmc_profile;
  270. info->dev->cqp = cqp;
  271. I40IW_RING_INIT(cqp->sq_ring, cqp->sq_size);
  272. i40iw_debug(cqp->dev, I40IW_DEBUG_WQE,
  273. "%s: sq_size[%04d] hw_sq_size[%04d] sq_base[%p] sq_pa[%llxh] cqp[%p] polarity[x%04X]\n",
  274. __func__, cqp->sq_size, cqp->hw_sq_size,
  275. cqp->sq_base, cqp->sq_pa, cqp, cqp->polarity);
  276. return 0;
  277. }
  278. /**
  279. * i40iw_sc_cqp_create - create cqp during bringup
  280. * @cqp: struct for cqp hw
  281. * @disable_pfpdus: if pfpdu to be disabled
  282. * @maj_err: If error, major err number
  283. * @min_err: If error, minor err number
  284. */
  285. static enum i40iw_status_code i40iw_sc_cqp_create(struct i40iw_sc_cqp *cqp,
  286. bool disable_pfpdus,
  287. u16 *maj_err,
  288. u16 *min_err)
  289. {
  290. u64 temp;
  291. u32 cnt = 0, p1, p2, val = 0, err_code;
  292. enum i40iw_status_code ret_code;
  293. ret_code = i40iw_allocate_dma_mem(cqp->dev->hw,
  294. &cqp->sdbuf,
  295. 128,
  296. I40IW_SD_BUF_ALIGNMENT);
  297. if (ret_code)
  298. goto exit;
  299. temp = LS_64(cqp->hw_sq_size, I40IW_CQPHC_SQSIZE) |
  300. LS_64(cqp->struct_ver, I40IW_CQPHC_SVER);
  301. if (disable_pfpdus)
  302. temp |= LS_64(1, I40IW_CQPHC_DISABLE_PFPDUS);
  303. set_64bit_val(cqp->host_ctx, 0, temp);
  304. set_64bit_val(cqp->host_ctx, 8, cqp->sq_pa);
  305. temp = LS_64(cqp->enabled_vf_count, I40IW_CQPHC_ENABLED_VFS) |
  306. LS_64(cqp->hmc_profile, I40IW_CQPHC_HMC_PROFILE);
  307. set_64bit_val(cqp->host_ctx, 16, temp);
  308. set_64bit_val(cqp->host_ctx, 24, (uintptr_t)cqp);
  309. set_64bit_val(cqp->host_ctx, 32, 0);
  310. set_64bit_val(cqp->host_ctx, 40, 0);
  311. set_64bit_val(cqp->host_ctx, 48, 0);
  312. set_64bit_val(cqp->host_ctx, 56, 0);
  313. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQP_HOST_CTX",
  314. cqp->host_ctx, I40IW_CQP_CTX_SIZE * 8);
  315. p1 = RS_32_1(cqp->host_ctx_pa, 32);
  316. p2 = (u32)cqp->host_ctx_pa;
  317. if (cqp->dev->is_pf) {
  318. i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPHIGH, p1);
  319. i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPLOW, p2);
  320. } else {
  321. i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPHIGH1, p1);
  322. i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPLOW1, p2);
  323. }
  324. do {
  325. if (cnt++ > I40IW_DONE_COUNT) {
  326. i40iw_free_dma_mem(cqp->dev->hw, &cqp->sdbuf);
  327. ret_code = I40IW_ERR_TIMEOUT;
  328. /*
  329. * read PFPE_CQPERRORCODES register to get the minor
  330. * and major error code
  331. */
  332. if (cqp->dev->is_pf)
  333. err_code = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CQPERRCODES);
  334. else
  335. err_code = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CQPERRCODES1);
  336. *min_err = RS_32(err_code, I40E_PFPE_CQPERRCODES_CQP_MINOR_CODE);
  337. *maj_err = RS_32(err_code, I40E_PFPE_CQPERRCODES_CQP_MAJOR_CODE);
  338. goto exit;
  339. }
  340. udelay(I40IW_SLEEP_COUNT);
  341. if (cqp->dev->is_pf)
  342. val = i40iw_rd32(cqp->dev->hw, I40E_PFPE_CCQPSTATUS);
  343. else
  344. val = i40iw_rd32(cqp->dev->hw, I40E_VFPE_CCQPSTATUS1);
  345. } while (!val);
  346. exit:
  347. if (!ret_code)
  348. cqp->process_cqp_sds = i40iw_update_sds_noccq;
  349. return ret_code;
  350. }
  351. /**
  352. * i40iw_sc_cqp_post_sq - post of cqp's sq
  353. * @cqp: struct for cqp hw
  354. */
  355. void i40iw_sc_cqp_post_sq(struct i40iw_sc_cqp *cqp)
  356. {
  357. if (cqp->dev->is_pf)
  358. i40iw_wr32(cqp->dev->hw, I40E_PFPE_CQPDB, I40IW_RING_GETCURRENT_HEAD(cqp->sq_ring));
  359. else
  360. i40iw_wr32(cqp->dev->hw, I40E_VFPE_CQPDB1, I40IW_RING_GETCURRENT_HEAD(cqp->sq_ring));
  361. i40iw_debug(cqp->dev,
  362. I40IW_DEBUG_WQE,
  363. "%s: HEAD_TAIL[%04d,%04d,%04d]\n",
  364. __func__,
  365. cqp->sq_ring.head,
  366. cqp->sq_ring.tail,
  367. cqp->sq_ring.size);
  368. }
  369. /**
  370. * i40iw_sc_cqp_get_next_send_wqe - get next wqe on cqp sq
  371. * @cqp: struct for cqp hw
  372. * @wqe_idx: we index of cqp ring
  373. */
  374. u64 *i40iw_sc_cqp_get_next_send_wqe(struct i40iw_sc_cqp *cqp, u64 scratch)
  375. {
  376. u64 *wqe = NULL;
  377. u32 wqe_idx;
  378. enum i40iw_status_code ret_code;
  379. if (I40IW_RING_FULL_ERR(cqp->sq_ring)) {
  380. i40iw_debug(cqp->dev,
  381. I40IW_DEBUG_WQE,
  382. "%s: ring is full head %x tail %x size %x\n",
  383. __func__,
  384. cqp->sq_ring.head,
  385. cqp->sq_ring.tail,
  386. cqp->sq_ring.size);
  387. return NULL;
  388. }
  389. I40IW_ATOMIC_RING_MOVE_HEAD(cqp->sq_ring, wqe_idx, ret_code);
  390. if (ret_code)
  391. return NULL;
  392. if (!wqe_idx)
  393. cqp->polarity = !cqp->polarity;
  394. wqe = cqp->sq_base[wqe_idx].elem;
  395. cqp->scratch_array[wqe_idx] = scratch;
  396. I40IW_CQP_INIT_WQE(wqe);
  397. return wqe;
  398. }
  399. /**
  400. * i40iw_sc_cqp_destroy - destroy cqp during close
  401. * @cqp: struct for cqp hw
  402. */
  403. static enum i40iw_status_code i40iw_sc_cqp_destroy(struct i40iw_sc_cqp *cqp)
  404. {
  405. u32 cnt = 0, val = 1;
  406. enum i40iw_status_code ret_code = 0;
  407. u32 cqpstat_addr;
  408. if (cqp->dev->is_pf) {
  409. i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPHIGH, 0);
  410. i40iw_wr32(cqp->dev->hw, I40E_PFPE_CCQPLOW, 0);
  411. cqpstat_addr = I40E_PFPE_CCQPSTATUS;
  412. } else {
  413. i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPHIGH1, 0);
  414. i40iw_wr32(cqp->dev->hw, I40E_VFPE_CCQPLOW1, 0);
  415. cqpstat_addr = I40E_VFPE_CCQPSTATUS1;
  416. }
  417. do {
  418. if (cnt++ > I40IW_DONE_COUNT) {
  419. ret_code = I40IW_ERR_TIMEOUT;
  420. break;
  421. }
  422. udelay(I40IW_SLEEP_COUNT);
  423. val = i40iw_rd32(cqp->dev->hw, cqpstat_addr);
  424. } while (val);
  425. i40iw_free_dma_mem(cqp->dev->hw, &cqp->sdbuf);
  426. return ret_code;
  427. }
  428. /**
  429. * i40iw_sc_ccq_arm - enable intr for control cq
  430. * @ccq: ccq sc struct
  431. */
  432. static void i40iw_sc_ccq_arm(struct i40iw_sc_cq *ccq)
  433. {
  434. u64 temp_val;
  435. u16 sw_cq_sel;
  436. u8 arm_next_se;
  437. u8 arm_seq_num;
  438. /* write to cq doorbell shadow area */
  439. /* arm next se should always be zero */
  440. get_64bit_val(ccq->cq_uk.shadow_area, 32, &temp_val);
  441. sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
  442. arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
  443. arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
  444. arm_seq_num++;
  445. temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
  446. LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
  447. LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
  448. LS_64(1, I40IW_CQ_DBSA_ARM_NEXT);
  449. set_64bit_val(ccq->cq_uk.shadow_area, 32, temp_val);
  450. wmb(); /* make sure shadow area is updated before arming */
  451. if (ccq->dev->is_pf)
  452. i40iw_wr32(ccq->dev->hw, I40E_PFPE_CQARM, ccq->cq_uk.cq_id);
  453. else
  454. i40iw_wr32(ccq->dev->hw, I40E_VFPE_CQARM1, ccq->cq_uk.cq_id);
  455. }
  456. /**
  457. * i40iw_sc_ccq_get_cqe_info - get ccq's cq entry
  458. * @ccq: ccq sc struct
  459. * @info: completion q entry to return
  460. */
  461. static enum i40iw_status_code i40iw_sc_ccq_get_cqe_info(
  462. struct i40iw_sc_cq *ccq,
  463. struct i40iw_ccq_cqe_info *info)
  464. {
  465. u64 qp_ctx, temp, temp1;
  466. u64 *cqe;
  467. struct i40iw_sc_cqp *cqp;
  468. u32 wqe_idx;
  469. u8 polarity;
  470. enum i40iw_status_code ret_code = 0;
  471. if (ccq->cq_uk.avoid_mem_cflct)
  472. cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(&ccq->cq_uk);
  473. else
  474. cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(&ccq->cq_uk);
  475. get_64bit_val(cqe, 24, &temp);
  476. polarity = (u8)RS_64(temp, I40IW_CQ_VALID);
  477. if (polarity != ccq->cq_uk.polarity)
  478. return I40IW_ERR_QUEUE_EMPTY;
  479. get_64bit_val(cqe, 8, &qp_ctx);
  480. cqp = (struct i40iw_sc_cqp *)(unsigned long)qp_ctx;
  481. info->error = (bool)RS_64(temp, I40IW_CQ_ERROR);
  482. info->min_err_code = (u16)RS_64(temp, I40IW_CQ_MINERR);
  483. if (info->error) {
  484. info->maj_err_code = (u16)RS_64(temp, I40IW_CQ_MAJERR);
  485. info->min_err_code = (u16)RS_64(temp, I40IW_CQ_MINERR);
  486. }
  487. wqe_idx = (u32)RS_64(temp, I40IW_CQ_WQEIDX);
  488. info->scratch = cqp->scratch_array[wqe_idx];
  489. get_64bit_val(cqe, 16, &temp1);
  490. info->op_ret_val = (u32)RS_64(temp1, I40IW_CCQ_OPRETVAL);
  491. get_64bit_val(cqp->sq_base[wqe_idx].elem, 24, &temp1);
  492. info->op_code = (u8)RS_64(temp1, I40IW_CQPSQ_OPCODE);
  493. info->cqp = cqp;
  494. /* move the head for cq */
  495. I40IW_RING_MOVE_HEAD(ccq->cq_uk.cq_ring, ret_code);
  496. if (I40IW_RING_GETCURRENT_HEAD(ccq->cq_uk.cq_ring) == 0)
  497. ccq->cq_uk.polarity ^= 1;
  498. /* update cq tail in cq shadow memory also */
  499. I40IW_RING_MOVE_TAIL(ccq->cq_uk.cq_ring);
  500. set_64bit_val(ccq->cq_uk.shadow_area,
  501. 0,
  502. I40IW_RING_GETCURRENT_HEAD(ccq->cq_uk.cq_ring));
  503. wmb(); /* write shadow area before tail */
  504. I40IW_RING_MOVE_TAIL(cqp->sq_ring);
  505. return ret_code;
  506. }
  507. /**
  508. * i40iw_sc_poll_for_cqp_op_done - Waits for last write to complete in CQP SQ
  509. * @cqp: struct for cqp hw
  510. * @op_code: cqp opcode for completion
  511. * @info: completion q entry to return
  512. */
  513. static enum i40iw_status_code i40iw_sc_poll_for_cqp_op_done(
  514. struct i40iw_sc_cqp *cqp,
  515. u8 op_code,
  516. struct i40iw_ccq_cqe_info *compl_info)
  517. {
  518. struct i40iw_ccq_cqe_info info;
  519. struct i40iw_sc_cq *ccq;
  520. enum i40iw_status_code ret_code = 0;
  521. u32 cnt = 0;
  522. memset(&info, 0, sizeof(info));
  523. ccq = cqp->dev->ccq;
  524. while (1) {
  525. if (cnt++ > I40IW_DONE_COUNT)
  526. return I40IW_ERR_TIMEOUT;
  527. if (i40iw_sc_ccq_get_cqe_info(ccq, &info)) {
  528. udelay(I40IW_SLEEP_COUNT);
  529. continue;
  530. }
  531. if (info.error) {
  532. ret_code = I40IW_ERR_CQP_COMPL_ERROR;
  533. break;
  534. }
  535. /* check if opcode is cq create */
  536. if (op_code != info.op_code) {
  537. i40iw_debug(cqp->dev, I40IW_DEBUG_WQE,
  538. "%s: opcode mismatch for my op code 0x%x, returned opcode %x\n",
  539. __func__, op_code, info.op_code);
  540. }
  541. /* success, exit out of the loop */
  542. if (op_code == info.op_code)
  543. break;
  544. }
  545. if (compl_info)
  546. memcpy(compl_info, &info, sizeof(*compl_info));
  547. return ret_code;
  548. }
  549. /**
  550. * i40iw_sc_manage_push_page - Handle push page
  551. * @cqp: struct for cqp hw
  552. * @info: push page info
  553. * @scratch: u64 saved to be used during cqp completion
  554. * @post_sq: flag for cqp db to ring
  555. */
  556. static enum i40iw_status_code i40iw_sc_manage_push_page(
  557. struct i40iw_sc_cqp *cqp,
  558. struct i40iw_cqp_manage_push_page_info *info,
  559. u64 scratch,
  560. bool post_sq)
  561. {
  562. u64 *wqe;
  563. u64 header;
  564. if (info->push_idx >= I40IW_MAX_PUSH_PAGE_COUNT)
  565. return I40IW_ERR_INVALID_PUSH_PAGE_INDEX;
  566. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  567. if (!wqe)
  568. return I40IW_ERR_RING_FULL;
  569. set_64bit_val(wqe, 16, info->qs_handle);
  570. header = LS_64(info->push_idx, I40IW_CQPSQ_MPP_PPIDX) |
  571. LS_64(I40IW_CQP_OP_MANAGE_PUSH_PAGES, I40IW_CQPSQ_OPCODE) |
  572. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
  573. LS_64(info->free_page, I40IW_CQPSQ_MPP_FREE_PAGE);
  574. i40iw_insert_wqe_hdr(wqe, header);
  575. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_PUSH_PAGES WQE",
  576. wqe, I40IW_CQP_WQE_SIZE * 8);
  577. if (post_sq)
  578. i40iw_sc_cqp_post_sq(cqp);
  579. return 0;
  580. }
  581. /**
  582. * i40iw_sc_manage_hmc_pm_func_table - manage of function table
  583. * @cqp: struct for cqp hw
  584. * @scratch: u64 saved to be used during cqp completion
  585. * @vf_index: vf index for cqp
  586. * @free_pm_fcn: function number
  587. * @post_sq: flag for cqp db to ring
  588. */
  589. static enum i40iw_status_code i40iw_sc_manage_hmc_pm_func_table(
  590. struct i40iw_sc_cqp *cqp,
  591. u64 scratch,
  592. u8 vf_index,
  593. bool free_pm_fcn,
  594. bool post_sq)
  595. {
  596. u64 *wqe;
  597. u64 header;
  598. if (vf_index >= I40IW_MAX_VF_PER_PF)
  599. return I40IW_ERR_INVALID_VF_ID;
  600. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  601. if (!wqe)
  602. return I40IW_ERR_RING_FULL;
  603. header = LS_64(vf_index, I40IW_CQPSQ_MHMC_VFIDX) |
  604. LS_64(I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE, I40IW_CQPSQ_OPCODE) |
  605. LS_64(free_pm_fcn, I40IW_CQPSQ_MHMC_FREEPMFN) |
  606. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  607. i40iw_insert_wqe_hdr(wqe, header);
  608. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_HMC_PM_FUNC_TABLE WQE",
  609. wqe, I40IW_CQP_WQE_SIZE * 8);
  610. if (post_sq)
  611. i40iw_sc_cqp_post_sq(cqp);
  612. return 0;
  613. }
  614. /**
  615. * i40iw_sc_set_hmc_resource_profile - cqp wqe for hmc profile
  616. * @cqp: struct for cqp hw
  617. * @scratch: u64 saved to be used during cqp completion
  618. * @hmc_profile_type: type of profile to set
  619. * @vf_num: vf number for profile
  620. * @post_sq: flag for cqp db to ring
  621. * @poll_registers: flag to poll register for cqp completion
  622. */
  623. static enum i40iw_status_code i40iw_sc_set_hmc_resource_profile(
  624. struct i40iw_sc_cqp *cqp,
  625. u64 scratch,
  626. u8 hmc_profile_type,
  627. u8 vf_num, bool post_sq,
  628. bool poll_registers)
  629. {
  630. u64 *wqe;
  631. u64 header;
  632. u32 val, tail, error;
  633. enum i40iw_status_code ret_code = 0;
  634. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  635. if (!wqe)
  636. return I40IW_ERR_RING_FULL;
  637. set_64bit_val(wqe, 16,
  638. (LS_64(hmc_profile_type, I40IW_CQPSQ_SHMCRP_HMC_PROFILE) |
  639. LS_64(vf_num, I40IW_CQPSQ_SHMCRP_VFNUM)));
  640. header = LS_64(I40IW_CQP_OP_SET_HMC_RESOURCE_PROFILE, I40IW_CQPSQ_OPCODE) |
  641. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  642. i40iw_insert_wqe_hdr(wqe, header);
  643. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_HMC_PM_FUNC_TABLE WQE",
  644. wqe, I40IW_CQP_WQE_SIZE * 8);
  645. i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
  646. if (error)
  647. return I40IW_ERR_CQP_COMPL_ERROR;
  648. if (post_sq) {
  649. i40iw_sc_cqp_post_sq(cqp);
  650. if (poll_registers)
  651. ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000000);
  652. else
  653. ret_code = i40iw_sc_poll_for_cqp_op_done(cqp,
  654. I40IW_CQP_OP_SHMC_PAGES_ALLOCATED,
  655. NULL);
  656. }
  657. return ret_code;
  658. }
  659. /**
  660. * i40iw_sc_manage_hmc_pm_func_table_done - wait for cqp wqe completion for function table
  661. * @cqp: struct for cqp hw
  662. */
  663. static enum i40iw_status_code i40iw_sc_manage_hmc_pm_func_table_done(struct i40iw_sc_cqp *cqp)
  664. {
  665. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE, NULL);
  666. }
  667. /**
  668. * i40iw_sc_commit_fpm_values_done - wait for cqp eqe completion for fpm commit
  669. * @cqp: struct for cqp hw
  670. */
  671. static enum i40iw_status_code i40iw_sc_commit_fpm_values_done(struct i40iw_sc_cqp *cqp)
  672. {
  673. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_COMMIT_FPM_VALUES, NULL);
  674. }
  675. /**
  676. * i40iw_sc_commit_fpm_values - cqp wqe for commit fpm values
  677. * @cqp: struct for cqp hw
  678. * @scratch: u64 saved to be used during cqp completion
  679. * @hmc_fn_id: hmc function id
  680. * @commit_fpm_mem; Memory for fpm values
  681. * @post_sq: flag for cqp db to ring
  682. * @wait_type: poll ccq or cqp registers for cqp completion
  683. */
  684. static enum i40iw_status_code i40iw_sc_commit_fpm_values(
  685. struct i40iw_sc_cqp *cqp,
  686. u64 scratch,
  687. u8 hmc_fn_id,
  688. struct i40iw_dma_mem *commit_fpm_mem,
  689. bool post_sq,
  690. u8 wait_type)
  691. {
  692. u64 *wqe;
  693. u64 header;
  694. u32 tail, val, error;
  695. enum i40iw_status_code ret_code = 0;
  696. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  697. if (!wqe)
  698. return I40IW_ERR_RING_FULL;
  699. set_64bit_val(wqe, 16, hmc_fn_id);
  700. set_64bit_val(wqe, 32, commit_fpm_mem->pa);
  701. header = LS_64(I40IW_CQP_OP_COMMIT_FPM_VALUES, I40IW_CQPSQ_OPCODE) |
  702. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  703. i40iw_insert_wqe_hdr(wqe, header);
  704. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "COMMIT_FPM_VALUES WQE",
  705. wqe, I40IW_CQP_WQE_SIZE * 8);
  706. i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
  707. if (error)
  708. return I40IW_ERR_CQP_COMPL_ERROR;
  709. if (post_sq) {
  710. i40iw_sc_cqp_post_sq(cqp);
  711. if (wait_type == I40IW_CQP_WAIT_POLL_REGS)
  712. ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
  713. else if (wait_type == I40IW_CQP_WAIT_POLL_CQ)
  714. ret_code = i40iw_sc_commit_fpm_values_done(cqp);
  715. }
  716. return ret_code;
  717. }
  718. /**
  719. * i40iw_sc_query_fpm_values_done - poll for cqp wqe completion for query fpm
  720. * @cqp: struct for cqp hw
  721. */
  722. static enum i40iw_status_code i40iw_sc_query_fpm_values_done(struct i40iw_sc_cqp *cqp)
  723. {
  724. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_QUERY_FPM_VALUES, NULL);
  725. }
  726. /**
  727. * i40iw_sc_query_fpm_values - cqp wqe query fpm values
  728. * @cqp: struct for cqp hw
  729. * @scratch: u64 saved to be used during cqp completion
  730. * @hmc_fn_id: hmc function id
  731. * @query_fpm_mem: memory for return fpm values
  732. * @post_sq: flag for cqp db to ring
  733. * @wait_type: poll ccq or cqp registers for cqp completion
  734. */
  735. static enum i40iw_status_code i40iw_sc_query_fpm_values(
  736. struct i40iw_sc_cqp *cqp,
  737. u64 scratch,
  738. u8 hmc_fn_id,
  739. struct i40iw_dma_mem *query_fpm_mem,
  740. bool post_sq,
  741. u8 wait_type)
  742. {
  743. u64 *wqe;
  744. u64 header;
  745. u32 tail, val, error;
  746. enum i40iw_status_code ret_code = 0;
  747. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  748. if (!wqe)
  749. return I40IW_ERR_RING_FULL;
  750. set_64bit_val(wqe, 16, hmc_fn_id);
  751. set_64bit_val(wqe, 32, query_fpm_mem->pa);
  752. header = LS_64(I40IW_CQP_OP_QUERY_FPM_VALUES, I40IW_CQPSQ_OPCODE) |
  753. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  754. i40iw_insert_wqe_hdr(wqe, header);
  755. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QUERY_FPM WQE",
  756. wqe, I40IW_CQP_WQE_SIZE * 8);
  757. /* read the tail from CQP_TAIL register */
  758. i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
  759. if (error)
  760. return I40IW_ERR_CQP_COMPL_ERROR;
  761. if (post_sq) {
  762. i40iw_sc_cqp_post_sq(cqp);
  763. if (wait_type == I40IW_CQP_WAIT_POLL_REGS)
  764. ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
  765. else if (wait_type == I40IW_CQP_WAIT_POLL_CQ)
  766. ret_code = i40iw_sc_query_fpm_values_done(cqp);
  767. }
  768. return ret_code;
  769. }
  770. /**
  771. * i40iw_sc_add_arp_cache_entry - cqp wqe add arp cache entry
  772. * @cqp: struct for cqp hw
  773. * @info: arp entry information
  774. * @scratch: u64 saved to be used during cqp completion
  775. * @post_sq: flag for cqp db to ring
  776. */
  777. static enum i40iw_status_code i40iw_sc_add_arp_cache_entry(
  778. struct i40iw_sc_cqp *cqp,
  779. struct i40iw_add_arp_cache_entry_info *info,
  780. u64 scratch,
  781. bool post_sq)
  782. {
  783. u64 *wqe;
  784. u64 temp, header;
  785. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  786. if (!wqe)
  787. return I40IW_ERR_RING_FULL;
  788. set_64bit_val(wqe, 8, info->reach_max);
  789. temp = info->mac_addr[5] |
  790. LS_64_1(info->mac_addr[4], 8) |
  791. LS_64_1(info->mac_addr[3], 16) |
  792. LS_64_1(info->mac_addr[2], 24) |
  793. LS_64_1(info->mac_addr[1], 32) |
  794. LS_64_1(info->mac_addr[0], 40);
  795. set_64bit_val(wqe, 16, temp);
  796. header = info->arp_index |
  797. LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
  798. LS_64((info->permanent ? 1 : 0), I40IW_CQPSQ_MAT_PERMANENT) |
  799. LS_64(1, I40IW_CQPSQ_MAT_ENTRYVALID) |
  800. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  801. i40iw_insert_wqe_hdr(wqe, header);
  802. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ARP_CACHE_ENTRY WQE",
  803. wqe, I40IW_CQP_WQE_SIZE * 8);
  804. if (post_sq)
  805. i40iw_sc_cqp_post_sq(cqp);
  806. return 0;
  807. }
  808. /**
  809. * i40iw_sc_del_arp_cache_entry - dele arp cache entry
  810. * @cqp: struct for cqp hw
  811. * @scratch: u64 saved to be used during cqp completion
  812. * @arp_index: arp index to delete arp entry
  813. * @post_sq: flag for cqp db to ring
  814. */
  815. static enum i40iw_status_code i40iw_sc_del_arp_cache_entry(
  816. struct i40iw_sc_cqp *cqp,
  817. u64 scratch,
  818. u16 arp_index,
  819. bool post_sq)
  820. {
  821. u64 *wqe;
  822. u64 header;
  823. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  824. if (!wqe)
  825. return I40IW_ERR_RING_FULL;
  826. header = arp_index |
  827. LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
  828. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  829. i40iw_insert_wqe_hdr(wqe, header);
  830. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ARP_CACHE_DEL_ENTRY WQE",
  831. wqe, I40IW_CQP_WQE_SIZE * 8);
  832. if (post_sq)
  833. i40iw_sc_cqp_post_sq(cqp);
  834. return 0;
  835. }
  836. /**
  837. * i40iw_sc_query_arp_cache_entry - cqp wqe to query arp and arp index
  838. * @cqp: struct for cqp hw
  839. * @scratch: u64 saved to be used during cqp completion
  840. * @arp_index: arp index to delete arp entry
  841. * @post_sq: flag for cqp db to ring
  842. */
  843. static enum i40iw_status_code i40iw_sc_query_arp_cache_entry(
  844. struct i40iw_sc_cqp *cqp,
  845. u64 scratch,
  846. u16 arp_index,
  847. bool post_sq)
  848. {
  849. u64 *wqe;
  850. u64 header;
  851. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  852. if (!wqe)
  853. return I40IW_ERR_RING_FULL;
  854. header = arp_index |
  855. LS_64(I40IW_CQP_OP_MANAGE_ARP, I40IW_CQPSQ_OPCODE) |
  856. LS_64(1, I40IW_CQPSQ_MAT_QUERY) |
  857. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  858. i40iw_insert_wqe_hdr(wqe, header);
  859. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QUERY_ARP_CACHE_ENTRY WQE",
  860. wqe, I40IW_CQP_WQE_SIZE * 8);
  861. if (post_sq)
  862. i40iw_sc_cqp_post_sq(cqp);
  863. return 0;
  864. }
  865. /**
  866. * i40iw_sc_manage_apbvt_entry - for adding and deleting apbvt entries
  867. * @cqp: struct for cqp hw
  868. * @info: info for apbvt entry to add or delete
  869. * @scratch: u64 saved to be used during cqp completion
  870. * @post_sq: flag for cqp db to ring
  871. */
  872. static enum i40iw_status_code i40iw_sc_manage_apbvt_entry(
  873. struct i40iw_sc_cqp *cqp,
  874. struct i40iw_apbvt_info *info,
  875. u64 scratch,
  876. bool post_sq)
  877. {
  878. u64 *wqe;
  879. u64 header;
  880. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  881. if (!wqe)
  882. return I40IW_ERR_RING_FULL;
  883. set_64bit_val(wqe, 16, info->port);
  884. header = LS_64(I40IW_CQP_OP_MANAGE_APBVT, I40IW_CQPSQ_OPCODE) |
  885. LS_64(info->add, I40IW_CQPSQ_MAPT_ADDPORT) |
  886. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  887. i40iw_insert_wqe_hdr(wqe, header);
  888. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_APBVT WQE",
  889. wqe, I40IW_CQP_WQE_SIZE * 8);
  890. if (post_sq)
  891. i40iw_sc_cqp_post_sq(cqp);
  892. return 0;
  893. }
  894. /**
  895. * i40iw_sc_manage_qhash_table_entry - manage quad hash entries
  896. * @cqp: struct for cqp hw
  897. * @info: info for quad hash to manage
  898. * @scratch: u64 saved to be used during cqp completion
  899. * @post_sq: flag for cqp db to ring
  900. *
  901. * This is called before connection establishment is started. For passive connections, when
  902. * listener is created, it will call with entry type of I40IW_QHASH_TYPE_TCP_SYN with local
  903. * ip address and tcp port. When SYN is received (passive connections) or
  904. * sent (active connections), this routine is called with entry type of
  905. * I40IW_QHASH_TYPE_TCP_ESTABLISHED and quad is passed in info.
  906. *
  907. * When iwarp connection is done and its state moves to RTS, the quad hash entry in
  908. * the hardware will point to iwarp's qp number and requires no calls from the driver.
  909. */
  910. static enum i40iw_status_code i40iw_sc_manage_qhash_table_entry(
  911. struct i40iw_sc_cqp *cqp,
  912. struct i40iw_qhash_table_info *info,
  913. u64 scratch,
  914. bool post_sq)
  915. {
  916. u64 *wqe;
  917. u64 qw1 = 0;
  918. u64 qw2 = 0;
  919. u64 temp;
  920. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  921. if (!wqe)
  922. return I40IW_ERR_RING_FULL;
  923. temp = info->mac_addr[5] |
  924. LS_64_1(info->mac_addr[4], 8) |
  925. LS_64_1(info->mac_addr[3], 16) |
  926. LS_64_1(info->mac_addr[2], 24) |
  927. LS_64_1(info->mac_addr[1], 32) |
  928. LS_64_1(info->mac_addr[0], 40);
  929. set_64bit_val(wqe, 0, temp);
  930. qw1 = LS_64(info->qp_num, I40IW_CQPSQ_QHASH_QPN) |
  931. LS_64(info->dest_port, I40IW_CQPSQ_QHASH_DEST_PORT);
  932. if (info->ipv4_valid) {
  933. set_64bit_val(wqe,
  934. 48,
  935. LS_64(info->dest_ip[0], I40IW_CQPSQ_QHASH_ADDR3));
  936. } else {
  937. set_64bit_val(wqe,
  938. 56,
  939. LS_64(info->dest_ip[0], I40IW_CQPSQ_QHASH_ADDR0) |
  940. LS_64(info->dest_ip[1], I40IW_CQPSQ_QHASH_ADDR1));
  941. set_64bit_val(wqe,
  942. 48,
  943. LS_64(info->dest_ip[2], I40IW_CQPSQ_QHASH_ADDR2) |
  944. LS_64(info->dest_ip[3], I40IW_CQPSQ_QHASH_ADDR3));
  945. }
  946. qw2 = LS_64(cqp->dev->qs_handle, I40IW_CQPSQ_QHASH_QS_HANDLE);
  947. if (info->vlan_valid)
  948. qw2 |= LS_64(info->vlan_id, I40IW_CQPSQ_QHASH_VLANID);
  949. set_64bit_val(wqe, 16, qw2);
  950. if (info->entry_type == I40IW_QHASH_TYPE_TCP_ESTABLISHED) {
  951. qw1 |= LS_64(info->src_port, I40IW_CQPSQ_QHASH_SRC_PORT);
  952. if (!info->ipv4_valid) {
  953. set_64bit_val(wqe,
  954. 40,
  955. LS_64(info->src_ip[0], I40IW_CQPSQ_QHASH_ADDR0) |
  956. LS_64(info->src_ip[1], I40IW_CQPSQ_QHASH_ADDR1));
  957. set_64bit_val(wqe,
  958. 32,
  959. LS_64(info->src_ip[2], I40IW_CQPSQ_QHASH_ADDR2) |
  960. LS_64(info->src_ip[3], I40IW_CQPSQ_QHASH_ADDR3));
  961. } else {
  962. set_64bit_val(wqe,
  963. 32,
  964. LS_64(info->src_ip[0], I40IW_CQPSQ_QHASH_ADDR3));
  965. }
  966. }
  967. set_64bit_val(wqe, 8, qw1);
  968. temp = LS_64(cqp->polarity, I40IW_CQPSQ_QHASH_WQEVALID) |
  969. LS_64(I40IW_CQP_OP_MANAGE_QUAD_HASH_TABLE_ENTRY, I40IW_CQPSQ_QHASH_OPCODE) |
  970. LS_64(info->manage, I40IW_CQPSQ_QHASH_MANAGE) |
  971. LS_64(info->ipv4_valid, I40IW_CQPSQ_QHASH_IPV4VALID) |
  972. LS_64(info->vlan_valid, I40IW_CQPSQ_QHASH_VLANVALID) |
  973. LS_64(info->entry_type, I40IW_CQPSQ_QHASH_ENTRYTYPE);
  974. i40iw_insert_wqe_hdr(wqe, temp);
  975. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "MANAGE_QHASH WQE",
  976. wqe, I40IW_CQP_WQE_SIZE * 8);
  977. if (post_sq)
  978. i40iw_sc_cqp_post_sq(cqp);
  979. return 0;
  980. }
  981. /**
  982. * i40iw_sc_alloc_local_mac_ipaddr_entry - cqp wqe for loc mac entry
  983. * @cqp: struct for cqp hw
  984. * @scratch: u64 saved to be used during cqp completion
  985. * @post_sq: flag for cqp db to ring
  986. */
  987. static enum i40iw_status_code i40iw_sc_alloc_local_mac_ipaddr_entry(
  988. struct i40iw_sc_cqp *cqp,
  989. u64 scratch,
  990. bool post_sq)
  991. {
  992. u64 *wqe;
  993. u64 header;
  994. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  995. if (!wqe)
  996. return I40IW_ERR_RING_FULL;
  997. header = LS_64(I40IW_CQP_OP_ALLOCATE_LOC_MAC_IP_TABLE_ENTRY, I40IW_CQPSQ_OPCODE) |
  998. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  999. i40iw_insert_wqe_hdr(wqe, header);
  1000. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ALLOCATE_LOCAL_MAC_IPADDR WQE",
  1001. wqe, I40IW_CQP_WQE_SIZE * 8);
  1002. if (post_sq)
  1003. i40iw_sc_cqp_post_sq(cqp);
  1004. return 0;
  1005. }
  1006. /**
  1007. * i40iw_sc_add_local_mac_ipaddr_entry - add mac enry
  1008. * @cqp: struct for cqp hw
  1009. * @info:mac addr info
  1010. * @scratch: u64 saved to be used during cqp completion
  1011. * @post_sq: flag for cqp db to ring
  1012. */
  1013. static enum i40iw_status_code i40iw_sc_add_local_mac_ipaddr_entry(
  1014. struct i40iw_sc_cqp *cqp,
  1015. struct i40iw_local_mac_ipaddr_entry_info *info,
  1016. u64 scratch,
  1017. bool post_sq)
  1018. {
  1019. u64 *wqe;
  1020. u64 temp, header;
  1021. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1022. if (!wqe)
  1023. return I40IW_ERR_RING_FULL;
  1024. temp = info->mac_addr[5] |
  1025. LS_64_1(info->mac_addr[4], 8) |
  1026. LS_64_1(info->mac_addr[3], 16) |
  1027. LS_64_1(info->mac_addr[2], 24) |
  1028. LS_64_1(info->mac_addr[1], 32) |
  1029. LS_64_1(info->mac_addr[0], 40);
  1030. set_64bit_val(wqe, 32, temp);
  1031. header = LS_64(info->entry_idx, I40IW_CQPSQ_MLIPA_IPTABLEIDX) |
  1032. LS_64(I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE, I40IW_CQPSQ_OPCODE) |
  1033. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1034. i40iw_insert_wqe_hdr(wqe, header);
  1035. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "ADD_LOCAL_MAC_IPADDR WQE",
  1036. wqe, I40IW_CQP_WQE_SIZE * 8);
  1037. if (post_sq)
  1038. i40iw_sc_cqp_post_sq(cqp);
  1039. return 0;
  1040. }
  1041. /**
  1042. * i40iw_sc_del_local_mac_ipaddr_entry - cqp wqe to dele local mac
  1043. * @cqp: struct for cqp hw
  1044. * @scratch: u64 saved to be used during cqp completion
  1045. * @entry_idx: index of mac entry
  1046. * @ ignore_ref_count: to force mac adde delete
  1047. * @post_sq: flag for cqp db to ring
  1048. */
  1049. static enum i40iw_status_code i40iw_sc_del_local_mac_ipaddr_entry(
  1050. struct i40iw_sc_cqp *cqp,
  1051. u64 scratch,
  1052. u8 entry_idx,
  1053. u8 ignore_ref_count,
  1054. bool post_sq)
  1055. {
  1056. u64 *wqe;
  1057. u64 header;
  1058. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1059. if (!wqe)
  1060. return I40IW_ERR_RING_FULL;
  1061. header = LS_64(entry_idx, I40IW_CQPSQ_MLIPA_IPTABLEIDX) |
  1062. LS_64(I40IW_CQP_OP_MANAGE_LOC_MAC_IP_TABLE, I40IW_CQPSQ_OPCODE) |
  1063. LS_64(1, I40IW_CQPSQ_MLIPA_FREEENTRY) |
  1064. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
  1065. LS_64(ignore_ref_count, I40IW_CQPSQ_MLIPA_IGNORE_REF_CNT);
  1066. i40iw_insert_wqe_hdr(wqe, header);
  1067. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "DEL_LOCAL_MAC_IPADDR WQE",
  1068. wqe, I40IW_CQP_WQE_SIZE * 8);
  1069. if (post_sq)
  1070. i40iw_sc_cqp_post_sq(cqp);
  1071. return 0;
  1072. }
  1073. /**
  1074. * i40iw_sc_cqp_nop - send a nop wqe
  1075. * @cqp: struct for cqp hw
  1076. * @scratch: u64 saved to be used during cqp completion
  1077. * @post_sq: flag for cqp db to ring
  1078. */
  1079. static enum i40iw_status_code i40iw_sc_cqp_nop(struct i40iw_sc_cqp *cqp,
  1080. u64 scratch,
  1081. bool post_sq)
  1082. {
  1083. u64 *wqe;
  1084. u64 header;
  1085. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1086. if (!wqe)
  1087. return I40IW_ERR_RING_FULL;
  1088. header = LS_64(I40IW_CQP_OP_NOP, I40IW_CQPSQ_OPCODE) |
  1089. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1090. i40iw_insert_wqe_hdr(wqe, header);
  1091. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "NOP WQE",
  1092. wqe, I40IW_CQP_WQE_SIZE * 8);
  1093. if (post_sq)
  1094. i40iw_sc_cqp_post_sq(cqp);
  1095. return 0;
  1096. }
  1097. /**
  1098. * i40iw_sc_ceq_init - initialize ceq
  1099. * @ceq: ceq sc structure
  1100. * @info: ceq initialization info
  1101. */
  1102. static enum i40iw_status_code i40iw_sc_ceq_init(struct i40iw_sc_ceq *ceq,
  1103. struct i40iw_ceq_init_info *info)
  1104. {
  1105. u32 pble_obj_cnt;
  1106. if ((info->elem_cnt < I40IW_MIN_CEQ_ENTRIES) ||
  1107. (info->elem_cnt > I40IW_MAX_CEQ_ENTRIES))
  1108. return I40IW_ERR_INVALID_SIZE;
  1109. if (info->ceq_id >= I40IW_MAX_CEQID)
  1110. return I40IW_ERR_INVALID_CEQ_ID;
  1111. pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  1112. if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
  1113. return I40IW_ERR_INVALID_PBLE_INDEX;
  1114. ceq->size = sizeof(*ceq);
  1115. ceq->ceqe_base = (struct i40iw_ceqe *)info->ceqe_base;
  1116. ceq->ceq_id = info->ceq_id;
  1117. ceq->dev = info->dev;
  1118. ceq->elem_cnt = info->elem_cnt;
  1119. ceq->ceq_elem_pa = info->ceqe_pa;
  1120. ceq->virtual_map = info->virtual_map;
  1121. ceq->pbl_chunk_size = (ceq->virtual_map ? info->pbl_chunk_size : 0);
  1122. ceq->first_pm_pbl_idx = (ceq->virtual_map ? info->first_pm_pbl_idx : 0);
  1123. ceq->pbl_list = (ceq->virtual_map ? info->pbl_list : NULL);
  1124. ceq->tph_en = info->tph_en;
  1125. ceq->tph_val = info->tph_val;
  1126. ceq->polarity = 1;
  1127. I40IW_RING_INIT(ceq->ceq_ring, ceq->elem_cnt);
  1128. ceq->dev->ceq[info->ceq_id] = ceq;
  1129. return 0;
  1130. }
  1131. /**
  1132. * i40iw_sc_ceq_create - create ceq wqe
  1133. * @ceq: ceq sc structure
  1134. * @scratch: u64 saved to be used during cqp completion
  1135. * @post_sq: flag for cqp db to ring
  1136. */
  1137. static enum i40iw_status_code i40iw_sc_ceq_create(struct i40iw_sc_ceq *ceq,
  1138. u64 scratch,
  1139. bool post_sq)
  1140. {
  1141. struct i40iw_sc_cqp *cqp;
  1142. u64 *wqe;
  1143. u64 header;
  1144. cqp = ceq->dev->cqp;
  1145. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1146. if (!wqe)
  1147. return I40IW_ERR_RING_FULL;
  1148. set_64bit_val(wqe, 16, ceq->elem_cnt);
  1149. set_64bit_val(wqe, 32, (ceq->virtual_map ? 0 : ceq->ceq_elem_pa));
  1150. set_64bit_val(wqe, 48, (ceq->virtual_map ? ceq->first_pm_pbl_idx : 0));
  1151. set_64bit_val(wqe, 56, LS_64(ceq->tph_val, I40IW_CQPSQ_TPHVAL));
  1152. header = ceq->ceq_id |
  1153. LS_64(I40IW_CQP_OP_CREATE_CEQ, I40IW_CQPSQ_OPCODE) |
  1154. LS_64(ceq->pbl_chunk_size, I40IW_CQPSQ_CEQ_LPBLSIZE) |
  1155. LS_64(ceq->virtual_map, I40IW_CQPSQ_CEQ_VMAP) |
  1156. LS_64(ceq->tph_en, I40IW_CQPSQ_TPHEN) |
  1157. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1158. i40iw_insert_wqe_hdr(wqe, header);
  1159. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CEQ_CREATE WQE",
  1160. wqe, I40IW_CQP_WQE_SIZE * 8);
  1161. if (post_sq)
  1162. i40iw_sc_cqp_post_sq(cqp);
  1163. return 0;
  1164. }
  1165. /**
  1166. * i40iw_sc_cceq_create_done - poll for control ceq wqe to complete
  1167. * @ceq: ceq sc structure
  1168. */
  1169. static enum i40iw_status_code i40iw_sc_cceq_create_done(struct i40iw_sc_ceq *ceq)
  1170. {
  1171. struct i40iw_sc_cqp *cqp;
  1172. cqp = ceq->dev->cqp;
  1173. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_CEQ, NULL);
  1174. }
  1175. /**
  1176. * i40iw_sc_cceq_destroy_done - poll for destroy cceq to complete
  1177. * @ceq: ceq sc structure
  1178. */
  1179. static enum i40iw_status_code i40iw_sc_cceq_destroy_done(struct i40iw_sc_ceq *ceq)
  1180. {
  1181. struct i40iw_sc_cqp *cqp;
  1182. cqp = ceq->dev->cqp;
  1183. cqp->process_cqp_sds = i40iw_update_sds_noccq;
  1184. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_DESTROY_CEQ, NULL);
  1185. }
  1186. /**
  1187. * i40iw_sc_cceq_create - create cceq
  1188. * @ceq: ceq sc structure
  1189. * @scratch: u64 saved to be used during cqp completion
  1190. */
  1191. static enum i40iw_status_code i40iw_sc_cceq_create(struct i40iw_sc_ceq *ceq, u64 scratch)
  1192. {
  1193. enum i40iw_status_code ret_code;
  1194. ret_code = i40iw_sc_ceq_create(ceq, scratch, true);
  1195. if (!ret_code)
  1196. ret_code = i40iw_sc_cceq_create_done(ceq);
  1197. return ret_code;
  1198. }
  1199. /**
  1200. * i40iw_sc_ceq_destroy - destroy ceq
  1201. * @ceq: ceq sc structure
  1202. * @scratch: u64 saved to be used during cqp completion
  1203. * @post_sq: flag for cqp db to ring
  1204. */
  1205. static enum i40iw_status_code i40iw_sc_ceq_destroy(struct i40iw_sc_ceq *ceq,
  1206. u64 scratch,
  1207. bool post_sq)
  1208. {
  1209. struct i40iw_sc_cqp *cqp;
  1210. u64 *wqe;
  1211. u64 header;
  1212. cqp = ceq->dev->cqp;
  1213. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1214. if (!wqe)
  1215. return I40IW_ERR_RING_FULL;
  1216. set_64bit_val(wqe, 16, ceq->elem_cnt);
  1217. set_64bit_val(wqe, 48, ceq->first_pm_pbl_idx);
  1218. header = ceq->ceq_id |
  1219. LS_64(I40IW_CQP_OP_DESTROY_CEQ, I40IW_CQPSQ_OPCODE) |
  1220. LS_64(ceq->pbl_chunk_size, I40IW_CQPSQ_CEQ_LPBLSIZE) |
  1221. LS_64(ceq->virtual_map, I40IW_CQPSQ_CEQ_VMAP) |
  1222. LS_64(ceq->tph_en, I40IW_CQPSQ_TPHEN) |
  1223. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1224. i40iw_insert_wqe_hdr(wqe, header);
  1225. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CEQ_DESTROY WQE",
  1226. wqe, I40IW_CQP_WQE_SIZE * 8);
  1227. if (post_sq)
  1228. i40iw_sc_cqp_post_sq(cqp);
  1229. return 0;
  1230. }
  1231. /**
  1232. * i40iw_sc_process_ceq - process ceq
  1233. * @dev: sc device struct
  1234. * @ceq: ceq sc structure
  1235. */
  1236. static void *i40iw_sc_process_ceq(struct i40iw_sc_dev *dev, struct i40iw_sc_ceq *ceq)
  1237. {
  1238. u64 temp;
  1239. u64 *ceqe;
  1240. struct i40iw_sc_cq *cq = NULL;
  1241. u8 polarity;
  1242. ceqe = (u64 *)I40IW_GET_CURRENT_CEQ_ELEMENT(ceq);
  1243. get_64bit_val(ceqe, 0, &temp);
  1244. polarity = (u8)RS_64(temp, I40IW_CEQE_VALID);
  1245. if (polarity != ceq->polarity)
  1246. return cq;
  1247. cq = (struct i40iw_sc_cq *)(unsigned long)LS_64_1(temp, 1);
  1248. I40IW_RING_MOVE_TAIL(ceq->ceq_ring);
  1249. if (I40IW_RING_GETCURRENT_TAIL(ceq->ceq_ring) == 0)
  1250. ceq->polarity ^= 1;
  1251. if (dev->is_pf)
  1252. i40iw_wr32(dev->hw, I40E_PFPE_CQACK, cq->cq_uk.cq_id);
  1253. else
  1254. i40iw_wr32(dev->hw, I40E_VFPE_CQACK1, cq->cq_uk.cq_id);
  1255. return cq;
  1256. }
  1257. /**
  1258. * i40iw_sc_aeq_init - initialize aeq
  1259. * @aeq: aeq structure ptr
  1260. * @info: aeq initialization info
  1261. */
  1262. static enum i40iw_status_code i40iw_sc_aeq_init(struct i40iw_sc_aeq *aeq,
  1263. struct i40iw_aeq_init_info *info)
  1264. {
  1265. u32 pble_obj_cnt;
  1266. if ((info->elem_cnt < I40IW_MIN_AEQ_ENTRIES) ||
  1267. (info->elem_cnt > I40IW_MAX_AEQ_ENTRIES))
  1268. return I40IW_ERR_INVALID_SIZE;
  1269. pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  1270. if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
  1271. return I40IW_ERR_INVALID_PBLE_INDEX;
  1272. aeq->size = sizeof(*aeq);
  1273. aeq->polarity = 1;
  1274. aeq->aeqe_base = (struct i40iw_sc_aeqe *)info->aeqe_base;
  1275. aeq->dev = info->dev;
  1276. aeq->elem_cnt = info->elem_cnt;
  1277. aeq->aeq_elem_pa = info->aeq_elem_pa;
  1278. I40IW_RING_INIT(aeq->aeq_ring, aeq->elem_cnt);
  1279. info->dev->aeq = aeq;
  1280. aeq->virtual_map = info->virtual_map;
  1281. aeq->pbl_list = (aeq->virtual_map ? info->pbl_list : NULL);
  1282. aeq->pbl_chunk_size = (aeq->virtual_map ? info->pbl_chunk_size : 0);
  1283. aeq->first_pm_pbl_idx = (aeq->virtual_map ? info->first_pm_pbl_idx : 0);
  1284. info->dev->aeq = aeq;
  1285. return 0;
  1286. }
  1287. /**
  1288. * i40iw_sc_aeq_create - create aeq
  1289. * @aeq: aeq structure ptr
  1290. * @scratch: u64 saved to be used during cqp completion
  1291. * @post_sq: flag for cqp db to ring
  1292. */
  1293. static enum i40iw_status_code i40iw_sc_aeq_create(struct i40iw_sc_aeq *aeq,
  1294. u64 scratch,
  1295. bool post_sq)
  1296. {
  1297. u64 *wqe;
  1298. struct i40iw_sc_cqp *cqp;
  1299. u64 header;
  1300. cqp = aeq->dev->cqp;
  1301. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1302. if (!wqe)
  1303. return I40IW_ERR_RING_FULL;
  1304. set_64bit_val(wqe, 16, aeq->elem_cnt);
  1305. set_64bit_val(wqe, 32,
  1306. (aeq->virtual_map ? 0 : aeq->aeq_elem_pa));
  1307. set_64bit_val(wqe, 48,
  1308. (aeq->virtual_map ? aeq->first_pm_pbl_idx : 0));
  1309. header = LS_64(I40IW_CQP_OP_CREATE_AEQ, I40IW_CQPSQ_OPCODE) |
  1310. LS_64(aeq->pbl_chunk_size, I40IW_CQPSQ_AEQ_LPBLSIZE) |
  1311. LS_64(aeq->virtual_map, I40IW_CQPSQ_AEQ_VMAP) |
  1312. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1313. i40iw_insert_wqe_hdr(wqe, header);
  1314. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "AEQ_CREATE WQE",
  1315. wqe, I40IW_CQP_WQE_SIZE * 8);
  1316. if (post_sq)
  1317. i40iw_sc_cqp_post_sq(cqp);
  1318. return 0;
  1319. }
  1320. /**
  1321. * i40iw_sc_aeq_destroy - destroy aeq during close
  1322. * @aeq: aeq structure ptr
  1323. * @scratch: u64 saved to be used during cqp completion
  1324. * @post_sq: flag for cqp db to ring
  1325. */
  1326. static enum i40iw_status_code i40iw_sc_aeq_destroy(struct i40iw_sc_aeq *aeq,
  1327. u64 scratch,
  1328. bool post_sq)
  1329. {
  1330. u64 *wqe;
  1331. struct i40iw_sc_cqp *cqp;
  1332. u64 header;
  1333. cqp = aeq->dev->cqp;
  1334. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1335. if (!wqe)
  1336. return I40IW_ERR_RING_FULL;
  1337. set_64bit_val(wqe, 16, aeq->elem_cnt);
  1338. set_64bit_val(wqe, 48, aeq->first_pm_pbl_idx);
  1339. header = LS_64(I40IW_CQP_OP_DESTROY_AEQ, I40IW_CQPSQ_OPCODE) |
  1340. LS_64(aeq->pbl_chunk_size, I40IW_CQPSQ_AEQ_LPBLSIZE) |
  1341. LS_64(aeq->virtual_map, I40IW_CQPSQ_AEQ_VMAP) |
  1342. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1343. i40iw_insert_wqe_hdr(wqe, header);
  1344. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "AEQ_DESTROY WQE",
  1345. wqe, I40IW_CQP_WQE_SIZE * 8);
  1346. if (post_sq)
  1347. i40iw_sc_cqp_post_sq(cqp);
  1348. return 0;
  1349. }
  1350. /**
  1351. * i40iw_sc_get_next_aeqe - get next aeq entry
  1352. * @aeq: aeq structure ptr
  1353. * @info: aeqe info to be returned
  1354. */
  1355. static enum i40iw_status_code i40iw_sc_get_next_aeqe(struct i40iw_sc_aeq *aeq,
  1356. struct i40iw_aeqe_info *info)
  1357. {
  1358. u64 temp, compl_ctx;
  1359. u64 *aeqe;
  1360. u16 wqe_idx;
  1361. u8 ae_src;
  1362. u8 polarity;
  1363. aeqe = (u64 *)I40IW_GET_CURRENT_AEQ_ELEMENT(aeq);
  1364. get_64bit_val(aeqe, 0, &compl_ctx);
  1365. get_64bit_val(aeqe, 8, &temp);
  1366. polarity = (u8)RS_64(temp, I40IW_AEQE_VALID);
  1367. if (aeq->polarity != polarity)
  1368. return I40IW_ERR_QUEUE_EMPTY;
  1369. i40iw_debug_buf(aeq->dev, I40IW_DEBUG_WQE, "AEQ_ENTRY", aeqe, 16);
  1370. ae_src = (u8)RS_64(temp, I40IW_AEQE_AESRC);
  1371. wqe_idx = (u16)RS_64(temp, I40IW_AEQE_WQDESCIDX);
  1372. info->qp_cq_id = (u32)RS_64(temp, I40IW_AEQE_QPCQID);
  1373. info->ae_id = (u16)RS_64(temp, I40IW_AEQE_AECODE);
  1374. info->tcp_state = (u8)RS_64(temp, I40IW_AEQE_TCPSTATE);
  1375. info->iwarp_state = (u8)RS_64(temp, I40IW_AEQE_IWSTATE);
  1376. info->q2_data_written = (u8)RS_64(temp, I40IW_AEQE_Q2DATA);
  1377. info->aeqe_overflow = (bool)RS_64(temp, I40IW_AEQE_OVERFLOW);
  1378. switch (ae_src) {
  1379. case I40IW_AE_SOURCE_RQ:
  1380. case I40IW_AE_SOURCE_RQ_0011:
  1381. info->qp = true;
  1382. info->wqe_idx = wqe_idx;
  1383. info->compl_ctx = compl_ctx;
  1384. break;
  1385. case I40IW_AE_SOURCE_CQ:
  1386. case I40IW_AE_SOURCE_CQ_0110:
  1387. case I40IW_AE_SOURCE_CQ_1010:
  1388. case I40IW_AE_SOURCE_CQ_1110:
  1389. info->cq = true;
  1390. info->compl_ctx = LS_64_1(compl_ctx, 1);
  1391. break;
  1392. case I40IW_AE_SOURCE_SQ:
  1393. case I40IW_AE_SOURCE_SQ_0111:
  1394. info->qp = true;
  1395. info->sq = true;
  1396. info->wqe_idx = wqe_idx;
  1397. info->compl_ctx = compl_ctx;
  1398. break;
  1399. case I40IW_AE_SOURCE_IN_RR_WR:
  1400. case I40IW_AE_SOURCE_IN_RR_WR_1011:
  1401. info->qp = true;
  1402. info->compl_ctx = compl_ctx;
  1403. info->in_rdrsp_wr = true;
  1404. break;
  1405. case I40IW_AE_SOURCE_OUT_RR:
  1406. case I40IW_AE_SOURCE_OUT_RR_1111:
  1407. info->qp = true;
  1408. info->compl_ctx = compl_ctx;
  1409. info->out_rdrsp = true;
  1410. break;
  1411. default:
  1412. break;
  1413. }
  1414. I40IW_RING_MOVE_TAIL(aeq->aeq_ring);
  1415. if (I40IW_RING_GETCURRENT_TAIL(aeq->aeq_ring) == 0)
  1416. aeq->polarity ^= 1;
  1417. return 0;
  1418. }
  1419. /**
  1420. * i40iw_sc_repost_aeq_entries - repost completed aeq entries
  1421. * @dev: sc device struct
  1422. * @count: allocate count
  1423. */
  1424. static enum i40iw_status_code i40iw_sc_repost_aeq_entries(struct i40iw_sc_dev *dev,
  1425. u32 count)
  1426. {
  1427. if (count > I40IW_MAX_AEQ_ALLOCATE_COUNT)
  1428. return I40IW_ERR_INVALID_SIZE;
  1429. if (dev->is_pf)
  1430. i40iw_wr32(dev->hw, I40E_PFPE_AEQALLOC, count);
  1431. else
  1432. i40iw_wr32(dev->hw, I40E_VFPE_AEQALLOC1, count);
  1433. return 0;
  1434. }
  1435. /**
  1436. * i40iw_sc_aeq_create_done - create aeq
  1437. * @aeq: aeq structure ptr
  1438. */
  1439. static enum i40iw_status_code i40iw_sc_aeq_create_done(struct i40iw_sc_aeq *aeq)
  1440. {
  1441. struct i40iw_sc_cqp *cqp;
  1442. cqp = aeq->dev->cqp;
  1443. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_AEQ, NULL);
  1444. }
  1445. /**
  1446. * i40iw_sc_aeq_destroy_done - destroy of aeq during close
  1447. * @aeq: aeq structure ptr
  1448. */
  1449. static enum i40iw_status_code i40iw_sc_aeq_destroy_done(struct i40iw_sc_aeq *aeq)
  1450. {
  1451. struct i40iw_sc_cqp *cqp;
  1452. cqp = aeq->dev->cqp;
  1453. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_DESTROY_AEQ, NULL);
  1454. }
  1455. /**
  1456. * i40iw_sc_ccq_init - initialize control cq
  1457. * @cq: sc's cq ctruct
  1458. * @info: info for control cq initialization
  1459. */
  1460. static enum i40iw_status_code i40iw_sc_ccq_init(struct i40iw_sc_cq *cq,
  1461. struct i40iw_ccq_init_info *info)
  1462. {
  1463. u32 pble_obj_cnt;
  1464. if (info->num_elem < I40IW_MIN_CQ_SIZE || info->num_elem > I40IW_MAX_CQ_SIZE)
  1465. return I40IW_ERR_INVALID_SIZE;
  1466. if (info->ceq_id > I40IW_MAX_CEQID)
  1467. return I40IW_ERR_INVALID_CEQ_ID;
  1468. pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  1469. if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
  1470. return I40IW_ERR_INVALID_PBLE_INDEX;
  1471. cq->cq_pa = info->cq_pa;
  1472. cq->cq_uk.cq_base = info->cq_base;
  1473. cq->shadow_area_pa = info->shadow_area_pa;
  1474. cq->cq_uk.shadow_area = info->shadow_area;
  1475. cq->shadow_read_threshold = info->shadow_read_threshold;
  1476. cq->dev = info->dev;
  1477. cq->ceq_id = info->ceq_id;
  1478. cq->cq_uk.cq_size = info->num_elem;
  1479. cq->cq_type = I40IW_CQ_TYPE_CQP;
  1480. cq->ceqe_mask = info->ceqe_mask;
  1481. I40IW_RING_INIT(cq->cq_uk.cq_ring, info->num_elem);
  1482. cq->cq_uk.cq_id = 0; /* control cq is id 0 always */
  1483. cq->ceq_id_valid = info->ceq_id_valid;
  1484. cq->tph_en = info->tph_en;
  1485. cq->tph_val = info->tph_val;
  1486. cq->cq_uk.avoid_mem_cflct = info->avoid_mem_cflct;
  1487. cq->pbl_list = info->pbl_list;
  1488. cq->virtual_map = info->virtual_map;
  1489. cq->pbl_chunk_size = info->pbl_chunk_size;
  1490. cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
  1491. cq->cq_uk.polarity = true;
  1492. /* following are only for iw cqs so initialize them to zero */
  1493. cq->cq_uk.cqe_alloc_reg = NULL;
  1494. info->dev->ccq = cq;
  1495. return 0;
  1496. }
  1497. /**
  1498. * i40iw_sc_ccq_create_done - poll cqp for ccq create
  1499. * @ccq: ccq sc struct
  1500. */
  1501. static enum i40iw_status_code i40iw_sc_ccq_create_done(struct i40iw_sc_cq *ccq)
  1502. {
  1503. struct i40iw_sc_cqp *cqp;
  1504. cqp = ccq->dev->cqp;
  1505. return i40iw_sc_poll_for_cqp_op_done(cqp, I40IW_CQP_OP_CREATE_CQ, NULL);
  1506. }
  1507. /**
  1508. * i40iw_sc_ccq_create - create control cq
  1509. * @ccq: ccq sc struct
  1510. * @scratch: u64 saved to be used during cqp completion
  1511. * @check_overflow: overlow flag for ccq
  1512. * @post_sq: flag for cqp db to ring
  1513. */
  1514. static enum i40iw_status_code i40iw_sc_ccq_create(struct i40iw_sc_cq *ccq,
  1515. u64 scratch,
  1516. bool check_overflow,
  1517. bool post_sq)
  1518. {
  1519. u64 *wqe;
  1520. struct i40iw_sc_cqp *cqp;
  1521. u64 header;
  1522. enum i40iw_status_code ret_code;
  1523. cqp = ccq->dev->cqp;
  1524. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1525. if (!wqe)
  1526. return I40IW_ERR_RING_FULL;
  1527. set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
  1528. set_64bit_val(wqe, 8, RS_64_1(ccq, 1));
  1529. set_64bit_val(wqe, 16,
  1530. LS_64(ccq->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
  1531. set_64bit_val(wqe, 32, (ccq->virtual_map ? 0 : ccq->cq_pa));
  1532. set_64bit_val(wqe, 40, ccq->shadow_area_pa);
  1533. set_64bit_val(wqe, 48,
  1534. (ccq->virtual_map ? ccq->first_pm_pbl_idx : 0));
  1535. set_64bit_val(wqe, 56,
  1536. LS_64(ccq->tph_val, I40IW_CQPSQ_TPHVAL));
  1537. header = ccq->cq_uk.cq_id |
  1538. LS_64((ccq->ceq_id_valid ? ccq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
  1539. LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
  1540. LS_64(ccq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
  1541. LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
  1542. LS_64(ccq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
  1543. LS_64(ccq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
  1544. LS_64(ccq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
  1545. LS_64(ccq->tph_en, I40IW_CQPSQ_TPHEN) |
  1546. LS_64(ccq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
  1547. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1548. i40iw_insert_wqe_hdr(wqe, header);
  1549. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CCQ_CREATE WQE",
  1550. wqe, I40IW_CQP_WQE_SIZE * 8);
  1551. if (post_sq) {
  1552. i40iw_sc_cqp_post_sq(cqp);
  1553. ret_code = i40iw_sc_ccq_create_done(ccq);
  1554. if (ret_code)
  1555. return ret_code;
  1556. }
  1557. cqp->process_cqp_sds = i40iw_cqp_sds_cmd;
  1558. return 0;
  1559. }
  1560. /**
  1561. * i40iw_sc_ccq_destroy - destroy ccq during close
  1562. * @ccq: ccq sc struct
  1563. * @scratch: u64 saved to be used during cqp completion
  1564. * @post_sq: flag for cqp db to ring
  1565. */
  1566. static enum i40iw_status_code i40iw_sc_ccq_destroy(struct i40iw_sc_cq *ccq,
  1567. u64 scratch,
  1568. bool post_sq)
  1569. {
  1570. struct i40iw_sc_cqp *cqp;
  1571. u64 *wqe;
  1572. u64 header;
  1573. enum i40iw_status_code ret_code = 0;
  1574. u32 tail, val, error;
  1575. cqp = ccq->dev->cqp;
  1576. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1577. if (!wqe)
  1578. return I40IW_ERR_RING_FULL;
  1579. set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
  1580. set_64bit_val(wqe, 8, RS_64_1(ccq, 1));
  1581. set_64bit_val(wqe, 40, ccq->shadow_area_pa);
  1582. header = ccq->cq_uk.cq_id |
  1583. LS_64((ccq->ceq_id_valid ? ccq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
  1584. LS_64(I40IW_CQP_OP_DESTROY_CQ, I40IW_CQPSQ_OPCODE) |
  1585. LS_64(ccq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
  1586. LS_64(ccq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
  1587. LS_64(ccq->tph_en, I40IW_CQPSQ_TPHEN) |
  1588. LS_64(ccq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
  1589. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1590. i40iw_insert_wqe_hdr(wqe, header);
  1591. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CCQ_DESTROY WQE",
  1592. wqe, I40IW_CQP_WQE_SIZE * 8);
  1593. i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
  1594. if (error)
  1595. return I40IW_ERR_CQP_COMPL_ERROR;
  1596. if (post_sq) {
  1597. i40iw_sc_cqp_post_sq(cqp);
  1598. ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000);
  1599. }
  1600. return ret_code;
  1601. }
  1602. /**
  1603. * i40iw_sc_cq_init - initialize completion q
  1604. * @cq: cq struct
  1605. * @info: cq initialization info
  1606. */
  1607. static enum i40iw_status_code i40iw_sc_cq_init(struct i40iw_sc_cq *cq,
  1608. struct i40iw_cq_init_info *info)
  1609. {
  1610. u32 __iomem *cqe_alloc_reg = NULL;
  1611. enum i40iw_status_code ret_code;
  1612. u32 pble_obj_cnt;
  1613. u32 arm_offset;
  1614. pble_obj_cnt = info->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  1615. if (info->virtual_map && (info->first_pm_pbl_idx >= pble_obj_cnt))
  1616. return I40IW_ERR_INVALID_PBLE_INDEX;
  1617. cq->cq_pa = info->cq_base_pa;
  1618. cq->dev = info->dev;
  1619. cq->ceq_id = info->ceq_id;
  1620. arm_offset = (info->dev->is_pf) ? I40E_PFPE_CQARM : I40E_VFPE_CQARM1;
  1621. if (i40iw_get_hw_addr(cq->dev))
  1622. cqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(cq->dev) +
  1623. arm_offset);
  1624. info->cq_uk_init_info.cqe_alloc_reg = cqe_alloc_reg;
  1625. ret_code = i40iw_cq_uk_init(&cq->cq_uk, &info->cq_uk_init_info);
  1626. if (ret_code)
  1627. return ret_code;
  1628. cq->virtual_map = info->virtual_map;
  1629. cq->pbl_chunk_size = info->pbl_chunk_size;
  1630. cq->ceqe_mask = info->ceqe_mask;
  1631. cq->cq_type = (info->type) ? info->type : I40IW_CQ_TYPE_IWARP;
  1632. cq->shadow_area_pa = info->shadow_area_pa;
  1633. cq->shadow_read_threshold = info->shadow_read_threshold;
  1634. cq->ceq_id_valid = info->ceq_id_valid;
  1635. cq->tph_en = info->tph_en;
  1636. cq->tph_val = info->tph_val;
  1637. cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
  1638. return 0;
  1639. }
  1640. /**
  1641. * i40iw_sc_cq_create - create completion q
  1642. * @cq: cq struct
  1643. * @scratch: u64 saved to be used during cqp completion
  1644. * @check_overflow: flag for overflow check
  1645. * @post_sq: flag for cqp db to ring
  1646. */
  1647. static enum i40iw_status_code i40iw_sc_cq_create(struct i40iw_sc_cq *cq,
  1648. u64 scratch,
  1649. bool check_overflow,
  1650. bool post_sq)
  1651. {
  1652. u64 *wqe;
  1653. struct i40iw_sc_cqp *cqp;
  1654. u64 header;
  1655. if (cq->cq_uk.cq_id > I40IW_MAX_CQID)
  1656. return I40IW_ERR_INVALID_CQ_ID;
  1657. if (cq->ceq_id > I40IW_MAX_CEQID)
  1658. return I40IW_ERR_INVALID_CEQ_ID;
  1659. cqp = cq->dev->cqp;
  1660. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1661. if (!wqe)
  1662. return I40IW_ERR_RING_FULL;
  1663. set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
  1664. set_64bit_val(wqe, 8, RS_64_1(cq, 1));
  1665. set_64bit_val(wqe,
  1666. 16,
  1667. LS_64(cq->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
  1668. set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
  1669. set_64bit_val(wqe, 40, cq->shadow_area_pa);
  1670. set_64bit_val(wqe, 48, (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
  1671. set_64bit_val(wqe, 56, LS_64(cq->tph_val, I40IW_CQPSQ_TPHVAL));
  1672. header = cq->cq_uk.cq_id |
  1673. LS_64((cq->ceq_id_valid ? cq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
  1674. LS_64(I40IW_CQP_OP_CREATE_CQ, I40IW_CQPSQ_OPCODE) |
  1675. LS_64(cq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
  1676. LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
  1677. LS_64(cq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
  1678. LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
  1679. LS_64(cq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
  1680. LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
  1681. LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
  1682. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1683. i40iw_insert_wqe_hdr(wqe, header);
  1684. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_CREATE WQE",
  1685. wqe, I40IW_CQP_WQE_SIZE * 8);
  1686. if (post_sq)
  1687. i40iw_sc_cqp_post_sq(cqp);
  1688. return 0;
  1689. }
  1690. /**
  1691. * i40iw_sc_cq_destroy - destroy completion q
  1692. * @cq: cq struct
  1693. * @scratch: u64 saved to be used during cqp completion
  1694. * @post_sq: flag for cqp db to ring
  1695. */
  1696. static enum i40iw_status_code i40iw_sc_cq_destroy(struct i40iw_sc_cq *cq,
  1697. u64 scratch,
  1698. bool post_sq)
  1699. {
  1700. struct i40iw_sc_cqp *cqp;
  1701. u64 *wqe;
  1702. u64 header;
  1703. cqp = cq->dev->cqp;
  1704. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1705. if (!wqe)
  1706. return I40IW_ERR_RING_FULL;
  1707. set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
  1708. set_64bit_val(wqe, 8, RS_64_1(cq, 1));
  1709. set_64bit_val(wqe, 40, cq->shadow_area_pa);
  1710. set_64bit_val(wqe, 48, (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
  1711. header = cq->cq_uk.cq_id |
  1712. LS_64((cq->ceq_id_valid ? cq->ceq_id : 0), I40IW_CQPSQ_CQ_CEQID) |
  1713. LS_64(I40IW_CQP_OP_DESTROY_CQ, I40IW_CQPSQ_OPCODE) |
  1714. LS_64(cq->pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
  1715. LS_64(cq->virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
  1716. LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
  1717. LS_64(cq->ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
  1718. LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
  1719. LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
  1720. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1721. i40iw_insert_wqe_hdr(wqe, header);
  1722. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_DESTROY WQE",
  1723. wqe, I40IW_CQP_WQE_SIZE * 8);
  1724. if (post_sq)
  1725. i40iw_sc_cqp_post_sq(cqp);
  1726. return 0;
  1727. }
  1728. /**
  1729. * i40iw_sc_cq_modify - modify a Completion Queue
  1730. * @cq: cq struct
  1731. * @info: modification info struct
  1732. * @scratch:
  1733. * @post_sq: flag to post to sq
  1734. */
  1735. static enum i40iw_status_code i40iw_sc_cq_modify(struct i40iw_sc_cq *cq,
  1736. struct i40iw_modify_cq_info *info,
  1737. u64 scratch,
  1738. bool post_sq)
  1739. {
  1740. struct i40iw_sc_cqp *cqp;
  1741. u64 *wqe;
  1742. u64 header;
  1743. u32 cq_size, ceq_id, first_pm_pbl_idx;
  1744. u8 pbl_chunk_size;
  1745. bool virtual_map, ceq_id_valid, check_overflow;
  1746. u32 pble_obj_cnt;
  1747. if (info->ceq_valid && (info->ceq_id > I40IW_MAX_CEQID))
  1748. return I40IW_ERR_INVALID_CEQ_ID;
  1749. pble_obj_cnt = cq->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  1750. if (info->cq_resize && info->virtual_map &&
  1751. (info->first_pm_pbl_idx >= pble_obj_cnt))
  1752. return I40IW_ERR_INVALID_PBLE_INDEX;
  1753. cqp = cq->dev->cqp;
  1754. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1755. if (!wqe)
  1756. return I40IW_ERR_RING_FULL;
  1757. cq->pbl_list = info->pbl_list;
  1758. cq->cq_pa = info->cq_pa;
  1759. cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
  1760. cq_size = info->cq_resize ? info->cq_size : cq->cq_uk.cq_size;
  1761. if (info->ceq_change) {
  1762. ceq_id_valid = true;
  1763. ceq_id = info->ceq_id;
  1764. } else {
  1765. ceq_id_valid = cq->ceq_id_valid;
  1766. ceq_id = ceq_id_valid ? cq->ceq_id : 0;
  1767. }
  1768. virtual_map = info->cq_resize ? info->virtual_map : cq->virtual_map;
  1769. first_pm_pbl_idx = (info->cq_resize ?
  1770. (info->virtual_map ? info->first_pm_pbl_idx : 0) :
  1771. (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
  1772. pbl_chunk_size = (info->cq_resize ?
  1773. (info->virtual_map ? info->pbl_chunk_size : 0) :
  1774. (cq->virtual_map ? cq->pbl_chunk_size : 0));
  1775. check_overflow = info->check_overflow_change ? info->check_overflow :
  1776. cq->check_overflow;
  1777. cq->cq_uk.cq_size = cq_size;
  1778. cq->ceq_id_valid = ceq_id_valid;
  1779. cq->ceq_id = ceq_id;
  1780. cq->virtual_map = virtual_map;
  1781. cq->first_pm_pbl_idx = first_pm_pbl_idx;
  1782. cq->pbl_chunk_size = pbl_chunk_size;
  1783. cq->check_overflow = check_overflow;
  1784. set_64bit_val(wqe, 0, cq_size);
  1785. set_64bit_val(wqe, 8, RS_64_1(cq, 1));
  1786. set_64bit_val(wqe, 16,
  1787. LS_64(info->shadow_read_threshold, I40IW_CQPSQ_CQ_SHADOW_READ_THRESHOLD));
  1788. set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
  1789. set_64bit_val(wqe, 40, cq->shadow_area_pa);
  1790. set_64bit_val(wqe, 48, (cq->virtual_map ? first_pm_pbl_idx : 0));
  1791. set_64bit_val(wqe, 56, LS_64(cq->tph_val, I40IW_CQPSQ_TPHVAL));
  1792. header = cq->cq_uk.cq_id |
  1793. LS_64(ceq_id, I40IW_CQPSQ_CQ_CEQID) |
  1794. LS_64(I40IW_CQP_OP_MODIFY_CQ, I40IW_CQPSQ_OPCODE) |
  1795. LS_64(info->cq_resize, I40IW_CQPSQ_CQ_CQRESIZE) |
  1796. LS_64(pbl_chunk_size, I40IW_CQPSQ_CQ_LPBLSIZE) |
  1797. LS_64(check_overflow, I40IW_CQPSQ_CQ_CHKOVERFLOW) |
  1798. LS_64(virtual_map, I40IW_CQPSQ_CQ_VIRTMAP) |
  1799. LS_64(cq->ceqe_mask, I40IW_CQPSQ_CQ_ENCEQEMASK) |
  1800. LS_64(ceq_id_valid, I40IW_CQPSQ_CQ_CEQIDVALID) |
  1801. LS_64(cq->tph_en, I40IW_CQPSQ_TPHEN) |
  1802. LS_64(cq->cq_uk.avoid_mem_cflct, I40IW_CQPSQ_CQ_AVOIDMEMCNFLCT) |
  1803. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1804. i40iw_insert_wqe_hdr(wqe, header);
  1805. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "CQ_MODIFY WQE",
  1806. wqe, I40IW_CQP_WQE_SIZE * 8);
  1807. if (post_sq)
  1808. i40iw_sc_cqp_post_sq(cqp);
  1809. return 0;
  1810. }
  1811. /**
  1812. * i40iw_sc_qp_init - initialize qp
  1813. * @qp: sc qp
  1814. * @info: initialization qp info
  1815. */
  1816. static enum i40iw_status_code i40iw_sc_qp_init(struct i40iw_sc_qp *qp,
  1817. struct i40iw_qp_init_info *info)
  1818. {
  1819. u32 __iomem *wqe_alloc_reg = NULL;
  1820. enum i40iw_status_code ret_code;
  1821. u32 pble_obj_cnt;
  1822. u8 wqe_size;
  1823. u32 offset;
  1824. qp->dev = info->pd->dev;
  1825. qp->sq_pa = info->sq_pa;
  1826. qp->rq_pa = info->rq_pa;
  1827. qp->hw_host_ctx_pa = info->host_ctx_pa;
  1828. qp->q2_pa = info->q2_pa;
  1829. qp->shadow_area_pa = info->shadow_area_pa;
  1830. qp->q2_buf = info->q2;
  1831. qp->pd = info->pd;
  1832. qp->hw_host_ctx = info->host_ctx;
  1833. offset = (qp->pd->dev->is_pf) ? I40E_PFPE_WQEALLOC : I40E_VFPE_WQEALLOC1;
  1834. if (i40iw_get_hw_addr(qp->pd->dev))
  1835. wqe_alloc_reg = (u32 __iomem *)(i40iw_get_hw_addr(qp->pd->dev) +
  1836. offset);
  1837. info->qp_uk_init_info.wqe_alloc_reg = wqe_alloc_reg;
  1838. ret_code = i40iw_qp_uk_init(&qp->qp_uk, &info->qp_uk_init_info);
  1839. if (ret_code)
  1840. return ret_code;
  1841. qp->virtual_map = info->virtual_map;
  1842. pble_obj_cnt = info->pd->dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  1843. if ((info->virtual_map && (info->sq_pa >= pble_obj_cnt)) ||
  1844. (info->virtual_map && (info->rq_pa >= pble_obj_cnt)))
  1845. return I40IW_ERR_INVALID_PBLE_INDEX;
  1846. qp->llp_stream_handle = (void *)(-1);
  1847. qp->qp_type = (info->type) ? info->type : I40IW_QP_TYPE_IWARP;
  1848. qp->hw_sq_size = i40iw_get_encoded_wqe_size(qp->qp_uk.sq_ring.size,
  1849. false);
  1850. i40iw_debug(qp->dev, I40IW_DEBUG_WQE, "%s: hw_sq_size[%04d] sq_ring.size[%04d]\n",
  1851. __func__, qp->hw_sq_size, qp->qp_uk.sq_ring.size);
  1852. ret_code = i40iw_fragcnt_to_wqesize_rq(qp->qp_uk.max_rq_frag_cnt,
  1853. &wqe_size);
  1854. if (ret_code)
  1855. return ret_code;
  1856. qp->hw_rq_size = i40iw_get_encoded_wqe_size(qp->qp_uk.rq_size *
  1857. (wqe_size / I40IW_QP_WQE_MIN_SIZE), false);
  1858. i40iw_debug(qp->dev, I40IW_DEBUG_WQE,
  1859. "%s: hw_rq_size[%04d] qp_uk.rq_size[%04d] wqe_size[%04d]\n",
  1860. __func__, qp->hw_rq_size, qp->qp_uk.rq_size, wqe_size);
  1861. qp->sq_tph_val = info->sq_tph_val;
  1862. qp->rq_tph_val = info->rq_tph_val;
  1863. qp->sq_tph_en = info->sq_tph_en;
  1864. qp->rq_tph_en = info->rq_tph_en;
  1865. qp->rcv_tph_en = info->rcv_tph_en;
  1866. qp->xmit_tph_en = info->xmit_tph_en;
  1867. qp->qs_handle = qp->pd->dev->qs_handle;
  1868. qp->exception_lan_queue = qp->pd->dev->exception_lan_queue;
  1869. return 0;
  1870. }
  1871. /**
  1872. * i40iw_sc_qp_create - create qp
  1873. * @qp: sc qp
  1874. * @info: qp create info
  1875. * @scratch: u64 saved to be used during cqp completion
  1876. * @post_sq: flag for cqp db to ring
  1877. */
  1878. static enum i40iw_status_code i40iw_sc_qp_create(
  1879. struct i40iw_sc_qp *qp,
  1880. struct i40iw_create_qp_info *info,
  1881. u64 scratch,
  1882. bool post_sq)
  1883. {
  1884. struct i40iw_sc_cqp *cqp;
  1885. u64 *wqe;
  1886. u64 header;
  1887. if ((qp->qp_uk.qp_id < I40IW_MIN_IW_QP_ID) ||
  1888. (qp->qp_uk.qp_id > I40IW_MAX_IW_QP_ID))
  1889. return I40IW_ERR_INVALID_QP_ID;
  1890. cqp = qp->pd->dev->cqp;
  1891. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1892. if (!wqe)
  1893. return I40IW_ERR_RING_FULL;
  1894. set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
  1895. set_64bit_val(wqe, 40, qp->shadow_area_pa);
  1896. header = qp->qp_uk.qp_id |
  1897. LS_64(I40IW_CQP_OP_CREATE_QP, I40IW_CQPSQ_OPCODE) |
  1898. LS_64((info->ord_valid ? 1 : 0), I40IW_CQPSQ_QP_ORDVALID) |
  1899. LS_64(info->tcp_ctx_valid, I40IW_CQPSQ_QP_TOECTXVALID) |
  1900. LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
  1901. LS_64(qp->virtual_map, I40IW_CQPSQ_QP_VQ) |
  1902. LS_64(info->cq_num_valid, I40IW_CQPSQ_QP_CQNUMVALID) |
  1903. LS_64(info->static_rsrc, I40IW_CQPSQ_QP_STATRSRC) |
  1904. LS_64(info->arp_cache_idx_valid, I40IW_CQPSQ_QP_ARPTABIDXVALID) |
  1905. LS_64(info->next_iwarp_state, I40IW_CQPSQ_QP_NEXTIWSTATE) |
  1906. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1907. i40iw_insert_wqe_hdr(wqe, header);
  1908. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_CREATE WQE",
  1909. wqe, I40IW_CQP_WQE_SIZE * 8);
  1910. if (post_sq)
  1911. i40iw_sc_cqp_post_sq(cqp);
  1912. return 0;
  1913. }
  1914. /**
  1915. * i40iw_sc_qp_modify - modify qp cqp wqe
  1916. * @qp: sc qp
  1917. * @info: modify qp info
  1918. * @scratch: u64 saved to be used during cqp completion
  1919. * @post_sq: flag for cqp db to ring
  1920. */
  1921. static enum i40iw_status_code i40iw_sc_qp_modify(
  1922. struct i40iw_sc_qp *qp,
  1923. struct i40iw_modify_qp_info *info,
  1924. u64 scratch,
  1925. bool post_sq)
  1926. {
  1927. u64 *wqe;
  1928. struct i40iw_sc_cqp *cqp;
  1929. u64 header;
  1930. u8 term_actions = 0;
  1931. u8 term_len = 0;
  1932. cqp = qp->pd->dev->cqp;
  1933. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1934. if (!wqe)
  1935. return I40IW_ERR_RING_FULL;
  1936. if (info->next_iwarp_state == I40IW_QP_STATE_TERMINATE) {
  1937. if (info->dont_send_fin)
  1938. term_actions += I40IWQP_TERM_SEND_TERM_ONLY;
  1939. if (info->dont_send_term)
  1940. term_actions += I40IWQP_TERM_SEND_FIN_ONLY;
  1941. if ((term_actions == I40IWQP_TERM_SEND_TERM_AND_FIN) ||
  1942. (term_actions == I40IWQP_TERM_SEND_TERM_ONLY))
  1943. term_len = info->termlen;
  1944. }
  1945. set_64bit_val(wqe,
  1946. 8,
  1947. LS_64(info->new_mss, I40IW_CQPSQ_QP_NEWMSS) |
  1948. LS_64(term_len, I40IW_CQPSQ_QP_TERMLEN));
  1949. set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
  1950. set_64bit_val(wqe, 40, qp->shadow_area_pa);
  1951. header = qp->qp_uk.qp_id |
  1952. LS_64(I40IW_CQP_OP_MODIFY_QP, I40IW_CQPSQ_OPCODE) |
  1953. LS_64(info->ord_valid, I40IW_CQPSQ_QP_ORDVALID) |
  1954. LS_64(info->tcp_ctx_valid, I40IW_CQPSQ_QP_TOECTXVALID) |
  1955. LS_64(info->cached_var_valid, I40IW_CQPSQ_QP_CACHEDVARVALID) |
  1956. LS_64(qp->virtual_map, I40IW_CQPSQ_QP_VQ) |
  1957. LS_64(info->cq_num_valid, I40IW_CQPSQ_QP_CQNUMVALID) |
  1958. LS_64(info->force_loopback, I40IW_CQPSQ_QP_FORCELOOPBACK) |
  1959. LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
  1960. LS_64(info->mss_change, I40IW_CQPSQ_QP_MSSCHANGE) |
  1961. LS_64(info->static_rsrc, I40IW_CQPSQ_QP_STATRSRC) |
  1962. LS_64(info->remove_hash_idx, I40IW_CQPSQ_QP_REMOVEHASHENTRY) |
  1963. LS_64(term_actions, I40IW_CQPSQ_QP_TERMACT) |
  1964. LS_64(info->reset_tcp_conn, I40IW_CQPSQ_QP_RESETCON) |
  1965. LS_64(info->arp_cache_idx_valid, I40IW_CQPSQ_QP_ARPTABIDXVALID) |
  1966. LS_64(info->next_iwarp_state, I40IW_CQPSQ_QP_NEXTIWSTATE) |
  1967. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  1968. i40iw_insert_wqe_hdr(wqe, header);
  1969. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_MODIFY WQE",
  1970. wqe, I40IW_CQP_WQE_SIZE * 8);
  1971. if (post_sq)
  1972. i40iw_sc_cqp_post_sq(cqp);
  1973. return 0;
  1974. }
  1975. /**
  1976. * i40iw_sc_qp_destroy - cqp destroy qp
  1977. * @qp: sc qp
  1978. * @scratch: u64 saved to be used during cqp completion
  1979. * @remove_hash_idx: flag if to remove hash idx
  1980. * @ignore_mw_bnd: memory window bind flag
  1981. * @post_sq: flag for cqp db to ring
  1982. */
  1983. static enum i40iw_status_code i40iw_sc_qp_destroy(
  1984. struct i40iw_sc_qp *qp,
  1985. u64 scratch,
  1986. bool remove_hash_idx,
  1987. bool ignore_mw_bnd,
  1988. bool post_sq)
  1989. {
  1990. u64 *wqe;
  1991. struct i40iw_sc_cqp *cqp;
  1992. u64 header;
  1993. cqp = qp->pd->dev->cqp;
  1994. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  1995. if (!wqe)
  1996. return I40IW_ERR_RING_FULL;
  1997. set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
  1998. set_64bit_val(wqe, 40, qp->shadow_area_pa);
  1999. header = qp->qp_uk.qp_id |
  2000. LS_64(I40IW_CQP_OP_DESTROY_QP, I40IW_CQPSQ_OPCODE) |
  2001. LS_64(qp->qp_type, I40IW_CQPSQ_QP_QPTYPE) |
  2002. LS_64(ignore_mw_bnd, I40IW_CQPSQ_QP_IGNOREMWBOUND) |
  2003. LS_64(remove_hash_idx, I40IW_CQPSQ_QP_REMOVEHASHENTRY) |
  2004. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2005. i40iw_insert_wqe_hdr(wqe, header);
  2006. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_DESTROY WQE",
  2007. wqe, I40IW_CQP_WQE_SIZE * 8);
  2008. if (post_sq)
  2009. i40iw_sc_cqp_post_sq(cqp);
  2010. return 0;
  2011. }
  2012. /**
  2013. * i40iw_sc_qp_flush_wqes - flush qp's wqe
  2014. * @qp: sc qp
  2015. * @info: dlush information
  2016. * @scratch: u64 saved to be used during cqp completion
  2017. * @post_sq: flag for cqp db to ring
  2018. */
  2019. static enum i40iw_status_code i40iw_sc_qp_flush_wqes(
  2020. struct i40iw_sc_qp *qp,
  2021. struct i40iw_qp_flush_info *info,
  2022. u64 scratch,
  2023. bool post_sq)
  2024. {
  2025. u64 temp = 0;
  2026. u64 *wqe;
  2027. struct i40iw_sc_cqp *cqp;
  2028. u64 header;
  2029. bool flush_sq = false, flush_rq = false;
  2030. if (info->rq && !qp->flush_rq)
  2031. flush_rq = true;
  2032. if (info->sq && !qp->flush_sq)
  2033. flush_sq = true;
  2034. qp->flush_sq |= flush_sq;
  2035. qp->flush_rq |= flush_rq;
  2036. if (!flush_sq && !flush_rq) {
  2037. if (info->ae_code != I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR)
  2038. return 0;
  2039. }
  2040. cqp = qp->pd->dev->cqp;
  2041. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2042. if (!wqe)
  2043. return I40IW_ERR_RING_FULL;
  2044. if (info->userflushcode) {
  2045. if (flush_rq) {
  2046. temp |= LS_64(info->rq_minor_code, I40IW_CQPSQ_FWQE_RQMNERR) |
  2047. LS_64(info->rq_major_code, I40IW_CQPSQ_FWQE_RQMJERR);
  2048. }
  2049. if (flush_sq) {
  2050. temp |= LS_64(info->sq_minor_code, I40IW_CQPSQ_FWQE_SQMNERR) |
  2051. LS_64(info->sq_major_code, I40IW_CQPSQ_FWQE_SQMJERR);
  2052. }
  2053. }
  2054. set_64bit_val(wqe, 16, temp);
  2055. temp = (info->generate_ae) ?
  2056. info->ae_code | LS_64(info->ae_source, I40IW_CQPSQ_FWQE_AESOURCE) : 0;
  2057. set_64bit_val(wqe, 8, temp);
  2058. header = qp->qp_uk.qp_id |
  2059. LS_64(I40IW_CQP_OP_FLUSH_WQES, I40IW_CQPSQ_OPCODE) |
  2060. LS_64(info->generate_ae, I40IW_CQPSQ_FWQE_GENERATE_AE) |
  2061. LS_64(info->userflushcode, I40IW_CQPSQ_FWQE_USERFLCODE) |
  2062. LS_64(flush_sq, I40IW_CQPSQ_FWQE_FLUSHSQ) |
  2063. LS_64(flush_rq, I40IW_CQPSQ_FWQE_FLUSHRQ) |
  2064. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2065. i40iw_insert_wqe_hdr(wqe, header);
  2066. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "QP_FLUSH WQE",
  2067. wqe, I40IW_CQP_WQE_SIZE * 8);
  2068. if (post_sq)
  2069. i40iw_sc_cqp_post_sq(cqp);
  2070. return 0;
  2071. }
  2072. /**
  2073. * i40iw_sc_qp_upload_context - upload qp's context
  2074. * @dev: sc device struct
  2075. * @info: upload context info ptr for return
  2076. * @scratch: u64 saved to be used during cqp completion
  2077. * @post_sq: flag for cqp db to ring
  2078. */
  2079. static enum i40iw_status_code i40iw_sc_qp_upload_context(
  2080. struct i40iw_sc_dev *dev,
  2081. struct i40iw_upload_context_info *info,
  2082. u64 scratch,
  2083. bool post_sq)
  2084. {
  2085. u64 *wqe;
  2086. struct i40iw_sc_cqp *cqp;
  2087. u64 header;
  2088. cqp = dev->cqp;
  2089. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2090. if (!wqe)
  2091. return I40IW_ERR_RING_FULL;
  2092. set_64bit_val(wqe, 16, info->buf_pa);
  2093. header = LS_64(info->qp_id, I40IW_CQPSQ_UCTX_QPID) |
  2094. LS_64(I40IW_CQP_OP_UPLOAD_CONTEXT, I40IW_CQPSQ_OPCODE) |
  2095. LS_64(info->qp_type, I40IW_CQPSQ_UCTX_QPTYPE) |
  2096. LS_64(info->raw_format, I40IW_CQPSQ_UCTX_RAWFORMAT) |
  2097. LS_64(info->freeze_qp, I40IW_CQPSQ_UCTX_FREEZEQP) |
  2098. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2099. i40iw_insert_wqe_hdr(wqe, header);
  2100. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "QP_UPLOAD_CTX WQE",
  2101. wqe, I40IW_CQP_WQE_SIZE * 8);
  2102. if (post_sq)
  2103. i40iw_sc_cqp_post_sq(cqp);
  2104. return 0;
  2105. }
  2106. /**
  2107. * i40iw_sc_qp_setctx - set qp's context
  2108. * @qp: sc qp
  2109. * @qp_ctx: context ptr
  2110. * @info: ctx info
  2111. */
  2112. static enum i40iw_status_code i40iw_sc_qp_setctx(
  2113. struct i40iw_sc_qp *qp,
  2114. u64 *qp_ctx,
  2115. struct i40iw_qp_host_ctx_info *info)
  2116. {
  2117. struct i40iwarp_offload_info *iw;
  2118. struct i40iw_tcp_offload_info *tcp;
  2119. u64 qw0, qw3, qw7 = 0;
  2120. iw = info->iwarp_info;
  2121. tcp = info->tcp_info;
  2122. qw0 = LS_64(qp->qp_uk.rq_wqe_size, I40IWQPC_RQWQESIZE) |
  2123. LS_64(info->err_rq_idx_valid, I40IWQPC_ERR_RQ_IDX_VALID) |
  2124. LS_64(qp->rcv_tph_en, I40IWQPC_RCVTPHEN) |
  2125. LS_64(qp->xmit_tph_en, I40IWQPC_XMITTPHEN) |
  2126. LS_64(qp->rq_tph_en, I40IWQPC_RQTPHEN) |
  2127. LS_64(qp->sq_tph_en, I40IWQPC_SQTPHEN) |
  2128. LS_64(info->push_idx, I40IWQPC_PPIDX) |
  2129. LS_64(info->push_mode_en, I40IWQPC_PMENA);
  2130. set_64bit_val(qp_ctx, 8, qp->sq_pa);
  2131. set_64bit_val(qp_ctx, 16, qp->rq_pa);
  2132. qw3 = LS_64(qp->src_mac_addr_idx, I40IWQPC_SRCMACADDRIDX) |
  2133. LS_64(qp->hw_rq_size, I40IWQPC_RQSIZE) |
  2134. LS_64(qp->hw_sq_size, I40IWQPC_SQSIZE);
  2135. set_64bit_val(qp_ctx,
  2136. 128,
  2137. LS_64(info->err_rq_idx, I40IWQPC_ERR_RQ_IDX));
  2138. set_64bit_val(qp_ctx,
  2139. 136,
  2140. LS_64(info->send_cq_num, I40IWQPC_TXCQNUM) |
  2141. LS_64(info->rcv_cq_num, I40IWQPC_RXCQNUM));
  2142. set_64bit_val(qp_ctx,
  2143. 168,
  2144. LS_64(info->qp_compl_ctx, I40IWQPC_QPCOMPCTX));
  2145. set_64bit_val(qp_ctx,
  2146. 176,
  2147. LS_64(qp->sq_tph_val, I40IWQPC_SQTPHVAL) |
  2148. LS_64(qp->rq_tph_val, I40IWQPC_RQTPHVAL) |
  2149. LS_64(qp->qs_handle, I40IWQPC_QSHANDLE) |
  2150. LS_64(qp->exception_lan_queue, I40IWQPC_EXCEPTION_LAN_QUEUE));
  2151. if (info->iwarp_info_valid) {
  2152. qw0 |= LS_64(iw->ddp_ver, I40IWQPC_DDP_VER) |
  2153. LS_64(iw->rdmap_ver, I40IWQPC_RDMAP_VER);
  2154. qw7 |= LS_64(iw->pd_id, I40IWQPC_PDIDX);
  2155. set_64bit_val(qp_ctx, 144, qp->q2_pa);
  2156. set_64bit_val(qp_ctx,
  2157. 152,
  2158. LS_64(iw->last_byte_sent, I40IWQPC_LASTBYTESENT));
  2159. /*
  2160. * Hard-code IRD_SIZE to hw-limit, 128, in qpctx, i.e matching an
  2161. *advertisable IRD of 64
  2162. */
  2163. iw->ird_size = I40IW_QPCTX_ENCD_MAXIRD;
  2164. set_64bit_val(qp_ctx,
  2165. 160,
  2166. LS_64(iw->ord_size, I40IWQPC_ORDSIZE) |
  2167. LS_64(iw->ird_size, I40IWQPC_IRDSIZE) |
  2168. LS_64(iw->wr_rdresp_en, I40IWQPC_WRRDRSPOK) |
  2169. LS_64(iw->rd_enable, I40IWQPC_RDOK) |
  2170. LS_64(iw->snd_mark_en, I40IWQPC_SNDMARKERS) |
  2171. LS_64(iw->bind_en, I40IWQPC_BINDEN) |
  2172. LS_64(iw->fast_reg_en, I40IWQPC_FASTREGEN) |
  2173. LS_64(iw->priv_mode_en, I40IWQPC_PRIVEN) |
  2174. LS_64(1, I40IWQPC_IWARPMODE) |
  2175. LS_64(iw->rcv_mark_en, I40IWQPC_RCVMARKERS) |
  2176. LS_64(iw->align_hdrs, I40IWQPC_ALIGNHDRS) |
  2177. LS_64(iw->rcv_no_mpa_crc, I40IWQPC_RCVNOMPACRC) |
  2178. LS_64(iw->rcv_mark_offset, I40IWQPC_RCVMARKOFFSET) |
  2179. LS_64(iw->snd_mark_offset, I40IWQPC_SNDMARKOFFSET));
  2180. }
  2181. if (info->tcp_info_valid) {
  2182. qw0 |= LS_64(tcp->ipv4, I40IWQPC_IPV4) |
  2183. LS_64(tcp->no_nagle, I40IWQPC_NONAGLE) |
  2184. LS_64(tcp->insert_vlan_tag, I40IWQPC_INSERTVLANTAG) |
  2185. LS_64(tcp->time_stamp, I40IWQPC_TIMESTAMP) |
  2186. LS_64(tcp->cwnd_inc_limit, I40IWQPC_LIMIT) |
  2187. LS_64(tcp->drop_ooo_seg, I40IWQPC_DROPOOOSEG) |
  2188. LS_64(tcp->dup_ack_thresh, I40IWQPC_DUPACK_THRESH);
  2189. qw3 |= LS_64(tcp->ttl, I40IWQPC_TTL) |
  2190. LS_64(tcp->src_mac_addr_idx, I40IWQPC_SRCMACADDRIDX) |
  2191. LS_64(tcp->avoid_stretch_ack, I40IWQPC_AVOIDSTRETCHACK) |
  2192. LS_64(tcp->tos, I40IWQPC_TOS) |
  2193. LS_64(tcp->src_port, I40IWQPC_SRCPORTNUM) |
  2194. LS_64(tcp->dst_port, I40IWQPC_DESTPORTNUM);
  2195. qp->src_mac_addr_idx = tcp->src_mac_addr_idx;
  2196. set_64bit_val(qp_ctx,
  2197. 32,
  2198. LS_64(tcp->dest_ip_addr2, I40IWQPC_DESTIPADDR2) |
  2199. LS_64(tcp->dest_ip_addr3, I40IWQPC_DESTIPADDR3));
  2200. set_64bit_val(qp_ctx,
  2201. 40,
  2202. LS_64(tcp->dest_ip_addr0, I40IWQPC_DESTIPADDR0) |
  2203. LS_64(tcp->dest_ip_addr1, I40IWQPC_DESTIPADDR1));
  2204. set_64bit_val(qp_ctx,
  2205. 48,
  2206. LS_64(tcp->snd_mss, I40IWQPC_SNDMSS) |
  2207. LS_64(tcp->vlan_tag, I40IWQPC_VLANTAG) |
  2208. LS_64(tcp->arp_idx, I40IWQPC_ARPIDX));
  2209. qw7 |= LS_64(tcp->flow_label, I40IWQPC_FLOWLABEL) |
  2210. LS_64(tcp->wscale, I40IWQPC_WSCALE) |
  2211. LS_64(tcp->ignore_tcp_opt, I40IWQPC_IGNORE_TCP_OPT) |
  2212. LS_64(tcp->ignore_tcp_uns_opt, I40IWQPC_IGNORE_TCP_UNS_OPT) |
  2213. LS_64(tcp->tcp_state, I40IWQPC_TCPSTATE) |
  2214. LS_64(tcp->rcv_wscale, I40IWQPC_RCVSCALE) |
  2215. LS_64(tcp->snd_wscale, I40IWQPC_SNDSCALE);
  2216. set_64bit_val(qp_ctx,
  2217. 72,
  2218. LS_64(tcp->time_stamp_recent, I40IWQPC_TIMESTAMP_RECENT) |
  2219. LS_64(tcp->time_stamp_age, I40IWQPC_TIMESTAMP_AGE));
  2220. set_64bit_val(qp_ctx,
  2221. 80,
  2222. LS_64(tcp->snd_nxt, I40IWQPC_SNDNXT) |
  2223. LS_64(tcp->snd_wnd, I40IWQPC_SNDWND));
  2224. set_64bit_val(qp_ctx,
  2225. 88,
  2226. LS_64(tcp->rcv_nxt, I40IWQPC_RCVNXT) |
  2227. LS_64(tcp->rcv_wnd, I40IWQPC_RCVWND));
  2228. set_64bit_val(qp_ctx,
  2229. 96,
  2230. LS_64(tcp->snd_max, I40IWQPC_SNDMAX) |
  2231. LS_64(tcp->snd_una, I40IWQPC_SNDUNA));
  2232. set_64bit_val(qp_ctx,
  2233. 104,
  2234. LS_64(tcp->srtt, I40IWQPC_SRTT) |
  2235. LS_64(tcp->rtt_var, I40IWQPC_RTTVAR));
  2236. set_64bit_val(qp_ctx,
  2237. 112,
  2238. LS_64(tcp->ss_thresh, I40IWQPC_SSTHRESH) |
  2239. LS_64(tcp->cwnd, I40IWQPC_CWND));
  2240. set_64bit_val(qp_ctx,
  2241. 120,
  2242. LS_64(tcp->snd_wl1, I40IWQPC_SNDWL1) |
  2243. LS_64(tcp->snd_wl2, I40IWQPC_SNDWL2));
  2244. set_64bit_val(qp_ctx,
  2245. 128,
  2246. LS_64(tcp->max_snd_window, I40IWQPC_MAXSNDWND) |
  2247. LS_64(tcp->rexmit_thresh, I40IWQPC_REXMIT_THRESH));
  2248. set_64bit_val(qp_ctx,
  2249. 184,
  2250. LS_64(tcp->local_ipaddr3, I40IWQPC_LOCAL_IPADDR3) |
  2251. LS_64(tcp->local_ipaddr2, I40IWQPC_LOCAL_IPADDR2));
  2252. set_64bit_val(qp_ctx,
  2253. 192,
  2254. LS_64(tcp->local_ipaddr1, I40IWQPC_LOCAL_IPADDR1) |
  2255. LS_64(tcp->local_ipaddr0, I40IWQPC_LOCAL_IPADDR0));
  2256. }
  2257. set_64bit_val(qp_ctx, 0, qw0);
  2258. set_64bit_val(qp_ctx, 24, qw3);
  2259. set_64bit_val(qp_ctx, 56, qw7);
  2260. i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "QP_HOST)CTX WQE",
  2261. qp_ctx, I40IW_QP_CTX_SIZE);
  2262. return 0;
  2263. }
  2264. /**
  2265. * i40iw_sc_alloc_stag - mr stag alloc
  2266. * @dev: sc device struct
  2267. * @info: stag info
  2268. * @scratch: u64 saved to be used during cqp completion
  2269. * @post_sq: flag for cqp db to ring
  2270. */
  2271. static enum i40iw_status_code i40iw_sc_alloc_stag(
  2272. struct i40iw_sc_dev *dev,
  2273. struct i40iw_allocate_stag_info *info,
  2274. u64 scratch,
  2275. bool post_sq)
  2276. {
  2277. u64 *wqe;
  2278. struct i40iw_sc_cqp *cqp;
  2279. u64 header;
  2280. cqp = dev->cqp;
  2281. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2282. if (!wqe)
  2283. return I40IW_ERR_RING_FULL;
  2284. set_64bit_val(wqe,
  2285. 8,
  2286. LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID) |
  2287. LS_64(info->total_len, I40IW_CQPSQ_STAG_STAGLEN));
  2288. set_64bit_val(wqe,
  2289. 16,
  2290. LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
  2291. set_64bit_val(wqe,
  2292. 40,
  2293. LS_64(info->hmc_fcn_index, I40IW_CQPSQ_STAG_HMCFNIDX));
  2294. header = LS_64(I40IW_CQP_OP_ALLOC_STAG, I40IW_CQPSQ_OPCODE) |
  2295. LS_64(1, I40IW_CQPSQ_STAG_MR) |
  2296. LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
  2297. LS_64(info->chunk_size, I40IW_CQPSQ_STAG_LPBLSIZE) |
  2298. LS_64(info->page_size, I40IW_CQPSQ_STAG_HPAGESIZE) |
  2299. LS_64(info->remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
  2300. LS_64(info->use_hmc_fcn_index, I40IW_CQPSQ_STAG_USEHMCFNIDX) |
  2301. LS_64(info->use_pf_rid, I40IW_CQPSQ_STAG_USEPFRID) |
  2302. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2303. i40iw_insert_wqe_hdr(wqe, header);
  2304. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "ALLOC_STAG WQE",
  2305. wqe, I40IW_CQP_WQE_SIZE * 8);
  2306. if (post_sq)
  2307. i40iw_sc_cqp_post_sq(cqp);
  2308. return 0;
  2309. }
  2310. /**
  2311. * i40iw_sc_mr_reg_non_shared - non-shared mr registration
  2312. * @dev: sc device struct
  2313. * @info: mr info
  2314. * @scratch: u64 saved to be used during cqp completion
  2315. * @post_sq: flag for cqp db to ring
  2316. */
  2317. static enum i40iw_status_code i40iw_sc_mr_reg_non_shared(
  2318. struct i40iw_sc_dev *dev,
  2319. struct i40iw_reg_ns_stag_info *info,
  2320. u64 scratch,
  2321. bool post_sq)
  2322. {
  2323. u64 *wqe;
  2324. u64 temp;
  2325. struct i40iw_sc_cqp *cqp;
  2326. u64 header;
  2327. u32 pble_obj_cnt;
  2328. bool remote_access;
  2329. u8 addr_type;
  2330. if (info->access_rights & (I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY |
  2331. I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY))
  2332. remote_access = true;
  2333. else
  2334. remote_access = false;
  2335. pble_obj_cnt = dev->hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt;
  2336. if (info->chunk_size && (info->first_pm_pbl_index >= pble_obj_cnt))
  2337. return I40IW_ERR_INVALID_PBLE_INDEX;
  2338. cqp = dev->cqp;
  2339. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2340. if (!wqe)
  2341. return I40IW_ERR_RING_FULL;
  2342. temp = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? (uintptr_t)info->va : info->fbo;
  2343. set_64bit_val(wqe, 0, temp);
  2344. set_64bit_val(wqe,
  2345. 8,
  2346. LS_64(info->total_len, I40IW_CQPSQ_STAG_STAGLEN) |
  2347. LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
  2348. set_64bit_val(wqe,
  2349. 16,
  2350. LS_64(info->stag_key, I40IW_CQPSQ_STAG_KEY) |
  2351. LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
  2352. if (!info->chunk_size) {
  2353. set_64bit_val(wqe, 32, info->reg_addr_pa);
  2354. set_64bit_val(wqe, 48, 0);
  2355. } else {
  2356. set_64bit_val(wqe, 32, 0);
  2357. set_64bit_val(wqe, 48, info->first_pm_pbl_index);
  2358. }
  2359. set_64bit_val(wqe, 40, info->hmc_fcn_index);
  2360. set_64bit_val(wqe, 56, 0);
  2361. addr_type = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? 1 : 0;
  2362. header = LS_64(I40IW_CQP_OP_REG_MR, I40IW_CQPSQ_OPCODE) |
  2363. LS_64(1, I40IW_CQPSQ_STAG_MR) |
  2364. LS_64(info->chunk_size, I40IW_CQPSQ_STAG_LPBLSIZE) |
  2365. LS_64(info->page_size, I40IW_CQPSQ_STAG_HPAGESIZE) |
  2366. LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
  2367. LS_64(remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
  2368. LS_64(addr_type, I40IW_CQPSQ_STAG_VABASEDTO) |
  2369. LS_64(info->use_hmc_fcn_index, I40IW_CQPSQ_STAG_USEHMCFNIDX) |
  2370. LS_64(info->use_pf_rid, I40IW_CQPSQ_STAG_USEPFRID) |
  2371. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2372. i40iw_insert_wqe_hdr(wqe, header);
  2373. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MR_REG_NS WQE",
  2374. wqe, I40IW_CQP_WQE_SIZE * 8);
  2375. if (post_sq)
  2376. i40iw_sc_cqp_post_sq(cqp);
  2377. return 0;
  2378. }
  2379. /**
  2380. * i40iw_sc_mr_reg_shared - registered shared memory region
  2381. * @dev: sc device struct
  2382. * @info: info for shared memory registeration
  2383. * @scratch: u64 saved to be used during cqp completion
  2384. * @post_sq: flag for cqp db to ring
  2385. */
  2386. static enum i40iw_status_code i40iw_sc_mr_reg_shared(
  2387. struct i40iw_sc_dev *dev,
  2388. struct i40iw_register_shared_stag *info,
  2389. u64 scratch,
  2390. bool post_sq)
  2391. {
  2392. u64 *wqe;
  2393. struct i40iw_sc_cqp *cqp;
  2394. u64 temp, va64, fbo, header;
  2395. u32 va32;
  2396. bool remote_access;
  2397. u8 addr_type;
  2398. if (info->access_rights & (I40IW_ACCESS_FLAGS_REMOTEREAD_ONLY |
  2399. I40IW_ACCESS_FLAGS_REMOTEWRITE_ONLY))
  2400. remote_access = true;
  2401. else
  2402. remote_access = false;
  2403. cqp = dev->cqp;
  2404. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2405. if (!wqe)
  2406. return I40IW_ERR_RING_FULL;
  2407. va64 = (uintptr_t)(info->va);
  2408. va32 = (u32)(va64 & 0x00000000FFFFFFFF);
  2409. fbo = (u64)(va32 & (4096 - 1));
  2410. set_64bit_val(wqe,
  2411. 0,
  2412. (info->addr_type == I40IW_ADDR_TYPE_VA_BASED ? (uintptr_t)info->va : fbo));
  2413. set_64bit_val(wqe,
  2414. 8,
  2415. LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
  2416. temp = LS_64(info->new_stag_key, I40IW_CQPSQ_STAG_KEY) |
  2417. LS_64(info->new_stag_idx, I40IW_CQPSQ_STAG_IDX) |
  2418. LS_64(info->parent_stag_idx, I40IW_CQPSQ_STAG_PARENTSTAGIDX);
  2419. set_64bit_val(wqe, 16, temp);
  2420. addr_type = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? 1 : 0;
  2421. header = LS_64(I40IW_CQP_OP_REG_SMR, I40IW_CQPSQ_OPCODE) |
  2422. LS_64(1, I40IW_CQPSQ_STAG_MR) |
  2423. LS_64(info->access_rights, I40IW_CQPSQ_STAG_ARIGHTS) |
  2424. LS_64(remote_access, I40IW_CQPSQ_STAG_REMACCENABLED) |
  2425. LS_64(addr_type, I40IW_CQPSQ_STAG_VABASEDTO) |
  2426. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2427. i40iw_insert_wqe_hdr(wqe, header);
  2428. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MR_REG_SHARED WQE",
  2429. wqe, I40IW_CQP_WQE_SIZE * 8);
  2430. if (post_sq)
  2431. i40iw_sc_cqp_post_sq(cqp);
  2432. return 0;
  2433. }
  2434. /**
  2435. * i40iw_sc_dealloc_stag - deallocate stag
  2436. * @dev: sc device struct
  2437. * @info: dealloc stag info
  2438. * @scratch: u64 saved to be used during cqp completion
  2439. * @post_sq: flag for cqp db to ring
  2440. */
  2441. static enum i40iw_status_code i40iw_sc_dealloc_stag(
  2442. struct i40iw_sc_dev *dev,
  2443. struct i40iw_dealloc_stag_info *info,
  2444. u64 scratch,
  2445. bool post_sq)
  2446. {
  2447. u64 header;
  2448. u64 *wqe;
  2449. struct i40iw_sc_cqp *cqp;
  2450. cqp = dev->cqp;
  2451. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2452. if (!wqe)
  2453. return I40IW_ERR_RING_FULL;
  2454. set_64bit_val(wqe,
  2455. 8,
  2456. LS_64(info->pd_id, I40IW_CQPSQ_STAG_PDID));
  2457. set_64bit_val(wqe,
  2458. 16,
  2459. LS_64(info->stag_idx, I40IW_CQPSQ_STAG_IDX));
  2460. header = LS_64(I40IW_CQP_OP_DEALLOC_STAG, I40IW_CQPSQ_OPCODE) |
  2461. LS_64(info->mr, I40IW_CQPSQ_STAG_MR) |
  2462. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2463. i40iw_insert_wqe_hdr(wqe, header);
  2464. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "DEALLOC_STAG WQE",
  2465. wqe, I40IW_CQP_WQE_SIZE * 8);
  2466. if (post_sq)
  2467. i40iw_sc_cqp_post_sq(cqp);
  2468. return 0;
  2469. }
  2470. /**
  2471. * i40iw_sc_query_stag - query hardware for stag
  2472. * @dev: sc device struct
  2473. * @scratch: u64 saved to be used during cqp completion
  2474. * @stag_index: stag index for query
  2475. * @post_sq: flag for cqp db to ring
  2476. */
  2477. static enum i40iw_status_code i40iw_sc_query_stag(struct i40iw_sc_dev *dev,
  2478. u64 scratch,
  2479. u32 stag_index,
  2480. bool post_sq)
  2481. {
  2482. u64 header;
  2483. u64 *wqe;
  2484. struct i40iw_sc_cqp *cqp;
  2485. cqp = dev->cqp;
  2486. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2487. if (!wqe)
  2488. return I40IW_ERR_RING_FULL;
  2489. set_64bit_val(wqe,
  2490. 16,
  2491. LS_64(stag_index, I40IW_CQPSQ_QUERYSTAG_IDX));
  2492. header = LS_64(I40IW_CQP_OP_QUERY_STAG, I40IW_CQPSQ_OPCODE) |
  2493. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2494. i40iw_insert_wqe_hdr(wqe, header);
  2495. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "QUERY_STAG WQE",
  2496. wqe, I40IW_CQP_WQE_SIZE * 8);
  2497. if (post_sq)
  2498. i40iw_sc_cqp_post_sq(cqp);
  2499. return 0;
  2500. }
  2501. /**
  2502. * i40iw_sc_mw_alloc - mw allocate
  2503. * @dev: sc device struct
  2504. * @scratch: u64 saved to be used during cqp completion
  2505. * @mw_stag_index:stag index
  2506. * @pd_id: pd is for this mw
  2507. * @post_sq: flag for cqp db to ring
  2508. */
  2509. static enum i40iw_status_code i40iw_sc_mw_alloc(
  2510. struct i40iw_sc_dev *dev,
  2511. u64 scratch,
  2512. u32 mw_stag_index,
  2513. u16 pd_id,
  2514. bool post_sq)
  2515. {
  2516. u64 header;
  2517. struct i40iw_sc_cqp *cqp;
  2518. u64 *wqe;
  2519. cqp = dev->cqp;
  2520. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2521. if (!wqe)
  2522. return I40IW_ERR_RING_FULL;
  2523. set_64bit_val(wqe, 8, LS_64(pd_id, I40IW_CQPSQ_STAG_PDID));
  2524. set_64bit_val(wqe,
  2525. 16,
  2526. LS_64(mw_stag_index, I40IW_CQPSQ_STAG_IDX));
  2527. header = LS_64(I40IW_CQP_OP_ALLOC_STAG, I40IW_CQPSQ_OPCODE) |
  2528. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2529. i40iw_insert_wqe_hdr(wqe, header);
  2530. i40iw_debug_buf(dev, I40IW_DEBUG_WQE, "MW_ALLOC WQE",
  2531. wqe, I40IW_CQP_WQE_SIZE * 8);
  2532. if (post_sq)
  2533. i40iw_sc_cqp_post_sq(cqp);
  2534. return 0;
  2535. }
  2536. /**
  2537. * i40iw_sc_mr_fast_register - Posts RDMA fast register mr WR to iwarp qp
  2538. * @qp: sc qp struct
  2539. * @info: fast mr info
  2540. * @post_sq: flag for cqp db to ring
  2541. */
  2542. enum i40iw_status_code i40iw_sc_mr_fast_register(
  2543. struct i40iw_sc_qp *qp,
  2544. struct i40iw_fast_reg_stag_info *info,
  2545. bool post_sq)
  2546. {
  2547. u64 temp, header;
  2548. u64 *wqe;
  2549. u32 wqe_idx;
  2550. wqe = i40iw_qp_get_next_send_wqe(&qp->qp_uk, &wqe_idx, I40IW_QP_WQE_MIN_SIZE,
  2551. 0, info->wr_id);
  2552. if (!wqe)
  2553. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  2554. i40iw_debug(qp->dev, I40IW_DEBUG_MR, "%s: wr_id[%llxh] wqe_idx[%04d] location[%p]\n",
  2555. __func__, info->wr_id, wqe_idx,
  2556. &qp->qp_uk.sq_wrtrk_array[wqe_idx].wrid);
  2557. temp = (info->addr_type == I40IW_ADDR_TYPE_VA_BASED) ? (uintptr_t)info->va : info->fbo;
  2558. set_64bit_val(wqe, 0, temp);
  2559. temp = RS_64(info->first_pm_pbl_index >> 16, I40IWQPSQ_FIRSTPMPBLIDXHI);
  2560. set_64bit_val(wqe,
  2561. 8,
  2562. LS_64(temp, I40IWQPSQ_FIRSTPMPBLIDXHI) |
  2563. LS_64(info->reg_addr_pa >> I40IWQPSQ_PBLADDR_SHIFT, I40IWQPSQ_PBLADDR));
  2564. set_64bit_val(wqe,
  2565. 16,
  2566. info->total_len |
  2567. LS_64(info->first_pm_pbl_index, I40IWQPSQ_FIRSTPMPBLIDXLO));
  2568. header = LS_64(info->stag_key, I40IWQPSQ_STAGKEY) |
  2569. LS_64(info->stag_idx, I40IWQPSQ_STAGINDEX) |
  2570. LS_64(I40IWQP_OP_FAST_REGISTER, I40IWQPSQ_OPCODE) |
  2571. LS_64(info->chunk_size, I40IWQPSQ_LPBLSIZE) |
  2572. LS_64(info->page_size, I40IWQPSQ_HPAGESIZE) |
  2573. LS_64(info->access_rights, I40IWQPSQ_STAGRIGHTS) |
  2574. LS_64(info->addr_type, I40IWQPSQ_VABASEDTO) |
  2575. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  2576. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  2577. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  2578. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
  2579. i40iw_insert_wqe_hdr(wqe, header);
  2580. i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "FAST_REG WQE",
  2581. wqe, I40IW_QP_WQE_MIN_SIZE);
  2582. if (post_sq)
  2583. i40iw_qp_post_wr(&qp->qp_uk);
  2584. return 0;
  2585. }
  2586. /**
  2587. * i40iw_sc_send_lsmm - send last streaming mode message
  2588. * @qp: sc qp struct
  2589. * @lsmm_buf: buffer with lsmm message
  2590. * @size: size of lsmm buffer
  2591. * @stag: stag of lsmm buffer
  2592. */
  2593. static void i40iw_sc_send_lsmm(struct i40iw_sc_qp *qp,
  2594. void *lsmm_buf,
  2595. u32 size,
  2596. i40iw_stag stag)
  2597. {
  2598. u64 *wqe;
  2599. u64 header;
  2600. struct i40iw_qp_uk *qp_uk;
  2601. qp_uk = &qp->qp_uk;
  2602. wqe = qp_uk->sq_base->elem;
  2603. set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
  2604. set_64bit_val(wqe, 8, (size | LS_64(stag, I40IWQPSQ_FRAG_STAG)));
  2605. set_64bit_val(wqe, 16, 0);
  2606. header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
  2607. LS_64(1, I40IWQPSQ_STREAMMODE) |
  2608. LS_64(1, I40IWQPSQ_WAITFORRCVPDU) |
  2609. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
  2610. i40iw_insert_wqe_hdr(wqe, header);
  2611. i40iw_debug_buf(qp->dev, I40IW_DEBUG_QP, "SEND_LSMM WQE",
  2612. wqe, I40IW_QP_WQE_MIN_SIZE);
  2613. }
  2614. /**
  2615. * i40iw_sc_send_lsmm_nostag - for privilege qp
  2616. * @qp: sc qp struct
  2617. * @lsmm_buf: buffer with lsmm message
  2618. * @size: size of lsmm buffer
  2619. */
  2620. static void i40iw_sc_send_lsmm_nostag(struct i40iw_sc_qp *qp,
  2621. void *lsmm_buf,
  2622. u32 size)
  2623. {
  2624. u64 *wqe;
  2625. u64 header;
  2626. struct i40iw_qp_uk *qp_uk;
  2627. qp_uk = &qp->qp_uk;
  2628. wqe = qp_uk->sq_base->elem;
  2629. set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
  2630. set_64bit_val(wqe, 8, size);
  2631. set_64bit_val(wqe, 16, 0);
  2632. header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
  2633. LS_64(1, I40IWQPSQ_STREAMMODE) |
  2634. LS_64(1, I40IWQPSQ_WAITFORRCVPDU) |
  2635. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
  2636. i40iw_insert_wqe_hdr(wqe, header);
  2637. i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "SEND_LSMM_NOSTAG WQE",
  2638. wqe, I40IW_QP_WQE_MIN_SIZE);
  2639. }
  2640. /**
  2641. * i40iw_sc_send_rtt - send last read0 or write0
  2642. * @qp: sc qp struct
  2643. * @read: Do read0 or write0
  2644. */
  2645. static void i40iw_sc_send_rtt(struct i40iw_sc_qp *qp, bool read)
  2646. {
  2647. u64 *wqe;
  2648. u64 header;
  2649. struct i40iw_qp_uk *qp_uk;
  2650. qp_uk = &qp->qp_uk;
  2651. wqe = qp_uk->sq_base->elem;
  2652. set_64bit_val(wqe, 0, 0);
  2653. set_64bit_val(wqe, 8, 0);
  2654. set_64bit_val(wqe, 16, 0);
  2655. if (read) {
  2656. header = LS_64(0x1234, I40IWQPSQ_REMSTAG) |
  2657. LS_64(I40IWQP_OP_RDMA_READ, I40IWQPSQ_OPCODE) |
  2658. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
  2659. set_64bit_val(wqe, 8, ((u64)0xabcd << 32));
  2660. } else {
  2661. header = LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  2662. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
  2663. }
  2664. i40iw_insert_wqe_hdr(wqe, header);
  2665. i40iw_debug_buf(qp->dev, I40IW_DEBUG_WQE, "RTR WQE",
  2666. wqe, I40IW_QP_WQE_MIN_SIZE);
  2667. }
  2668. /**
  2669. * i40iw_sc_post_wqe0 - send wqe with opcode
  2670. * @qp: sc qp struct
  2671. * @opcode: opcode to use for wqe0
  2672. */
  2673. static enum i40iw_status_code i40iw_sc_post_wqe0(struct i40iw_sc_qp *qp, u8 opcode)
  2674. {
  2675. u64 *wqe;
  2676. u64 header;
  2677. struct i40iw_qp_uk *qp_uk;
  2678. qp_uk = &qp->qp_uk;
  2679. wqe = qp_uk->sq_base->elem;
  2680. if (!wqe)
  2681. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  2682. switch (opcode) {
  2683. case I40IWQP_OP_NOP:
  2684. set_64bit_val(wqe, 0, 0);
  2685. set_64bit_val(wqe, 8, 0);
  2686. set_64bit_val(wqe, 16, 0);
  2687. header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
  2688. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID);
  2689. i40iw_insert_wqe_hdr(wqe, header);
  2690. break;
  2691. case I40IWQP_OP_RDMA_SEND:
  2692. set_64bit_val(wqe, 0, 0);
  2693. set_64bit_val(wqe, 8, 0);
  2694. set_64bit_val(wqe, 16, 0);
  2695. header = LS_64(I40IWQP_OP_RDMA_SEND, I40IWQPSQ_OPCODE) |
  2696. LS_64(qp->qp_uk.swqe_polarity, I40IWQPSQ_VALID) |
  2697. LS_64(1, I40IWQPSQ_STREAMMODE) |
  2698. LS_64(1, I40IWQPSQ_WAITFORRCVPDU);
  2699. i40iw_insert_wqe_hdr(wqe, header);
  2700. break;
  2701. default:
  2702. i40iw_debug(qp->dev, I40IW_DEBUG_QP, "%s: Invalid WQE zero opcode\n",
  2703. __func__);
  2704. break;
  2705. }
  2706. return 0;
  2707. }
  2708. /**
  2709. * i40iw_sc_init_iw_hmc() - queries fpm values using cqp and populates hmc_info
  2710. * @dev : ptr to i40iw_dev struct
  2711. * @hmc_fn_id: hmc function id
  2712. */
  2713. enum i40iw_status_code i40iw_sc_init_iw_hmc(struct i40iw_sc_dev *dev, u8 hmc_fn_id)
  2714. {
  2715. struct i40iw_hmc_info *hmc_info;
  2716. struct i40iw_dma_mem query_fpm_mem;
  2717. struct i40iw_virt_mem virt_mem;
  2718. struct i40iw_vfdev *vf_dev = NULL;
  2719. u32 mem_size;
  2720. enum i40iw_status_code ret_code = 0;
  2721. bool poll_registers = true;
  2722. u16 iw_vf_idx;
  2723. u8 wait_type;
  2724. if (hmc_fn_id >= I40IW_MAX_VF_FPM_ID ||
  2725. (dev->hmc_fn_id != hmc_fn_id && hmc_fn_id < I40IW_FIRST_VF_FPM_ID))
  2726. return I40IW_ERR_INVALID_HMCFN_ID;
  2727. i40iw_debug(dev, I40IW_DEBUG_HMC, "hmc_fn_id %u, dev->hmc_fn_id %u\n", hmc_fn_id,
  2728. dev->hmc_fn_id);
  2729. if (hmc_fn_id == dev->hmc_fn_id) {
  2730. hmc_info = dev->hmc_info;
  2731. query_fpm_mem.pa = dev->fpm_query_buf_pa;
  2732. query_fpm_mem.va = dev->fpm_query_buf;
  2733. } else {
  2734. vf_dev = i40iw_vfdev_from_fpm(dev, hmc_fn_id);
  2735. if (!vf_dev)
  2736. return I40IW_ERR_INVALID_VF_ID;
  2737. hmc_info = &vf_dev->hmc_info;
  2738. iw_vf_idx = vf_dev->iw_vf_idx;
  2739. i40iw_debug(dev, I40IW_DEBUG_HMC, "vf_dev %p, hmc_info %p, hmc_obj %p\n", vf_dev,
  2740. hmc_info, hmc_info->hmc_obj);
  2741. if (!vf_dev->fpm_query_buf) {
  2742. if (!dev->vf_fpm_query_buf[iw_vf_idx].va) {
  2743. ret_code = i40iw_alloc_query_fpm_buf(dev,
  2744. &dev->vf_fpm_query_buf[iw_vf_idx]);
  2745. if (ret_code)
  2746. return ret_code;
  2747. }
  2748. vf_dev->fpm_query_buf = dev->vf_fpm_query_buf[iw_vf_idx].va;
  2749. vf_dev->fpm_query_buf_pa = dev->vf_fpm_query_buf[iw_vf_idx].pa;
  2750. }
  2751. query_fpm_mem.pa = vf_dev->fpm_query_buf_pa;
  2752. query_fpm_mem.va = vf_dev->fpm_query_buf;
  2753. /**
  2754. * It is HARDWARE specific:
  2755. * this call is done by PF for VF and
  2756. * i40iw_sc_query_fpm_values needs ccq poll
  2757. * because PF ccq is already created.
  2758. */
  2759. poll_registers = false;
  2760. }
  2761. hmc_info->hmc_fn_id = hmc_fn_id;
  2762. if (hmc_fn_id != dev->hmc_fn_id) {
  2763. ret_code =
  2764. i40iw_cqp_query_fpm_values_cmd(dev, &query_fpm_mem, hmc_fn_id);
  2765. } else {
  2766. wait_type = poll_registers ? (u8)I40IW_CQP_WAIT_POLL_REGS :
  2767. (u8)I40IW_CQP_WAIT_POLL_CQ;
  2768. ret_code = i40iw_sc_query_fpm_values(
  2769. dev->cqp,
  2770. 0,
  2771. hmc_info->hmc_fn_id,
  2772. &query_fpm_mem,
  2773. true,
  2774. wait_type);
  2775. }
  2776. if (ret_code)
  2777. return ret_code;
  2778. /* parse the fpm_query_buf and fill hmc obj info */
  2779. ret_code =
  2780. i40iw_sc_parse_fpm_query_buf((u64 *)query_fpm_mem.va,
  2781. hmc_info,
  2782. &dev->hmc_fpm_misc);
  2783. if (ret_code)
  2784. return ret_code;
  2785. i40iw_debug_buf(dev, I40IW_DEBUG_HMC, "QUERY FPM BUFFER",
  2786. query_fpm_mem.va, I40IW_QUERY_FPM_BUF_SIZE);
  2787. if (hmc_fn_id != dev->hmc_fn_id) {
  2788. i40iw_cqp_commit_fpm_values_cmd(dev, &query_fpm_mem, hmc_fn_id);
  2789. /* parse the fpm_commit_buf and fill hmc obj info */
  2790. i40iw_sc_parse_fpm_commit_buf((u64 *)query_fpm_mem.va, hmc_info->hmc_obj, &hmc_info->sd_table.sd_cnt);
  2791. mem_size = sizeof(struct i40iw_hmc_sd_entry) *
  2792. (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index);
  2793. ret_code = i40iw_allocate_virt_mem(dev->hw, &virt_mem, mem_size);
  2794. if (ret_code)
  2795. return ret_code;
  2796. hmc_info->sd_table.sd_entry = virt_mem.va;
  2797. }
  2798. /* fill size of objects which are fixed */
  2799. hmc_info->hmc_obj[I40IW_HMC_IW_XFFL].size = 4;
  2800. hmc_info->hmc_obj[I40IW_HMC_IW_Q1FL].size = 4;
  2801. hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].size = 8;
  2802. hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].size = 8192;
  2803. hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].max_cnt = 1;
  2804. return ret_code;
  2805. }
  2806. /**
  2807. * i40iw_sc_configure_iw_fpm() - commits hmc obj cnt values using cqp command and
  2808. * populates fpm base address in hmc_info
  2809. * @dev : ptr to i40iw_dev struct
  2810. * @hmc_fn_id: hmc function id
  2811. */
  2812. static enum i40iw_status_code i40iw_sc_configure_iw_fpm(struct i40iw_sc_dev *dev,
  2813. u8 hmc_fn_id)
  2814. {
  2815. struct i40iw_hmc_info *hmc_info;
  2816. struct i40iw_hmc_obj_info *obj_info;
  2817. u64 *buf;
  2818. struct i40iw_dma_mem commit_fpm_mem;
  2819. u32 i, j;
  2820. enum i40iw_status_code ret_code = 0;
  2821. bool poll_registers = true;
  2822. u8 wait_type;
  2823. if (hmc_fn_id >= I40IW_MAX_VF_FPM_ID ||
  2824. (dev->hmc_fn_id != hmc_fn_id && hmc_fn_id < I40IW_FIRST_VF_FPM_ID))
  2825. return I40IW_ERR_INVALID_HMCFN_ID;
  2826. if (hmc_fn_id == dev->hmc_fn_id) {
  2827. hmc_info = dev->hmc_info;
  2828. } else {
  2829. hmc_info = i40iw_vf_hmcinfo_from_fpm(dev, hmc_fn_id);
  2830. poll_registers = false;
  2831. }
  2832. if (!hmc_info)
  2833. return I40IW_ERR_BAD_PTR;
  2834. obj_info = hmc_info->hmc_obj;
  2835. buf = dev->fpm_commit_buf;
  2836. /* copy cnt values in commit buf */
  2837. for (i = I40IW_HMC_IW_QP, j = 0; i <= I40IW_HMC_IW_PBLE;
  2838. i++, j += 8)
  2839. set_64bit_val(buf, j, (u64)obj_info[i].cnt);
  2840. set_64bit_val(buf, 40, 0); /* APBVT rsvd */
  2841. commit_fpm_mem.pa = dev->fpm_commit_buf_pa;
  2842. commit_fpm_mem.va = dev->fpm_commit_buf;
  2843. wait_type = poll_registers ? (u8)I40IW_CQP_WAIT_POLL_REGS :
  2844. (u8)I40IW_CQP_WAIT_POLL_CQ;
  2845. ret_code = i40iw_sc_commit_fpm_values(
  2846. dev->cqp,
  2847. 0,
  2848. hmc_info->hmc_fn_id,
  2849. &commit_fpm_mem,
  2850. true,
  2851. wait_type);
  2852. /* parse the fpm_commit_buf and fill hmc obj info */
  2853. if (!ret_code)
  2854. ret_code = i40iw_sc_parse_fpm_commit_buf(dev->fpm_commit_buf,
  2855. hmc_info->hmc_obj,
  2856. &hmc_info->sd_table.sd_cnt);
  2857. i40iw_debug_buf(dev, I40IW_DEBUG_HMC, "COMMIT FPM BUFFER",
  2858. commit_fpm_mem.va, I40IW_COMMIT_FPM_BUF_SIZE);
  2859. return ret_code;
  2860. }
  2861. /**
  2862. * cqp_sds_wqe_fill - fill cqp wqe doe sd
  2863. * @cqp: struct for cqp hw
  2864. * @info; sd info for wqe
  2865. * @scratch: u64 saved to be used during cqp completion
  2866. */
  2867. static enum i40iw_status_code cqp_sds_wqe_fill(struct i40iw_sc_cqp *cqp,
  2868. struct i40iw_update_sds_info *info,
  2869. u64 scratch)
  2870. {
  2871. u64 data;
  2872. u64 header;
  2873. u64 *wqe;
  2874. int mem_entries, wqe_entries;
  2875. struct i40iw_dma_mem *sdbuf = &cqp->sdbuf;
  2876. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2877. if (!wqe)
  2878. return I40IW_ERR_RING_FULL;
  2879. I40IW_CQP_INIT_WQE(wqe);
  2880. wqe_entries = (info->cnt > 3) ? 3 : info->cnt;
  2881. mem_entries = info->cnt - wqe_entries;
  2882. header = LS_64(I40IW_CQP_OP_UPDATE_PE_SDS, I40IW_CQPSQ_OPCODE) |
  2883. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID) |
  2884. LS_64(mem_entries, I40IW_CQPSQ_UPESD_ENTRY_COUNT);
  2885. if (mem_entries) {
  2886. memcpy(sdbuf->va, &info->entry[3], (mem_entries << 4));
  2887. data = sdbuf->pa;
  2888. } else {
  2889. data = 0;
  2890. }
  2891. data |= LS_64(info->hmc_fn_id, I40IW_CQPSQ_UPESD_HMCFNID);
  2892. set_64bit_val(wqe, 16, data);
  2893. switch (wqe_entries) {
  2894. case 3:
  2895. set_64bit_val(wqe, 48,
  2896. (LS_64(info->entry[2].cmd, I40IW_CQPSQ_UPESD_SDCMD) |
  2897. LS_64(1, I40IW_CQPSQ_UPESD_ENTRY_VALID)));
  2898. set_64bit_val(wqe, 56, info->entry[2].data);
  2899. /* fallthrough */
  2900. case 2:
  2901. set_64bit_val(wqe, 32,
  2902. (LS_64(info->entry[1].cmd, I40IW_CQPSQ_UPESD_SDCMD) |
  2903. LS_64(1, I40IW_CQPSQ_UPESD_ENTRY_VALID)));
  2904. set_64bit_val(wqe, 40, info->entry[1].data);
  2905. /* fallthrough */
  2906. case 1:
  2907. set_64bit_val(wqe, 0,
  2908. LS_64(info->entry[0].cmd, I40IW_CQPSQ_UPESD_SDCMD));
  2909. set_64bit_val(wqe, 8, info->entry[0].data);
  2910. break;
  2911. default:
  2912. break;
  2913. }
  2914. i40iw_insert_wqe_hdr(wqe, header);
  2915. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "UPDATE_PE_SDS WQE",
  2916. wqe, I40IW_CQP_WQE_SIZE * 8);
  2917. return 0;
  2918. }
  2919. /**
  2920. * i40iw_update_pe_sds - cqp wqe for sd
  2921. * @dev: ptr to i40iw_dev struct
  2922. * @info: sd info for sd's
  2923. * @scratch: u64 saved to be used during cqp completion
  2924. */
  2925. static enum i40iw_status_code i40iw_update_pe_sds(struct i40iw_sc_dev *dev,
  2926. struct i40iw_update_sds_info *info,
  2927. u64 scratch)
  2928. {
  2929. struct i40iw_sc_cqp *cqp = dev->cqp;
  2930. enum i40iw_status_code ret_code;
  2931. ret_code = cqp_sds_wqe_fill(cqp, info, scratch);
  2932. if (!ret_code)
  2933. i40iw_sc_cqp_post_sq(cqp);
  2934. return ret_code;
  2935. }
  2936. /**
  2937. * i40iw_update_sds_noccq - update sd before ccq created
  2938. * @dev: sc device struct
  2939. * @info: sd info for sd's
  2940. */
  2941. enum i40iw_status_code i40iw_update_sds_noccq(struct i40iw_sc_dev *dev,
  2942. struct i40iw_update_sds_info *info)
  2943. {
  2944. u32 error, val, tail;
  2945. struct i40iw_sc_cqp *cqp = dev->cqp;
  2946. enum i40iw_status_code ret_code;
  2947. ret_code = cqp_sds_wqe_fill(cqp, info, 0);
  2948. if (ret_code)
  2949. return ret_code;
  2950. i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
  2951. if (error)
  2952. return I40IW_ERR_CQP_COMPL_ERROR;
  2953. i40iw_sc_cqp_post_sq(cqp);
  2954. ret_code = i40iw_cqp_poll_registers(cqp, tail, I40IW_DONE_COUNT);
  2955. return ret_code;
  2956. }
  2957. /**
  2958. * i40iw_sc_suspend_qp - suspend qp for param change
  2959. * @cqp: struct for cqp hw
  2960. * @qp: sc qp struct
  2961. * @scratch: u64 saved to be used during cqp completion
  2962. */
  2963. enum i40iw_status_code i40iw_sc_suspend_qp(struct i40iw_sc_cqp *cqp,
  2964. struct i40iw_sc_qp *qp,
  2965. u64 scratch)
  2966. {
  2967. u64 header;
  2968. u64 *wqe;
  2969. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2970. if (!wqe)
  2971. return I40IW_ERR_RING_FULL;
  2972. header = LS_64(qp->qp_uk.qp_id, I40IW_CQPSQ_SUSPENDQP_QPID) |
  2973. LS_64(I40IW_CQP_OP_SUSPEND_QP, I40IW_CQPSQ_OPCODE) |
  2974. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  2975. i40iw_insert_wqe_hdr(wqe, header);
  2976. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "SUSPEND_QP WQE",
  2977. wqe, I40IW_CQP_WQE_SIZE * 8);
  2978. i40iw_sc_cqp_post_sq(cqp);
  2979. return 0;
  2980. }
  2981. /**
  2982. * i40iw_sc_resume_qp - resume qp after suspend
  2983. * @cqp: struct for cqp hw
  2984. * @qp: sc qp struct
  2985. * @scratch: u64 saved to be used during cqp completion
  2986. */
  2987. enum i40iw_status_code i40iw_sc_resume_qp(struct i40iw_sc_cqp *cqp,
  2988. struct i40iw_sc_qp *qp,
  2989. u64 scratch)
  2990. {
  2991. u64 header;
  2992. u64 *wqe;
  2993. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  2994. if (!wqe)
  2995. return I40IW_ERR_RING_FULL;
  2996. set_64bit_val(wqe,
  2997. 16,
  2998. LS_64(qp->qs_handle, I40IW_CQPSQ_RESUMEQP_QSHANDLE));
  2999. header = LS_64(qp->qp_uk.qp_id, I40IW_CQPSQ_RESUMEQP_QPID) |
  3000. LS_64(I40IW_CQP_OP_RESUME_QP, I40IW_CQPSQ_OPCODE) |
  3001. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  3002. i40iw_insert_wqe_hdr(wqe, header);
  3003. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "RESUME_QP WQE",
  3004. wqe, I40IW_CQP_WQE_SIZE * 8);
  3005. i40iw_sc_cqp_post_sq(cqp);
  3006. return 0;
  3007. }
  3008. /**
  3009. * i40iw_sc_static_hmc_pages_allocated - cqp wqe to allocate hmc pages
  3010. * @cqp: struct for cqp hw
  3011. * @scratch: u64 saved to be used during cqp completion
  3012. * @hmc_fn_id: hmc function id
  3013. * @post_sq: flag for cqp db to ring
  3014. * @poll_registers: flag to poll register for cqp completion
  3015. */
  3016. enum i40iw_status_code i40iw_sc_static_hmc_pages_allocated(
  3017. struct i40iw_sc_cqp *cqp,
  3018. u64 scratch,
  3019. u8 hmc_fn_id,
  3020. bool post_sq,
  3021. bool poll_registers)
  3022. {
  3023. u64 header;
  3024. u64 *wqe;
  3025. u32 tail, val, error;
  3026. enum i40iw_status_code ret_code = 0;
  3027. wqe = i40iw_sc_cqp_get_next_send_wqe(cqp, scratch);
  3028. if (!wqe)
  3029. return I40IW_ERR_RING_FULL;
  3030. set_64bit_val(wqe,
  3031. 16,
  3032. LS_64(hmc_fn_id, I40IW_SHMC_PAGE_ALLOCATED_HMC_FN_ID));
  3033. header = LS_64(I40IW_CQP_OP_SHMC_PAGES_ALLOCATED, I40IW_CQPSQ_OPCODE) |
  3034. LS_64(cqp->polarity, I40IW_CQPSQ_WQEVALID);
  3035. i40iw_insert_wqe_hdr(wqe, header);
  3036. i40iw_debug_buf(cqp->dev, I40IW_DEBUG_WQE, "SHMC_PAGES_ALLOCATED WQE",
  3037. wqe, I40IW_CQP_WQE_SIZE * 8);
  3038. i40iw_get_cqp_reg_info(cqp, &val, &tail, &error);
  3039. if (error) {
  3040. ret_code = I40IW_ERR_CQP_COMPL_ERROR;
  3041. return ret_code;
  3042. }
  3043. if (post_sq) {
  3044. i40iw_sc_cqp_post_sq(cqp);
  3045. if (poll_registers)
  3046. /* check for cqp sq tail update */
  3047. ret_code = i40iw_cqp_poll_registers(cqp, tail, 1000);
  3048. else
  3049. ret_code = i40iw_sc_poll_for_cqp_op_done(cqp,
  3050. I40IW_CQP_OP_SHMC_PAGES_ALLOCATED,
  3051. NULL);
  3052. }
  3053. return ret_code;
  3054. }
  3055. /**
  3056. * i40iw_ring_full - check if cqp ring is full
  3057. * @cqp: struct for cqp hw
  3058. */
  3059. static bool i40iw_ring_full(struct i40iw_sc_cqp *cqp)
  3060. {
  3061. return I40IW_RING_FULL_ERR(cqp->sq_ring);
  3062. }
  3063. /**
  3064. * i40iw_est_sd - returns approximate number of SDs for HMC
  3065. * @dev: sc device struct
  3066. * @hmc_info: hmc structure, size and count for HMC objects
  3067. */
  3068. static u64 i40iw_est_sd(struct i40iw_sc_dev *dev, struct i40iw_hmc_info *hmc_info)
  3069. {
  3070. int i;
  3071. u64 size = 0;
  3072. u64 sd;
  3073. for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_PBLE; i++)
  3074. size += hmc_info->hmc_obj[i].cnt * hmc_info->hmc_obj[i].size;
  3075. if (dev->is_pf)
  3076. size += hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt * hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].size;
  3077. if (size & 0x1FFFFF)
  3078. sd = (size >> 21) + 1; /* add 1 for remainder */
  3079. else
  3080. sd = size >> 21;
  3081. if (!dev->is_pf) {
  3082. /* 2MB alignment for VF PBLE HMC */
  3083. size = hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt * hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].size;
  3084. if (size & 0x1FFFFF)
  3085. sd += (size >> 21) + 1; /* add 1 for remainder */
  3086. else
  3087. sd += size >> 21;
  3088. }
  3089. return sd;
  3090. }
  3091. /**
  3092. * i40iw_config_fpm_values - configure HMC objects
  3093. * @dev: sc device struct
  3094. * @qp_count: desired qp count
  3095. */
  3096. enum i40iw_status_code i40iw_config_fpm_values(struct i40iw_sc_dev *dev, u32 qp_count)
  3097. {
  3098. struct i40iw_virt_mem virt_mem;
  3099. u32 i, mem_size;
  3100. u32 qpwantedoriginal, qpwanted, mrwanted, pblewanted;
  3101. u32 powerof2;
  3102. u64 sd_needed;
  3103. u32 loop_count = 0;
  3104. struct i40iw_hmc_info *hmc_info;
  3105. struct i40iw_hmc_fpm_misc *hmc_fpm_misc;
  3106. enum i40iw_status_code ret_code = 0;
  3107. hmc_info = dev->hmc_info;
  3108. hmc_fpm_misc = &dev->hmc_fpm_misc;
  3109. ret_code = i40iw_sc_init_iw_hmc(dev, dev->hmc_fn_id);
  3110. if (ret_code) {
  3111. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3112. "i40iw_sc_init_iw_hmc returned error_code = %d\n",
  3113. ret_code);
  3114. return ret_code;
  3115. }
  3116. for (i = I40IW_HMC_IW_QP; i < I40IW_HMC_IW_MAX; i++)
  3117. hmc_info->hmc_obj[i].cnt = hmc_info->hmc_obj[i].max_cnt;
  3118. sd_needed = i40iw_est_sd(dev, hmc_info);
  3119. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3120. "%s: FW initial max sd_count[%08lld] first_sd_index[%04d]\n",
  3121. __func__, sd_needed, hmc_info->first_sd_index);
  3122. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3123. "%s: sd count %d where max sd is %d\n",
  3124. __func__, hmc_info->sd_table.sd_cnt,
  3125. hmc_fpm_misc->max_sds);
  3126. qpwanted = min(qp_count, hmc_info->hmc_obj[I40IW_HMC_IW_QP].max_cnt);
  3127. qpwantedoriginal = qpwanted;
  3128. mrwanted = hmc_info->hmc_obj[I40IW_HMC_IW_MR].max_cnt;
  3129. pblewanted = hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].max_cnt;
  3130. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3131. "req_qp=%d max_sd=%d, max_qp = %d, max_cq=%d, max_mr=%d, max_pble=%d\n",
  3132. qp_count, hmc_fpm_misc->max_sds,
  3133. hmc_info->hmc_obj[I40IW_HMC_IW_QP].max_cnt,
  3134. hmc_info->hmc_obj[I40IW_HMC_IW_CQ].max_cnt,
  3135. hmc_info->hmc_obj[I40IW_HMC_IW_MR].max_cnt,
  3136. hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].max_cnt);
  3137. do {
  3138. ++loop_count;
  3139. hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt = qpwanted;
  3140. hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt =
  3141. min(2 * qpwanted, hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt);
  3142. hmc_info->hmc_obj[I40IW_HMC_IW_SRQ].cnt = 0x00; /* Reserved */
  3143. hmc_info->hmc_obj[I40IW_HMC_IW_HTE].cnt =
  3144. qpwanted * hmc_fpm_misc->ht_multiplier;
  3145. hmc_info->hmc_obj[I40IW_HMC_IW_ARP].cnt =
  3146. hmc_info->hmc_obj[I40IW_HMC_IW_ARP].max_cnt;
  3147. hmc_info->hmc_obj[I40IW_HMC_IW_APBVT_ENTRY].cnt = 1;
  3148. hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt = mrwanted;
  3149. hmc_info->hmc_obj[I40IW_HMC_IW_XF].cnt = I40IW_MAX_WQ_ENTRIES * qpwanted;
  3150. hmc_info->hmc_obj[I40IW_HMC_IW_Q1].cnt = 4 * I40IW_MAX_IRD_SIZE * qpwanted;
  3151. hmc_info->hmc_obj[I40IW_HMC_IW_XFFL].cnt =
  3152. hmc_info->hmc_obj[I40IW_HMC_IW_XF].cnt / hmc_fpm_misc->xf_block_size;
  3153. hmc_info->hmc_obj[I40IW_HMC_IW_Q1FL].cnt =
  3154. hmc_info->hmc_obj[I40IW_HMC_IW_Q1].cnt / hmc_fpm_misc->q1_block_size;
  3155. hmc_info->hmc_obj[I40IW_HMC_IW_TIMER].cnt =
  3156. ((qpwanted) / 512 + 1) * hmc_fpm_misc->timer_bucket;
  3157. hmc_info->hmc_obj[I40IW_HMC_IW_FSIMC].cnt = 0x00;
  3158. hmc_info->hmc_obj[I40IW_HMC_IW_FSIAV].cnt = 0x00;
  3159. hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt = pblewanted;
  3160. /* How much memory is needed for all the objects. */
  3161. sd_needed = i40iw_est_sd(dev, hmc_info);
  3162. if ((loop_count > 1000) ||
  3163. ((!(loop_count % 10)) &&
  3164. (qpwanted > qpwantedoriginal * 2 / 3))) {
  3165. if (qpwanted > FPM_MULTIPLIER) {
  3166. qpwanted -= FPM_MULTIPLIER;
  3167. powerof2 = 1;
  3168. while (powerof2 < qpwanted)
  3169. powerof2 *= 2;
  3170. powerof2 /= 2;
  3171. qpwanted = powerof2;
  3172. } else {
  3173. qpwanted /= 2;
  3174. }
  3175. }
  3176. if (mrwanted > FPM_MULTIPLIER * 10)
  3177. mrwanted -= FPM_MULTIPLIER * 10;
  3178. if (pblewanted > FPM_MULTIPLIER * 1000)
  3179. pblewanted -= FPM_MULTIPLIER * 1000;
  3180. } while (sd_needed > hmc_fpm_misc->max_sds && loop_count < 2000);
  3181. sd_needed = i40iw_est_sd(dev, hmc_info);
  3182. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3183. "loop_cnt=%d, sd_needed=%lld, qpcnt = %d, cqcnt=%d, mrcnt=%d, pblecnt=%d\n",
  3184. loop_count, sd_needed,
  3185. hmc_info->hmc_obj[I40IW_HMC_IW_QP].cnt,
  3186. hmc_info->hmc_obj[I40IW_HMC_IW_CQ].cnt,
  3187. hmc_info->hmc_obj[I40IW_HMC_IW_MR].cnt,
  3188. hmc_info->hmc_obj[I40IW_HMC_IW_PBLE].cnt);
  3189. ret_code = i40iw_sc_configure_iw_fpm(dev, dev->hmc_fn_id);
  3190. if (ret_code) {
  3191. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3192. "configure_iw_fpm returned error_code[x%08X]\n",
  3193. i40iw_rd32(dev->hw, dev->is_pf ? I40E_PFPE_CQPERRCODES : I40E_VFPE_CQPERRCODES1));
  3194. return ret_code;
  3195. }
  3196. mem_size = sizeof(struct i40iw_hmc_sd_entry) *
  3197. (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index + 1);
  3198. ret_code = i40iw_allocate_virt_mem(dev->hw, &virt_mem, mem_size);
  3199. if (ret_code) {
  3200. i40iw_debug(dev, I40IW_DEBUG_HMC,
  3201. "%s: failed to allocate memory for sd_entry buffer\n",
  3202. __func__);
  3203. return ret_code;
  3204. }
  3205. hmc_info->sd_table.sd_entry = virt_mem.va;
  3206. return ret_code;
  3207. }
  3208. /**
  3209. * i40iw_exec_cqp_cmd - execute cqp cmd when wqe are available
  3210. * @dev: rdma device
  3211. * @pcmdinfo: cqp command info
  3212. */
  3213. static enum i40iw_status_code i40iw_exec_cqp_cmd(struct i40iw_sc_dev *dev,
  3214. struct cqp_commands_info *pcmdinfo)
  3215. {
  3216. enum i40iw_status_code status;
  3217. struct i40iw_dma_mem values_mem;
  3218. dev->cqp_cmd_stats[pcmdinfo->cqp_cmd]++;
  3219. switch (pcmdinfo->cqp_cmd) {
  3220. case OP_DELETE_LOCAL_MAC_IPADDR_ENTRY:
  3221. status = i40iw_sc_del_local_mac_ipaddr_entry(
  3222. pcmdinfo->in.u.del_local_mac_ipaddr_entry.cqp,
  3223. pcmdinfo->in.u.del_local_mac_ipaddr_entry.scratch,
  3224. pcmdinfo->in.u.del_local_mac_ipaddr_entry.entry_idx,
  3225. pcmdinfo->in.u.del_local_mac_ipaddr_entry.ignore_ref_count,
  3226. pcmdinfo->post_sq);
  3227. break;
  3228. case OP_CEQ_DESTROY:
  3229. status = i40iw_sc_ceq_destroy(pcmdinfo->in.u.ceq_destroy.ceq,
  3230. pcmdinfo->in.u.ceq_destroy.scratch,
  3231. pcmdinfo->post_sq);
  3232. break;
  3233. case OP_AEQ_DESTROY:
  3234. status = i40iw_sc_aeq_destroy(pcmdinfo->in.u.aeq_destroy.aeq,
  3235. pcmdinfo->in.u.aeq_destroy.scratch,
  3236. pcmdinfo->post_sq);
  3237. break;
  3238. case OP_DELETE_ARP_CACHE_ENTRY:
  3239. status = i40iw_sc_del_arp_cache_entry(
  3240. pcmdinfo->in.u.del_arp_cache_entry.cqp,
  3241. pcmdinfo->in.u.del_arp_cache_entry.scratch,
  3242. pcmdinfo->in.u.del_arp_cache_entry.arp_index,
  3243. pcmdinfo->post_sq);
  3244. break;
  3245. case OP_MANAGE_APBVT_ENTRY:
  3246. status = i40iw_sc_manage_apbvt_entry(
  3247. pcmdinfo->in.u.manage_apbvt_entry.cqp,
  3248. &pcmdinfo->in.u.manage_apbvt_entry.info,
  3249. pcmdinfo->in.u.manage_apbvt_entry.scratch,
  3250. pcmdinfo->post_sq);
  3251. break;
  3252. case OP_CEQ_CREATE:
  3253. status = i40iw_sc_ceq_create(pcmdinfo->in.u.ceq_create.ceq,
  3254. pcmdinfo->in.u.ceq_create.scratch,
  3255. pcmdinfo->post_sq);
  3256. break;
  3257. case OP_AEQ_CREATE:
  3258. status = i40iw_sc_aeq_create(pcmdinfo->in.u.aeq_create.aeq,
  3259. pcmdinfo->in.u.aeq_create.scratch,
  3260. pcmdinfo->post_sq);
  3261. break;
  3262. case OP_ALLOC_LOCAL_MAC_IPADDR_ENTRY:
  3263. status = i40iw_sc_alloc_local_mac_ipaddr_entry(
  3264. pcmdinfo->in.u.alloc_local_mac_ipaddr_entry.cqp,
  3265. pcmdinfo->in.u.alloc_local_mac_ipaddr_entry.scratch,
  3266. pcmdinfo->post_sq);
  3267. break;
  3268. case OP_ADD_LOCAL_MAC_IPADDR_ENTRY:
  3269. status = i40iw_sc_add_local_mac_ipaddr_entry(
  3270. pcmdinfo->in.u.add_local_mac_ipaddr_entry.cqp,
  3271. &pcmdinfo->in.u.add_local_mac_ipaddr_entry.info,
  3272. pcmdinfo->in.u.add_local_mac_ipaddr_entry.scratch,
  3273. pcmdinfo->post_sq);
  3274. break;
  3275. case OP_MANAGE_QHASH_TABLE_ENTRY:
  3276. status = i40iw_sc_manage_qhash_table_entry(
  3277. pcmdinfo->in.u.manage_qhash_table_entry.cqp,
  3278. &pcmdinfo->in.u.manage_qhash_table_entry.info,
  3279. pcmdinfo->in.u.manage_qhash_table_entry.scratch,
  3280. pcmdinfo->post_sq);
  3281. break;
  3282. case OP_QP_MODIFY:
  3283. status = i40iw_sc_qp_modify(
  3284. pcmdinfo->in.u.qp_modify.qp,
  3285. &pcmdinfo->in.u.qp_modify.info,
  3286. pcmdinfo->in.u.qp_modify.scratch,
  3287. pcmdinfo->post_sq);
  3288. break;
  3289. case OP_QP_UPLOAD_CONTEXT:
  3290. status = i40iw_sc_qp_upload_context(
  3291. pcmdinfo->in.u.qp_upload_context.dev,
  3292. &pcmdinfo->in.u.qp_upload_context.info,
  3293. pcmdinfo->in.u.qp_upload_context.scratch,
  3294. pcmdinfo->post_sq);
  3295. break;
  3296. case OP_CQ_CREATE:
  3297. status = i40iw_sc_cq_create(
  3298. pcmdinfo->in.u.cq_create.cq,
  3299. pcmdinfo->in.u.cq_create.scratch,
  3300. pcmdinfo->in.u.cq_create.check_overflow,
  3301. pcmdinfo->post_sq);
  3302. break;
  3303. case OP_CQ_DESTROY:
  3304. status = i40iw_sc_cq_destroy(
  3305. pcmdinfo->in.u.cq_destroy.cq,
  3306. pcmdinfo->in.u.cq_destroy.scratch,
  3307. pcmdinfo->post_sq);
  3308. break;
  3309. case OP_QP_CREATE:
  3310. status = i40iw_sc_qp_create(
  3311. pcmdinfo->in.u.qp_create.qp,
  3312. &pcmdinfo->in.u.qp_create.info,
  3313. pcmdinfo->in.u.qp_create.scratch,
  3314. pcmdinfo->post_sq);
  3315. break;
  3316. case OP_QP_DESTROY:
  3317. status = i40iw_sc_qp_destroy(
  3318. pcmdinfo->in.u.qp_destroy.qp,
  3319. pcmdinfo->in.u.qp_destroy.scratch,
  3320. pcmdinfo->in.u.qp_destroy.remove_hash_idx,
  3321. pcmdinfo->in.u.qp_destroy.
  3322. ignore_mw_bnd,
  3323. pcmdinfo->post_sq);
  3324. break;
  3325. case OP_ALLOC_STAG:
  3326. status = i40iw_sc_alloc_stag(
  3327. pcmdinfo->in.u.alloc_stag.dev,
  3328. &pcmdinfo->in.u.alloc_stag.info,
  3329. pcmdinfo->in.u.alloc_stag.scratch,
  3330. pcmdinfo->post_sq);
  3331. break;
  3332. case OP_MR_REG_NON_SHARED:
  3333. status = i40iw_sc_mr_reg_non_shared(
  3334. pcmdinfo->in.u.mr_reg_non_shared.dev,
  3335. &pcmdinfo->in.u.mr_reg_non_shared.info,
  3336. pcmdinfo->in.u.mr_reg_non_shared.scratch,
  3337. pcmdinfo->post_sq);
  3338. break;
  3339. case OP_DEALLOC_STAG:
  3340. status = i40iw_sc_dealloc_stag(
  3341. pcmdinfo->in.u.dealloc_stag.dev,
  3342. &pcmdinfo->in.u.dealloc_stag.info,
  3343. pcmdinfo->in.u.dealloc_stag.scratch,
  3344. pcmdinfo->post_sq);
  3345. break;
  3346. case OP_MW_ALLOC:
  3347. status = i40iw_sc_mw_alloc(
  3348. pcmdinfo->in.u.mw_alloc.dev,
  3349. pcmdinfo->in.u.mw_alloc.scratch,
  3350. pcmdinfo->in.u.mw_alloc.mw_stag_index,
  3351. pcmdinfo->in.u.mw_alloc.pd_id,
  3352. pcmdinfo->post_sq);
  3353. break;
  3354. case OP_QP_FLUSH_WQES:
  3355. status = i40iw_sc_qp_flush_wqes(
  3356. pcmdinfo->in.u.qp_flush_wqes.qp,
  3357. &pcmdinfo->in.u.qp_flush_wqes.info,
  3358. pcmdinfo->in.u.qp_flush_wqes.
  3359. scratch, pcmdinfo->post_sq);
  3360. break;
  3361. case OP_ADD_ARP_CACHE_ENTRY:
  3362. status = i40iw_sc_add_arp_cache_entry(
  3363. pcmdinfo->in.u.add_arp_cache_entry.cqp,
  3364. &pcmdinfo->in.u.add_arp_cache_entry.info,
  3365. pcmdinfo->in.u.add_arp_cache_entry.scratch,
  3366. pcmdinfo->post_sq);
  3367. break;
  3368. case OP_MANAGE_PUSH_PAGE:
  3369. status = i40iw_sc_manage_push_page(
  3370. pcmdinfo->in.u.manage_push_page.cqp,
  3371. &pcmdinfo->in.u.manage_push_page.info,
  3372. pcmdinfo->in.u.manage_push_page.scratch,
  3373. pcmdinfo->post_sq);
  3374. break;
  3375. case OP_UPDATE_PE_SDS:
  3376. /* case I40IW_CQP_OP_UPDATE_PE_SDS */
  3377. status = i40iw_update_pe_sds(
  3378. pcmdinfo->in.u.update_pe_sds.dev,
  3379. &pcmdinfo->in.u.update_pe_sds.info,
  3380. pcmdinfo->in.u.update_pe_sds.
  3381. scratch);
  3382. break;
  3383. case OP_MANAGE_HMC_PM_FUNC_TABLE:
  3384. status = i40iw_sc_manage_hmc_pm_func_table(
  3385. pcmdinfo->in.u.manage_hmc_pm.dev->cqp,
  3386. pcmdinfo->in.u.manage_hmc_pm.scratch,
  3387. (u8)pcmdinfo->in.u.manage_hmc_pm.info.vf_id,
  3388. pcmdinfo->in.u.manage_hmc_pm.info.free_fcn,
  3389. true);
  3390. break;
  3391. case OP_SUSPEND:
  3392. status = i40iw_sc_suspend_qp(
  3393. pcmdinfo->in.u.suspend_resume.cqp,
  3394. pcmdinfo->in.u.suspend_resume.qp,
  3395. pcmdinfo->in.u.suspend_resume.scratch);
  3396. break;
  3397. case OP_RESUME:
  3398. status = i40iw_sc_resume_qp(
  3399. pcmdinfo->in.u.suspend_resume.cqp,
  3400. pcmdinfo->in.u.suspend_resume.qp,
  3401. pcmdinfo->in.u.suspend_resume.scratch);
  3402. break;
  3403. case OP_MANAGE_VF_PBLE_BP:
  3404. status = i40iw_manage_vf_pble_bp(
  3405. pcmdinfo->in.u.manage_vf_pble_bp.cqp,
  3406. &pcmdinfo->in.u.manage_vf_pble_bp.info,
  3407. pcmdinfo->in.u.manage_vf_pble_bp.scratch, true);
  3408. break;
  3409. case OP_QUERY_FPM_VALUES:
  3410. values_mem.pa = pcmdinfo->in.u.query_fpm_values.fpm_values_pa;
  3411. values_mem.va = pcmdinfo->in.u.query_fpm_values.fpm_values_va;
  3412. status = i40iw_sc_query_fpm_values(
  3413. pcmdinfo->in.u.query_fpm_values.cqp,
  3414. pcmdinfo->in.u.query_fpm_values.scratch,
  3415. pcmdinfo->in.u.query_fpm_values.hmc_fn_id,
  3416. &values_mem, true, I40IW_CQP_WAIT_EVENT);
  3417. break;
  3418. case OP_COMMIT_FPM_VALUES:
  3419. values_mem.pa = pcmdinfo->in.u.commit_fpm_values.fpm_values_pa;
  3420. values_mem.va = pcmdinfo->in.u.commit_fpm_values.fpm_values_va;
  3421. status = i40iw_sc_commit_fpm_values(
  3422. pcmdinfo->in.u.commit_fpm_values.cqp,
  3423. pcmdinfo->in.u.commit_fpm_values.scratch,
  3424. pcmdinfo->in.u.commit_fpm_values.hmc_fn_id,
  3425. &values_mem,
  3426. true,
  3427. I40IW_CQP_WAIT_EVENT);
  3428. break;
  3429. default:
  3430. status = I40IW_NOT_SUPPORTED;
  3431. break;
  3432. }
  3433. return status;
  3434. }
  3435. /**
  3436. * i40iw_process_cqp_cmd - process all cqp commands
  3437. * @dev: sc device struct
  3438. * @pcmdinfo: cqp command info
  3439. */
  3440. enum i40iw_status_code i40iw_process_cqp_cmd(struct i40iw_sc_dev *dev,
  3441. struct cqp_commands_info *pcmdinfo)
  3442. {
  3443. enum i40iw_status_code status = 0;
  3444. unsigned long flags;
  3445. spin_lock_irqsave(&dev->cqp_lock, flags);
  3446. if (list_empty(&dev->cqp_cmd_head) && !i40iw_ring_full(dev->cqp))
  3447. status = i40iw_exec_cqp_cmd(dev, pcmdinfo);
  3448. else
  3449. list_add_tail(&pcmdinfo->cqp_cmd_entry, &dev->cqp_cmd_head);
  3450. spin_unlock_irqrestore(&dev->cqp_lock, flags);
  3451. return status;
  3452. }
  3453. /**
  3454. * i40iw_process_bh - called from tasklet for cqp list
  3455. * @dev: sc device struct
  3456. */
  3457. enum i40iw_status_code i40iw_process_bh(struct i40iw_sc_dev *dev)
  3458. {
  3459. enum i40iw_status_code status = 0;
  3460. struct cqp_commands_info *pcmdinfo;
  3461. unsigned long flags;
  3462. spin_lock_irqsave(&dev->cqp_lock, flags);
  3463. while (!list_empty(&dev->cqp_cmd_head) && !i40iw_ring_full(dev->cqp)) {
  3464. pcmdinfo = (struct cqp_commands_info *)i40iw_remove_head(&dev->cqp_cmd_head);
  3465. status = i40iw_exec_cqp_cmd(dev, pcmdinfo);
  3466. if (status)
  3467. break;
  3468. }
  3469. spin_unlock_irqrestore(&dev->cqp_lock, flags);
  3470. return status;
  3471. }
  3472. /**
  3473. * i40iw_iwarp_opcode - determine if incoming is rdma layer
  3474. * @info: aeq info for the packet
  3475. * @pkt: packet for error
  3476. */
  3477. static u32 i40iw_iwarp_opcode(struct i40iw_aeqe_info *info, u8 *pkt)
  3478. {
  3479. __be16 *mpa;
  3480. u32 opcode = 0xffffffff;
  3481. if (info->q2_data_written) {
  3482. mpa = (__be16 *)pkt;
  3483. opcode = ntohs(mpa[1]) & 0xf;
  3484. }
  3485. return opcode;
  3486. }
  3487. /**
  3488. * i40iw_locate_mpa - return pointer to mpa in the pkt
  3489. * @pkt: packet with data
  3490. */
  3491. static u8 *i40iw_locate_mpa(u8 *pkt)
  3492. {
  3493. /* skip over ethernet header */
  3494. pkt += I40IW_MAC_HLEN;
  3495. /* Skip over IP and TCP headers */
  3496. pkt += 4 * (pkt[0] & 0x0f);
  3497. pkt += 4 * ((pkt[12] >> 4) & 0x0f);
  3498. return pkt;
  3499. }
  3500. /**
  3501. * i40iw_setup_termhdr - termhdr for terminate pkt
  3502. * @qp: sc qp ptr for pkt
  3503. * @hdr: term hdr
  3504. * @opcode: flush opcode for termhdr
  3505. * @layer_etype: error layer + error type
  3506. * @err: error cod ein the header
  3507. */
  3508. static void i40iw_setup_termhdr(struct i40iw_sc_qp *qp,
  3509. struct i40iw_terminate_hdr *hdr,
  3510. enum i40iw_flush_opcode opcode,
  3511. u8 layer_etype,
  3512. u8 err)
  3513. {
  3514. qp->flush_code = opcode;
  3515. hdr->layer_etype = layer_etype;
  3516. hdr->error_code = err;
  3517. }
  3518. /**
  3519. * i40iw_bld_terminate_hdr - build terminate message header
  3520. * @qp: qp associated with received terminate AE
  3521. * @info: the struct contiaing AE information
  3522. */
  3523. static int i40iw_bld_terminate_hdr(struct i40iw_sc_qp *qp,
  3524. struct i40iw_aeqe_info *info)
  3525. {
  3526. u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
  3527. u16 ddp_seg_len;
  3528. int copy_len = 0;
  3529. u8 is_tagged = 0;
  3530. enum i40iw_flush_opcode flush_code = FLUSH_INVALID;
  3531. u32 opcode;
  3532. struct i40iw_terminate_hdr *termhdr;
  3533. termhdr = (struct i40iw_terminate_hdr *)qp->q2_buf;
  3534. memset(termhdr, 0, Q2_BAD_FRAME_OFFSET);
  3535. if (info->q2_data_written) {
  3536. /* Use data from offending packet to fill in ddp & rdma hdrs */
  3537. pkt = i40iw_locate_mpa(pkt);
  3538. ddp_seg_len = ntohs(*(__be16 *)pkt);
  3539. if (ddp_seg_len) {
  3540. copy_len = 2;
  3541. termhdr->hdrct = DDP_LEN_FLAG;
  3542. if (pkt[2] & 0x80) {
  3543. is_tagged = 1;
  3544. if (ddp_seg_len >= TERM_DDP_LEN_TAGGED) {
  3545. copy_len += TERM_DDP_LEN_TAGGED;
  3546. termhdr->hdrct |= DDP_HDR_FLAG;
  3547. }
  3548. } else {
  3549. if (ddp_seg_len >= TERM_DDP_LEN_UNTAGGED) {
  3550. copy_len += TERM_DDP_LEN_UNTAGGED;
  3551. termhdr->hdrct |= DDP_HDR_FLAG;
  3552. }
  3553. if (ddp_seg_len >= (TERM_DDP_LEN_UNTAGGED + TERM_RDMA_LEN)) {
  3554. if ((pkt[3] & RDMA_OPCODE_MASK) == RDMA_READ_REQ_OPCODE) {
  3555. copy_len += TERM_RDMA_LEN;
  3556. termhdr->hdrct |= RDMA_HDR_FLAG;
  3557. }
  3558. }
  3559. }
  3560. }
  3561. }
  3562. opcode = i40iw_iwarp_opcode(info, pkt);
  3563. switch (info->ae_id) {
  3564. case I40IW_AE_AMP_UNALLOCATED_STAG:
  3565. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3566. if (opcode == I40IW_OP_TYPE_RDMA_WRITE)
  3567. i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
  3568. (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_INV_STAG);
  3569. else
  3570. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3571. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_STAG);
  3572. break;
  3573. case I40IW_AE_AMP_BOUNDS_VIOLATION:
  3574. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3575. if (info->q2_data_written)
  3576. i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
  3577. (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_BOUNDS);
  3578. else
  3579. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3580. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_BOUNDS);
  3581. break;
  3582. case I40IW_AE_AMP_BAD_PD:
  3583. switch (opcode) {
  3584. case I40IW_OP_TYPE_RDMA_WRITE:
  3585. i40iw_setup_termhdr(qp, termhdr, FLUSH_PROT_ERR,
  3586. (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_UNASSOC_STAG);
  3587. break;
  3588. case I40IW_OP_TYPE_SEND_INV:
  3589. case I40IW_OP_TYPE_SEND_SOL_INV:
  3590. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3591. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_CANT_INV_STAG);
  3592. break;
  3593. default:
  3594. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3595. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_UNASSOC_STAG);
  3596. }
  3597. break;
  3598. case I40IW_AE_AMP_INVALID_STAG:
  3599. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3600. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3601. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_INV_STAG);
  3602. break;
  3603. case I40IW_AE_AMP_BAD_QP:
  3604. i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
  3605. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_QN);
  3606. break;
  3607. case I40IW_AE_AMP_BAD_STAG_KEY:
  3608. case I40IW_AE_AMP_BAD_STAG_INDEX:
  3609. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3610. switch (opcode) {
  3611. case I40IW_OP_TYPE_SEND_INV:
  3612. case I40IW_OP_TYPE_SEND_SOL_INV:
  3613. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_OP_ERR,
  3614. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_CANT_INV_STAG);
  3615. break;
  3616. default:
  3617. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3618. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_INV_STAG);
  3619. }
  3620. break;
  3621. case I40IW_AE_AMP_RIGHTS_VIOLATION:
  3622. case I40IW_AE_AMP_INVALIDATE_NO_REMOTE_ACCESS_RIGHTS:
  3623. case I40IW_AE_PRIV_OPERATION_DENIED:
  3624. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3625. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3626. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_ACCESS);
  3627. break;
  3628. case I40IW_AE_AMP_TO_WRAP:
  3629. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3630. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  3631. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT, RDMAP_TO_WRAP);
  3632. break;
  3633. case I40IW_AE_LLP_RECEIVED_MARKER_AND_LENGTH_FIELDS_DONT_MATCH:
  3634. i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
  3635. (LAYER_MPA << 4) | DDP_LLP, MPA_MARKER);
  3636. break;
  3637. case I40IW_AE_LLP_RECEIVED_MPA_CRC_ERROR:
  3638. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3639. (LAYER_MPA << 4) | DDP_LLP, MPA_CRC);
  3640. break;
  3641. case I40IW_AE_LLP_SEGMENT_TOO_LARGE:
  3642. case I40IW_AE_LLP_SEGMENT_TOO_SMALL:
  3643. i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
  3644. (LAYER_DDP << 4) | DDP_CATASTROPHIC, DDP_CATASTROPHIC_LOCAL);
  3645. break;
  3646. case I40IW_AE_LCE_QP_CATASTROPHIC:
  3647. case I40IW_AE_DDP_NO_L_BIT:
  3648. i40iw_setup_termhdr(qp, termhdr, FLUSH_FATAL_ERR,
  3649. (LAYER_DDP << 4) | DDP_CATASTROPHIC, DDP_CATASTROPHIC_LOCAL);
  3650. break;
  3651. case I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN:
  3652. case I40IW_AE_DDP_INVALID_MSN_RANGE_IS_NOT_VALID:
  3653. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3654. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MSN_RANGE);
  3655. break;
  3656. case I40IW_AE_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
  3657. qp->eventtype = TERM_EVENT_QP_ACCESS_ERR;
  3658. i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_LEN_ERR,
  3659. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_TOO_LONG);
  3660. break;
  3661. case I40IW_AE_DDP_UBE_INVALID_DDP_VERSION:
  3662. if (is_tagged)
  3663. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3664. (LAYER_DDP << 4) | DDP_TAGGED_BUFFER, DDP_TAGGED_INV_DDP_VER);
  3665. else
  3666. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3667. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_DDP_VER);
  3668. break;
  3669. case I40IW_AE_DDP_UBE_INVALID_MO:
  3670. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3671. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MO);
  3672. break;
  3673. case I40IW_AE_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
  3674. i40iw_setup_termhdr(qp, termhdr, FLUSH_REM_OP_ERR,
  3675. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_MSN_NO_BUF);
  3676. break;
  3677. case I40IW_AE_DDP_UBE_INVALID_QN:
  3678. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3679. (LAYER_DDP << 4) | DDP_UNTAGGED_BUFFER, DDP_UNTAGGED_INV_QN);
  3680. break;
  3681. case I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
  3682. i40iw_setup_termhdr(qp, termhdr, FLUSH_GENERAL_ERR,
  3683. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_INV_RDMAP_VER);
  3684. break;
  3685. case I40IW_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
  3686. i40iw_setup_termhdr(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
  3687. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_UNEXPECTED_OP);
  3688. break;
  3689. default:
  3690. i40iw_setup_termhdr(qp, termhdr, FLUSH_FATAL_ERR,
  3691. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP, RDMAP_UNSPECIFIED);
  3692. break;
  3693. }
  3694. if (copy_len)
  3695. memcpy(termhdr + 1, pkt, copy_len);
  3696. if (flush_code && !info->in_rdrsp_wr)
  3697. qp->sq_flush = (info->sq) ? true : false;
  3698. return sizeof(struct i40iw_terminate_hdr) + copy_len;
  3699. }
  3700. /**
  3701. * i40iw_terminate_send_fin() - Send fin for terminate message
  3702. * @qp: qp associated with received terminate AE
  3703. */
  3704. void i40iw_terminate_send_fin(struct i40iw_sc_qp *qp)
  3705. {
  3706. /* Send the fin only */
  3707. i40iw_term_modify_qp(qp,
  3708. I40IW_QP_STATE_TERMINATE,
  3709. I40IWQP_TERM_SEND_FIN_ONLY,
  3710. 0);
  3711. }
  3712. /**
  3713. * i40iw_terminate_connection() - Bad AE and send terminate to remote QP
  3714. * @qp: qp associated with received terminate AE
  3715. * @info: the struct contiaing AE information
  3716. */
  3717. void i40iw_terminate_connection(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info)
  3718. {
  3719. u8 termlen = 0;
  3720. if (qp->term_flags & I40IW_TERM_SENT)
  3721. return; /* Sanity check */
  3722. /* Eventtype can change from bld_terminate_hdr */
  3723. qp->eventtype = TERM_EVENT_QP_FATAL;
  3724. termlen = i40iw_bld_terminate_hdr(qp, info);
  3725. i40iw_terminate_start_timer(qp);
  3726. qp->term_flags |= I40IW_TERM_SENT;
  3727. i40iw_term_modify_qp(qp, I40IW_QP_STATE_TERMINATE,
  3728. I40IWQP_TERM_SEND_TERM_ONLY, termlen);
  3729. }
  3730. /**
  3731. * i40iw_terminate_received - handle terminate received AE
  3732. * @qp: qp associated with received terminate AE
  3733. * @info: the struct contiaing AE information
  3734. */
  3735. void i40iw_terminate_received(struct i40iw_sc_qp *qp, struct i40iw_aeqe_info *info)
  3736. {
  3737. u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
  3738. __be32 *mpa;
  3739. u8 ddp_ctl;
  3740. u8 rdma_ctl;
  3741. u16 aeq_id = 0;
  3742. struct i40iw_terminate_hdr *termhdr;
  3743. mpa = (__be32 *)i40iw_locate_mpa(pkt);
  3744. if (info->q2_data_written) {
  3745. /* did not validate the frame - do it now */
  3746. ddp_ctl = (ntohl(mpa[0]) >> 8) & 0xff;
  3747. rdma_ctl = ntohl(mpa[0]) & 0xff;
  3748. if ((ddp_ctl & 0xc0) != 0x40)
  3749. aeq_id = I40IW_AE_LCE_QP_CATASTROPHIC;
  3750. else if ((ddp_ctl & 0x03) != 1)
  3751. aeq_id = I40IW_AE_DDP_UBE_INVALID_DDP_VERSION;
  3752. else if (ntohl(mpa[2]) != 2)
  3753. aeq_id = I40IW_AE_DDP_UBE_INVALID_QN;
  3754. else if (ntohl(mpa[3]) != 1)
  3755. aeq_id = I40IW_AE_DDP_INVALID_MSN_GAP_IN_MSN;
  3756. else if (ntohl(mpa[4]) != 0)
  3757. aeq_id = I40IW_AE_DDP_UBE_INVALID_MO;
  3758. else if ((rdma_ctl & 0xc0) != 0x40)
  3759. aeq_id = I40IW_AE_RDMAP_ROE_INVALID_RDMAP_VERSION;
  3760. info->ae_id = aeq_id;
  3761. if (info->ae_id) {
  3762. /* Bad terminate recvd - send back a terminate */
  3763. i40iw_terminate_connection(qp, info);
  3764. return;
  3765. }
  3766. }
  3767. qp->term_flags |= I40IW_TERM_RCVD;
  3768. qp->eventtype = TERM_EVENT_QP_FATAL;
  3769. termhdr = (struct i40iw_terminate_hdr *)&mpa[5];
  3770. if (termhdr->layer_etype == RDMAP_REMOTE_PROT ||
  3771. termhdr->layer_etype == RDMAP_REMOTE_OP) {
  3772. i40iw_terminate_done(qp, 0);
  3773. } else {
  3774. i40iw_terminate_start_timer(qp);
  3775. i40iw_terminate_send_fin(qp);
  3776. }
  3777. }
  3778. /**
  3779. * i40iw_hw_stat_init - Initiliaze HW stats table
  3780. * @devstat: pestat struct
  3781. * @fcn_idx: PCI fn id
  3782. * @hw: PF i40iw_hw structure.
  3783. * @is_pf: Is it a PF?
  3784. *
  3785. * Populate the HW stat table with register offset addr for each
  3786. * stat. And start the perioidic stats timer.
  3787. */
  3788. static void i40iw_hw_stat_init(struct i40iw_dev_pestat *devstat,
  3789. u8 fcn_idx,
  3790. struct i40iw_hw *hw, bool is_pf)
  3791. {
  3792. u32 stat_reg_offset;
  3793. u32 stat_index;
  3794. struct i40iw_dev_hw_stat_offsets *stat_table =
  3795. &devstat->hw_stat_offsets;
  3796. struct i40iw_dev_hw_stats *last_rd_stats = &devstat->last_read_hw_stats;
  3797. devstat->hw = hw;
  3798. if (is_pf) {
  3799. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] =
  3800. I40E_GLPES_PFIP4RXDISCARD(fcn_idx);
  3801. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] =
  3802. I40E_GLPES_PFIP4RXTRUNC(fcn_idx);
  3803. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] =
  3804. I40E_GLPES_PFIP4TXNOROUTE(fcn_idx);
  3805. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD] =
  3806. I40E_GLPES_PFIP6RXDISCARD(fcn_idx);
  3807. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC] =
  3808. I40E_GLPES_PFIP6RXTRUNC(fcn_idx);
  3809. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE] =
  3810. I40E_GLPES_PFIP6TXNOROUTE(fcn_idx);
  3811. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRTXSEG] =
  3812. I40E_GLPES_PFTCPRTXSEG(fcn_idx);
  3813. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXOPTERR] =
  3814. I40E_GLPES_PFTCPRXOPTERR(fcn_idx);
  3815. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXPROTOERR] =
  3816. I40E_GLPES_PFTCPRXPROTOERR(fcn_idx);
  3817. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXOCTS] =
  3818. I40E_GLPES_PFIP4RXOCTSLO(fcn_idx);
  3819. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] =
  3820. I40E_GLPES_PFIP4RXPKTSLO(fcn_idx);
  3821. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] =
  3822. I40E_GLPES_PFIP4RXFRAGSLO(fcn_idx);
  3823. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] =
  3824. I40E_GLPES_PFIP4RXMCPKTSLO(fcn_idx);
  3825. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXOCTS] =
  3826. I40E_GLPES_PFIP4TXOCTSLO(fcn_idx);
  3827. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXPKTS] =
  3828. I40E_GLPES_PFIP4TXPKTSLO(fcn_idx);
  3829. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] =
  3830. I40E_GLPES_PFIP4TXFRAGSLO(fcn_idx);
  3831. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] =
  3832. I40E_GLPES_PFIP4TXMCPKTSLO(fcn_idx);
  3833. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXOCTS] =
  3834. I40E_GLPES_PFIP6RXOCTSLO(fcn_idx);
  3835. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXPKTS] =
  3836. I40E_GLPES_PFIP6RXPKTSLO(fcn_idx);
  3837. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS] =
  3838. I40E_GLPES_PFIP6RXFRAGSLO(fcn_idx);
  3839. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS] =
  3840. I40E_GLPES_PFIP6RXMCPKTSLO(fcn_idx);
  3841. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXOCTS] =
  3842. I40E_GLPES_PFIP6TXOCTSLO(fcn_idx);
  3843. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
  3844. I40E_GLPES_PFIP6TXPKTSLO(fcn_idx);
  3845. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
  3846. I40E_GLPES_PFIP6TXPKTSLO(fcn_idx);
  3847. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS] =
  3848. I40E_GLPES_PFIP6TXFRAGSLO(fcn_idx);
  3849. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPRXSEGS] =
  3850. I40E_GLPES_PFTCPRXSEGSLO(fcn_idx);
  3851. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPTXSEG] =
  3852. I40E_GLPES_PFTCPTXSEGLO(fcn_idx);
  3853. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXRDS] =
  3854. I40E_GLPES_PFRDMARXRDSLO(fcn_idx);
  3855. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXSNDS] =
  3856. I40E_GLPES_PFRDMARXSNDSLO(fcn_idx);
  3857. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXWRS] =
  3858. I40E_GLPES_PFRDMARXWRSLO(fcn_idx);
  3859. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXRDS] =
  3860. I40E_GLPES_PFRDMATXRDSLO(fcn_idx);
  3861. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXSNDS] =
  3862. I40E_GLPES_PFRDMATXSNDSLO(fcn_idx);
  3863. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXWRS] =
  3864. I40E_GLPES_PFRDMATXWRSLO(fcn_idx);
  3865. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVBND] =
  3866. I40E_GLPES_PFRDMAVBNDLO(fcn_idx);
  3867. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVINV] =
  3868. I40E_GLPES_PFRDMAVINVLO(fcn_idx);
  3869. } else {
  3870. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] =
  3871. I40E_GLPES_VFIP4RXDISCARD(fcn_idx);
  3872. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] =
  3873. I40E_GLPES_VFIP4RXTRUNC(fcn_idx);
  3874. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] =
  3875. I40E_GLPES_VFIP4TXNOROUTE(fcn_idx);
  3876. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD] =
  3877. I40E_GLPES_VFIP6RXDISCARD(fcn_idx);
  3878. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC] =
  3879. I40E_GLPES_VFIP6RXTRUNC(fcn_idx);
  3880. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE] =
  3881. I40E_GLPES_VFIP6TXNOROUTE(fcn_idx);
  3882. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRTXSEG] =
  3883. I40E_GLPES_VFTCPRTXSEG(fcn_idx);
  3884. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXOPTERR] =
  3885. I40E_GLPES_VFTCPRXOPTERR(fcn_idx);
  3886. stat_table->stat_offset_32[I40IW_HW_STAT_INDEX_TCPRXPROTOERR] =
  3887. I40E_GLPES_VFTCPRXPROTOERR(fcn_idx);
  3888. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXOCTS] =
  3889. I40E_GLPES_VFIP4RXOCTSLO(fcn_idx);
  3890. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] =
  3891. I40E_GLPES_VFIP4RXPKTSLO(fcn_idx);
  3892. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] =
  3893. I40E_GLPES_VFIP4RXFRAGSLO(fcn_idx);
  3894. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] =
  3895. I40E_GLPES_VFIP4RXMCPKTSLO(fcn_idx);
  3896. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXOCTS] =
  3897. I40E_GLPES_VFIP4TXOCTSLO(fcn_idx);
  3898. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXPKTS] =
  3899. I40E_GLPES_VFIP4TXPKTSLO(fcn_idx);
  3900. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] =
  3901. I40E_GLPES_VFIP4TXFRAGSLO(fcn_idx);
  3902. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] =
  3903. I40E_GLPES_VFIP4TXMCPKTSLO(fcn_idx);
  3904. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXOCTS] =
  3905. I40E_GLPES_VFIP6RXOCTSLO(fcn_idx);
  3906. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXPKTS] =
  3907. I40E_GLPES_VFIP6RXPKTSLO(fcn_idx);
  3908. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS] =
  3909. I40E_GLPES_VFIP6RXFRAGSLO(fcn_idx);
  3910. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS] =
  3911. I40E_GLPES_VFIP6RXMCPKTSLO(fcn_idx);
  3912. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXOCTS] =
  3913. I40E_GLPES_VFIP6TXOCTSLO(fcn_idx);
  3914. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
  3915. I40E_GLPES_VFIP6TXPKTSLO(fcn_idx);
  3916. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXPKTS] =
  3917. I40E_GLPES_VFIP6TXPKTSLO(fcn_idx);
  3918. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS] =
  3919. I40E_GLPES_VFIP6TXFRAGSLO(fcn_idx);
  3920. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPRXSEGS] =
  3921. I40E_GLPES_VFTCPRXSEGSLO(fcn_idx);
  3922. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_TCPTXSEG] =
  3923. I40E_GLPES_VFTCPTXSEGLO(fcn_idx);
  3924. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXRDS] =
  3925. I40E_GLPES_VFRDMARXRDSLO(fcn_idx);
  3926. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXSNDS] =
  3927. I40E_GLPES_VFRDMARXSNDSLO(fcn_idx);
  3928. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMARXWRS] =
  3929. I40E_GLPES_VFRDMARXWRSLO(fcn_idx);
  3930. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXRDS] =
  3931. I40E_GLPES_VFRDMATXRDSLO(fcn_idx);
  3932. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXSNDS] =
  3933. I40E_GLPES_VFRDMATXSNDSLO(fcn_idx);
  3934. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMATXWRS] =
  3935. I40E_GLPES_VFRDMATXWRSLO(fcn_idx);
  3936. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVBND] =
  3937. I40E_GLPES_VFRDMAVBNDLO(fcn_idx);
  3938. stat_table->stat_offset_64[I40IW_HW_STAT_INDEX_RDMAVINV] =
  3939. I40E_GLPES_VFRDMAVINVLO(fcn_idx);
  3940. }
  3941. for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_64;
  3942. stat_index++) {
  3943. stat_reg_offset = stat_table->stat_offset_64[stat_index];
  3944. last_rd_stats->stat_value_64[stat_index] =
  3945. readq(devstat->hw->hw_addr + stat_reg_offset);
  3946. }
  3947. for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_32;
  3948. stat_index++) {
  3949. stat_reg_offset = stat_table->stat_offset_32[stat_index];
  3950. last_rd_stats->stat_value_32[stat_index] =
  3951. i40iw_rd32(devstat->hw, stat_reg_offset);
  3952. }
  3953. }
  3954. /**
  3955. * i40iw_hw_stat_read_32 - Read 32-bit HW stat counters and accommodates for roll-overs.
  3956. * @devstat: pestat struct
  3957. * @index: index in HW stat table which contains offset reg-addr
  3958. * @value: hw stat value
  3959. */
  3960. static void i40iw_hw_stat_read_32(struct i40iw_dev_pestat *devstat,
  3961. enum i40iw_hw_stat_index_32b index,
  3962. u64 *value)
  3963. {
  3964. struct i40iw_dev_hw_stat_offsets *stat_table =
  3965. &devstat->hw_stat_offsets;
  3966. struct i40iw_dev_hw_stats *last_rd_stats = &devstat->last_read_hw_stats;
  3967. struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats;
  3968. u64 new_stat_value = 0;
  3969. u32 stat_reg_offset = stat_table->stat_offset_32[index];
  3970. new_stat_value = i40iw_rd32(devstat->hw, stat_reg_offset);
  3971. /*roll-over case */
  3972. if (new_stat_value < last_rd_stats->stat_value_32[index])
  3973. hw_stats->stat_value_32[index] += new_stat_value;
  3974. else
  3975. hw_stats->stat_value_32[index] +=
  3976. new_stat_value - last_rd_stats->stat_value_32[index];
  3977. last_rd_stats->stat_value_32[index] = new_stat_value;
  3978. *value = hw_stats->stat_value_32[index];
  3979. }
  3980. /**
  3981. * i40iw_hw_stat_read_64 - Read HW stat counters (greater than 32-bit) and accommodates for roll-overs.
  3982. * @devstat: pestat struct
  3983. * @index: index in HW stat table which contains offset reg-addr
  3984. * @value: hw stat value
  3985. */
  3986. static void i40iw_hw_stat_read_64(struct i40iw_dev_pestat *devstat,
  3987. enum i40iw_hw_stat_index_64b index,
  3988. u64 *value)
  3989. {
  3990. struct i40iw_dev_hw_stat_offsets *stat_table =
  3991. &devstat->hw_stat_offsets;
  3992. struct i40iw_dev_hw_stats *last_rd_stats = &devstat->last_read_hw_stats;
  3993. struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats;
  3994. u64 new_stat_value = 0;
  3995. u32 stat_reg_offset = stat_table->stat_offset_64[index];
  3996. new_stat_value = readq(devstat->hw->hw_addr + stat_reg_offset);
  3997. /*roll-over case */
  3998. if (new_stat_value < last_rd_stats->stat_value_64[index])
  3999. hw_stats->stat_value_64[index] += new_stat_value;
  4000. else
  4001. hw_stats->stat_value_64[index] +=
  4002. new_stat_value - last_rd_stats->stat_value_64[index];
  4003. last_rd_stats->stat_value_64[index] = new_stat_value;
  4004. *value = hw_stats->stat_value_64[index];
  4005. }
  4006. /**
  4007. * i40iw_hw_stat_read_all - read all HW stat counters
  4008. * @devstat: pestat struct
  4009. * @stat_values: hw stats structure
  4010. *
  4011. * Read all the HW stat counters and populates hw_stats structure
  4012. * of passed-in dev's pestat as well as copy created in stat_values.
  4013. */
  4014. static void i40iw_hw_stat_read_all(struct i40iw_dev_pestat *devstat,
  4015. struct i40iw_dev_hw_stats *stat_values)
  4016. {
  4017. u32 stat_index;
  4018. for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_32;
  4019. stat_index++)
  4020. i40iw_hw_stat_read_32(devstat, stat_index,
  4021. &stat_values->stat_value_32[stat_index]);
  4022. for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_64;
  4023. stat_index++)
  4024. i40iw_hw_stat_read_64(devstat, stat_index,
  4025. &stat_values->stat_value_64[stat_index]);
  4026. }
  4027. /**
  4028. * i40iw_hw_stat_refresh_all - Update all HW stat structs
  4029. * @devstat: pestat struct
  4030. * @stat_values: hw stats structure
  4031. *
  4032. * Read all the HW stat counters to refresh values in hw_stats structure
  4033. * of passed-in dev's pestat
  4034. */
  4035. static void i40iw_hw_stat_refresh_all(struct i40iw_dev_pestat *devstat)
  4036. {
  4037. u64 stat_value;
  4038. u32 stat_index;
  4039. for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_32;
  4040. stat_index++)
  4041. i40iw_hw_stat_read_32(devstat, stat_index, &stat_value);
  4042. for (stat_index = 0; stat_index < I40IW_HW_STAT_INDEX_MAX_64;
  4043. stat_index++)
  4044. i40iw_hw_stat_read_64(devstat, stat_index, &stat_value);
  4045. }
  4046. static struct i40iw_cqp_ops iw_cqp_ops = {
  4047. i40iw_sc_cqp_init,
  4048. i40iw_sc_cqp_create,
  4049. i40iw_sc_cqp_post_sq,
  4050. i40iw_sc_cqp_get_next_send_wqe,
  4051. i40iw_sc_cqp_destroy,
  4052. i40iw_sc_poll_for_cqp_op_done
  4053. };
  4054. static struct i40iw_ccq_ops iw_ccq_ops = {
  4055. i40iw_sc_ccq_init,
  4056. i40iw_sc_ccq_create,
  4057. i40iw_sc_ccq_destroy,
  4058. i40iw_sc_ccq_create_done,
  4059. i40iw_sc_ccq_get_cqe_info,
  4060. i40iw_sc_ccq_arm
  4061. };
  4062. static struct i40iw_ceq_ops iw_ceq_ops = {
  4063. i40iw_sc_ceq_init,
  4064. i40iw_sc_ceq_create,
  4065. i40iw_sc_cceq_create_done,
  4066. i40iw_sc_cceq_destroy_done,
  4067. i40iw_sc_cceq_create,
  4068. i40iw_sc_ceq_destroy,
  4069. i40iw_sc_process_ceq
  4070. };
  4071. static struct i40iw_aeq_ops iw_aeq_ops = {
  4072. i40iw_sc_aeq_init,
  4073. i40iw_sc_aeq_create,
  4074. i40iw_sc_aeq_destroy,
  4075. i40iw_sc_get_next_aeqe,
  4076. i40iw_sc_repost_aeq_entries,
  4077. i40iw_sc_aeq_create_done,
  4078. i40iw_sc_aeq_destroy_done
  4079. };
  4080. /* iwarp pd ops */
  4081. static struct i40iw_pd_ops iw_pd_ops = {
  4082. i40iw_sc_pd_init,
  4083. };
  4084. static struct i40iw_priv_qp_ops iw_priv_qp_ops = {
  4085. .qp_init = i40iw_sc_qp_init,
  4086. .qp_create = i40iw_sc_qp_create,
  4087. .qp_modify = i40iw_sc_qp_modify,
  4088. .qp_destroy = i40iw_sc_qp_destroy,
  4089. .qp_flush_wqes = i40iw_sc_qp_flush_wqes,
  4090. .qp_upload_context = i40iw_sc_qp_upload_context,
  4091. .qp_setctx = i40iw_sc_qp_setctx,
  4092. .qp_send_lsmm = i40iw_sc_send_lsmm,
  4093. .qp_send_lsmm_nostag = i40iw_sc_send_lsmm_nostag,
  4094. .qp_send_rtt = i40iw_sc_send_rtt,
  4095. .qp_post_wqe0 = i40iw_sc_post_wqe0,
  4096. .iw_mr_fast_register = i40iw_sc_mr_fast_register
  4097. };
  4098. static struct i40iw_priv_cq_ops iw_priv_cq_ops = {
  4099. i40iw_sc_cq_init,
  4100. i40iw_sc_cq_create,
  4101. i40iw_sc_cq_destroy,
  4102. i40iw_sc_cq_modify,
  4103. };
  4104. static struct i40iw_mr_ops iw_mr_ops = {
  4105. i40iw_sc_alloc_stag,
  4106. i40iw_sc_mr_reg_non_shared,
  4107. i40iw_sc_mr_reg_shared,
  4108. i40iw_sc_dealloc_stag,
  4109. i40iw_sc_query_stag,
  4110. i40iw_sc_mw_alloc
  4111. };
  4112. static struct i40iw_cqp_misc_ops iw_cqp_misc_ops = {
  4113. i40iw_sc_manage_push_page,
  4114. i40iw_sc_manage_hmc_pm_func_table,
  4115. i40iw_sc_set_hmc_resource_profile,
  4116. i40iw_sc_commit_fpm_values,
  4117. i40iw_sc_query_fpm_values,
  4118. i40iw_sc_static_hmc_pages_allocated,
  4119. i40iw_sc_add_arp_cache_entry,
  4120. i40iw_sc_del_arp_cache_entry,
  4121. i40iw_sc_query_arp_cache_entry,
  4122. i40iw_sc_manage_apbvt_entry,
  4123. i40iw_sc_manage_qhash_table_entry,
  4124. i40iw_sc_alloc_local_mac_ipaddr_entry,
  4125. i40iw_sc_add_local_mac_ipaddr_entry,
  4126. i40iw_sc_del_local_mac_ipaddr_entry,
  4127. i40iw_sc_cqp_nop,
  4128. i40iw_sc_commit_fpm_values_done,
  4129. i40iw_sc_query_fpm_values_done,
  4130. i40iw_sc_manage_hmc_pm_func_table_done,
  4131. i40iw_sc_suspend_qp,
  4132. i40iw_sc_resume_qp
  4133. };
  4134. static struct i40iw_hmc_ops iw_hmc_ops = {
  4135. i40iw_sc_init_iw_hmc,
  4136. i40iw_sc_parse_fpm_query_buf,
  4137. i40iw_sc_configure_iw_fpm,
  4138. i40iw_sc_parse_fpm_commit_buf,
  4139. i40iw_sc_create_hmc_obj,
  4140. i40iw_sc_del_hmc_obj,
  4141. NULL,
  4142. NULL
  4143. };
  4144. static const struct i40iw_device_pestat_ops iw_device_pestat_ops = {
  4145. i40iw_hw_stat_init,
  4146. i40iw_hw_stat_read_32,
  4147. i40iw_hw_stat_read_64,
  4148. i40iw_hw_stat_read_all,
  4149. i40iw_hw_stat_refresh_all
  4150. };
  4151. /**
  4152. * i40iw_device_init_pestat - Initialize the pestat structure
  4153. * @dev: pestat struct
  4154. */
  4155. enum i40iw_status_code i40iw_device_init_pestat(struct i40iw_dev_pestat *devstat)
  4156. {
  4157. devstat->ops = iw_device_pestat_ops;
  4158. return 0;
  4159. }
  4160. /**
  4161. * i40iw_device_init - Initialize IWARP device
  4162. * @dev: IWARP device pointer
  4163. * @info: IWARP init info
  4164. */
  4165. enum i40iw_status_code i40iw_device_init(struct i40iw_sc_dev *dev,
  4166. struct i40iw_device_init_info *info)
  4167. {
  4168. u32 val;
  4169. u32 vchnl_ver = 0;
  4170. u16 hmc_fcn = 0;
  4171. enum i40iw_status_code ret_code = 0;
  4172. u8 db_size;
  4173. spin_lock_init(&dev->cqp_lock);
  4174. INIT_LIST_HEAD(&dev->cqp_cmd_head); /* for the cqp commands backlog. */
  4175. i40iw_device_init_uk(&dev->dev_uk);
  4176. dev->debug_mask = info->debug_mask;
  4177. ret_code = i40iw_device_init_pestat(&dev->dev_pestat);
  4178. if (ret_code) {
  4179. i40iw_debug(dev, I40IW_DEBUG_DEV,
  4180. "%s: i40iw_device_init_pestat failed\n", __func__);
  4181. return ret_code;
  4182. }
  4183. dev->hmc_fn_id = info->hmc_fn_id;
  4184. dev->qs_handle = info->qs_handle;
  4185. dev->exception_lan_queue = info->exception_lan_queue;
  4186. dev->is_pf = info->is_pf;
  4187. dev->fpm_query_buf_pa = info->fpm_query_buf_pa;
  4188. dev->fpm_query_buf = info->fpm_query_buf;
  4189. dev->fpm_commit_buf_pa = info->fpm_commit_buf_pa;
  4190. dev->fpm_commit_buf = info->fpm_commit_buf;
  4191. dev->hw = info->hw;
  4192. dev->hw->hw_addr = info->bar0;
  4193. val = i40iw_rd32(dev->hw, I40E_GLPCI_DREVID);
  4194. dev->hw_rev = (u8)RS_32(val, I40E_GLPCI_DREVID_DEFAULT_REVID);
  4195. if (dev->is_pf) {
  4196. dev->dev_pestat.ops.iw_hw_stat_init(&dev->dev_pestat,
  4197. dev->hmc_fn_id, dev->hw, true);
  4198. spin_lock_init(&dev->dev_pestat.stats_lock);
  4199. /*start the periodic stats_timer */
  4200. i40iw_hw_stats_start_timer(dev);
  4201. val = i40iw_rd32(dev->hw, I40E_GLPCI_LBARCTRL);
  4202. db_size = (u8)RS_32(val, I40E_GLPCI_LBARCTRL_PE_DB_SIZE);
  4203. if ((db_size != I40IW_PE_DB_SIZE_4M) &&
  4204. (db_size != I40IW_PE_DB_SIZE_8M)) {
  4205. i40iw_debug(dev, I40IW_DEBUG_DEV,
  4206. "%s: PE doorbell is not enabled in CSR val 0x%x\n",
  4207. __func__, val);
  4208. ret_code = I40IW_ERR_PE_DOORBELL_NOT_ENABLED;
  4209. return ret_code;
  4210. }
  4211. dev->db_addr = dev->hw->hw_addr + I40IW_DB_ADDR_OFFSET;
  4212. dev->vchnl_if.vchnl_recv = i40iw_vchnl_recv_pf;
  4213. } else {
  4214. dev->db_addr = dev->hw->hw_addr + I40IW_VF_DB_ADDR_OFFSET;
  4215. }
  4216. dev->cqp_ops = &iw_cqp_ops;
  4217. dev->ccq_ops = &iw_ccq_ops;
  4218. dev->ceq_ops = &iw_ceq_ops;
  4219. dev->aeq_ops = &iw_aeq_ops;
  4220. dev->cqp_misc_ops = &iw_cqp_misc_ops;
  4221. dev->iw_pd_ops = &iw_pd_ops;
  4222. dev->iw_priv_qp_ops = &iw_priv_qp_ops;
  4223. dev->iw_priv_cq_ops = &iw_priv_cq_ops;
  4224. dev->mr_ops = &iw_mr_ops;
  4225. dev->hmc_ops = &iw_hmc_ops;
  4226. dev->vchnl_if.vchnl_send = info->vchnl_send;
  4227. if (dev->vchnl_if.vchnl_send)
  4228. dev->vchnl_up = true;
  4229. else
  4230. dev->vchnl_up = false;
  4231. if (!dev->is_pf) {
  4232. dev->vchnl_if.vchnl_recv = i40iw_vchnl_recv_vf;
  4233. ret_code = i40iw_vchnl_vf_get_ver(dev, &vchnl_ver);
  4234. if (!ret_code) {
  4235. i40iw_debug(dev, I40IW_DEBUG_DEV,
  4236. "%s: Get Channel version rc = 0x%0x, version is %u\n",
  4237. __func__, ret_code, vchnl_ver);
  4238. ret_code = i40iw_vchnl_vf_get_hmc_fcn(dev, &hmc_fcn);
  4239. if (!ret_code) {
  4240. i40iw_debug(dev, I40IW_DEBUG_DEV,
  4241. "%s Get HMC function rc = 0x%0x, hmc fcn is %u\n",
  4242. __func__, ret_code, hmc_fcn);
  4243. dev->hmc_fn_id = (u8)hmc_fcn;
  4244. }
  4245. }
  4246. }
  4247. dev->iw_vf_cqp_ops = &iw_vf_cqp_ops;
  4248. return ret_code;
  4249. }