ctrl.c 166 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489
  1. // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
  2. /* Copyright (c) 2015 - 2021 Intel Corporation */
  3. #include <linux/etherdevice.h>
  4. #include "osdep.h"
  5. #include "hmc.h"
  6. #include "defs.h"
  7. #include "type.h"
  8. #include "ws.h"
  9. #include "protos.h"
  10. /**
  11. * irdma_get_qp_from_list - get next qp from a list
  12. * @head: Listhead of qp's
  13. * @qp: current qp
  14. */
  15. struct irdma_sc_qp *irdma_get_qp_from_list(struct list_head *head,
  16. struct irdma_sc_qp *qp)
  17. {
  18. struct list_head *lastentry;
  19. struct list_head *entry = NULL;
  20. if (list_empty(head))
  21. return NULL;
  22. if (!qp) {
  23. entry = head->next;
  24. } else {
  25. lastentry = &qp->list;
  26. entry = lastentry->next;
  27. if (entry == head)
  28. return NULL;
  29. }
  30. return container_of(entry, struct irdma_sc_qp, list);
  31. }
  32. /**
  33. * irdma_sc_suspend_resume_qps - suspend/resume all qp's on VSI
  34. * @vsi: the VSI struct pointer
  35. * @op: Set to IRDMA_OP_RESUME or IRDMA_OP_SUSPEND
  36. */
  37. void irdma_sc_suspend_resume_qps(struct irdma_sc_vsi *vsi, u8 op)
  38. {
  39. struct irdma_sc_qp *qp = NULL;
  40. u8 i;
  41. for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++) {
  42. mutex_lock(&vsi->qos[i].qos_mutex);
  43. qp = irdma_get_qp_from_list(&vsi->qos[i].qplist, qp);
  44. while (qp) {
  45. if (op == IRDMA_OP_RESUME) {
  46. if (!qp->dev->ws_add(vsi, i)) {
  47. qp->qs_handle =
  48. vsi->qos[qp->user_pri].qs_handle;
  49. irdma_cqp_qp_suspend_resume(qp, op);
  50. } else {
  51. irdma_cqp_qp_suspend_resume(qp, op);
  52. irdma_modify_qp_to_err(qp);
  53. }
  54. } else if (op == IRDMA_OP_SUSPEND) {
  55. /* issue cqp suspend command */
  56. if (!irdma_cqp_qp_suspend_resume(qp, op))
  57. atomic_inc(&vsi->qp_suspend_reqs);
  58. }
  59. qp = irdma_get_qp_from_list(&vsi->qos[i].qplist, qp);
  60. }
  61. mutex_unlock(&vsi->qos[i].qos_mutex);
  62. }
  63. }
  64. static void irdma_set_qos_info(struct irdma_sc_vsi *vsi,
  65. struct irdma_l2params *l2p)
  66. {
  67. u8 i;
  68. vsi->qos_rel_bw = l2p->vsi_rel_bw;
  69. vsi->qos_prio_type = l2p->vsi_prio_type;
  70. vsi->dscp_mode = l2p->dscp_mode;
  71. if (l2p->dscp_mode) {
  72. memcpy(vsi->dscp_map, l2p->dscp_map, sizeof(vsi->dscp_map));
  73. for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++)
  74. l2p->up2tc[i] = i;
  75. }
  76. for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++) {
  77. if (vsi->dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1)
  78. vsi->qos[i].qs_handle = l2p->qs_handle_list[i];
  79. vsi->qos[i].traffic_class = l2p->up2tc[i];
  80. vsi->qos[i].rel_bw =
  81. l2p->tc_info[vsi->qos[i].traffic_class].rel_bw;
  82. vsi->qos[i].prio_type =
  83. l2p->tc_info[vsi->qos[i].traffic_class].prio_type;
  84. vsi->qos[i].valid = false;
  85. }
  86. }
  87. /**
  88. * irdma_change_l2params - given the new l2 parameters, change all qp
  89. * @vsi: RDMA VSI pointer
  90. * @l2params: New parameters from l2
  91. */
  92. void irdma_change_l2params(struct irdma_sc_vsi *vsi,
  93. struct irdma_l2params *l2params)
  94. {
  95. if (l2params->mtu_changed) {
  96. vsi->mtu = l2params->mtu;
  97. if (vsi->ieq)
  98. irdma_reinitialize_ieq(vsi);
  99. }
  100. if (!l2params->tc_changed)
  101. return;
  102. vsi->tc_change_pending = false;
  103. irdma_set_qos_info(vsi, l2params);
  104. irdma_sc_suspend_resume_qps(vsi, IRDMA_OP_RESUME);
  105. }
  106. /**
  107. * irdma_qp_rem_qos - remove qp from qos lists during destroy qp
  108. * @qp: qp to be removed from qos
  109. */
  110. void irdma_qp_rem_qos(struct irdma_sc_qp *qp)
  111. {
  112. struct irdma_sc_vsi *vsi = qp->vsi;
  113. ibdev_dbg(to_ibdev(qp->dev),
  114. "DCB: DCB: Remove qp[%d] UP[%d] qset[%d] on_qoslist[%d]\n",
  115. qp->qp_uk.qp_id, qp->user_pri, qp->qs_handle,
  116. qp->on_qoslist);
  117. mutex_lock(&vsi->qos[qp->user_pri].qos_mutex);
  118. if (qp->on_qoslist) {
  119. qp->on_qoslist = false;
  120. list_del(&qp->list);
  121. }
  122. mutex_unlock(&vsi->qos[qp->user_pri].qos_mutex);
  123. }
  124. /**
  125. * irdma_qp_add_qos - called during setctx for qp to be added to qos
  126. * @qp: qp to be added to qos
  127. */
  128. void irdma_qp_add_qos(struct irdma_sc_qp *qp)
  129. {
  130. struct irdma_sc_vsi *vsi = qp->vsi;
  131. ibdev_dbg(to_ibdev(qp->dev),
  132. "DCB: DCB: Add qp[%d] UP[%d] qset[%d] on_qoslist[%d]\n",
  133. qp->qp_uk.qp_id, qp->user_pri, qp->qs_handle,
  134. qp->on_qoslist);
  135. mutex_lock(&vsi->qos[qp->user_pri].qos_mutex);
  136. if (!qp->on_qoslist) {
  137. list_add(&qp->list, &vsi->qos[qp->user_pri].qplist);
  138. qp->on_qoslist = true;
  139. qp->qs_handle = vsi->qos[qp->user_pri].qs_handle;
  140. }
  141. mutex_unlock(&vsi->qos[qp->user_pri].qos_mutex);
  142. }
  143. /**
  144. * irdma_sc_pd_init - initialize sc pd struct
  145. * @dev: sc device struct
  146. * @pd: sc pd ptr
  147. * @pd_id: pd_id for allocated pd
  148. * @abi_ver: User/Kernel ABI version
  149. */
  150. void irdma_sc_pd_init(struct irdma_sc_dev *dev, struct irdma_sc_pd *pd, u32 pd_id,
  151. int abi_ver)
  152. {
  153. pd->pd_id = pd_id;
  154. pd->abi_ver = abi_ver;
  155. pd->dev = dev;
  156. }
  157. /**
  158. * irdma_sc_add_arp_cache_entry - cqp wqe add arp cache entry
  159. * @cqp: struct for cqp hw
  160. * @info: arp entry information
  161. * @scratch: u64 saved to be used during cqp completion
  162. * @post_sq: flag for cqp db to ring
  163. */
  164. static int irdma_sc_add_arp_cache_entry(struct irdma_sc_cqp *cqp,
  165. struct irdma_add_arp_cache_entry_info *info,
  166. u64 scratch, bool post_sq)
  167. {
  168. __le64 *wqe;
  169. u64 hdr;
  170. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  171. if (!wqe)
  172. return -ENOMEM;
  173. set_64bit_val(wqe, 8, info->reach_max);
  174. set_64bit_val(wqe, 16, ether_addr_to_u64(info->mac_addr));
  175. hdr = info->arp_index |
  176. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_MANAGE_ARP) |
  177. FIELD_PREP(IRDMA_CQPSQ_MAT_PERMANENT, (info->permanent ? 1 : 0)) |
  178. FIELD_PREP(IRDMA_CQPSQ_MAT_ENTRYVALID, 1) |
  179. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  180. dma_wmb(); /* make sure WQE is written before valid bit is set */
  181. set_64bit_val(wqe, 24, hdr);
  182. print_hex_dump_debug("WQE: ARP_CACHE_ENTRY WQE", DUMP_PREFIX_OFFSET,
  183. 16, 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  184. if (post_sq)
  185. irdma_sc_cqp_post_sq(cqp);
  186. return 0;
  187. }
  188. /**
  189. * irdma_sc_del_arp_cache_entry - dele arp cache entry
  190. * @cqp: struct for cqp hw
  191. * @scratch: u64 saved to be used during cqp completion
  192. * @arp_index: arp index to delete arp entry
  193. * @post_sq: flag for cqp db to ring
  194. */
  195. static int irdma_sc_del_arp_cache_entry(struct irdma_sc_cqp *cqp, u64 scratch,
  196. u16 arp_index, bool post_sq)
  197. {
  198. __le64 *wqe;
  199. u64 hdr;
  200. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  201. if (!wqe)
  202. return -ENOMEM;
  203. hdr = arp_index |
  204. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_MANAGE_ARP) |
  205. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  206. dma_wmb(); /* make sure WQE is written before valid bit is set */
  207. set_64bit_val(wqe, 24, hdr);
  208. print_hex_dump_debug("WQE: ARP_CACHE_DEL_ENTRY WQE",
  209. DUMP_PREFIX_OFFSET, 16, 8, wqe,
  210. IRDMA_CQP_WQE_SIZE * 8, false);
  211. if (post_sq)
  212. irdma_sc_cqp_post_sq(cqp);
  213. return 0;
  214. }
  215. /**
  216. * irdma_sc_manage_apbvt_entry - for adding and deleting apbvt entries
  217. * @cqp: struct for cqp hw
  218. * @info: info for apbvt entry to add or delete
  219. * @scratch: u64 saved to be used during cqp completion
  220. * @post_sq: flag for cqp db to ring
  221. */
  222. static int irdma_sc_manage_apbvt_entry(struct irdma_sc_cqp *cqp,
  223. struct irdma_apbvt_info *info,
  224. u64 scratch, bool post_sq)
  225. {
  226. __le64 *wqe;
  227. u64 hdr;
  228. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  229. if (!wqe)
  230. return -ENOMEM;
  231. set_64bit_val(wqe, 16, info->port);
  232. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_MANAGE_APBVT) |
  233. FIELD_PREP(IRDMA_CQPSQ_MAPT_ADDPORT, info->add) |
  234. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  235. dma_wmb(); /* make sure WQE is written before valid bit is set */
  236. set_64bit_val(wqe, 24, hdr);
  237. print_hex_dump_debug("WQE: MANAGE_APBVT WQE", DUMP_PREFIX_OFFSET, 16,
  238. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  239. if (post_sq)
  240. irdma_sc_cqp_post_sq(cqp);
  241. return 0;
  242. }
  243. /**
  244. * irdma_sc_manage_qhash_table_entry - manage quad hash entries
  245. * @cqp: struct for cqp hw
  246. * @info: info for quad hash to manage
  247. * @scratch: u64 saved to be used during cqp completion
  248. * @post_sq: flag for cqp db to ring
  249. *
  250. * This is called before connection establishment is started.
  251. * For passive connections, when listener is created, it will
  252. * call with entry type of IRDMA_QHASH_TYPE_TCP_SYN with local
  253. * ip address and tcp port. When SYN is received (passive
  254. * connections) or sent (active connections), this routine is
  255. * called with entry type of IRDMA_QHASH_TYPE_TCP_ESTABLISHED
  256. * and quad is passed in info.
  257. *
  258. * When iwarp connection is done and its state moves to RTS, the
  259. * quad hash entry in the hardware will point to iwarp's qp
  260. * number and requires no calls from the driver.
  261. */
  262. static int
  263. irdma_sc_manage_qhash_table_entry(struct irdma_sc_cqp *cqp,
  264. struct irdma_qhash_table_info *info,
  265. u64 scratch, bool post_sq)
  266. {
  267. __le64 *wqe;
  268. u64 qw1 = 0;
  269. u64 qw2 = 0;
  270. u64 temp;
  271. struct irdma_sc_vsi *vsi = info->vsi;
  272. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  273. if (!wqe)
  274. return -ENOMEM;
  275. set_64bit_val(wqe, 0, ether_addr_to_u64(info->mac_addr));
  276. qw1 = FIELD_PREP(IRDMA_CQPSQ_QHASH_QPN, info->qp_num) |
  277. FIELD_PREP(IRDMA_CQPSQ_QHASH_DEST_PORT, info->dest_port);
  278. if (info->ipv4_valid) {
  279. set_64bit_val(wqe, 48,
  280. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR3, info->dest_ip[0]));
  281. } else {
  282. set_64bit_val(wqe, 56,
  283. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR0, info->dest_ip[0]) |
  284. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR1, info->dest_ip[1]));
  285. set_64bit_val(wqe, 48,
  286. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR2, info->dest_ip[2]) |
  287. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR3, info->dest_ip[3]));
  288. }
  289. qw2 = FIELD_PREP(IRDMA_CQPSQ_QHASH_QS_HANDLE,
  290. vsi->qos[info->user_pri].qs_handle);
  291. if (info->vlan_valid)
  292. qw2 |= FIELD_PREP(IRDMA_CQPSQ_QHASH_VLANID, info->vlan_id);
  293. set_64bit_val(wqe, 16, qw2);
  294. if (info->entry_type == IRDMA_QHASH_TYPE_TCP_ESTABLISHED) {
  295. qw1 |= FIELD_PREP(IRDMA_CQPSQ_QHASH_SRC_PORT, info->src_port);
  296. if (!info->ipv4_valid) {
  297. set_64bit_val(wqe, 40,
  298. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR0, info->src_ip[0]) |
  299. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR1, info->src_ip[1]));
  300. set_64bit_val(wqe, 32,
  301. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR2, info->src_ip[2]) |
  302. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR3, info->src_ip[3]));
  303. } else {
  304. set_64bit_val(wqe, 32,
  305. FIELD_PREP(IRDMA_CQPSQ_QHASH_ADDR3, info->src_ip[0]));
  306. }
  307. }
  308. set_64bit_val(wqe, 8, qw1);
  309. temp = FIELD_PREP(IRDMA_CQPSQ_QHASH_WQEVALID, cqp->polarity) |
  310. FIELD_PREP(IRDMA_CQPSQ_QHASH_OPCODE,
  311. IRDMA_CQP_OP_MANAGE_QUAD_HASH_TABLE_ENTRY) |
  312. FIELD_PREP(IRDMA_CQPSQ_QHASH_MANAGE, info->manage) |
  313. FIELD_PREP(IRDMA_CQPSQ_QHASH_IPV4VALID, info->ipv4_valid) |
  314. FIELD_PREP(IRDMA_CQPSQ_QHASH_VLANVALID, info->vlan_valid) |
  315. FIELD_PREP(IRDMA_CQPSQ_QHASH_ENTRYTYPE, info->entry_type);
  316. dma_wmb(); /* make sure WQE is written before valid bit is set */
  317. set_64bit_val(wqe, 24, temp);
  318. print_hex_dump_debug("WQE: MANAGE_QHASH WQE", DUMP_PREFIX_OFFSET, 16,
  319. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  320. if (post_sq)
  321. irdma_sc_cqp_post_sq(cqp);
  322. return 0;
  323. }
  324. /**
  325. * irdma_sc_qp_init - initialize qp
  326. * @qp: sc qp
  327. * @info: initialization qp info
  328. */
  329. int irdma_sc_qp_init(struct irdma_sc_qp *qp, struct irdma_qp_init_info *info)
  330. {
  331. int ret_code;
  332. u32 pble_obj_cnt;
  333. u16 wqe_size;
  334. if (info->qp_uk_init_info.max_sq_frag_cnt >
  335. info->pd->dev->hw_attrs.uk_attrs.max_hw_wq_frags ||
  336. info->qp_uk_init_info.max_rq_frag_cnt >
  337. info->pd->dev->hw_attrs.uk_attrs.max_hw_wq_frags)
  338. return -EINVAL;
  339. qp->dev = info->pd->dev;
  340. qp->vsi = info->vsi;
  341. qp->ieq_qp = info->vsi->exception_lan_q;
  342. qp->sq_pa = info->sq_pa;
  343. qp->rq_pa = info->rq_pa;
  344. qp->hw_host_ctx_pa = info->host_ctx_pa;
  345. qp->q2_pa = info->q2_pa;
  346. qp->shadow_area_pa = info->shadow_area_pa;
  347. qp->q2_buf = info->q2;
  348. qp->pd = info->pd;
  349. qp->hw_host_ctx = info->host_ctx;
  350. info->qp_uk_init_info.wqe_alloc_db = qp->pd->dev->wqe_alloc_db;
  351. ret_code = irdma_uk_qp_init(&qp->qp_uk, &info->qp_uk_init_info);
  352. if (ret_code)
  353. return ret_code;
  354. qp->virtual_map = info->virtual_map;
  355. pble_obj_cnt = info->pd->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  356. if ((info->virtual_map && info->sq_pa >= pble_obj_cnt) ||
  357. (info->virtual_map && info->rq_pa >= pble_obj_cnt))
  358. return -EINVAL;
  359. qp->llp_stream_handle = (void *)(-1);
  360. qp->hw_sq_size = irdma_get_encoded_wqe_size(qp->qp_uk.sq_ring.size,
  361. IRDMA_QUEUE_TYPE_SQ_RQ);
  362. ibdev_dbg(to_ibdev(qp->dev),
  363. "WQE: hw_sq_size[%04d] sq_ring.size[%04d]\n",
  364. qp->hw_sq_size, qp->qp_uk.sq_ring.size);
  365. if (qp->qp_uk.uk_attrs->hw_rev == IRDMA_GEN_1 && qp->pd->abi_ver > 4)
  366. wqe_size = IRDMA_WQE_SIZE_128;
  367. else
  368. ret_code = irdma_fragcnt_to_wqesize_rq(qp->qp_uk.max_rq_frag_cnt,
  369. &wqe_size);
  370. if (ret_code)
  371. return ret_code;
  372. qp->hw_rq_size = irdma_get_encoded_wqe_size(qp->qp_uk.rq_size *
  373. (wqe_size / IRDMA_QP_WQE_MIN_SIZE), IRDMA_QUEUE_TYPE_SQ_RQ);
  374. ibdev_dbg(to_ibdev(qp->dev),
  375. "WQE: hw_rq_size[%04d] qp_uk.rq_size[%04d] wqe_size[%04d]\n",
  376. qp->hw_rq_size, qp->qp_uk.rq_size, wqe_size);
  377. qp->sq_tph_val = info->sq_tph_val;
  378. qp->rq_tph_val = info->rq_tph_val;
  379. qp->sq_tph_en = info->sq_tph_en;
  380. qp->rq_tph_en = info->rq_tph_en;
  381. qp->rcv_tph_en = info->rcv_tph_en;
  382. qp->xmit_tph_en = info->xmit_tph_en;
  383. qp->qp_uk.first_sq_wq = info->qp_uk_init_info.first_sq_wq;
  384. qp->qs_handle = qp->vsi->qos[qp->user_pri].qs_handle;
  385. return 0;
  386. }
  387. /**
  388. * irdma_sc_qp_create - create qp
  389. * @qp: sc qp
  390. * @info: qp create info
  391. * @scratch: u64 saved to be used during cqp completion
  392. * @post_sq: flag for cqp db to ring
  393. */
  394. int irdma_sc_qp_create(struct irdma_sc_qp *qp, struct irdma_create_qp_info *info,
  395. u64 scratch, bool post_sq)
  396. {
  397. struct irdma_sc_cqp *cqp;
  398. __le64 *wqe;
  399. u64 hdr;
  400. cqp = qp->dev->cqp;
  401. if (qp->qp_uk.qp_id < cqp->dev->hw_attrs.min_hw_qp_id ||
  402. qp->qp_uk.qp_id >= cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt)
  403. return -EINVAL;
  404. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  405. if (!wqe)
  406. return -ENOMEM;
  407. set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
  408. set_64bit_val(wqe, 40, qp->shadow_area_pa);
  409. hdr = qp->qp_uk.qp_id |
  410. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_CREATE_QP) |
  411. FIELD_PREP(IRDMA_CQPSQ_QP_ORDVALID, (info->ord_valid ? 1 : 0)) |
  412. FIELD_PREP(IRDMA_CQPSQ_QP_TOECTXVALID, info->tcp_ctx_valid) |
  413. FIELD_PREP(IRDMA_CQPSQ_QP_MACVALID, info->mac_valid) |
  414. FIELD_PREP(IRDMA_CQPSQ_QP_QPTYPE, qp->qp_uk.qp_type) |
  415. FIELD_PREP(IRDMA_CQPSQ_QP_VQ, qp->virtual_map) |
  416. FIELD_PREP(IRDMA_CQPSQ_QP_FORCELOOPBACK, info->force_lpb) |
  417. FIELD_PREP(IRDMA_CQPSQ_QP_CQNUMVALID, info->cq_num_valid) |
  418. FIELD_PREP(IRDMA_CQPSQ_QP_ARPTABIDXVALID,
  419. info->arp_cache_idx_valid) |
  420. FIELD_PREP(IRDMA_CQPSQ_QP_NEXTIWSTATE, info->next_iwarp_state) |
  421. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  422. dma_wmb(); /* make sure WQE is written before valid bit is set */
  423. set_64bit_val(wqe, 24, hdr);
  424. print_hex_dump_debug("WQE: QP_CREATE WQE", DUMP_PREFIX_OFFSET, 16, 8,
  425. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  426. if (post_sq)
  427. irdma_sc_cqp_post_sq(cqp);
  428. return 0;
  429. }
  430. /**
  431. * irdma_sc_qp_modify - modify qp cqp wqe
  432. * @qp: sc qp
  433. * @info: modify qp info
  434. * @scratch: u64 saved to be used during cqp completion
  435. * @post_sq: flag for cqp db to ring
  436. */
  437. int irdma_sc_qp_modify(struct irdma_sc_qp *qp, struct irdma_modify_qp_info *info,
  438. u64 scratch, bool post_sq)
  439. {
  440. __le64 *wqe;
  441. struct irdma_sc_cqp *cqp;
  442. u64 hdr;
  443. u8 term_actions = 0;
  444. u8 term_len = 0;
  445. cqp = qp->dev->cqp;
  446. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  447. if (!wqe)
  448. return -ENOMEM;
  449. if (info->next_iwarp_state == IRDMA_QP_STATE_TERMINATE) {
  450. if (info->dont_send_fin)
  451. term_actions += IRDMAQP_TERM_SEND_TERM_ONLY;
  452. if (info->dont_send_term)
  453. term_actions += IRDMAQP_TERM_SEND_FIN_ONLY;
  454. if (term_actions == IRDMAQP_TERM_SEND_TERM_AND_FIN ||
  455. term_actions == IRDMAQP_TERM_SEND_TERM_ONLY)
  456. term_len = info->termlen;
  457. }
  458. set_64bit_val(wqe, 8,
  459. FIELD_PREP(IRDMA_CQPSQ_QP_NEWMSS, info->new_mss) |
  460. FIELD_PREP(IRDMA_CQPSQ_QP_TERMLEN, term_len));
  461. set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
  462. set_64bit_val(wqe, 40, qp->shadow_area_pa);
  463. hdr = qp->qp_uk.qp_id |
  464. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_MODIFY_QP) |
  465. FIELD_PREP(IRDMA_CQPSQ_QP_ORDVALID, info->ord_valid) |
  466. FIELD_PREP(IRDMA_CQPSQ_QP_TOECTXVALID, info->tcp_ctx_valid) |
  467. FIELD_PREP(IRDMA_CQPSQ_QP_CACHEDVARVALID,
  468. info->cached_var_valid) |
  469. FIELD_PREP(IRDMA_CQPSQ_QP_VQ, qp->virtual_map) |
  470. FIELD_PREP(IRDMA_CQPSQ_QP_FORCELOOPBACK, info->force_lpb) |
  471. FIELD_PREP(IRDMA_CQPSQ_QP_CQNUMVALID, info->cq_num_valid) |
  472. FIELD_PREP(IRDMA_CQPSQ_QP_MACVALID, info->mac_valid) |
  473. FIELD_PREP(IRDMA_CQPSQ_QP_QPTYPE, qp->qp_uk.qp_type) |
  474. FIELD_PREP(IRDMA_CQPSQ_QP_MSSCHANGE, info->mss_change) |
  475. FIELD_PREP(IRDMA_CQPSQ_QP_REMOVEHASHENTRY,
  476. info->remove_hash_idx) |
  477. FIELD_PREP(IRDMA_CQPSQ_QP_TERMACT, term_actions) |
  478. FIELD_PREP(IRDMA_CQPSQ_QP_RESETCON, info->reset_tcp_conn) |
  479. FIELD_PREP(IRDMA_CQPSQ_QP_ARPTABIDXVALID,
  480. info->arp_cache_idx_valid) |
  481. FIELD_PREP(IRDMA_CQPSQ_QP_NEXTIWSTATE, info->next_iwarp_state) |
  482. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  483. dma_wmb(); /* make sure WQE is written before valid bit is set */
  484. set_64bit_val(wqe, 24, hdr);
  485. print_hex_dump_debug("WQE: QP_MODIFY WQE", DUMP_PREFIX_OFFSET, 16, 8,
  486. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  487. if (post_sq)
  488. irdma_sc_cqp_post_sq(cqp);
  489. return 0;
  490. }
  491. /**
  492. * irdma_sc_qp_destroy - cqp destroy qp
  493. * @qp: sc qp
  494. * @scratch: u64 saved to be used during cqp completion
  495. * @remove_hash_idx: flag if to remove hash idx
  496. * @ignore_mw_bnd: memory window bind flag
  497. * @post_sq: flag for cqp db to ring
  498. */
  499. int irdma_sc_qp_destroy(struct irdma_sc_qp *qp, u64 scratch,
  500. bool remove_hash_idx, bool ignore_mw_bnd, bool post_sq)
  501. {
  502. __le64 *wqe;
  503. struct irdma_sc_cqp *cqp;
  504. u64 hdr;
  505. cqp = qp->dev->cqp;
  506. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  507. if (!wqe)
  508. return -ENOMEM;
  509. set_64bit_val(wqe, 16, qp->hw_host_ctx_pa);
  510. set_64bit_val(wqe, 40, qp->shadow_area_pa);
  511. hdr = qp->qp_uk.qp_id |
  512. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_DESTROY_QP) |
  513. FIELD_PREP(IRDMA_CQPSQ_QP_QPTYPE, qp->qp_uk.qp_type) |
  514. FIELD_PREP(IRDMA_CQPSQ_QP_IGNOREMWBOUND, ignore_mw_bnd) |
  515. FIELD_PREP(IRDMA_CQPSQ_QP_REMOVEHASHENTRY, remove_hash_idx) |
  516. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  517. dma_wmb(); /* make sure WQE is written before valid bit is set */
  518. set_64bit_val(wqe, 24, hdr);
  519. print_hex_dump_debug("WQE: QP_DESTROY WQE", DUMP_PREFIX_OFFSET, 16, 8,
  520. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  521. if (post_sq)
  522. irdma_sc_cqp_post_sq(cqp);
  523. return 0;
  524. }
  525. /**
  526. * irdma_sc_get_encoded_ird_size -
  527. * @ird_size: IRD size
  528. * The ird from the connection is rounded to a supported HW setting and then encoded
  529. * for ird_size field of qp_ctx. Consumers are expected to provide valid ird size based
  530. * on hardware attributes. IRD size defaults to a value of 4 in case of invalid input
  531. */
  532. static u8 irdma_sc_get_encoded_ird_size(u16 ird_size)
  533. {
  534. switch (ird_size ?
  535. roundup_pow_of_two(2 * ird_size) : 4) {
  536. case 256:
  537. return IRDMA_IRD_HW_SIZE_256;
  538. case 128:
  539. return IRDMA_IRD_HW_SIZE_128;
  540. case 64:
  541. case 32:
  542. return IRDMA_IRD_HW_SIZE_64;
  543. case 16:
  544. case 8:
  545. return IRDMA_IRD_HW_SIZE_16;
  546. case 4:
  547. default:
  548. break;
  549. }
  550. return IRDMA_IRD_HW_SIZE_4;
  551. }
  552. /**
  553. * irdma_sc_qp_setctx_roce - set qp's context
  554. * @qp: sc qp
  555. * @qp_ctx: context ptr
  556. * @info: ctx info
  557. */
  558. void irdma_sc_qp_setctx_roce(struct irdma_sc_qp *qp, __le64 *qp_ctx,
  559. struct irdma_qp_host_ctx_info *info)
  560. {
  561. struct irdma_roce_offload_info *roce_info;
  562. struct irdma_udp_offload_info *udp;
  563. u8 push_mode_en;
  564. u32 push_idx;
  565. roce_info = info->roce_info;
  566. udp = info->udp_info;
  567. qp->user_pri = info->user_pri;
  568. if (qp->push_idx == IRDMA_INVALID_PUSH_PAGE_INDEX) {
  569. push_mode_en = 0;
  570. push_idx = 0;
  571. } else {
  572. push_mode_en = 1;
  573. push_idx = qp->push_idx;
  574. }
  575. set_64bit_val(qp_ctx, 0,
  576. FIELD_PREP(IRDMAQPC_RQWQESIZE, qp->qp_uk.rq_wqe_size) |
  577. FIELD_PREP(IRDMAQPC_RCVTPHEN, qp->rcv_tph_en) |
  578. FIELD_PREP(IRDMAQPC_XMITTPHEN, qp->xmit_tph_en) |
  579. FIELD_PREP(IRDMAQPC_RQTPHEN, qp->rq_tph_en) |
  580. FIELD_PREP(IRDMAQPC_SQTPHEN, qp->sq_tph_en) |
  581. FIELD_PREP(IRDMAQPC_PPIDX, push_idx) |
  582. FIELD_PREP(IRDMAQPC_PMENA, push_mode_en) |
  583. FIELD_PREP(IRDMAQPC_PDIDXHI, roce_info->pd_id >> 16) |
  584. FIELD_PREP(IRDMAQPC_DC_TCP_EN, roce_info->dctcp_en) |
  585. FIELD_PREP(IRDMAQPC_ERR_RQ_IDX_VALID, roce_info->err_rq_idx_valid) |
  586. FIELD_PREP(IRDMAQPC_ISQP1, roce_info->is_qp1) |
  587. FIELD_PREP(IRDMAQPC_ROCE_TVER, roce_info->roce_tver) |
  588. FIELD_PREP(IRDMAQPC_IPV4, udp->ipv4) |
  589. FIELD_PREP(IRDMAQPC_INSERTVLANTAG, udp->insert_vlan_tag));
  590. set_64bit_val(qp_ctx, 8, qp->sq_pa);
  591. set_64bit_val(qp_ctx, 16, qp->rq_pa);
  592. if ((roce_info->dcqcn_en || roce_info->dctcp_en) &&
  593. !(udp->tos & 0x03))
  594. udp->tos |= ECN_CODE_PT_VAL;
  595. set_64bit_val(qp_ctx, 24,
  596. FIELD_PREP(IRDMAQPC_RQSIZE, qp->hw_rq_size) |
  597. FIELD_PREP(IRDMAQPC_SQSIZE, qp->hw_sq_size) |
  598. FIELD_PREP(IRDMAQPC_TTL, udp->ttl) | FIELD_PREP(IRDMAQPC_TOS, udp->tos) |
  599. FIELD_PREP(IRDMAQPC_SRCPORTNUM, udp->src_port) |
  600. FIELD_PREP(IRDMAQPC_DESTPORTNUM, udp->dst_port));
  601. set_64bit_val(qp_ctx, 32,
  602. FIELD_PREP(IRDMAQPC_DESTIPADDR2, udp->dest_ip_addr[2]) |
  603. FIELD_PREP(IRDMAQPC_DESTIPADDR3, udp->dest_ip_addr[3]));
  604. set_64bit_val(qp_ctx, 40,
  605. FIELD_PREP(IRDMAQPC_DESTIPADDR0, udp->dest_ip_addr[0]) |
  606. FIELD_PREP(IRDMAQPC_DESTIPADDR1, udp->dest_ip_addr[1]));
  607. set_64bit_val(qp_ctx, 48,
  608. FIELD_PREP(IRDMAQPC_SNDMSS, udp->snd_mss) |
  609. FIELD_PREP(IRDMAQPC_VLANTAG, udp->vlan_tag) |
  610. FIELD_PREP(IRDMAQPC_ARPIDX, udp->arp_idx));
  611. set_64bit_val(qp_ctx, 56,
  612. FIELD_PREP(IRDMAQPC_PKEY, roce_info->p_key) |
  613. FIELD_PREP(IRDMAQPC_PDIDX, roce_info->pd_id) |
  614. FIELD_PREP(IRDMAQPC_ACKCREDITS, roce_info->ack_credits) |
  615. FIELD_PREP(IRDMAQPC_FLOWLABEL, udp->flow_label));
  616. set_64bit_val(qp_ctx, 64,
  617. FIELD_PREP(IRDMAQPC_QKEY, roce_info->qkey) |
  618. FIELD_PREP(IRDMAQPC_DESTQP, roce_info->dest_qp));
  619. set_64bit_val(qp_ctx, 80,
  620. FIELD_PREP(IRDMAQPC_PSNNXT, udp->psn_nxt) |
  621. FIELD_PREP(IRDMAQPC_LSN, udp->lsn));
  622. set_64bit_val(qp_ctx, 88,
  623. FIELD_PREP(IRDMAQPC_EPSN, udp->epsn));
  624. set_64bit_val(qp_ctx, 96,
  625. FIELD_PREP(IRDMAQPC_PSNMAX, udp->psn_max) |
  626. FIELD_PREP(IRDMAQPC_PSNUNA, udp->psn_una));
  627. set_64bit_val(qp_ctx, 112,
  628. FIELD_PREP(IRDMAQPC_CWNDROCE, udp->cwnd));
  629. set_64bit_val(qp_ctx, 128,
  630. FIELD_PREP(IRDMAQPC_ERR_RQ_IDX, roce_info->err_rq_idx) |
  631. FIELD_PREP(IRDMAQPC_RNRNAK_THRESH, udp->rnr_nak_thresh) |
  632. FIELD_PREP(IRDMAQPC_REXMIT_THRESH, udp->rexmit_thresh) |
  633. FIELD_PREP(IRDMAQPC_RTOMIN, roce_info->rtomin));
  634. set_64bit_val(qp_ctx, 136,
  635. FIELD_PREP(IRDMAQPC_TXCQNUM, info->send_cq_num) |
  636. FIELD_PREP(IRDMAQPC_RXCQNUM, info->rcv_cq_num));
  637. set_64bit_val(qp_ctx, 144,
  638. FIELD_PREP(IRDMAQPC_STAT_INDEX, info->stats_idx));
  639. set_64bit_val(qp_ctx, 152, ether_addr_to_u64(roce_info->mac_addr) << 16);
  640. set_64bit_val(qp_ctx, 160,
  641. FIELD_PREP(IRDMAQPC_ORDSIZE, roce_info->ord_size) |
  642. FIELD_PREP(IRDMAQPC_IRDSIZE, irdma_sc_get_encoded_ird_size(roce_info->ird_size)) |
  643. FIELD_PREP(IRDMAQPC_WRRDRSPOK, roce_info->wr_rdresp_en) |
  644. FIELD_PREP(IRDMAQPC_RDOK, roce_info->rd_en) |
  645. FIELD_PREP(IRDMAQPC_USESTATSINSTANCE, info->stats_idx_valid) |
  646. FIELD_PREP(IRDMAQPC_BINDEN, roce_info->bind_en) |
  647. FIELD_PREP(IRDMAQPC_FASTREGEN, roce_info->fast_reg_en) |
  648. FIELD_PREP(IRDMAQPC_DCQCNENABLE, roce_info->dcqcn_en) |
  649. FIELD_PREP(IRDMAQPC_RCVNOICRC, roce_info->rcv_no_icrc) |
  650. FIELD_PREP(IRDMAQPC_FW_CC_ENABLE, roce_info->fw_cc_enable) |
  651. FIELD_PREP(IRDMAQPC_UDPRIVCQENABLE, roce_info->udprivcq_en) |
  652. FIELD_PREP(IRDMAQPC_PRIVEN, roce_info->priv_mode_en) |
  653. FIELD_PREP(IRDMAQPC_TIMELYENABLE, roce_info->timely_en));
  654. set_64bit_val(qp_ctx, 168,
  655. FIELD_PREP(IRDMAQPC_QPCOMPCTX, info->qp_compl_ctx));
  656. set_64bit_val(qp_ctx, 176,
  657. FIELD_PREP(IRDMAQPC_SQTPHVAL, qp->sq_tph_val) |
  658. FIELD_PREP(IRDMAQPC_RQTPHVAL, qp->rq_tph_val) |
  659. FIELD_PREP(IRDMAQPC_QSHANDLE, qp->qs_handle));
  660. set_64bit_val(qp_ctx, 184,
  661. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR3, udp->local_ipaddr[3]) |
  662. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR2, udp->local_ipaddr[2]));
  663. set_64bit_val(qp_ctx, 192,
  664. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR1, udp->local_ipaddr[1]) |
  665. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR0, udp->local_ipaddr[0]));
  666. set_64bit_val(qp_ctx, 200,
  667. FIELD_PREP(IRDMAQPC_THIGH, roce_info->t_high) |
  668. FIELD_PREP(IRDMAQPC_TLOW, roce_info->t_low));
  669. set_64bit_val(qp_ctx, 208,
  670. FIELD_PREP(IRDMAQPC_REMENDPOINTIDX, info->rem_endpoint_idx));
  671. print_hex_dump_debug("WQE: QP_HOST CTX WQE", DUMP_PREFIX_OFFSET, 16,
  672. 8, qp_ctx, IRDMA_QP_CTX_SIZE, false);
  673. }
  674. /* irdma_sc_alloc_local_mac_entry - allocate a mac entry
  675. * @cqp: struct for cqp hw
  676. * @scratch: u64 saved to be used during cqp completion
  677. * @post_sq: flag for cqp db to ring
  678. */
  679. static int irdma_sc_alloc_local_mac_entry(struct irdma_sc_cqp *cqp, u64 scratch,
  680. bool post_sq)
  681. {
  682. __le64 *wqe;
  683. u64 hdr;
  684. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  685. if (!wqe)
  686. return -ENOMEM;
  687. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE,
  688. IRDMA_CQP_OP_ALLOCATE_LOC_MAC_TABLE_ENTRY) |
  689. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  690. dma_wmb(); /* make sure WQE is written before valid bit is set */
  691. set_64bit_val(wqe, 24, hdr);
  692. print_hex_dump_debug("WQE: ALLOCATE_LOCAL_MAC WQE",
  693. DUMP_PREFIX_OFFSET, 16, 8, wqe,
  694. IRDMA_CQP_WQE_SIZE * 8, false);
  695. if (post_sq)
  696. irdma_sc_cqp_post_sq(cqp);
  697. return 0;
  698. }
  699. /**
  700. * irdma_sc_add_local_mac_entry - add mac enry
  701. * @cqp: struct for cqp hw
  702. * @info:mac addr info
  703. * @scratch: u64 saved to be used during cqp completion
  704. * @post_sq: flag for cqp db to ring
  705. */
  706. static int irdma_sc_add_local_mac_entry(struct irdma_sc_cqp *cqp,
  707. struct irdma_local_mac_entry_info *info,
  708. u64 scratch, bool post_sq)
  709. {
  710. __le64 *wqe;
  711. u64 header;
  712. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  713. if (!wqe)
  714. return -ENOMEM;
  715. set_64bit_val(wqe, 32, ether_addr_to_u64(info->mac_addr));
  716. header = FIELD_PREP(IRDMA_CQPSQ_MLM_TABLEIDX, info->entry_idx) |
  717. FIELD_PREP(IRDMA_CQPSQ_OPCODE,
  718. IRDMA_CQP_OP_MANAGE_LOC_MAC_TABLE) |
  719. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  720. dma_wmb(); /* make sure WQE is written before valid bit is set */
  721. set_64bit_val(wqe, 24, header);
  722. print_hex_dump_debug("WQE: ADD_LOCAL_MAC WQE", DUMP_PREFIX_OFFSET, 16,
  723. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  724. if (post_sq)
  725. irdma_sc_cqp_post_sq(cqp);
  726. return 0;
  727. }
  728. /**
  729. * irdma_sc_del_local_mac_entry - cqp wqe to dele local mac
  730. * @cqp: struct for cqp hw
  731. * @scratch: u64 saved to be used during cqp completion
  732. * @entry_idx: index of mac entry
  733. * @ignore_ref_count: to force mac adde delete
  734. * @post_sq: flag for cqp db to ring
  735. */
  736. static int irdma_sc_del_local_mac_entry(struct irdma_sc_cqp *cqp, u64 scratch,
  737. u16 entry_idx, u8 ignore_ref_count,
  738. bool post_sq)
  739. {
  740. __le64 *wqe;
  741. u64 header;
  742. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  743. if (!wqe)
  744. return -ENOMEM;
  745. header = FIELD_PREP(IRDMA_CQPSQ_MLM_TABLEIDX, entry_idx) |
  746. FIELD_PREP(IRDMA_CQPSQ_OPCODE,
  747. IRDMA_CQP_OP_MANAGE_LOC_MAC_TABLE) |
  748. FIELD_PREP(IRDMA_CQPSQ_MLM_FREEENTRY, 1) |
  749. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity) |
  750. FIELD_PREP(IRDMA_CQPSQ_MLM_IGNORE_REF_CNT, ignore_ref_count);
  751. dma_wmb(); /* make sure WQE is written before valid bit is set */
  752. set_64bit_val(wqe, 24, header);
  753. print_hex_dump_debug("WQE: DEL_LOCAL_MAC_IPADDR WQE",
  754. DUMP_PREFIX_OFFSET, 16, 8, wqe,
  755. IRDMA_CQP_WQE_SIZE * 8, false);
  756. if (post_sq)
  757. irdma_sc_cqp_post_sq(cqp);
  758. return 0;
  759. }
  760. /**
  761. * irdma_sc_qp_setctx - set qp's context
  762. * @qp: sc qp
  763. * @qp_ctx: context ptr
  764. * @info: ctx info
  765. */
  766. void irdma_sc_qp_setctx(struct irdma_sc_qp *qp, __le64 *qp_ctx,
  767. struct irdma_qp_host_ctx_info *info)
  768. {
  769. struct irdma_iwarp_offload_info *iw;
  770. struct irdma_tcp_offload_info *tcp;
  771. struct irdma_sc_dev *dev;
  772. u8 push_mode_en;
  773. u32 push_idx;
  774. u64 qw0, qw3, qw7 = 0, qw16 = 0;
  775. u64 mac = 0;
  776. iw = info->iwarp_info;
  777. tcp = info->tcp_info;
  778. dev = qp->dev;
  779. if (iw->rcv_mark_en) {
  780. qp->pfpdu.marker_len = 4;
  781. qp->pfpdu.rcv_start_seq = tcp->rcv_nxt;
  782. }
  783. qp->user_pri = info->user_pri;
  784. if (qp->push_idx == IRDMA_INVALID_PUSH_PAGE_INDEX) {
  785. push_mode_en = 0;
  786. push_idx = 0;
  787. } else {
  788. push_mode_en = 1;
  789. push_idx = qp->push_idx;
  790. }
  791. qw0 = FIELD_PREP(IRDMAQPC_RQWQESIZE, qp->qp_uk.rq_wqe_size) |
  792. FIELD_PREP(IRDMAQPC_RCVTPHEN, qp->rcv_tph_en) |
  793. FIELD_PREP(IRDMAQPC_XMITTPHEN, qp->xmit_tph_en) |
  794. FIELD_PREP(IRDMAQPC_RQTPHEN, qp->rq_tph_en) |
  795. FIELD_PREP(IRDMAQPC_SQTPHEN, qp->sq_tph_en) |
  796. FIELD_PREP(IRDMAQPC_PPIDX, push_idx) |
  797. FIELD_PREP(IRDMAQPC_PMENA, push_mode_en);
  798. set_64bit_val(qp_ctx, 8, qp->sq_pa);
  799. set_64bit_val(qp_ctx, 16, qp->rq_pa);
  800. qw3 = FIELD_PREP(IRDMAQPC_RQSIZE, qp->hw_rq_size) |
  801. FIELD_PREP(IRDMAQPC_SQSIZE, qp->hw_sq_size);
  802. if (dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1)
  803. qw3 |= FIELD_PREP(IRDMAQPC_GEN1_SRCMACADDRIDX,
  804. qp->src_mac_addr_idx);
  805. set_64bit_val(qp_ctx, 136,
  806. FIELD_PREP(IRDMAQPC_TXCQNUM, info->send_cq_num) |
  807. FIELD_PREP(IRDMAQPC_RXCQNUM, info->rcv_cq_num));
  808. set_64bit_val(qp_ctx, 168,
  809. FIELD_PREP(IRDMAQPC_QPCOMPCTX, info->qp_compl_ctx));
  810. set_64bit_val(qp_ctx, 176,
  811. FIELD_PREP(IRDMAQPC_SQTPHVAL, qp->sq_tph_val) |
  812. FIELD_PREP(IRDMAQPC_RQTPHVAL, qp->rq_tph_val) |
  813. FIELD_PREP(IRDMAQPC_QSHANDLE, qp->qs_handle) |
  814. FIELD_PREP(IRDMAQPC_EXCEPTION_LAN_QUEUE, qp->ieq_qp));
  815. if (info->iwarp_info_valid) {
  816. qw0 |= FIELD_PREP(IRDMAQPC_DDP_VER, iw->ddp_ver) |
  817. FIELD_PREP(IRDMAQPC_RDMAP_VER, iw->rdmap_ver) |
  818. FIELD_PREP(IRDMAQPC_DC_TCP_EN, iw->dctcp_en) |
  819. FIELD_PREP(IRDMAQPC_ECN_EN, iw->ecn_en) |
  820. FIELD_PREP(IRDMAQPC_IBRDENABLE, iw->ib_rd_en) |
  821. FIELD_PREP(IRDMAQPC_PDIDXHI, iw->pd_id >> 16) |
  822. FIELD_PREP(IRDMAQPC_ERR_RQ_IDX_VALID,
  823. iw->err_rq_idx_valid);
  824. qw7 |= FIELD_PREP(IRDMAQPC_PDIDX, iw->pd_id);
  825. qw16 |= FIELD_PREP(IRDMAQPC_ERR_RQ_IDX, iw->err_rq_idx) |
  826. FIELD_PREP(IRDMAQPC_RTOMIN, iw->rtomin);
  827. set_64bit_val(qp_ctx, 144,
  828. FIELD_PREP(IRDMAQPC_Q2ADDR, qp->q2_pa >> 8) |
  829. FIELD_PREP(IRDMAQPC_STAT_INDEX, info->stats_idx));
  830. if (dev->hw_attrs.uk_attrs.hw_rev >= IRDMA_GEN_2)
  831. mac = ether_addr_to_u64(iw->mac_addr);
  832. set_64bit_val(qp_ctx, 152,
  833. mac << 16 | FIELD_PREP(IRDMAQPC_LASTBYTESENT, iw->last_byte_sent));
  834. set_64bit_val(qp_ctx, 160,
  835. FIELD_PREP(IRDMAQPC_ORDSIZE, iw->ord_size) |
  836. FIELD_PREP(IRDMAQPC_IRDSIZE, irdma_sc_get_encoded_ird_size(iw->ird_size)) |
  837. FIELD_PREP(IRDMAQPC_WRRDRSPOK, iw->wr_rdresp_en) |
  838. FIELD_PREP(IRDMAQPC_RDOK, iw->rd_en) |
  839. FIELD_PREP(IRDMAQPC_SNDMARKERS, iw->snd_mark_en) |
  840. FIELD_PREP(IRDMAQPC_BINDEN, iw->bind_en) |
  841. FIELD_PREP(IRDMAQPC_FASTREGEN, iw->fast_reg_en) |
  842. FIELD_PREP(IRDMAQPC_PRIVEN, iw->priv_mode_en) |
  843. FIELD_PREP(IRDMAQPC_USESTATSINSTANCE, info->stats_idx_valid) |
  844. FIELD_PREP(IRDMAQPC_IWARPMODE, 1) |
  845. FIELD_PREP(IRDMAQPC_RCVMARKERS, iw->rcv_mark_en) |
  846. FIELD_PREP(IRDMAQPC_ALIGNHDRS, iw->align_hdrs) |
  847. FIELD_PREP(IRDMAQPC_RCVNOMPACRC, iw->rcv_no_mpa_crc) |
  848. FIELD_PREP(IRDMAQPC_RCVMARKOFFSET, iw->rcv_mark_offset || !tcp ? iw->rcv_mark_offset : tcp->rcv_nxt) |
  849. FIELD_PREP(IRDMAQPC_SNDMARKOFFSET, iw->snd_mark_offset || !tcp ? iw->snd_mark_offset : tcp->snd_nxt) |
  850. FIELD_PREP(IRDMAQPC_TIMELYENABLE, iw->timely_en));
  851. }
  852. if (info->tcp_info_valid) {
  853. qw0 |= FIELD_PREP(IRDMAQPC_IPV4, tcp->ipv4) |
  854. FIELD_PREP(IRDMAQPC_NONAGLE, tcp->no_nagle) |
  855. FIELD_PREP(IRDMAQPC_INSERTVLANTAG,
  856. tcp->insert_vlan_tag) |
  857. FIELD_PREP(IRDMAQPC_TIMESTAMP, tcp->time_stamp) |
  858. FIELD_PREP(IRDMAQPC_LIMIT, tcp->cwnd_inc_limit) |
  859. FIELD_PREP(IRDMAQPC_DROPOOOSEG, tcp->drop_ooo_seg) |
  860. FIELD_PREP(IRDMAQPC_DUPACK_THRESH, tcp->dup_ack_thresh);
  861. if ((iw->ecn_en || iw->dctcp_en) && !(tcp->tos & 0x03))
  862. tcp->tos |= ECN_CODE_PT_VAL;
  863. qw3 |= FIELD_PREP(IRDMAQPC_TTL, tcp->ttl) |
  864. FIELD_PREP(IRDMAQPC_AVOIDSTRETCHACK, tcp->avoid_stretch_ack) |
  865. FIELD_PREP(IRDMAQPC_TOS, tcp->tos) |
  866. FIELD_PREP(IRDMAQPC_SRCPORTNUM, tcp->src_port) |
  867. FIELD_PREP(IRDMAQPC_DESTPORTNUM, tcp->dst_port);
  868. if (dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1) {
  869. qw3 |= FIELD_PREP(IRDMAQPC_GEN1_SRCMACADDRIDX, tcp->src_mac_addr_idx);
  870. qp->src_mac_addr_idx = tcp->src_mac_addr_idx;
  871. }
  872. set_64bit_val(qp_ctx, 32,
  873. FIELD_PREP(IRDMAQPC_DESTIPADDR2, tcp->dest_ip_addr[2]) |
  874. FIELD_PREP(IRDMAQPC_DESTIPADDR3, tcp->dest_ip_addr[3]));
  875. set_64bit_val(qp_ctx, 40,
  876. FIELD_PREP(IRDMAQPC_DESTIPADDR0, tcp->dest_ip_addr[0]) |
  877. FIELD_PREP(IRDMAQPC_DESTIPADDR1, tcp->dest_ip_addr[1]));
  878. set_64bit_val(qp_ctx, 48,
  879. FIELD_PREP(IRDMAQPC_SNDMSS, tcp->snd_mss) |
  880. FIELD_PREP(IRDMAQPC_SYN_RST_HANDLING, tcp->syn_rst_handling) |
  881. FIELD_PREP(IRDMAQPC_VLANTAG, tcp->vlan_tag) |
  882. FIELD_PREP(IRDMAQPC_ARPIDX, tcp->arp_idx));
  883. qw7 |= FIELD_PREP(IRDMAQPC_FLOWLABEL, tcp->flow_label) |
  884. FIELD_PREP(IRDMAQPC_WSCALE, tcp->wscale) |
  885. FIELD_PREP(IRDMAQPC_IGNORE_TCP_OPT,
  886. tcp->ignore_tcp_opt) |
  887. FIELD_PREP(IRDMAQPC_IGNORE_TCP_UNS_OPT,
  888. tcp->ignore_tcp_uns_opt) |
  889. FIELD_PREP(IRDMAQPC_TCPSTATE, tcp->tcp_state) |
  890. FIELD_PREP(IRDMAQPC_RCVSCALE, tcp->rcv_wscale) |
  891. FIELD_PREP(IRDMAQPC_SNDSCALE, tcp->snd_wscale);
  892. set_64bit_val(qp_ctx, 72,
  893. FIELD_PREP(IRDMAQPC_TIMESTAMP_RECENT, tcp->time_stamp_recent) |
  894. FIELD_PREP(IRDMAQPC_TIMESTAMP_AGE, tcp->time_stamp_age));
  895. set_64bit_val(qp_ctx, 80,
  896. FIELD_PREP(IRDMAQPC_SNDNXT, tcp->snd_nxt) |
  897. FIELD_PREP(IRDMAQPC_SNDWND, tcp->snd_wnd));
  898. set_64bit_val(qp_ctx, 88,
  899. FIELD_PREP(IRDMAQPC_RCVNXT, tcp->rcv_nxt) |
  900. FIELD_PREP(IRDMAQPC_RCVWND, tcp->rcv_wnd));
  901. set_64bit_val(qp_ctx, 96,
  902. FIELD_PREP(IRDMAQPC_SNDMAX, tcp->snd_max) |
  903. FIELD_PREP(IRDMAQPC_SNDUNA, tcp->snd_una));
  904. set_64bit_val(qp_ctx, 104,
  905. FIELD_PREP(IRDMAQPC_SRTT, tcp->srtt) |
  906. FIELD_PREP(IRDMAQPC_RTTVAR, tcp->rtt_var));
  907. set_64bit_val(qp_ctx, 112,
  908. FIELD_PREP(IRDMAQPC_SSTHRESH, tcp->ss_thresh) |
  909. FIELD_PREP(IRDMAQPC_CWND, tcp->cwnd));
  910. set_64bit_val(qp_ctx, 120,
  911. FIELD_PREP(IRDMAQPC_SNDWL1, tcp->snd_wl1) |
  912. FIELD_PREP(IRDMAQPC_SNDWL2, tcp->snd_wl2));
  913. qw16 |= FIELD_PREP(IRDMAQPC_MAXSNDWND, tcp->max_snd_window) |
  914. FIELD_PREP(IRDMAQPC_REXMIT_THRESH, tcp->rexmit_thresh);
  915. set_64bit_val(qp_ctx, 184,
  916. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR3, tcp->local_ipaddr[3]) |
  917. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR2, tcp->local_ipaddr[2]));
  918. set_64bit_val(qp_ctx, 192,
  919. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR1, tcp->local_ipaddr[1]) |
  920. FIELD_PREP(IRDMAQPC_LOCAL_IPADDR0, tcp->local_ipaddr[0]));
  921. set_64bit_val(qp_ctx, 200,
  922. FIELD_PREP(IRDMAQPC_THIGH, iw->t_high) |
  923. FIELD_PREP(IRDMAQPC_TLOW, iw->t_low));
  924. set_64bit_val(qp_ctx, 208,
  925. FIELD_PREP(IRDMAQPC_REMENDPOINTIDX, info->rem_endpoint_idx));
  926. }
  927. set_64bit_val(qp_ctx, 0, qw0);
  928. set_64bit_val(qp_ctx, 24, qw3);
  929. set_64bit_val(qp_ctx, 56, qw7);
  930. set_64bit_val(qp_ctx, 128, qw16);
  931. print_hex_dump_debug("WQE: QP_HOST CTX", DUMP_PREFIX_OFFSET, 16, 8,
  932. qp_ctx, IRDMA_QP_CTX_SIZE, false);
  933. }
  934. /**
  935. * irdma_sc_alloc_stag - mr stag alloc
  936. * @dev: sc device struct
  937. * @info: stag info
  938. * @scratch: u64 saved to be used during cqp completion
  939. * @post_sq: flag for cqp db to ring
  940. */
  941. static int irdma_sc_alloc_stag(struct irdma_sc_dev *dev,
  942. struct irdma_allocate_stag_info *info,
  943. u64 scratch, bool post_sq)
  944. {
  945. __le64 *wqe;
  946. struct irdma_sc_cqp *cqp;
  947. u64 hdr;
  948. enum irdma_page_size page_size;
  949. if (!info->total_len && !info->all_memory)
  950. return -EINVAL;
  951. if (info->page_size == 0x40000000)
  952. page_size = IRDMA_PAGE_SIZE_1G;
  953. else if (info->page_size == 0x200000)
  954. page_size = IRDMA_PAGE_SIZE_2M;
  955. else
  956. page_size = IRDMA_PAGE_SIZE_4K;
  957. cqp = dev->cqp;
  958. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  959. if (!wqe)
  960. return -ENOMEM;
  961. set_64bit_val(wqe, 8,
  962. FLD_LS_64(dev, info->pd_id, IRDMA_CQPSQ_STAG_PDID) |
  963. FIELD_PREP(IRDMA_CQPSQ_STAG_STAGLEN, info->total_len));
  964. set_64bit_val(wqe, 16,
  965. FIELD_PREP(IRDMA_CQPSQ_STAG_IDX, info->stag_idx));
  966. set_64bit_val(wqe, 40,
  967. FIELD_PREP(IRDMA_CQPSQ_STAG_HMCFNIDX, info->hmc_fcn_index));
  968. if (info->chunk_size)
  969. set_64bit_val(wqe, 48,
  970. FIELD_PREP(IRDMA_CQPSQ_STAG_FIRSTPMPBLIDX, info->first_pm_pbl_idx));
  971. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_ALLOC_STAG) |
  972. FIELD_PREP(IRDMA_CQPSQ_STAG_MR, 1) |
  973. FIELD_PREP(IRDMA_CQPSQ_STAG_ARIGHTS, info->access_rights) |
  974. FIELD_PREP(IRDMA_CQPSQ_STAG_LPBLSIZE, info->chunk_size) |
  975. FIELD_PREP(IRDMA_CQPSQ_STAG_HPAGESIZE, page_size) |
  976. FIELD_PREP(IRDMA_CQPSQ_STAG_REMACCENABLED, info->remote_access) |
  977. FIELD_PREP(IRDMA_CQPSQ_STAG_USEHMCFNIDX, info->use_hmc_fcn_index) |
  978. FIELD_PREP(IRDMA_CQPSQ_STAG_USEPFRID, info->use_pf_rid) |
  979. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  980. dma_wmb(); /* make sure WQE is written before valid bit is set */
  981. set_64bit_val(wqe, 24, hdr);
  982. print_hex_dump_debug("WQE: ALLOC_STAG WQE", DUMP_PREFIX_OFFSET, 16, 8,
  983. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  984. if (post_sq)
  985. irdma_sc_cqp_post_sq(cqp);
  986. return 0;
  987. }
  988. /**
  989. * irdma_sc_mr_reg_non_shared - non-shared mr registration
  990. * @dev: sc device struct
  991. * @info: mr info
  992. * @scratch: u64 saved to be used during cqp completion
  993. * @post_sq: flag for cqp db to ring
  994. */
  995. static int irdma_sc_mr_reg_non_shared(struct irdma_sc_dev *dev,
  996. struct irdma_reg_ns_stag_info *info,
  997. u64 scratch, bool post_sq)
  998. {
  999. __le64 *wqe;
  1000. u64 fbo;
  1001. struct irdma_sc_cqp *cqp;
  1002. u64 hdr;
  1003. u32 pble_obj_cnt;
  1004. bool remote_access;
  1005. u8 addr_type;
  1006. enum irdma_page_size page_size;
  1007. if (!info->total_len && !info->all_memory)
  1008. return -EINVAL;
  1009. if (info->page_size == 0x40000000)
  1010. page_size = IRDMA_PAGE_SIZE_1G;
  1011. else if (info->page_size == 0x200000)
  1012. page_size = IRDMA_PAGE_SIZE_2M;
  1013. else if (info->page_size == 0x1000)
  1014. page_size = IRDMA_PAGE_SIZE_4K;
  1015. else
  1016. return -EINVAL;
  1017. if (info->access_rights & (IRDMA_ACCESS_FLAGS_REMOTEREAD_ONLY |
  1018. IRDMA_ACCESS_FLAGS_REMOTEWRITE_ONLY))
  1019. remote_access = true;
  1020. else
  1021. remote_access = false;
  1022. pble_obj_cnt = dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  1023. if (info->chunk_size && info->first_pm_pbl_index >= pble_obj_cnt)
  1024. return -EINVAL;
  1025. cqp = dev->cqp;
  1026. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1027. if (!wqe)
  1028. return -ENOMEM;
  1029. fbo = info->va & (info->page_size - 1);
  1030. set_64bit_val(wqe, 0,
  1031. (info->addr_type == IRDMA_ADDR_TYPE_VA_BASED ?
  1032. info->va : fbo));
  1033. set_64bit_val(wqe, 8,
  1034. FIELD_PREP(IRDMA_CQPSQ_STAG_STAGLEN, info->total_len) |
  1035. FLD_LS_64(dev, info->pd_id, IRDMA_CQPSQ_STAG_PDID));
  1036. set_64bit_val(wqe, 16,
  1037. FIELD_PREP(IRDMA_CQPSQ_STAG_KEY, info->stag_key) |
  1038. FIELD_PREP(IRDMA_CQPSQ_STAG_IDX, info->stag_idx));
  1039. if (!info->chunk_size) {
  1040. set_64bit_val(wqe, 32, info->reg_addr_pa);
  1041. set_64bit_val(wqe, 48, 0);
  1042. } else {
  1043. set_64bit_val(wqe, 32, 0);
  1044. set_64bit_val(wqe, 48,
  1045. FIELD_PREP(IRDMA_CQPSQ_STAG_FIRSTPMPBLIDX, info->first_pm_pbl_index));
  1046. }
  1047. set_64bit_val(wqe, 40, info->hmc_fcn_index);
  1048. set_64bit_val(wqe, 56, 0);
  1049. addr_type = (info->addr_type == IRDMA_ADDR_TYPE_VA_BASED) ? 1 : 0;
  1050. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_REG_MR) |
  1051. FIELD_PREP(IRDMA_CQPSQ_STAG_MR, 1) |
  1052. FIELD_PREP(IRDMA_CQPSQ_STAG_LPBLSIZE, info->chunk_size) |
  1053. FIELD_PREP(IRDMA_CQPSQ_STAG_HPAGESIZE, page_size) |
  1054. FIELD_PREP(IRDMA_CQPSQ_STAG_ARIGHTS, info->access_rights) |
  1055. FIELD_PREP(IRDMA_CQPSQ_STAG_REMACCENABLED, remote_access) |
  1056. FIELD_PREP(IRDMA_CQPSQ_STAG_VABASEDTO, addr_type) |
  1057. FIELD_PREP(IRDMA_CQPSQ_STAG_USEHMCFNIDX, info->use_hmc_fcn_index) |
  1058. FIELD_PREP(IRDMA_CQPSQ_STAG_USEPFRID, info->use_pf_rid) |
  1059. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  1060. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1061. set_64bit_val(wqe, 24, hdr);
  1062. print_hex_dump_debug("WQE: MR_REG_NS WQE", DUMP_PREFIX_OFFSET, 16, 8,
  1063. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  1064. if (post_sq)
  1065. irdma_sc_cqp_post_sq(cqp);
  1066. return 0;
  1067. }
  1068. /**
  1069. * irdma_sc_dealloc_stag - deallocate stag
  1070. * @dev: sc device struct
  1071. * @info: dealloc stag info
  1072. * @scratch: u64 saved to be used during cqp completion
  1073. * @post_sq: flag for cqp db to ring
  1074. */
  1075. static int irdma_sc_dealloc_stag(struct irdma_sc_dev *dev,
  1076. struct irdma_dealloc_stag_info *info,
  1077. u64 scratch, bool post_sq)
  1078. {
  1079. u64 hdr;
  1080. __le64 *wqe;
  1081. struct irdma_sc_cqp *cqp;
  1082. cqp = dev->cqp;
  1083. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1084. if (!wqe)
  1085. return -ENOMEM;
  1086. set_64bit_val(wqe, 8,
  1087. FLD_LS_64(dev, info->pd_id, IRDMA_CQPSQ_STAG_PDID));
  1088. set_64bit_val(wqe, 16,
  1089. FIELD_PREP(IRDMA_CQPSQ_STAG_IDX, info->stag_idx));
  1090. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_DEALLOC_STAG) |
  1091. FIELD_PREP(IRDMA_CQPSQ_STAG_MR, info->mr) |
  1092. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  1093. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1094. set_64bit_val(wqe, 24, hdr);
  1095. print_hex_dump_debug("WQE: DEALLOC_STAG WQE", DUMP_PREFIX_OFFSET, 16,
  1096. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  1097. if (post_sq)
  1098. irdma_sc_cqp_post_sq(cqp);
  1099. return 0;
  1100. }
  1101. /**
  1102. * irdma_sc_mw_alloc - mw allocate
  1103. * @dev: sc device struct
  1104. * @info: memory window allocation information
  1105. * @scratch: u64 saved to be used during cqp completion
  1106. * @post_sq: flag for cqp db to ring
  1107. */
  1108. static int irdma_sc_mw_alloc(struct irdma_sc_dev *dev,
  1109. struct irdma_mw_alloc_info *info, u64 scratch,
  1110. bool post_sq)
  1111. {
  1112. u64 hdr;
  1113. struct irdma_sc_cqp *cqp;
  1114. __le64 *wqe;
  1115. cqp = dev->cqp;
  1116. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1117. if (!wqe)
  1118. return -ENOMEM;
  1119. set_64bit_val(wqe, 8,
  1120. FLD_LS_64(dev, info->pd_id, IRDMA_CQPSQ_STAG_PDID));
  1121. set_64bit_val(wqe, 16,
  1122. FIELD_PREP(IRDMA_CQPSQ_STAG_IDX, info->mw_stag_index));
  1123. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_ALLOC_STAG) |
  1124. FIELD_PREP(IRDMA_CQPSQ_STAG_MWTYPE, info->mw_wide) |
  1125. FIELD_PREP(IRDMA_CQPSQ_STAG_MW1_BIND_DONT_VLDT_KEY,
  1126. info->mw1_bind_dont_vldt_key) |
  1127. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  1128. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1129. set_64bit_val(wqe, 24, hdr);
  1130. print_hex_dump_debug("WQE: MW_ALLOC WQE", DUMP_PREFIX_OFFSET, 16, 8,
  1131. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  1132. if (post_sq)
  1133. irdma_sc_cqp_post_sq(cqp);
  1134. return 0;
  1135. }
  1136. /**
  1137. * irdma_sc_mr_fast_register - Posts RDMA fast register mr WR to iwarp qp
  1138. * @qp: sc qp struct
  1139. * @info: fast mr info
  1140. * @post_sq: flag for cqp db to ring
  1141. */
  1142. int irdma_sc_mr_fast_register(struct irdma_sc_qp *qp,
  1143. struct irdma_fast_reg_stag_info *info,
  1144. bool post_sq)
  1145. {
  1146. u64 temp, hdr;
  1147. __le64 *wqe;
  1148. u32 wqe_idx;
  1149. enum irdma_page_size page_size;
  1150. struct irdma_post_sq_info sq_info = {};
  1151. if (info->page_size == 0x40000000)
  1152. page_size = IRDMA_PAGE_SIZE_1G;
  1153. else if (info->page_size == 0x200000)
  1154. page_size = IRDMA_PAGE_SIZE_2M;
  1155. else
  1156. page_size = IRDMA_PAGE_SIZE_4K;
  1157. sq_info.wr_id = info->wr_id;
  1158. sq_info.signaled = info->signaled;
  1159. wqe = irdma_qp_get_next_send_wqe(&qp->qp_uk, &wqe_idx,
  1160. IRDMA_QP_WQE_MIN_QUANTA, 0, &sq_info);
  1161. if (!wqe)
  1162. return -ENOMEM;
  1163. irdma_clr_wqes(&qp->qp_uk, wqe_idx);
  1164. ibdev_dbg(to_ibdev(qp->dev),
  1165. "MR: wr_id[%llxh] wqe_idx[%04d] location[%p]\n",
  1166. info->wr_id, wqe_idx,
  1167. &qp->qp_uk.sq_wrtrk_array[wqe_idx].wrid);
  1168. temp = (info->addr_type == IRDMA_ADDR_TYPE_VA_BASED) ?
  1169. (uintptr_t)info->va : info->fbo;
  1170. set_64bit_val(wqe, 0, temp);
  1171. temp = FIELD_GET(IRDMAQPSQ_FIRSTPMPBLIDXHI,
  1172. info->first_pm_pbl_index >> 16);
  1173. set_64bit_val(wqe, 8,
  1174. FIELD_PREP(IRDMAQPSQ_FIRSTPMPBLIDXHI, temp) |
  1175. FIELD_PREP(IRDMAQPSQ_PBLADDR >> IRDMA_HW_PAGE_SHIFT, info->reg_addr_pa));
  1176. set_64bit_val(wqe, 16,
  1177. info->total_len |
  1178. FIELD_PREP(IRDMAQPSQ_FIRSTPMPBLIDXLO, info->first_pm_pbl_index));
  1179. hdr = FIELD_PREP(IRDMAQPSQ_STAGKEY, info->stag_key) |
  1180. FIELD_PREP(IRDMAQPSQ_STAGINDEX, info->stag_idx) |
  1181. FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_FAST_REGISTER) |
  1182. FIELD_PREP(IRDMAQPSQ_LPBLSIZE, info->chunk_size) |
  1183. FIELD_PREP(IRDMAQPSQ_HPAGESIZE, page_size) |
  1184. FIELD_PREP(IRDMAQPSQ_STAGRIGHTS, info->access_rights) |
  1185. FIELD_PREP(IRDMAQPSQ_VABASEDTO, info->addr_type) |
  1186. FIELD_PREP(IRDMAQPSQ_READFENCE, info->read_fence) |
  1187. FIELD_PREP(IRDMAQPSQ_LOCALFENCE, info->local_fence) |
  1188. FIELD_PREP(IRDMAQPSQ_SIGCOMPL, info->signaled) |
  1189. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity);
  1190. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1191. set_64bit_val(wqe, 24, hdr);
  1192. print_hex_dump_debug("WQE: FAST_REG WQE", DUMP_PREFIX_OFFSET, 16, 8,
  1193. wqe, IRDMA_QP_WQE_MIN_SIZE, false);
  1194. if (post_sq)
  1195. irdma_uk_qp_post_wr(&qp->qp_uk);
  1196. return 0;
  1197. }
  1198. /**
  1199. * irdma_sc_gen_rts_ae - request AE generated after RTS
  1200. * @qp: sc qp struct
  1201. */
  1202. static void irdma_sc_gen_rts_ae(struct irdma_sc_qp *qp)
  1203. {
  1204. __le64 *wqe;
  1205. u64 hdr;
  1206. struct irdma_qp_uk *qp_uk;
  1207. qp_uk = &qp->qp_uk;
  1208. wqe = qp_uk->sq_base[1].elem;
  1209. hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_NOP) |
  1210. FIELD_PREP(IRDMAQPSQ_LOCALFENCE, 1) |
  1211. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity);
  1212. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1213. set_64bit_val(wqe, 24, hdr);
  1214. print_hex_dump_debug("QP: NOP W/LOCAL FENCE WQE", DUMP_PREFIX_OFFSET,
  1215. 16, 8, wqe, IRDMA_QP_WQE_MIN_SIZE, false);
  1216. wqe = qp_uk->sq_base[2].elem;
  1217. hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_GEN_RTS_AE) |
  1218. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity);
  1219. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1220. set_64bit_val(wqe, 24, hdr);
  1221. print_hex_dump_debug("QP: CONN EST WQE", DUMP_PREFIX_OFFSET, 16, 8,
  1222. wqe, IRDMA_QP_WQE_MIN_SIZE, false);
  1223. }
  1224. /**
  1225. * irdma_sc_send_lsmm - send last streaming mode message
  1226. * @qp: sc qp struct
  1227. * @lsmm_buf: buffer with lsmm message
  1228. * @size: size of lsmm buffer
  1229. * @stag: stag of lsmm buffer
  1230. */
  1231. void irdma_sc_send_lsmm(struct irdma_sc_qp *qp, void *lsmm_buf, u32 size,
  1232. irdma_stag stag)
  1233. {
  1234. __le64 *wqe;
  1235. u64 hdr;
  1236. struct irdma_qp_uk *qp_uk;
  1237. qp_uk = &qp->qp_uk;
  1238. wqe = qp_uk->sq_base->elem;
  1239. set_64bit_val(wqe, 0, (uintptr_t)lsmm_buf);
  1240. if (qp->qp_uk.uk_attrs->hw_rev == IRDMA_GEN_1) {
  1241. set_64bit_val(wqe, 8,
  1242. FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_LEN, size) |
  1243. FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_STAG, stag));
  1244. } else {
  1245. set_64bit_val(wqe, 8,
  1246. FIELD_PREP(IRDMAQPSQ_FRAG_LEN, size) |
  1247. FIELD_PREP(IRDMAQPSQ_FRAG_STAG, stag) |
  1248. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity));
  1249. }
  1250. set_64bit_val(wqe, 16, 0);
  1251. hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_RDMA_SEND) |
  1252. FIELD_PREP(IRDMAQPSQ_STREAMMODE, 1) |
  1253. FIELD_PREP(IRDMAQPSQ_WAITFORRCVPDU, 1) |
  1254. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity);
  1255. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1256. set_64bit_val(wqe, 24, hdr);
  1257. print_hex_dump_debug("WQE: SEND_LSMM WQE", DUMP_PREFIX_OFFSET, 16, 8,
  1258. wqe, IRDMA_QP_WQE_MIN_SIZE, false);
  1259. if (qp->dev->hw_attrs.uk_attrs.feature_flags & IRDMA_FEATURE_RTS_AE)
  1260. irdma_sc_gen_rts_ae(qp);
  1261. }
  1262. /**
  1263. * irdma_sc_send_rtt - send last read0 or write0
  1264. * @qp: sc qp struct
  1265. * @read: Do read0 or write0
  1266. */
  1267. void irdma_sc_send_rtt(struct irdma_sc_qp *qp, bool read)
  1268. {
  1269. __le64 *wqe;
  1270. u64 hdr;
  1271. struct irdma_qp_uk *qp_uk;
  1272. qp_uk = &qp->qp_uk;
  1273. wqe = qp_uk->sq_base->elem;
  1274. set_64bit_val(wqe, 0, 0);
  1275. set_64bit_val(wqe, 16, 0);
  1276. if (read) {
  1277. if (qp->qp_uk.uk_attrs->hw_rev == IRDMA_GEN_1) {
  1278. set_64bit_val(wqe, 8,
  1279. FIELD_PREP(IRDMAQPSQ_GEN1_FRAG_STAG, 0xabcd));
  1280. } else {
  1281. set_64bit_val(wqe, 8,
  1282. (u64)0xabcd | FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity));
  1283. }
  1284. hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, 0x1234) |
  1285. FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_RDMA_READ) |
  1286. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity);
  1287. } else {
  1288. if (qp->qp_uk.uk_attrs->hw_rev == IRDMA_GEN_1) {
  1289. set_64bit_val(wqe, 8, 0);
  1290. } else {
  1291. set_64bit_val(wqe, 8,
  1292. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity));
  1293. }
  1294. hdr = FIELD_PREP(IRDMAQPSQ_OPCODE, IRDMAQP_OP_RDMA_WRITE) |
  1295. FIELD_PREP(IRDMAQPSQ_VALID, qp->qp_uk.swqe_polarity);
  1296. }
  1297. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1298. set_64bit_val(wqe, 24, hdr);
  1299. print_hex_dump_debug("WQE: RTR WQE", DUMP_PREFIX_OFFSET, 16, 8, wqe,
  1300. IRDMA_QP_WQE_MIN_SIZE, false);
  1301. if (qp->dev->hw_attrs.uk_attrs.feature_flags & IRDMA_FEATURE_RTS_AE)
  1302. irdma_sc_gen_rts_ae(qp);
  1303. }
  1304. /**
  1305. * irdma_iwarp_opcode - determine if incoming is rdma layer
  1306. * @info: aeq info for the packet
  1307. * @pkt: packet for error
  1308. */
  1309. static u32 irdma_iwarp_opcode(struct irdma_aeqe_info *info, u8 *pkt)
  1310. {
  1311. __be16 *mpa;
  1312. u32 opcode = 0xffffffff;
  1313. if (info->q2_data_written) {
  1314. mpa = (__be16 *)pkt;
  1315. opcode = ntohs(mpa[1]) & 0xf;
  1316. }
  1317. return opcode;
  1318. }
  1319. /**
  1320. * irdma_locate_mpa - return pointer to mpa in the pkt
  1321. * @pkt: packet with data
  1322. */
  1323. static u8 *irdma_locate_mpa(u8 *pkt)
  1324. {
  1325. /* skip over ethernet header */
  1326. pkt += IRDMA_MAC_HLEN;
  1327. /* Skip over IP and TCP headers */
  1328. pkt += 4 * (pkt[0] & 0x0f);
  1329. pkt += 4 * ((pkt[12] >> 4) & 0x0f);
  1330. return pkt;
  1331. }
  1332. /**
  1333. * irdma_bld_termhdr_ctrl - setup terminate hdr control fields
  1334. * @qp: sc qp ptr for pkt
  1335. * @hdr: term hdr
  1336. * @opcode: flush opcode for termhdr
  1337. * @layer_etype: error layer + error type
  1338. * @err: error cod ein the header
  1339. */
  1340. static void irdma_bld_termhdr_ctrl(struct irdma_sc_qp *qp,
  1341. struct irdma_terminate_hdr *hdr,
  1342. enum irdma_flush_opcode opcode,
  1343. u8 layer_etype, u8 err)
  1344. {
  1345. qp->flush_code = opcode;
  1346. hdr->layer_etype = layer_etype;
  1347. hdr->error_code = err;
  1348. }
  1349. /**
  1350. * irdma_bld_termhdr_ddp_rdma - setup ddp and rdma hdrs in terminate hdr
  1351. * @pkt: ptr to mpa in offending pkt
  1352. * @hdr: term hdr
  1353. * @copy_len: offending pkt length to be copied to term hdr
  1354. * @is_tagged: DDP tagged or untagged
  1355. */
  1356. static void irdma_bld_termhdr_ddp_rdma(u8 *pkt, struct irdma_terminate_hdr *hdr,
  1357. int *copy_len, u8 *is_tagged)
  1358. {
  1359. u16 ddp_seg_len;
  1360. ddp_seg_len = ntohs(*(__be16 *)pkt);
  1361. if (ddp_seg_len) {
  1362. *copy_len = 2;
  1363. hdr->hdrct = DDP_LEN_FLAG;
  1364. if (pkt[2] & 0x80) {
  1365. *is_tagged = 1;
  1366. if (ddp_seg_len >= TERM_DDP_LEN_TAGGED) {
  1367. *copy_len += TERM_DDP_LEN_TAGGED;
  1368. hdr->hdrct |= DDP_HDR_FLAG;
  1369. }
  1370. } else {
  1371. if (ddp_seg_len >= TERM_DDP_LEN_UNTAGGED) {
  1372. *copy_len += TERM_DDP_LEN_UNTAGGED;
  1373. hdr->hdrct |= DDP_HDR_FLAG;
  1374. }
  1375. if (ddp_seg_len >= (TERM_DDP_LEN_UNTAGGED + TERM_RDMA_LEN) &&
  1376. ((pkt[3] & RDMA_OPCODE_M) == RDMA_READ_REQ_OPCODE)) {
  1377. *copy_len += TERM_RDMA_LEN;
  1378. hdr->hdrct |= RDMA_HDR_FLAG;
  1379. }
  1380. }
  1381. }
  1382. }
  1383. /**
  1384. * irdma_bld_terminate_hdr - build terminate message header
  1385. * @qp: qp associated with received terminate AE
  1386. * @info: the struct contiaing AE information
  1387. */
  1388. static int irdma_bld_terminate_hdr(struct irdma_sc_qp *qp,
  1389. struct irdma_aeqe_info *info)
  1390. {
  1391. u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
  1392. int copy_len = 0;
  1393. u8 is_tagged = 0;
  1394. u32 opcode;
  1395. struct irdma_terminate_hdr *termhdr;
  1396. termhdr = (struct irdma_terminate_hdr *)qp->q2_buf;
  1397. memset(termhdr, 0, Q2_BAD_FRAME_OFFSET);
  1398. if (info->q2_data_written) {
  1399. pkt = irdma_locate_mpa(pkt);
  1400. irdma_bld_termhdr_ddp_rdma(pkt, termhdr, &copy_len, &is_tagged);
  1401. }
  1402. opcode = irdma_iwarp_opcode(info, pkt);
  1403. qp->event_type = IRDMA_QP_EVENT_CATASTROPHIC;
  1404. qp->sq_flush_code = info->sq;
  1405. qp->rq_flush_code = info->rq;
  1406. switch (info->ae_id) {
  1407. case IRDMA_AE_AMP_UNALLOCATED_STAG:
  1408. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1409. if (opcode == IRDMA_OP_TYPE_RDMA_WRITE)
  1410. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_PROT_ERR,
  1411. (LAYER_DDP << 4) | DDP_TAGGED_BUF,
  1412. DDP_TAGGED_INV_STAG);
  1413. else
  1414. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1415. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1416. RDMAP_INV_STAG);
  1417. break;
  1418. case IRDMA_AE_AMP_BOUNDS_VIOLATION:
  1419. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1420. if (info->q2_data_written)
  1421. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_PROT_ERR,
  1422. (LAYER_DDP << 4) | DDP_TAGGED_BUF,
  1423. DDP_TAGGED_BOUNDS);
  1424. else
  1425. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1426. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1427. RDMAP_INV_BOUNDS);
  1428. break;
  1429. case IRDMA_AE_AMP_BAD_PD:
  1430. switch (opcode) {
  1431. case IRDMA_OP_TYPE_RDMA_WRITE:
  1432. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_PROT_ERR,
  1433. (LAYER_DDP << 4) | DDP_TAGGED_BUF,
  1434. DDP_TAGGED_UNASSOC_STAG);
  1435. break;
  1436. case IRDMA_OP_TYPE_SEND_INV:
  1437. case IRDMA_OP_TYPE_SEND_SOL_INV:
  1438. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1439. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1440. RDMAP_CANT_INV_STAG);
  1441. break;
  1442. default:
  1443. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1444. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1445. RDMAP_UNASSOC_STAG);
  1446. }
  1447. break;
  1448. case IRDMA_AE_AMP_INVALID_STAG:
  1449. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1450. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1451. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1452. RDMAP_INV_STAG);
  1453. break;
  1454. case IRDMA_AE_AMP_BAD_QP:
  1455. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_LOC_QP_OP_ERR,
  1456. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1457. DDP_UNTAGGED_INV_QN);
  1458. break;
  1459. case IRDMA_AE_AMP_BAD_STAG_KEY:
  1460. case IRDMA_AE_AMP_BAD_STAG_INDEX:
  1461. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1462. switch (opcode) {
  1463. case IRDMA_OP_TYPE_SEND_INV:
  1464. case IRDMA_OP_TYPE_SEND_SOL_INV:
  1465. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_OP_ERR,
  1466. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP,
  1467. RDMAP_CANT_INV_STAG);
  1468. break;
  1469. default:
  1470. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1471. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP,
  1472. RDMAP_INV_STAG);
  1473. }
  1474. break;
  1475. case IRDMA_AE_AMP_RIGHTS_VIOLATION:
  1476. case IRDMA_AE_AMP_INVALIDATE_NO_REMOTE_ACCESS_RIGHTS:
  1477. case IRDMA_AE_PRIV_OPERATION_DENIED:
  1478. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1479. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1480. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1481. RDMAP_ACCESS);
  1482. break;
  1483. case IRDMA_AE_AMP_TO_WRAP:
  1484. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1485. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_ACCESS_ERR,
  1486. (LAYER_RDMA << 4) | RDMAP_REMOTE_PROT,
  1487. RDMAP_TO_WRAP);
  1488. break;
  1489. case IRDMA_AE_LLP_RECEIVED_MPA_CRC_ERROR:
  1490. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1491. (LAYER_MPA << 4) | DDP_LLP, MPA_CRC);
  1492. break;
  1493. case IRDMA_AE_LLP_SEGMENT_TOO_SMALL:
  1494. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_LOC_LEN_ERR,
  1495. (LAYER_DDP << 4) | DDP_CATASTROPHIC,
  1496. DDP_CATASTROPHIC_LOCAL);
  1497. break;
  1498. case IRDMA_AE_LCE_QP_CATASTROPHIC:
  1499. case IRDMA_AE_DDP_NO_L_BIT:
  1500. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_FATAL_ERR,
  1501. (LAYER_DDP << 4) | DDP_CATASTROPHIC,
  1502. DDP_CATASTROPHIC_LOCAL);
  1503. break;
  1504. case IRDMA_AE_DDP_INVALID_MSN_GAP_IN_MSN:
  1505. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1506. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1507. DDP_UNTAGGED_INV_MSN_RANGE);
  1508. break;
  1509. case IRDMA_AE_DDP_UBE_DDP_MESSAGE_TOO_LONG_FOR_AVAILABLE_BUFFER:
  1510. qp->event_type = IRDMA_QP_EVENT_ACCESS_ERR;
  1511. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_LOC_LEN_ERR,
  1512. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1513. DDP_UNTAGGED_INV_TOO_LONG);
  1514. break;
  1515. case IRDMA_AE_DDP_UBE_INVALID_DDP_VERSION:
  1516. if (is_tagged)
  1517. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1518. (LAYER_DDP << 4) | DDP_TAGGED_BUF,
  1519. DDP_TAGGED_INV_DDP_VER);
  1520. else
  1521. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1522. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1523. DDP_UNTAGGED_INV_DDP_VER);
  1524. break;
  1525. case IRDMA_AE_DDP_UBE_INVALID_MO:
  1526. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1527. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1528. DDP_UNTAGGED_INV_MO);
  1529. break;
  1530. case IRDMA_AE_DDP_UBE_INVALID_MSN_NO_BUFFER_AVAILABLE:
  1531. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_REM_OP_ERR,
  1532. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1533. DDP_UNTAGGED_INV_MSN_NO_BUF);
  1534. break;
  1535. case IRDMA_AE_DDP_UBE_INVALID_QN:
  1536. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1537. (LAYER_DDP << 4) | DDP_UNTAGGED_BUF,
  1538. DDP_UNTAGGED_INV_QN);
  1539. break;
  1540. case IRDMA_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
  1541. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_GENERAL_ERR,
  1542. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP,
  1543. RDMAP_INV_RDMAP_VER);
  1544. break;
  1545. default:
  1546. irdma_bld_termhdr_ctrl(qp, termhdr, FLUSH_FATAL_ERR,
  1547. (LAYER_RDMA << 4) | RDMAP_REMOTE_OP,
  1548. RDMAP_UNSPECIFIED);
  1549. break;
  1550. }
  1551. if (copy_len)
  1552. memcpy(termhdr + 1, pkt, copy_len);
  1553. return sizeof(struct irdma_terminate_hdr) + copy_len;
  1554. }
  1555. /**
  1556. * irdma_terminate_send_fin() - Send fin for terminate message
  1557. * @qp: qp associated with received terminate AE
  1558. */
  1559. void irdma_terminate_send_fin(struct irdma_sc_qp *qp)
  1560. {
  1561. irdma_term_modify_qp(qp, IRDMA_QP_STATE_TERMINATE,
  1562. IRDMAQP_TERM_SEND_FIN_ONLY, 0);
  1563. }
  1564. /**
  1565. * irdma_terminate_connection() - Bad AE and send terminate to remote QP
  1566. * @qp: qp associated with received terminate AE
  1567. * @info: the struct contiaing AE information
  1568. */
  1569. void irdma_terminate_connection(struct irdma_sc_qp *qp,
  1570. struct irdma_aeqe_info *info)
  1571. {
  1572. u8 termlen = 0;
  1573. if (qp->term_flags & IRDMA_TERM_SENT)
  1574. return;
  1575. termlen = irdma_bld_terminate_hdr(qp, info);
  1576. irdma_terminate_start_timer(qp);
  1577. qp->term_flags |= IRDMA_TERM_SENT;
  1578. irdma_term_modify_qp(qp, IRDMA_QP_STATE_TERMINATE,
  1579. IRDMAQP_TERM_SEND_TERM_ONLY, termlen);
  1580. }
  1581. /**
  1582. * irdma_terminate_received - handle terminate received AE
  1583. * @qp: qp associated with received terminate AE
  1584. * @info: the struct contiaing AE information
  1585. */
  1586. void irdma_terminate_received(struct irdma_sc_qp *qp,
  1587. struct irdma_aeqe_info *info)
  1588. {
  1589. u8 *pkt = qp->q2_buf + Q2_BAD_FRAME_OFFSET;
  1590. __be32 *mpa;
  1591. u8 ddp_ctl;
  1592. u8 rdma_ctl;
  1593. u16 aeq_id = 0;
  1594. struct irdma_terminate_hdr *termhdr;
  1595. mpa = (__be32 *)irdma_locate_mpa(pkt);
  1596. if (info->q2_data_written) {
  1597. /* did not validate the frame - do it now */
  1598. ddp_ctl = (ntohl(mpa[0]) >> 8) & 0xff;
  1599. rdma_ctl = ntohl(mpa[0]) & 0xff;
  1600. if ((ddp_ctl & 0xc0) != 0x40)
  1601. aeq_id = IRDMA_AE_LCE_QP_CATASTROPHIC;
  1602. else if ((ddp_ctl & 0x03) != 1)
  1603. aeq_id = IRDMA_AE_DDP_UBE_INVALID_DDP_VERSION;
  1604. else if (ntohl(mpa[2]) != 2)
  1605. aeq_id = IRDMA_AE_DDP_UBE_INVALID_QN;
  1606. else if (ntohl(mpa[3]) != 1)
  1607. aeq_id = IRDMA_AE_DDP_INVALID_MSN_GAP_IN_MSN;
  1608. else if (ntohl(mpa[4]) != 0)
  1609. aeq_id = IRDMA_AE_DDP_UBE_INVALID_MO;
  1610. else if ((rdma_ctl & 0xc0) != 0x40)
  1611. aeq_id = IRDMA_AE_RDMAP_ROE_INVALID_RDMAP_VERSION;
  1612. info->ae_id = aeq_id;
  1613. if (info->ae_id) {
  1614. /* Bad terminate recvd - send back a terminate */
  1615. irdma_terminate_connection(qp, info);
  1616. return;
  1617. }
  1618. }
  1619. qp->term_flags |= IRDMA_TERM_RCVD;
  1620. qp->event_type = IRDMA_QP_EVENT_CATASTROPHIC;
  1621. termhdr = (struct irdma_terminate_hdr *)&mpa[5];
  1622. if (termhdr->layer_etype == RDMAP_REMOTE_PROT ||
  1623. termhdr->layer_etype == RDMAP_REMOTE_OP) {
  1624. irdma_terminate_done(qp, 0);
  1625. } else {
  1626. irdma_terminate_start_timer(qp);
  1627. irdma_terminate_send_fin(qp);
  1628. }
  1629. }
  1630. static int irdma_null_ws_add(struct irdma_sc_vsi *vsi, u8 user_pri)
  1631. {
  1632. return 0;
  1633. }
  1634. static void irdma_null_ws_remove(struct irdma_sc_vsi *vsi, u8 user_pri)
  1635. {
  1636. /* do nothing */
  1637. }
  1638. static void irdma_null_ws_reset(struct irdma_sc_vsi *vsi)
  1639. {
  1640. /* do nothing */
  1641. }
  1642. /**
  1643. * irdma_sc_vsi_init - Init the vsi structure
  1644. * @vsi: pointer to vsi structure to initialize
  1645. * @info: the info used to initialize the vsi struct
  1646. */
  1647. void irdma_sc_vsi_init(struct irdma_sc_vsi *vsi,
  1648. struct irdma_vsi_init_info *info)
  1649. {
  1650. int i;
  1651. vsi->dev = info->dev;
  1652. vsi->back_vsi = info->back_vsi;
  1653. vsi->register_qset = info->register_qset;
  1654. vsi->unregister_qset = info->unregister_qset;
  1655. vsi->mtu = info->params->mtu;
  1656. vsi->exception_lan_q = info->exception_lan_q;
  1657. vsi->vsi_idx = info->pf_data_vsi_num;
  1658. irdma_set_qos_info(vsi, info->params);
  1659. for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++) {
  1660. mutex_init(&vsi->qos[i].qos_mutex);
  1661. INIT_LIST_HEAD(&vsi->qos[i].qplist);
  1662. }
  1663. if (vsi->register_qset) {
  1664. vsi->dev->ws_add = irdma_ws_add;
  1665. vsi->dev->ws_remove = irdma_ws_remove;
  1666. vsi->dev->ws_reset = irdma_ws_reset;
  1667. } else {
  1668. vsi->dev->ws_add = irdma_null_ws_add;
  1669. vsi->dev->ws_remove = irdma_null_ws_remove;
  1670. vsi->dev->ws_reset = irdma_null_ws_reset;
  1671. }
  1672. }
  1673. /**
  1674. * irdma_get_stats_idx - Return stats index
  1675. * @vsi: pointer to the vsi
  1676. */
  1677. static u8 irdma_get_stats_idx(struct irdma_sc_vsi *vsi)
  1678. {
  1679. struct irdma_stats_inst_info stats_info = {};
  1680. struct irdma_sc_dev *dev = vsi->dev;
  1681. u8 i;
  1682. if (dev->hw_attrs.uk_attrs.hw_rev >= IRDMA_GEN_2) {
  1683. if (!irdma_cqp_stats_inst_cmd(vsi, IRDMA_OP_STATS_ALLOCATE,
  1684. &stats_info))
  1685. return stats_info.stats_idx;
  1686. }
  1687. for (i = 0; i < IRDMA_MAX_STATS_COUNT_GEN_1; i++) {
  1688. if (!dev->stats_idx_array[i]) {
  1689. dev->stats_idx_array[i] = true;
  1690. return i;
  1691. }
  1692. }
  1693. return IRDMA_INVALID_STATS_IDX;
  1694. }
  1695. /**
  1696. * irdma_hw_stats_init_gen1 - Initialize stat reg table used for gen1
  1697. * @vsi: vsi structure where hw_regs are set
  1698. *
  1699. * Populate the HW stats table
  1700. */
  1701. static void irdma_hw_stats_init_gen1(struct irdma_sc_vsi *vsi)
  1702. {
  1703. struct irdma_sc_dev *dev = vsi->dev;
  1704. const struct irdma_hw_stat_map *map;
  1705. u64 *stat_reg = vsi->hw_stats_regs;
  1706. u64 *regs = dev->hw_stats_regs;
  1707. u16 i, stats_reg_set = vsi->stats_idx;
  1708. map = dev->hw_stats_map;
  1709. /* First 4 stat instances are reserved for port level statistics. */
  1710. stats_reg_set += vsi->stats_inst_alloc ? IRDMA_FIRST_NON_PF_STAT : 0;
  1711. for (i = 0; i < dev->hw_attrs.max_stat_idx; i++) {
  1712. if (map[i].bitmask <= IRDMA_MAX_STATS_32)
  1713. stat_reg[i] = regs[i] + stats_reg_set * sizeof(u32);
  1714. else
  1715. stat_reg[i] = regs[i] + stats_reg_set * sizeof(u64);
  1716. }
  1717. }
  1718. /**
  1719. * irdma_vsi_stats_init - Initialize the vsi statistics
  1720. * @vsi: pointer to the vsi structure
  1721. * @info: The info structure used for initialization
  1722. */
  1723. int irdma_vsi_stats_init(struct irdma_sc_vsi *vsi,
  1724. struct irdma_vsi_stats_info *info)
  1725. {
  1726. struct irdma_dma_mem *stats_buff_mem;
  1727. vsi->pestat = info->pestat;
  1728. vsi->pestat->hw = vsi->dev->hw;
  1729. vsi->pestat->vsi = vsi;
  1730. stats_buff_mem = &vsi->pestat->gather_info.stats_buff_mem;
  1731. stats_buff_mem->size = ALIGN(IRDMA_GATHER_STATS_BUF_SIZE * 2, 1);
  1732. stats_buff_mem->va = dma_alloc_coherent(vsi->pestat->hw->device,
  1733. stats_buff_mem->size,
  1734. &stats_buff_mem->pa,
  1735. GFP_KERNEL);
  1736. if (!stats_buff_mem->va)
  1737. return -ENOMEM;
  1738. vsi->pestat->gather_info.gather_stats_va = stats_buff_mem->va;
  1739. vsi->pestat->gather_info.last_gather_stats_va =
  1740. (void *)((uintptr_t)stats_buff_mem->va +
  1741. IRDMA_GATHER_STATS_BUF_SIZE);
  1742. irdma_hw_stats_start_timer(vsi);
  1743. /* when stat allocation is not required default to fcn_id. */
  1744. vsi->stats_idx = info->fcn_id;
  1745. if (info->alloc_stats_inst) {
  1746. u8 stats_idx = irdma_get_stats_idx(vsi);
  1747. if (stats_idx != IRDMA_INVALID_STATS_IDX) {
  1748. vsi->stats_inst_alloc = true;
  1749. vsi->stats_idx = stats_idx;
  1750. vsi->pestat->gather_info.use_stats_inst = true;
  1751. vsi->pestat->gather_info.stats_inst_index = stats_idx;
  1752. }
  1753. }
  1754. if (vsi->dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1)
  1755. irdma_hw_stats_init_gen1(vsi);
  1756. return 0;
  1757. }
  1758. /**
  1759. * irdma_vsi_stats_free - Free the vsi stats
  1760. * @vsi: pointer to the vsi structure
  1761. */
  1762. void irdma_vsi_stats_free(struct irdma_sc_vsi *vsi)
  1763. {
  1764. struct irdma_stats_inst_info stats_info = {};
  1765. struct irdma_sc_dev *dev = vsi->dev;
  1766. u8 stats_idx = vsi->stats_idx;
  1767. if (dev->hw_attrs.uk_attrs.hw_rev >= IRDMA_GEN_2) {
  1768. if (vsi->stats_inst_alloc) {
  1769. stats_info.stats_idx = vsi->stats_idx;
  1770. irdma_cqp_stats_inst_cmd(vsi, IRDMA_OP_STATS_FREE,
  1771. &stats_info);
  1772. }
  1773. } else {
  1774. if (vsi->stats_inst_alloc &&
  1775. stats_idx < vsi->dev->hw_attrs.max_stat_inst)
  1776. vsi->dev->stats_idx_array[stats_idx] = false;
  1777. }
  1778. if (!vsi->pestat)
  1779. return;
  1780. irdma_hw_stats_stop_timer(vsi);
  1781. dma_free_coherent(vsi->pestat->hw->device,
  1782. vsi->pestat->gather_info.stats_buff_mem.size,
  1783. vsi->pestat->gather_info.stats_buff_mem.va,
  1784. vsi->pestat->gather_info.stats_buff_mem.pa);
  1785. vsi->pestat->gather_info.stats_buff_mem.va = NULL;
  1786. }
  1787. /**
  1788. * irdma_get_encoded_wqe_size - given wq size, returns hardware encoded size
  1789. * @wqsize: size of the wq (sq, rq) to encoded_size
  1790. * @queue_type: queue type selected for the calculation algorithm
  1791. */
  1792. u8 irdma_get_encoded_wqe_size(u32 wqsize, enum irdma_queue_type queue_type)
  1793. {
  1794. u8 encoded_size = 0;
  1795. /* cqp sq's hw coded value starts from 1 for size of 4
  1796. * while it starts from 0 for qp' wq's.
  1797. */
  1798. if (queue_type == IRDMA_QUEUE_TYPE_CQP)
  1799. encoded_size = 1;
  1800. wqsize >>= 2;
  1801. while (wqsize >>= 1)
  1802. encoded_size++;
  1803. return encoded_size;
  1804. }
  1805. /**
  1806. * irdma_sc_gather_stats - collect the statistics
  1807. * @cqp: struct for cqp hw
  1808. * @info: gather stats info structure
  1809. * @scratch: u64 saved to be used during cqp completion
  1810. */
  1811. static int irdma_sc_gather_stats(struct irdma_sc_cqp *cqp,
  1812. struct irdma_stats_gather_info *info,
  1813. u64 scratch)
  1814. {
  1815. __le64 *wqe;
  1816. u64 temp;
  1817. if (info->stats_buff_mem.size < IRDMA_GATHER_STATS_BUF_SIZE)
  1818. return -ENOMEM;
  1819. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1820. if (!wqe)
  1821. return -ENOMEM;
  1822. set_64bit_val(wqe, 40,
  1823. FIELD_PREP(IRDMA_CQPSQ_STATS_HMC_FCN_INDEX, info->hmc_fcn_index));
  1824. set_64bit_val(wqe, 32, info->stats_buff_mem.pa);
  1825. temp = FIELD_PREP(IRDMA_CQPSQ_STATS_WQEVALID, cqp->polarity) |
  1826. FIELD_PREP(IRDMA_CQPSQ_STATS_USE_INST, info->use_stats_inst) |
  1827. FIELD_PREP(IRDMA_CQPSQ_STATS_INST_INDEX,
  1828. info->stats_inst_index) |
  1829. FIELD_PREP(IRDMA_CQPSQ_STATS_USE_HMC_FCN_INDEX,
  1830. info->use_hmc_fcn_index) |
  1831. FIELD_PREP(IRDMA_CQPSQ_STATS_OP, IRDMA_CQP_OP_GATHER_STATS);
  1832. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1833. set_64bit_val(wqe, 24, temp);
  1834. print_hex_dump_debug("STATS: GATHER_STATS WQE", DUMP_PREFIX_OFFSET,
  1835. 16, 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  1836. irdma_sc_cqp_post_sq(cqp);
  1837. ibdev_dbg(to_ibdev(cqp->dev),
  1838. "STATS: CQP SQ head 0x%x tail 0x%x size 0x%x\n",
  1839. cqp->sq_ring.head, cqp->sq_ring.tail, cqp->sq_ring.size);
  1840. return 0;
  1841. }
  1842. /**
  1843. * irdma_sc_manage_stats_inst - allocate or free stats instance
  1844. * @cqp: struct for cqp hw
  1845. * @info: stats info structure
  1846. * @alloc: alloc vs. delete flag
  1847. * @scratch: u64 saved to be used during cqp completion
  1848. */
  1849. static int irdma_sc_manage_stats_inst(struct irdma_sc_cqp *cqp,
  1850. struct irdma_stats_inst_info *info,
  1851. bool alloc, u64 scratch)
  1852. {
  1853. __le64 *wqe;
  1854. u64 temp;
  1855. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1856. if (!wqe)
  1857. return -ENOMEM;
  1858. set_64bit_val(wqe, 40,
  1859. FIELD_PREP(IRDMA_CQPSQ_STATS_HMC_FCN_INDEX, info->hmc_fn_id));
  1860. temp = FIELD_PREP(IRDMA_CQPSQ_STATS_WQEVALID, cqp->polarity) |
  1861. FIELD_PREP(IRDMA_CQPSQ_STATS_ALLOC_INST, alloc) |
  1862. FIELD_PREP(IRDMA_CQPSQ_STATS_USE_HMC_FCN_INDEX,
  1863. info->use_hmc_fcn_index) |
  1864. FIELD_PREP(IRDMA_CQPSQ_STATS_INST_INDEX, info->stats_idx) |
  1865. FIELD_PREP(IRDMA_CQPSQ_STATS_OP, IRDMA_CQP_OP_MANAGE_STATS);
  1866. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1867. set_64bit_val(wqe, 24, temp);
  1868. print_hex_dump_debug("WQE: MANAGE_STATS WQE", DUMP_PREFIX_OFFSET, 16,
  1869. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  1870. irdma_sc_cqp_post_sq(cqp);
  1871. return 0;
  1872. }
  1873. /**
  1874. * irdma_sc_set_up_map - set the up map table
  1875. * @cqp: struct for cqp hw
  1876. * @info: User priority map info
  1877. * @scratch: u64 saved to be used during cqp completion
  1878. */
  1879. static int irdma_sc_set_up_map(struct irdma_sc_cqp *cqp,
  1880. struct irdma_up_info *info, u64 scratch)
  1881. {
  1882. __le64 *wqe;
  1883. u64 temp = 0;
  1884. int i;
  1885. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1886. if (!wqe)
  1887. return -ENOMEM;
  1888. for (i = 0; i < IRDMA_MAX_USER_PRIORITY; i++)
  1889. temp |= (u64)info->map[i] << (i * 8);
  1890. set_64bit_val(wqe, 0, temp);
  1891. set_64bit_val(wqe, 40,
  1892. FIELD_PREP(IRDMA_CQPSQ_UP_CNPOVERRIDE, info->cnp_up_override) |
  1893. FIELD_PREP(IRDMA_CQPSQ_UP_HMCFCNIDX, info->hmc_fcn_idx));
  1894. temp = FIELD_PREP(IRDMA_CQPSQ_UP_WQEVALID, cqp->polarity) |
  1895. FIELD_PREP(IRDMA_CQPSQ_UP_USEVLAN, info->use_vlan) |
  1896. FIELD_PREP(IRDMA_CQPSQ_UP_USEOVERRIDE,
  1897. info->use_cnp_up_override) |
  1898. FIELD_PREP(IRDMA_CQPSQ_UP_OP, IRDMA_CQP_OP_UP_MAP);
  1899. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1900. set_64bit_val(wqe, 24, temp);
  1901. print_hex_dump_debug("WQE: UPMAP WQE", DUMP_PREFIX_OFFSET, 16, 8, wqe,
  1902. IRDMA_CQP_WQE_SIZE * 8, false);
  1903. irdma_sc_cqp_post_sq(cqp);
  1904. return 0;
  1905. }
  1906. /**
  1907. * irdma_sc_manage_ws_node - create/modify/destroy WS node
  1908. * @cqp: struct for cqp hw
  1909. * @info: node info structure
  1910. * @node_op: 0 for add 1 for modify, 2 for delete
  1911. * @scratch: u64 saved to be used during cqp completion
  1912. */
  1913. static int irdma_sc_manage_ws_node(struct irdma_sc_cqp *cqp,
  1914. struct irdma_ws_node_info *info,
  1915. enum irdma_ws_node_op node_op, u64 scratch)
  1916. {
  1917. __le64 *wqe;
  1918. u64 temp = 0;
  1919. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1920. if (!wqe)
  1921. return -ENOMEM;
  1922. set_64bit_val(wqe, 32,
  1923. FIELD_PREP(IRDMA_CQPSQ_WS_VSI, info->vsi) |
  1924. FIELD_PREP(IRDMA_CQPSQ_WS_WEIGHT, info->weight));
  1925. temp = FIELD_PREP(IRDMA_CQPSQ_WS_WQEVALID, cqp->polarity) |
  1926. FIELD_PREP(IRDMA_CQPSQ_WS_NODEOP, node_op) |
  1927. FIELD_PREP(IRDMA_CQPSQ_WS_ENABLENODE, info->enable) |
  1928. FIELD_PREP(IRDMA_CQPSQ_WS_NODETYPE, info->type_leaf) |
  1929. FIELD_PREP(IRDMA_CQPSQ_WS_PRIOTYPE, info->prio_type) |
  1930. FIELD_PREP(IRDMA_CQPSQ_WS_TC, info->tc) |
  1931. FIELD_PREP(IRDMA_CQPSQ_WS_OP, IRDMA_CQP_OP_WORK_SCHED_NODE) |
  1932. FIELD_PREP(IRDMA_CQPSQ_WS_PARENTID, info->parent_id) |
  1933. FIELD_PREP(IRDMA_CQPSQ_WS_NODEID, info->id);
  1934. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1935. set_64bit_val(wqe, 24, temp);
  1936. print_hex_dump_debug("WQE: MANAGE_WS WQE", DUMP_PREFIX_OFFSET, 16, 8,
  1937. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  1938. irdma_sc_cqp_post_sq(cqp);
  1939. return 0;
  1940. }
  1941. /**
  1942. * irdma_sc_qp_flush_wqes - flush qp's wqe
  1943. * @qp: sc qp
  1944. * @info: dlush information
  1945. * @scratch: u64 saved to be used during cqp completion
  1946. * @post_sq: flag for cqp db to ring
  1947. */
  1948. int irdma_sc_qp_flush_wqes(struct irdma_sc_qp *qp,
  1949. struct irdma_qp_flush_info *info, u64 scratch,
  1950. bool post_sq)
  1951. {
  1952. u64 temp = 0;
  1953. __le64 *wqe;
  1954. struct irdma_sc_cqp *cqp;
  1955. u64 hdr;
  1956. bool flush_sq = false, flush_rq = false;
  1957. if (info->rq && !qp->flush_rq)
  1958. flush_rq = true;
  1959. if (info->sq && !qp->flush_sq)
  1960. flush_sq = true;
  1961. qp->flush_sq |= flush_sq;
  1962. qp->flush_rq |= flush_rq;
  1963. if (!flush_sq && !flush_rq) {
  1964. ibdev_dbg(to_ibdev(qp->dev),
  1965. "CQP: Additional flush request ignored for qp %x\n",
  1966. qp->qp_uk.qp_id);
  1967. return -EALREADY;
  1968. }
  1969. cqp = qp->pd->dev->cqp;
  1970. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  1971. if (!wqe)
  1972. return -ENOMEM;
  1973. if (info->userflushcode) {
  1974. if (flush_rq)
  1975. temp |= FIELD_PREP(IRDMA_CQPSQ_FWQE_RQMNERR,
  1976. info->rq_minor_code) |
  1977. FIELD_PREP(IRDMA_CQPSQ_FWQE_RQMJERR,
  1978. info->rq_major_code);
  1979. if (flush_sq)
  1980. temp |= FIELD_PREP(IRDMA_CQPSQ_FWQE_SQMNERR,
  1981. info->sq_minor_code) |
  1982. FIELD_PREP(IRDMA_CQPSQ_FWQE_SQMJERR,
  1983. info->sq_major_code);
  1984. }
  1985. set_64bit_val(wqe, 16, temp);
  1986. temp = (info->generate_ae) ?
  1987. info->ae_code | FIELD_PREP(IRDMA_CQPSQ_FWQE_AESOURCE,
  1988. info->ae_src) : 0;
  1989. set_64bit_val(wqe, 8, temp);
  1990. hdr = qp->qp_uk.qp_id |
  1991. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_FLUSH_WQES) |
  1992. FIELD_PREP(IRDMA_CQPSQ_FWQE_GENERATE_AE, info->generate_ae) |
  1993. FIELD_PREP(IRDMA_CQPSQ_FWQE_USERFLCODE, info->userflushcode) |
  1994. FIELD_PREP(IRDMA_CQPSQ_FWQE_FLUSHSQ, flush_sq) |
  1995. FIELD_PREP(IRDMA_CQPSQ_FWQE_FLUSHRQ, flush_rq) |
  1996. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  1997. dma_wmb(); /* make sure WQE is written before valid bit is set */
  1998. set_64bit_val(wqe, 24, hdr);
  1999. print_hex_dump_debug("WQE: QP_FLUSH WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2000. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2001. if (post_sq)
  2002. irdma_sc_cqp_post_sq(cqp);
  2003. return 0;
  2004. }
  2005. /**
  2006. * irdma_sc_gen_ae - generate AE, uses flush WQE CQP OP
  2007. * @qp: sc qp
  2008. * @info: gen ae information
  2009. * @scratch: u64 saved to be used during cqp completion
  2010. * @post_sq: flag for cqp db to ring
  2011. */
  2012. static int irdma_sc_gen_ae(struct irdma_sc_qp *qp,
  2013. struct irdma_gen_ae_info *info, u64 scratch,
  2014. bool post_sq)
  2015. {
  2016. u64 temp;
  2017. __le64 *wqe;
  2018. struct irdma_sc_cqp *cqp;
  2019. u64 hdr;
  2020. cqp = qp->pd->dev->cqp;
  2021. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2022. if (!wqe)
  2023. return -ENOMEM;
  2024. temp = info->ae_code | FIELD_PREP(IRDMA_CQPSQ_FWQE_AESOURCE,
  2025. info->ae_src);
  2026. set_64bit_val(wqe, 8, temp);
  2027. hdr = qp->qp_uk.qp_id | FIELD_PREP(IRDMA_CQPSQ_OPCODE,
  2028. IRDMA_CQP_OP_GEN_AE) |
  2029. FIELD_PREP(IRDMA_CQPSQ_FWQE_GENERATE_AE, 1) |
  2030. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2031. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2032. set_64bit_val(wqe, 24, hdr);
  2033. print_hex_dump_debug("WQE: GEN_AE WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2034. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2035. if (post_sq)
  2036. irdma_sc_cqp_post_sq(cqp);
  2037. return 0;
  2038. }
  2039. /*** irdma_sc_qp_upload_context - upload qp's context
  2040. * @dev: sc device struct
  2041. * @info: upload context info ptr for return
  2042. * @scratch: u64 saved to be used during cqp completion
  2043. * @post_sq: flag for cqp db to ring
  2044. */
  2045. static int irdma_sc_qp_upload_context(struct irdma_sc_dev *dev,
  2046. struct irdma_upload_context_info *info,
  2047. u64 scratch, bool post_sq)
  2048. {
  2049. __le64 *wqe;
  2050. struct irdma_sc_cqp *cqp;
  2051. u64 hdr;
  2052. cqp = dev->cqp;
  2053. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2054. if (!wqe)
  2055. return -ENOMEM;
  2056. set_64bit_val(wqe, 16, info->buf_pa);
  2057. hdr = FIELD_PREP(IRDMA_CQPSQ_UCTX_QPID, info->qp_id) |
  2058. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_UPLOAD_CONTEXT) |
  2059. FIELD_PREP(IRDMA_CQPSQ_UCTX_QPTYPE, info->qp_type) |
  2060. FIELD_PREP(IRDMA_CQPSQ_UCTX_RAWFORMAT, info->raw_format) |
  2061. FIELD_PREP(IRDMA_CQPSQ_UCTX_FREEZEQP, info->freeze_qp) |
  2062. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2063. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2064. set_64bit_val(wqe, 24, hdr);
  2065. print_hex_dump_debug("WQE: QP_UPLOAD_CTX WQE", DUMP_PREFIX_OFFSET, 16,
  2066. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2067. if (post_sq)
  2068. irdma_sc_cqp_post_sq(cqp);
  2069. return 0;
  2070. }
  2071. /**
  2072. * irdma_sc_manage_push_page - Handle push page
  2073. * @cqp: struct for cqp hw
  2074. * @info: push page info
  2075. * @scratch: u64 saved to be used during cqp completion
  2076. * @post_sq: flag for cqp db to ring
  2077. */
  2078. static int irdma_sc_manage_push_page(struct irdma_sc_cqp *cqp,
  2079. struct irdma_cqp_manage_push_page_info *info,
  2080. u64 scratch, bool post_sq)
  2081. {
  2082. __le64 *wqe;
  2083. u64 hdr;
  2084. if (info->free_page &&
  2085. info->push_idx >= cqp->dev->hw_attrs.max_hw_device_pages)
  2086. return -EINVAL;
  2087. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2088. if (!wqe)
  2089. return -ENOMEM;
  2090. set_64bit_val(wqe, 16, info->qs_handle);
  2091. hdr = FIELD_PREP(IRDMA_CQPSQ_MPP_PPIDX, info->push_idx) |
  2092. FIELD_PREP(IRDMA_CQPSQ_MPP_PPTYPE, info->push_page_type) |
  2093. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_MANAGE_PUSH_PAGES) |
  2094. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity) |
  2095. FIELD_PREP(IRDMA_CQPSQ_MPP_FREE_PAGE, info->free_page);
  2096. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2097. set_64bit_val(wqe, 24, hdr);
  2098. print_hex_dump_debug("WQE: MANAGE_PUSH_PAGES WQE", DUMP_PREFIX_OFFSET,
  2099. 16, 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2100. if (post_sq)
  2101. irdma_sc_cqp_post_sq(cqp);
  2102. return 0;
  2103. }
  2104. /**
  2105. * irdma_sc_suspend_qp - suspend qp for param change
  2106. * @cqp: struct for cqp hw
  2107. * @qp: sc qp struct
  2108. * @scratch: u64 saved to be used during cqp completion
  2109. */
  2110. static int irdma_sc_suspend_qp(struct irdma_sc_cqp *cqp, struct irdma_sc_qp *qp,
  2111. u64 scratch)
  2112. {
  2113. u64 hdr;
  2114. __le64 *wqe;
  2115. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2116. if (!wqe)
  2117. return -ENOMEM;
  2118. hdr = FIELD_PREP(IRDMA_CQPSQ_SUSPENDQP_QPID, qp->qp_uk.qp_id) |
  2119. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_SUSPEND_QP) |
  2120. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2121. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2122. set_64bit_val(wqe, 24, hdr);
  2123. print_hex_dump_debug("WQE: SUSPEND_QP WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2124. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2125. irdma_sc_cqp_post_sq(cqp);
  2126. return 0;
  2127. }
  2128. /**
  2129. * irdma_sc_resume_qp - resume qp after suspend
  2130. * @cqp: struct for cqp hw
  2131. * @qp: sc qp struct
  2132. * @scratch: u64 saved to be used during cqp completion
  2133. */
  2134. static int irdma_sc_resume_qp(struct irdma_sc_cqp *cqp, struct irdma_sc_qp *qp,
  2135. u64 scratch)
  2136. {
  2137. u64 hdr;
  2138. __le64 *wqe;
  2139. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2140. if (!wqe)
  2141. return -ENOMEM;
  2142. set_64bit_val(wqe, 16,
  2143. FIELD_PREP(IRDMA_CQPSQ_RESUMEQP_QSHANDLE, qp->qs_handle));
  2144. hdr = FIELD_PREP(IRDMA_CQPSQ_RESUMEQP_QPID, qp->qp_uk.qp_id) |
  2145. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_RESUME_QP) |
  2146. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2147. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2148. set_64bit_val(wqe, 24, hdr);
  2149. print_hex_dump_debug("WQE: RESUME_QP WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2150. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2151. irdma_sc_cqp_post_sq(cqp);
  2152. return 0;
  2153. }
  2154. /**
  2155. * irdma_sc_cq_ack - acknowledge completion q
  2156. * @cq: cq struct
  2157. */
  2158. static inline void irdma_sc_cq_ack(struct irdma_sc_cq *cq)
  2159. {
  2160. writel(cq->cq_uk.cq_id, cq->cq_uk.cq_ack_db);
  2161. }
  2162. /**
  2163. * irdma_sc_cq_init - initialize completion q
  2164. * @cq: cq struct
  2165. * @info: cq initialization info
  2166. */
  2167. int irdma_sc_cq_init(struct irdma_sc_cq *cq, struct irdma_cq_init_info *info)
  2168. {
  2169. u32 pble_obj_cnt;
  2170. pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  2171. if (info->virtual_map && info->first_pm_pbl_idx >= pble_obj_cnt)
  2172. return -EINVAL;
  2173. cq->cq_pa = info->cq_base_pa;
  2174. cq->dev = info->dev;
  2175. cq->ceq_id = info->ceq_id;
  2176. info->cq_uk_init_info.cqe_alloc_db = cq->dev->cq_arm_db;
  2177. info->cq_uk_init_info.cq_ack_db = cq->dev->cq_ack_db;
  2178. irdma_uk_cq_init(&cq->cq_uk, &info->cq_uk_init_info);
  2179. cq->virtual_map = info->virtual_map;
  2180. cq->pbl_chunk_size = info->pbl_chunk_size;
  2181. cq->ceqe_mask = info->ceqe_mask;
  2182. cq->cq_type = (info->type) ? info->type : IRDMA_CQ_TYPE_IWARP;
  2183. cq->shadow_area_pa = info->shadow_area_pa;
  2184. cq->shadow_read_threshold = info->shadow_read_threshold;
  2185. cq->ceq_id_valid = info->ceq_id_valid;
  2186. cq->tph_en = info->tph_en;
  2187. cq->tph_val = info->tph_val;
  2188. cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
  2189. cq->vsi = info->vsi;
  2190. return 0;
  2191. }
  2192. /**
  2193. * irdma_sc_cq_create - create completion q
  2194. * @cq: cq struct
  2195. * @scratch: u64 saved to be used during cqp completion
  2196. * @check_overflow: flag for overflow check
  2197. * @post_sq: flag for cqp db to ring
  2198. */
  2199. static int irdma_sc_cq_create(struct irdma_sc_cq *cq, u64 scratch,
  2200. bool check_overflow, bool post_sq)
  2201. {
  2202. __le64 *wqe;
  2203. struct irdma_sc_cqp *cqp;
  2204. u64 hdr;
  2205. struct irdma_sc_ceq *ceq;
  2206. int ret_code = 0;
  2207. cqp = cq->dev->cqp;
  2208. if (cq->cq_uk.cq_id >= cqp->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].max_cnt)
  2209. return -EINVAL;
  2210. if (cq->ceq_id >= cq->dev->hmc_fpm_misc.max_ceqs)
  2211. return -EINVAL;
  2212. ceq = cq->dev->ceq[cq->ceq_id];
  2213. if (ceq && ceq->reg_cq)
  2214. ret_code = irdma_sc_add_cq_ctx(ceq, cq);
  2215. if (ret_code)
  2216. return ret_code;
  2217. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2218. if (!wqe) {
  2219. if (ceq && ceq->reg_cq)
  2220. irdma_sc_remove_cq_ctx(ceq, cq);
  2221. return -ENOMEM;
  2222. }
  2223. set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
  2224. set_64bit_val(wqe, 8, (uintptr_t)cq >> 1);
  2225. set_64bit_val(wqe, 16,
  2226. FIELD_PREP(IRDMA_CQPSQ_CQ_SHADOW_READ_THRESHOLD, cq->shadow_read_threshold));
  2227. set_64bit_val(wqe, 32, (cq->virtual_map ? 0 : cq->cq_pa));
  2228. set_64bit_val(wqe, 40, cq->shadow_area_pa);
  2229. set_64bit_val(wqe, 48,
  2230. FIELD_PREP(IRDMA_CQPSQ_CQ_FIRSTPMPBLIDX, (cq->virtual_map ? cq->first_pm_pbl_idx : 0)));
  2231. set_64bit_val(wqe, 56,
  2232. FIELD_PREP(IRDMA_CQPSQ_TPHVAL, cq->tph_val) |
  2233. FIELD_PREP(IRDMA_CQPSQ_VSIIDX, cq->vsi->vsi_idx));
  2234. hdr = FLD_LS_64(cq->dev, cq->cq_uk.cq_id, IRDMA_CQPSQ_CQ_CQID) |
  2235. FLD_LS_64(cq->dev, (cq->ceq_id_valid ? cq->ceq_id : 0),
  2236. IRDMA_CQPSQ_CQ_CEQID) |
  2237. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_CREATE_CQ) |
  2238. FIELD_PREP(IRDMA_CQPSQ_CQ_LPBLSIZE, cq->pbl_chunk_size) |
  2239. FIELD_PREP(IRDMA_CQPSQ_CQ_CHKOVERFLOW, check_overflow) |
  2240. FIELD_PREP(IRDMA_CQPSQ_CQ_VIRTMAP, cq->virtual_map) |
  2241. FIELD_PREP(IRDMA_CQPSQ_CQ_ENCEQEMASK, cq->ceqe_mask) |
  2242. FIELD_PREP(IRDMA_CQPSQ_CQ_CEQIDVALID, cq->ceq_id_valid) |
  2243. FIELD_PREP(IRDMA_CQPSQ_TPHEN, cq->tph_en) |
  2244. FIELD_PREP(IRDMA_CQPSQ_CQ_AVOIDMEMCNFLCT,
  2245. cq->cq_uk.avoid_mem_cflct) |
  2246. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2247. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2248. set_64bit_val(wqe, 24, hdr);
  2249. print_hex_dump_debug("WQE: CQ_CREATE WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2250. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2251. if (post_sq)
  2252. irdma_sc_cqp_post_sq(cqp);
  2253. return 0;
  2254. }
  2255. /**
  2256. * irdma_sc_cq_destroy - destroy completion q
  2257. * @cq: cq struct
  2258. * @scratch: u64 saved to be used during cqp completion
  2259. * @post_sq: flag for cqp db to ring
  2260. */
  2261. int irdma_sc_cq_destroy(struct irdma_sc_cq *cq, u64 scratch, bool post_sq)
  2262. {
  2263. struct irdma_sc_cqp *cqp;
  2264. __le64 *wqe;
  2265. u64 hdr;
  2266. struct irdma_sc_ceq *ceq;
  2267. cqp = cq->dev->cqp;
  2268. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2269. if (!wqe)
  2270. return -ENOMEM;
  2271. ceq = cq->dev->ceq[cq->ceq_id];
  2272. if (ceq && ceq->reg_cq)
  2273. irdma_sc_remove_cq_ctx(ceq, cq);
  2274. set_64bit_val(wqe, 0, cq->cq_uk.cq_size);
  2275. set_64bit_val(wqe, 8, (uintptr_t)cq >> 1);
  2276. set_64bit_val(wqe, 40, cq->shadow_area_pa);
  2277. set_64bit_val(wqe, 48,
  2278. (cq->virtual_map ? cq->first_pm_pbl_idx : 0));
  2279. hdr = cq->cq_uk.cq_id |
  2280. FLD_LS_64(cq->dev, (cq->ceq_id_valid ? cq->ceq_id : 0),
  2281. IRDMA_CQPSQ_CQ_CEQID) |
  2282. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_DESTROY_CQ) |
  2283. FIELD_PREP(IRDMA_CQPSQ_CQ_LPBLSIZE, cq->pbl_chunk_size) |
  2284. FIELD_PREP(IRDMA_CQPSQ_CQ_VIRTMAP, cq->virtual_map) |
  2285. FIELD_PREP(IRDMA_CQPSQ_CQ_ENCEQEMASK, cq->ceqe_mask) |
  2286. FIELD_PREP(IRDMA_CQPSQ_CQ_CEQIDVALID, cq->ceq_id_valid) |
  2287. FIELD_PREP(IRDMA_CQPSQ_TPHEN, cq->tph_en) |
  2288. FIELD_PREP(IRDMA_CQPSQ_CQ_AVOIDMEMCNFLCT, cq->cq_uk.avoid_mem_cflct) |
  2289. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2290. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2291. set_64bit_val(wqe, 24, hdr);
  2292. print_hex_dump_debug("WQE: CQ_DESTROY WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2293. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2294. if (post_sq)
  2295. irdma_sc_cqp_post_sq(cqp);
  2296. return 0;
  2297. }
  2298. /**
  2299. * irdma_sc_cq_resize - set resized cq buffer info
  2300. * @cq: resized cq
  2301. * @info: resized cq buffer info
  2302. */
  2303. void irdma_sc_cq_resize(struct irdma_sc_cq *cq, struct irdma_modify_cq_info *info)
  2304. {
  2305. cq->virtual_map = info->virtual_map;
  2306. cq->cq_pa = info->cq_pa;
  2307. cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
  2308. cq->pbl_chunk_size = info->pbl_chunk_size;
  2309. irdma_uk_cq_resize(&cq->cq_uk, info->cq_base, info->cq_size);
  2310. }
  2311. /**
  2312. * irdma_sc_cq_modify - modify a Completion Queue
  2313. * @cq: cq struct
  2314. * @info: modification info struct
  2315. * @scratch: u64 saved to be used during cqp completion
  2316. * @post_sq: flag to post to sq
  2317. */
  2318. static int irdma_sc_cq_modify(struct irdma_sc_cq *cq,
  2319. struct irdma_modify_cq_info *info, u64 scratch,
  2320. bool post_sq)
  2321. {
  2322. struct irdma_sc_cqp *cqp;
  2323. __le64 *wqe;
  2324. u64 hdr;
  2325. u32 pble_obj_cnt;
  2326. pble_obj_cnt = cq->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  2327. if (info->cq_resize && info->virtual_map &&
  2328. info->first_pm_pbl_idx >= pble_obj_cnt)
  2329. return -EINVAL;
  2330. cqp = cq->dev->cqp;
  2331. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  2332. if (!wqe)
  2333. return -ENOMEM;
  2334. set_64bit_val(wqe, 0, info->cq_size);
  2335. set_64bit_val(wqe, 8, (uintptr_t)cq >> 1);
  2336. set_64bit_val(wqe, 16,
  2337. FIELD_PREP(IRDMA_CQPSQ_CQ_SHADOW_READ_THRESHOLD, info->shadow_read_threshold));
  2338. set_64bit_val(wqe, 32, info->cq_pa);
  2339. set_64bit_val(wqe, 40, cq->shadow_area_pa);
  2340. set_64bit_val(wqe, 48, info->first_pm_pbl_idx);
  2341. set_64bit_val(wqe, 56,
  2342. FIELD_PREP(IRDMA_CQPSQ_TPHVAL, cq->tph_val) |
  2343. FIELD_PREP(IRDMA_CQPSQ_VSIIDX, cq->vsi->vsi_idx));
  2344. hdr = cq->cq_uk.cq_id |
  2345. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_MODIFY_CQ) |
  2346. FIELD_PREP(IRDMA_CQPSQ_CQ_CQRESIZE, info->cq_resize) |
  2347. FIELD_PREP(IRDMA_CQPSQ_CQ_LPBLSIZE, info->pbl_chunk_size) |
  2348. FIELD_PREP(IRDMA_CQPSQ_CQ_CHKOVERFLOW, info->check_overflow) |
  2349. FIELD_PREP(IRDMA_CQPSQ_CQ_VIRTMAP, info->virtual_map) |
  2350. FIELD_PREP(IRDMA_CQPSQ_CQ_ENCEQEMASK, cq->ceqe_mask) |
  2351. FIELD_PREP(IRDMA_CQPSQ_TPHEN, cq->tph_en) |
  2352. FIELD_PREP(IRDMA_CQPSQ_CQ_AVOIDMEMCNFLCT,
  2353. cq->cq_uk.avoid_mem_cflct) |
  2354. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  2355. dma_wmb(); /* make sure WQE is written before valid bit is set */
  2356. set_64bit_val(wqe, 24, hdr);
  2357. print_hex_dump_debug("WQE: CQ_MODIFY WQE", DUMP_PREFIX_OFFSET, 16, 8,
  2358. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  2359. if (post_sq)
  2360. irdma_sc_cqp_post_sq(cqp);
  2361. return 0;
  2362. }
  2363. /**
  2364. * irdma_check_cqp_progress - check cqp processing progress
  2365. * @timeout: timeout info struct
  2366. * @dev: sc device struct
  2367. */
  2368. void irdma_check_cqp_progress(struct irdma_cqp_timeout *timeout, struct irdma_sc_dev *dev)
  2369. {
  2370. u64 completed_ops = atomic64_read(&dev->cqp->completed_ops);
  2371. if (timeout->compl_cqp_cmds != completed_ops) {
  2372. timeout->compl_cqp_cmds = completed_ops;
  2373. timeout->count = 0;
  2374. } else if (timeout->compl_cqp_cmds != dev->cqp->requested_ops) {
  2375. timeout->count++;
  2376. }
  2377. }
  2378. /**
  2379. * irdma_get_cqp_reg_info - get head and tail for cqp using registers
  2380. * @cqp: struct for cqp hw
  2381. * @val: cqp tail register value
  2382. * @tail: wqtail register value
  2383. * @error: cqp processing err
  2384. */
  2385. static inline void irdma_get_cqp_reg_info(struct irdma_sc_cqp *cqp, u32 *val,
  2386. u32 *tail, u32 *error)
  2387. {
  2388. *val = readl(cqp->dev->hw_regs[IRDMA_CQPTAIL]);
  2389. *tail = FIELD_GET(IRDMA_CQPTAIL_WQTAIL, *val);
  2390. *error = FIELD_GET(IRDMA_CQPTAIL_CQP_OP_ERR, *val);
  2391. }
  2392. /**
  2393. * irdma_cqp_poll_registers - poll cqp registers
  2394. * @cqp: struct for cqp hw
  2395. * @tail: wqtail register value
  2396. * @count: how many times to try for completion
  2397. */
  2398. static int irdma_cqp_poll_registers(struct irdma_sc_cqp *cqp, u32 tail,
  2399. u32 count)
  2400. {
  2401. u32 i = 0;
  2402. u32 newtail, error, val;
  2403. while (i++ < count) {
  2404. irdma_get_cqp_reg_info(cqp, &val, &newtail, &error);
  2405. if (error) {
  2406. error = readl(cqp->dev->hw_regs[IRDMA_CQPERRCODES]);
  2407. ibdev_dbg(to_ibdev(cqp->dev),
  2408. "CQP: CQPERRCODES error_code[x%08X]\n",
  2409. error);
  2410. return -EIO;
  2411. }
  2412. if (newtail != tail) {
  2413. /* SUCCESS */
  2414. IRDMA_RING_MOVE_TAIL(cqp->sq_ring);
  2415. atomic64_inc(&cqp->completed_ops);
  2416. return 0;
  2417. }
  2418. udelay(cqp->dev->hw_attrs.max_sleep_count);
  2419. }
  2420. return -ETIMEDOUT;
  2421. }
  2422. /**
  2423. * irdma_sc_decode_fpm_commit - decode a 64 bit value into count and base
  2424. * @dev: sc device struct
  2425. * @buf: pointer to commit buffer
  2426. * @buf_idx: buffer index
  2427. * @obj_info: object info pointer
  2428. * @rsrc_idx: indexs of memory resource
  2429. */
  2430. static u64 irdma_sc_decode_fpm_commit(struct irdma_sc_dev *dev, __le64 *buf,
  2431. u32 buf_idx, struct irdma_hmc_obj_info *obj_info,
  2432. u32 rsrc_idx)
  2433. {
  2434. u64 temp;
  2435. get_64bit_val(buf, buf_idx, &temp);
  2436. switch (rsrc_idx) {
  2437. case IRDMA_HMC_IW_QP:
  2438. obj_info[rsrc_idx].cnt = (u32)FIELD_GET(IRDMA_COMMIT_FPM_QPCNT, temp);
  2439. break;
  2440. case IRDMA_HMC_IW_CQ:
  2441. obj_info[rsrc_idx].cnt = (u32)FLD_RS_64(dev, temp, IRDMA_COMMIT_FPM_CQCNT);
  2442. break;
  2443. case IRDMA_HMC_IW_APBVT_ENTRY:
  2444. obj_info[rsrc_idx].cnt = 1;
  2445. break;
  2446. default:
  2447. obj_info[rsrc_idx].cnt = (u32)temp;
  2448. break;
  2449. }
  2450. obj_info[rsrc_idx].base = (temp >> IRDMA_COMMIT_FPM_BASE_S) * 512;
  2451. return temp;
  2452. }
  2453. /**
  2454. * irdma_sc_parse_fpm_commit_buf - parse fpm commit buffer
  2455. * @dev: pointer to dev struct
  2456. * @buf: ptr to fpm commit buffer
  2457. * @info: ptr to irdma_hmc_obj_info struct
  2458. * @sd: number of SDs for HMC objects
  2459. *
  2460. * parses fpm commit info and copy base value
  2461. * of hmc objects in hmc_info
  2462. */
  2463. static void
  2464. irdma_sc_parse_fpm_commit_buf(struct irdma_sc_dev *dev, __le64 *buf,
  2465. struct irdma_hmc_obj_info *info, u32 *sd)
  2466. {
  2467. u64 size;
  2468. u32 i;
  2469. u64 max_base = 0;
  2470. u32 last_hmc_obj = 0;
  2471. irdma_sc_decode_fpm_commit(dev, buf, 0, info,
  2472. IRDMA_HMC_IW_QP);
  2473. irdma_sc_decode_fpm_commit(dev, buf, 8, info,
  2474. IRDMA_HMC_IW_CQ);
  2475. /* skiping RSRVD */
  2476. irdma_sc_decode_fpm_commit(dev, buf, 24, info,
  2477. IRDMA_HMC_IW_HTE);
  2478. irdma_sc_decode_fpm_commit(dev, buf, 32, info,
  2479. IRDMA_HMC_IW_ARP);
  2480. irdma_sc_decode_fpm_commit(dev, buf, 40, info,
  2481. IRDMA_HMC_IW_APBVT_ENTRY);
  2482. irdma_sc_decode_fpm_commit(dev, buf, 48, info,
  2483. IRDMA_HMC_IW_MR);
  2484. irdma_sc_decode_fpm_commit(dev, buf, 56, info,
  2485. IRDMA_HMC_IW_XF);
  2486. irdma_sc_decode_fpm_commit(dev, buf, 64, info,
  2487. IRDMA_HMC_IW_XFFL);
  2488. irdma_sc_decode_fpm_commit(dev, buf, 72, info,
  2489. IRDMA_HMC_IW_Q1);
  2490. irdma_sc_decode_fpm_commit(dev, buf, 80, info,
  2491. IRDMA_HMC_IW_Q1FL);
  2492. irdma_sc_decode_fpm_commit(dev, buf, 88, info,
  2493. IRDMA_HMC_IW_TIMER);
  2494. irdma_sc_decode_fpm_commit(dev, buf, 112, info,
  2495. IRDMA_HMC_IW_PBLE);
  2496. /* skipping RSVD. */
  2497. if (dev->hw_attrs.uk_attrs.hw_rev != IRDMA_GEN_1) {
  2498. irdma_sc_decode_fpm_commit(dev, buf, 96, info,
  2499. IRDMA_HMC_IW_FSIMC);
  2500. irdma_sc_decode_fpm_commit(dev, buf, 104, info,
  2501. IRDMA_HMC_IW_FSIAV);
  2502. irdma_sc_decode_fpm_commit(dev, buf, 128, info,
  2503. IRDMA_HMC_IW_RRF);
  2504. irdma_sc_decode_fpm_commit(dev, buf, 136, info,
  2505. IRDMA_HMC_IW_RRFFL);
  2506. irdma_sc_decode_fpm_commit(dev, buf, 144, info,
  2507. IRDMA_HMC_IW_HDR);
  2508. irdma_sc_decode_fpm_commit(dev, buf, 152, info,
  2509. IRDMA_HMC_IW_MD);
  2510. irdma_sc_decode_fpm_commit(dev, buf, 160, info,
  2511. IRDMA_HMC_IW_OOISC);
  2512. irdma_sc_decode_fpm_commit(dev, buf, 168, info,
  2513. IRDMA_HMC_IW_OOISCFFL);
  2514. }
  2515. /* searching for the last object in HMC to find the size of the HMC area. */
  2516. for (i = IRDMA_HMC_IW_QP; i < IRDMA_HMC_IW_MAX; i++) {
  2517. if (info[i].base > max_base) {
  2518. max_base = info[i].base;
  2519. last_hmc_obj = i;
  2520. }
  2521. }
  2522. size = info[last_hmc_obj].cnt * info[last_hmc_obj].size +
  2523. info[last_hmc_obj].base;
  2524. if (size & 0x1FFFFF)
  2525. *sd = (u32)((size >> 21) + 1); /* add 1 for remainder */
  2526. else
  2527. *sd = (u32)(size >> 21);
  2528. }
  2529. /**
  2530. * irdma_sc_decode_fpm_query() - Decode a 64 bit value into max count and size
  2531. * @buf: ptr to fpm query buffer
  2532. * @buf_idx: index into buf
  2533. * @obj_info: ptr to irdma_hmc_obj_info struct
  2534. * @rsrc_idx: resource index into info
  2535. *
  2536. * Decode a 64 bit value from fpm query buffer into max count and size
  2537. */
  2538. static u64 irdma_sc_decode_fpm_query(__le64 *buf, u32 buf_idx,
  2539. struct irdma_hmc_obj_info *obj_info,
  2540. u32 rsrc_idx)
  2541. {
  2542. u64 temp;
  2543. u32 size;
  2544. get_64bit_val(buf, buf_idx, &temp);
  2545. obj_info[rsrc_idx].max_cnt = (u32)temp;
  2546. size = (u32)(temp >> 32);
  2547. obj_info[rsrc_idx].size = BIT_ULL(size);
  2548. return temp;
  2549. }
  2550. /**
  2551. * irdma_sc_parse_fpm_query_buf() - parses fpm query buffer
  2552. * @dev: ptr to shared code device
  2553. * @buf: ptr to fpm query buffer
  2554. * @hmc_info: ptr to irdma_hmc_obj_info struct
  2555. * @hmc_fpm_misc: ptr to fpm data
  2556. *
  2557. * parses fpm query buffer and copy max_cnt and
  2558. * size value of hmc objects in hmc_info
  2559. */
  2560. static int irdma_sc_parse_fpm_query_buf(struct irdma_sc_dev *dev, __le64 *buf,
  2561. struct irdma_hmc_info *hmc_info,
  2562. struct irdma_hmc_fpm_misc *hmc_fpm_misc)
  2563. {
  2564. struct irdma_hmc_obj_info *obj_info;
  2565. u64 temp;
  2566. u32 size;
  2567. u16 max_pe_sds;
  2568. obj_info = hmc_info->hmc_obj;
  2569. get_64bit_val(buf, 0, &temp);
  2570. hmc_info->first_sd_index = (u16)FIELD_GET(IRDMA_QUERY_FPM_FIRST_PE_SD_INDEX, temp);
  2571. max_pe_sds = (u16)FIELD_GET(IRDMA_QUERY_FPM_MAX_PE_SDS, temp);
  2572. hmc_fpm_misc->max_sds = max_pe_sds;
  2573. hmc_info->sd_table.sd_cnt = max_pe_sds + hmc_info->first_sd_index;
  2574. get_64bit_val(buf, 8, &temp);
  2575. obj_info[IRDMA_HMC_IW_QP].max_cnt = (u32)FIELD_GET(IRDMA_QUERY_FPM_MAX_QPS, temp);
  2576. size = (u32)(temp >> 32);
  2577. obj_info[IRDMA_HMC_IW_QP].size = BIT_ULL(size);
  2578. get_64bit_val(buf, 16, &temp);
  2579. obj_info[IRDMA_HMC_IW_CQ].max_cnt = (u32)FIELD_GET(IRDMA_QUERY_FPM_MAX_CQS, temp);
  2580. size = (u32)(temp >> 32);
  2581. obj_info[IRDMA_HMC_IW_CQ].size = BIT_ULL(size);
  2582. irdma_sc_decode_fpm_query(buf, 32, obj_info, IRDMA_HMC_IW_HTE);
  2583. irdma_sc_decode_fpm_query(buf, 40, obj_info, IRDMA_HMC_IW_ARP);
  2584. obj_info[IRDMA_HMC_IW_APBVT_ENTRY].size = 8192;
  2585. obj_info[IRDMA_HMC_IW_APBVT_ENTRY].max_cnt = 1;
  2586. irdma_sc_decode_fpm_query(buf, 48, obj_info, IRDMA_HMC_IW_MR);
  2587. irdma_sc_decode_fpm_query(buf, 56, obj_info, IRDMA_HMC_IW_XF);
  2588. get_64bit_val(buf, 64, &temp);
  2589. obj_info[IRDMA_HMC_IW_XFFL].max_cnt = (u32)temp;
  2590. obj_info[IRDMA_HMC_IW_XFFL].size = 4;
  2591. hmc_fpm_misc->xf_block_size = FIELD_GET(IRDMA_QUERY_FPM_XFBLOCKSIZE, temp);
  2592. if (!hmc_fpm_misc->xf_block_size)
  2593. return -EINVAL;
  2594. irdma_sc_decode_fpm_query(buf, 72, obj_info, IRDMA_HMC_IW_Q1);
  2595. get_64bit_val(buf, 80, &temp);
  2596. obj_info[IRDMA_HMC_IW_Q1FL].max_cnt = (u32)temp;
  2597. obj_info[IRDMA_HMC_IW_Q1FL].size = 4;
  2598. hmc_fpm_misc->q1_block_size = FIELD_GET(IRDMA_QUERY_FPM_Q1BLOCKSIZE, temp);
  2599. if (!hmc_fpm_misc->q1_block_size)
  2600. return -EINVAL;
  2601. irdma_sc_decode_fpm_query(buf, 88, obj_info, IRDMA_HMC_IW_TIMER);
  2602. get_64bit_val(buf, 112, &temp);
  2603. obj_info[IRDMA_HMC_IW_PBLE].max_cnt = (u32)temp;
  2604. obj_info[IRDMA_HMC_IW_PBLE].size = 8;
  2605. get_64bit_val(buf, 120, &temp);
  2606. hmc_fpm_misc->max_ceqs = FIELD_GET(IRDMA_QUERY_FPM_MAX_CEQS, temp);
  2607. hmc_fpm_misc->ht_multiplier = FIELD_GET(IRDMA_QUERY_FPM_HTMULTIPLIER, temp);
  2608. hmc_fpm_misc->timer_bucket = FIELD_GET(IRDMA_QUERY_FPM_TIMERBUCKET, temp);
  2609. if (dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1)
  2610. return 0;
  2611. irdma_sc_decode_fpm_query(buf, 96, obj_info, IRDMA_HMC_IW_FSIMC);
  2612. irdma_sc_decode_fpm_query(buf, 104, obj_info, IRDMA_HMC_IW_FSIAV);
  2613. irdma_sc_decode_fpm_query(buf, 128, obj_info, IRDMA_HMC_IW_RRF);
  2614. get_64bit_val(buf, 136, &temp);
  2615. obj_info[IRDMA_HMC_IW_RRFFL].max_cnt = (u32)temp;
  2616. obj_info[IRDMA_HMC_IW_RRFFL].size = 4;
  2617. hmc_fpm_misc->rrf_block_size = FIELD_GET(IRDMA_QUERY_FPM_RRFBLOCKSIZE, temp);
  2618. if (!hmc_fpm_misc->rrf_block_size &&
  2619. obj_info[IRDMA_HMC_IW_RRFFL].max_cnt)
  2620. return -EINVAL;
  2621. irdma_sc_decode_fpm_query(buf, 144, obj_info, IRDMA_HMC_IW_HDR);
  2622. irdma_sc_decode_fpm_query(buf, 152, obj_info, IRDMA_HMC_IW_MD);
  2623. irdma_sc_decode_fpm_query(buf, 160, obj_info, IRDMA_HMC_IW_OOISC);
  2624. get_64bit_val(buf, 168, &temp);
  2625. obj_info[IRDMA_HMC_IW_OOISCFFL].max_cnt = (u32)temp;
  2626. obj_info[IRDMA_HMC_IW_OOISCFFL].size = 4;
  2627. hmc_fpm_misc->ooiscf_block_size = FIELD_GET(IRDMA_QUERY_FPM_OOISCFBLOCKSIZE, temp);
  2628. if (!hmc_fpm_misc->ooiscf_block_size &&
  2629. obj_info[IRDMA_HMC_IW_OOISCFFL].max_cnt)
  2630. return -EINVAL;
  2631. return 0;
  2632. }
  2633. /**
  2634. * irdma_sc_find_reg_cq - find cq ctx index
  2635. * @ceq: ceq sc structure
  2636. * @cq: cq sc structure
  2637. */
  2638. static u32 irdma_sc_find_reg_cq(struct irdma_sc_ceq *ceq,
  2639. struct irdma_sc_cq *cq)
  2640. {
  2641. u32 i;
  2642. for (i = 0; i < ceq->reg_cq_size; i++) {
  2643. if (cq == ceq->reg_cq[i])
  2644. return i;
  2645. }
  2646. return IRDMA_INVALID_CQ_IDX;
  2647. }
  2648. /**
  2649. * irdma_sc_add_cq_ctx - add cq ctx tracking for ceq
  2650. * @ceq: ceq sc structure
  2651. * @cq: cq sc structure
  2652. */
  2653. int irdma_sc_add_cq_ctx(struct irdma_sc_ceq *ceq, struct irdma_sc_cq *cq)
  2654. {
  2655. unsigned long flags;
  2656. spin_lock_irqsave(&ceq->req_cq_lock, flags);
  2657. if (ceq->reg_cq_size == ceq->elem_cnt) {
  2658. spin_unlock_irqrestore(&ceq->req_cq_lock, flags);
  2659. return -ENOMEM;
  2660. }
  2661. ceq->reg_cq[ceq->reg_cq_size++] = cq;
  2662. spin_unlock_irqrestore(&ceq->req_cq_lock, flags);
  2663. return 0;
  2664. }
  2665. /**
  2666. * irdma_sc_remove_cq_ctx - remove cq ctx tracking for ceq
  2667. * @ceq: ceq sc structure
  2668. * @cq: cq sc structure
  2669. */
  2670. void irdma_sc_remove_cq_ctx(struct irdma_sc_ceq *ceq, struct irdma_sc_cq *cq)
  2671. {
  2672. unsigned long flags;
  2673. u32 cq_ctx_idx;
  2674. spin_lock_irqsave(&ceq->req_cq_lock, flags);
  2675. cq_ctx_idx = irdma_sc_find_reg_cq(ceq, cq);
  2676. if (cq_ctx_idx == IRDMA_INVALID_CQ_IDX)
  2677. goto exit;
  2678. ceq->reg_cq_size--;
  2679. if (cq_ctx_idx != ceq->reg_cq_size)
  2680. ceq->reg_cq[cq_ctx_idx] = ceq->reg_cq[ceq->reg_cq_size];
  2681. ceq->reg_cq[ceq->reg_cq_size] = NULL;
  2682. exit:
  2683. spin_unlock_irqrestore(&ceq->req_cq_lock, flags);
  2684. }
  2685. /**
  2686. * irdma_sc_cqp_init - Initialize buffers for a control Queue Pair
  2687. * @cqp: IWARP control queue pair pointer
  2688. * @info: IWARP control queue pair init info pointer
  2689. *
  2690. * Initializes the object and context buffers for a control Queue Pair.
  2691. */
  2692. int irdma_sc_cqp_init(struct irdma_sc_cqp *cqp,
  2693. struct irdma_cqp_init_info *info)
  2694. {
  2695. u8 hw_sq_size;
  2696. if (info->sq_size > IRDMA_CQP_SW_SQSIZE_2048 ||
  2697. info->sq_size < IRDMA_CQP_SW_SQSIZE_4 ||
  2698. ((info->sq_size & (info->sq_size - 1))))
  2699. return -EINVAL;
  2700. hw_sq_size = irdma_get_encoded_wqe_size(info->sq_size,
  2701. IRDMA_QUEUE_TYPE_CQP);
  2702. cqp->size = sizeof(*cqp);
  2703. cqp->sq_size = info->sq_size;
  2704. cqp->hw_sq_size = hw_sq_size;
  2705. cqp->sq_base = info->sq;
  2706. cqp->host_ctx = info->host_ctx;
  2707. cqp->sq_pa = info->sq_pa;
  2708. cqp->host_ctx_pa = info->host_ctx_pa;
  2709. cqp->dev = info->dev;
  2710. cqp->struct_ver = info->struct_ver;
  2711. cqp->hw_maj_ver = info->hw_maj_ver;
  2712. cqp->hw_min_ver = info->hw_min_ver;
  2713. cqp->scratch_array = info->scratch_array;
  2714. cqp->polarity = 0;
  2715. cqp->en_datacenter_tcp = info->en_datacenter_tcp;
  2716. cqp->ena_vf_count = info->ena_vf_count;
  2717. cqp->hmc_profile = info->hmc_profile;
  2718. cqp->ceqs_per_vf = info->ceqs_per_vf;
  2719. cqp->disable_packed = info->disable_packed;
  2720. cqp->rocev2_rto_policy = info->rocev2_rto_policy;
  2721. cqp->protocol_used = info->protocol_used;
  2722. memcpy(&cqp->dcqcn_params, &info->dcqcn_params, sizeof(cqp->dcqcn_params));
  2723. info->dev->cqp = cqp;
  2724. IRDMA_RING_INIT(cqp->sq_ring, cqp->sq_size);
  2725. cqp->requested_ops = 0;
  2726. atomic64_set(&cqp->completed_ops, 0);
  2727. /* for the cqp commands backlog. */
  2728. INIT_LIST_HEAD(&cqp->dev->cqp_cmd_head);
  2729. writel(0, cqp->dev->hw_regs[IRDMA_CQPTAIL]);
  2730. writel(0, cqp->dev->hw_regs[IRDMA_CQPDB]);
  2731. writel(0, cqp->dev->hw_regs[IRDMA_CCQPSTATUS]);
  2732. ibdev_dbg(to_ibdev(cqp->dev),
  2733. "WQE: sq_size[%04d] hw_sq_size[%04d] sq_base[%p] sq_pa[%pK] cqp[%p] polarity[x%04x]\n",
  2734. cqp->sq_size, cqp->hw_sq_size, cqp->sq_base,
  2735. (u64 *)(uintptr_t)cqp->sq_pa, cqp, cqp->polarity);
  2736. return 0;
  2737. }
  2738. /**
  2739. * irdma_sc_cqp_create - create cqp during bringup
  2740. * @cqp: struct for cqp hw
  2741. * @maj_err: If error, major err number
  2742. * @min_err: If error, minor err number
  2743. */
  2744. int irdma_sc_cqp_create(struct irdma_sc_cqp *cqp, u16 *maj_err, u16 *min_err)
  2745. {
  2746. u64 temp;
  2747. u8 hw_rev;
  2748. u32 cnt = 0, p1, p2, val = 0, err_code;
  2749. int ret_code;
  2750. hw_rev = cqp->dev->hw_attrs.uk_attrs.hw_rev;
  2751. cqp->sdbuf.size = ALIGN(IRDMA_UPDATE_SD_BUFF_SIZE * cqp->sq_size,
  2752. IRDMA_SD_BUF_ALIGNMENT);
  2753. cqp->sdbuf.va = dma_alloc_coherent(cqp->dev->hw->device,
  2754. cqp->sdbuf.size, &cqp->sdbuf.pa,
  2755. GFP_KERNEL);
  2756. if (!cqp->sdbuf.va)
  2757. return -ENOMEM;
  2758. spin_lock_init(&cqp->dev->cqp_lock);
  2759. temp = FIELD_PREP(IRDMA_CQPHC_SQSIZE, cqp->hw_sq_size) |
  2760. FIELD_PREP(IRDMA_CQPHC_SVER, cqp->struct_ver) |
  2761. FIELD_PREP(IRDMA_CQPHC_DISABLE_PFPDUS, cqp->disable_packed) |
  2762. FIELD_PREP(IRDMA_CQPHC_CEQPERVF, cqp->ceqs_per_vf);
  2763. if (hw_rev >= IRDMA_GEN_2) {
  2764. temp |= FIELD_PREP(IRDMA_CQPHC_ROCEV2_RTO_POLICY,
  2765. cqp->rocev2_rto_policy) |
  2766. FIELD_PREP(IRDMA_CQPHC_PROTOCOL_USED,
  2767. cqp->protocol_used);
  2768. }
  2769. set_64bit_val(cqp->host_ctx, 0, temp);
  2770. set_64bit_val(cqp->host_ctx, 8, cqp->sq_pa);
  2771. temp = FIELD_PREP(IRDMA_CQPHC_ENABLED_VFS, cqp->ena_vf_count) |
  2772. FIELD_PREP(IRDMA_CQPHC_HMC_PROFILE, cqp->hmc_profile);
  2773. set_64bit_val(cqp->host_ctx, 16, temp);
  2774. set_64bit_val(cqp->host_ctx, 24, (uintptr_t)cqp);
  2775. temp = FIELD_PREP(IRDMA_CQPHC_HW_MAJVER, cqp->hw_maj_ver) |
  2776. FIELD_PREP(IRDMA_CQPHC_HW_MINVER, cqp->hw_min_ver);
  2777. if (hw_rev >= IRDMA_GEN_2) {
  2778. temp |= FIELD_PREP(IRDMA_CQPHC_MIN_RATE, cqp->dcqcn_params.min_rate) |
  2779. FIELD_PREP(IRDMA_CQPHC_MIN_DEC_FACTOR, cqp->dcqcn_params.min_dec_factor);
  2780. }
  2781. set_64bit_val(cqp->host_ctx, 32, temp);
  2782. set_64bit_val(cqp->host_ctx, 40, 0);
  2783. temp = 0;
  2784. if (hw_rev >= IRDMA_GEN_2) {
  2785. temp |= FIELD_PREP(IRDMA_CQPHC_DCQCN_T, cqp->dcqcn_params.dcqcn_t) |
  2786. FIELD_PREP(IRDMA_CQPHC_RAI_FACTOR, cqp->dcqcn_params.rai_factor) |
  2787. FIELD_PREP(IRDMA_CQPHC_HAI_FACTOR, cqp->dcqcn_params.hai_factor);
  2788. }
  2789. set_64bit_val(cqp->host_ctx, 48, temp);
  2790. temp = 0;
  2791. if (hw_rev >= IRDMA_GEN_2) {
  2792. temp |= FIELD_PREP(IRDMA_CQPHC_DCQCN_B, cqp->dcqcn_params.dcqcn_b) |
  2793. FIELD_PREP(IRDMA_CQPHC_DCQCN_F, cqp->dcqcn_params.dcqcn_f) |
  2794. FIELD_PREP(IRDMA_CQPHC_CC_CFG_VALID, cqp->dcqcn_params.cc_cfg_valid) |
  2795. FIELD_PREP(IRDMA_CQPHC_RREDUCE_MPERIOD, cqp->dcqcn_params.rreduce_mperiod);
  2796. }
  2797. set_64bit_val(cqp->host_ctx, 56, temp);
  2798. print_hex_dump_debug("WQE: CQP_HOST_CTX WQE", DUMP_PREFIX_OFFSET, 16,
  2799. 8, cqp->host_ctx, IRDMA_CQP_CTX_SIZE * 8, false);
  2800. p1 = cqp->host_ctx_pa >> 32;
  2801. p2 = (u32)cqp->host_ctx_pa;
  2802. writel(p1, cqp->dev->hw_regs[IRDMA_CCQPHIGH]);
  2803. writel(p2, cqp->dev->hw_regs[IRDMA_CCQPLOW]);
  2804. do {
  2805. if (cnt++ > cqp->dev->hw_attrs.max_done_count) {
  2806. ret_code = -ETIMEDOUT;
  2807. goto err;
  2808. }
  2809. udelay(cqp->dev->hw_attrs.max_sleep_count);
  2810. val = readl(cqp->dev->hw_regs[IRDMA_CCQPSTATUS]);
  2811. } while (!val);
  2812. if (FLD_RS_32(cqp->dev, val, IRDMA_CCQPSTATUS_CCQP_ERR)) {
  2813. ret_code = -EOPNOTSUPP;
  2814. goto err;
  2815. }
  2816. cqp->process_cqp_sds = irdma_update_sds_noccq;
  2817. return 0;
  2818. err:
  2819. dma_free_coherent(cqp->dev->hw->device, cqp->sdbuf.size,
  2820. cqp->sdbuf.va, cqp->sdbuf.pa);
  2821. cqp->sdbuf.va = NULL;
  2822. err_code = readl(cqp->dev->hw_regs[IRDMA_CQPERRCODES]);
  2823. *min_err = FIELD_GET(IRDMA_CQPERRCODES_CQP_MINOR_CODE, err_code);
  2824. *maj_err = FIELD_GET(IRDMA_CQPERRCODES_CQP_MAJOR_CODE, err_code);
  2825. return ret_code;
  2826. }
  2827. /**
  2828. * irdma_sc_cqp_post_sq - post of cqp's sq
  2829. * @cqp: struct for cqp hw
  2830. */
  2831. void irdma_sc_cqp_post_sq(struct irdma_sc_cqp *cqp)
  2832. {
  2833. writel(IRDMA_RING_CURRENT_HEAD(cqp->sq_ring), cqp->dev->cqp_db);
  2834. ibdev_dbg(to_ibdev(cqp->dev),
  2835. "WQE: CQP SQ head 0x%x tail 0x%x size 0x%x\n",
  2836. cqp->sq_ring.head, cqp->sq_ring.tail, cqp->sq_ring.size);
  2837. }
  2838. /**
  2839. * irdma_sc_cqp_get_next_send_wqe_idx - get next wqe on cqp sq
  2840. * and pass back index
  2841. * @cqp: CQP HW structure
  2842. * @scratch: private data for CQP WQE
  2843. * @wqe_idx: WQE index of CQP SQ
  2844. */
  2845. __le64 *irdma_sc_cqp_get_next_send_wqe_idx(struct irdma_sc_cqp *cqp, u64 scratch,
  2846. u32 *wqe_idx)
  2847. {
  2848. __le64 *wqe = NULL;
  2849. int ret_code;
  2850. if (IRDMA_RING_FULL_ERR(cqp->sq_ring)) {
  2851. ibdev_dbg(to_ibdev(cqp->dev),
  2852. "WQE: CQP SQ is full, head 0x%x tail 0x%x size 0x%x\n",
  2853. cqp->sq_ring.head, cqp->sq_ring.tail,
  2854. cqp->sq_ring.size);
  2855. return NULL;
  2856. }
  2857. IRDMA_ATOMIC_RING_MOVE_HEAD(cqp->sq_ring, *wqe_idx, ret_code);
  2858. if (ret_code)
  2859. return NULL;
  2860. cqp->requested_ops++;
  2861. if (!*wqe_idx)
  2862. cqp->polarity = !cqp->polarity;
  2863. wqe = cqp->sq_base[*wqe_idx].elem;
  2864. cqp->scratch_array[*wqe_idx] = scratch;
  2865. IRDMA_CQP_INIT_WQE(wqe);
  2866. return wqe;
  2867. }
  2868. /**
  2869. * irdma_sc_cqp_destroy - destroy cqp during close
  2870. * @cqp: struct for cqp hw
  2871. */
  2872. int irdma_sc_cqp_destroy(struct irdma_sc_cqp *cqp)
  2873. {
  2874. u32 cnt = 0, val;
  2875. int ret_code = 0;
  2876. writel(0, cqp->dev->hw_regs[IRDMA_CCQPHIGH]);
  2877. writel(0, cqp->dev->hw_regs[IRDMA_CCQPLOW]);
  2878. do {
  2879. if (cnt++ > cqp->dev->hw_attrs.max_done_count) {
  2880. ret_code = -ETIMEDOUT;
  2881. break;
  2882. }
  2883. udelay(cqp->dev->hw_attrs.max_sleep_count);
  2884. val = readl(cqp->dev->hw_regs[IRDMA_CCQPSTATUS]);
  2885. } while (FLD_RS_32(cqp->dev, val, IRDMA_CCQPSTATUS_CCQP_DONE));
  2886. dma_free_coherent(cqp->dev->hw->device, cqp->sdbuf.size,
  2887. cqp->sdbuf.va, cqp->sdbuf.pa);
  2888. cqp->sdbuf.va = NULL;
  2889. return ret_code;
  2890. }
  2891. /**
  2892. * irdma_sc_ccq_arm - enable intr for control cq
  2893. * @ccq: ccq sc struct
  2894. */
  2895. void irdma_sc_ccq_arm(struct irdma_sc_cq *ccq)
  2896. {
  2897. u64 temp_val;
  2898. u16 sw_cq_sel;
  2899. u8 arm_next_se;
  2900. u8 arm_seq_num;
  2901. get_64bit_val(ccq->cq_uk.shadow_area, 32, &temp_val);
  2902. sw_cq_sel = (u16)FIELD_GET(IRDMA_CQ_DBSA_SW_CQ_SELECT, temp_val);
  2903. arm_next_se = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_NEXT_SE, temp_val);
  2904. arm_seq_num = (u8)FIELD_GET(IRDMA_CQ_DBSA_ARM_SEQ_NUM, temp_val);
  2905. arm_seq_num++;
  2906. temp_val = FIELD_PREP(IRDMA_CQ_DBSA_ARM_SEQ_NUM, arm_seq_num) |
  2907. FIELD_PREP(IRDMA_CQ_DBSA_SW_CQ_SELECT, sw_cq_sel) |
  2908. FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT_SE, arm_next_se) |
  2909. FIELD_PREP(IRDMA_CQ_DBSA_ARM_NEXT, 1);
  2910. set_64bit_val(ccq->cq_uk.shadow_area, 32, temp_val);
  2911. dma_wmb(); /* make sure shadow area is updated before arming */
  2912. writel(ccq->cq_uk.cq_id, ccq->dev->cq_arm_db);
  2913. }
  2914. /**
  2915. * irdma_sc_ccq_get_cqe_info - get ccq's cq entry
  2916. * @ccq: ccq sc struct
  2917. * @info: completion q entry to return
  2918. */
  2919. int irdma_sc_ccq_get_cqe_info(struct irdma_sc_cq *ccq,
  2920. struct irdma_ccq_cqe_info *info)
  2921. {
  2922. u64 qp_ctx, temp, temp1;
  2923. __le64 *cqe;
  2924. struct irdma_sc_cqp *cqp;
  2925. u32 wqe_idx;
  2926. u32 error;
  2927. u8 polarity;
  2928. int ret_code = 0;
  2929. if (ccq->cq_uk.avoid_mem_cflct)
  2930. cqe = IRDMA_GET_CURRENT_EXTENDED_CQ_ELEM(&ccq->cq_uk);
  2931. else
  2932. cqe = IRDMA_GET_CURRENT_CQ_ELEM(&ccq->cq_uk);
  2933. get_64bit_val(cqe, 24, &temp);
  2934. polarity = (u8)FIELD_GET(IRDMA_CQ_VALID, temp);
  2935. if (polarity != ccq->cq_uk.polarity)
  2936. return -ENOENT;
  2937. /* Ensure CEQE contents are read after valid bit is checked */
  2938. dma_rmb();
  2939. get_64bit_val(cqe, 8, &qp_ctx);
  2940. cqp = (struct irdma_sc_cqp *)(unsigned long)qp_ctx;
  2941. info->error = (bool)FIELD_GET(IRDMA_CQ_ERROR, temp);
  2942. info->maj_err_code = IRDMA_CQPSQ_MAJ_NO_ERROR;
  2943. info->min_err_code = (u16)FIELD_GET(IRDMA_CQ_MINERR, temp);
  2944. if (info->error) {
  2945. info->maj_err_code = (u16)FIELD_GET(IRDMA_CQ_MAJERR, temp);
  2946. error = readl(cqp->dev->hw_regs[IRDMA_CQPERRCODES]);
  2947. ibdev_dbg(to_ibdev(cqp->dev),
  2948. "CQP: CQPERRCODES error_code[x%08X]\n", error);
  2949. }
  2950. wqe_idx = (u32)FIELD_GET(IRDMA_CQ_WQEIDX, temp);
  2951. info->scratch = cqp->scratch_array[wqe_idx];
  2952. get_64bit_val(cqe, 16, &temp1);
  2953. info->op_ret_val = (u32)FIELD_GET(IRDMA_CCQ_OPRETVAL, temp1);
  2954. get_64bit_val(cqp->sq_base[wqe_idx].elem, 24, &temp1);
  2955. info->op_code = (u8)FIELD_GET(IRDMA_CQPSQ_OPCODE, temp1);
  2956. info->cqp = cqp;
  2957. /* move the head for cq */
  2958. IRDMA_RING_MOVE_HEAD(ccq->cq_uk.cq_ring, ret_code);
  2959. if (!IRDMA_RING_CURRENT_HEAD(ccq->cq_uk.cq_ring))
  2960. ccq->cq_uk.polarity ^= 1;
  2961. /* update cq tail in cq shadow memory also */
  2962. IRDMA_RING_MOVE_TAIL(ccq->cq_uk.cq_ring);
  2963. set_64bit_val(ccq->cq_uk.shadow_area, 0,
  2964. IRDMA_RING_CURRENT_HEAD(ccq->cq_uk.cq_ring));
  2965. dma_wmb(); /* make sure shadow area is updated before moving tail */
  2966. IRDMA_RING_MOVE_TAIL(cqp->sq_ring);
  2967. atomic64_inc(&cqp->completed_ops);
  2968. return ret_code;
  2969. }
  2970. /**
  2971. * irdma_sc_poll_for_cqp_op_done - Waits for last write to complete in CQP SQ
  2972. * @cqp: struct for cqp hw
  2973. * @op_code: cqp opcode for completion
  2974. * @compl_info: completion q entry to return
  2975. */
  2976. int irdma_sc_poll_for_cqp_op_done(struct irdma_sc_cqp *cqp, u8 op_code,
  2977. struct irdma_ccq_cqe_info *compl_info)
  2978. {
  2979. struct irdma_ccq_cqe_info info = {};
  2980. struct irdma_sc_cq *ccq;
  2981. int ret_code = 0;
  2982. u32 cnt = 0;
  2983. ccq = cqp->dev->ccq;
  2984. while (1) {
  2985. if (cnt++ > 100 * cqp->dev->hw_attrs.max_done_count)
  2986. return -ETIMEDOUT;
  2987. if (irdma_sc_ccq_get_cqe_info(ccq, &info)) {
  2988. udelay(cqp->dev->hw_attrs.max_sleep_count);
  2989. continue;
  2990. }
  2991. if (info.error && info.op_code != IRDMA_CQP_OP_QUERY_STAG) {
  2992. ret_code = -EIO;
  2993. break;
  2994. }
  2995. /* make sure op code matches*/
  2996. if (op_code == info.op_code)
  2997. break;
  2998. ibdev_dbg(to_ibdev(cqp->dev),
  2999. "WQE: opcode mismatch for my op code 0x%x, returned opcode %x\n",
  3000. op_code, info.op_code);
  3001. }
  3002. if (compl_info)
  3003. memcpy(compl_info, &info, sizeof(*compl_info));
  3004. return ret_code;
  3005. }
  3006. /**
  3007. * irdma_sc_manage_hmc_pm_func_table - manage of function table
  3008. * @cqp: struct for cqp hw
  3009. * @scratch: u64 saved to be used during cqp completion
  3010. * @info: info for the manage function table operation
  3011. * @post_sq: flag for cqp db to ring
  3012. */
  3013. static int irdma_sc_manage_hmc_pm_func_table(struct irdma_sc_cqp *cqp,
  3014. struct irdma_hmc_fcn_info *info,
  3015. u64 scratch, bool post_sq)
  3016. {
  3017. __le64 *wqe;
  3018. u64 hdr;
  3019. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3020. if (!wqe)
  3021. return -ENOMEM;
  3022. set_64bit_val(wqe, 0, 0);
  3023. set_64bit_val(wqe, 8, 0);
  3024. set_64bit_val(wqe, 16, 0);
  3025. set_64bit_val(wqe, 32, 0);
  3026. set_64bit_val(wqe, 40, 0);
  3027. set_64bit_val(wqe, 48, 0);
  3028. set_64bit_val(wqe, 56, 0);
  3029. hdr = FIELD_PREP(IRDMA_CQPSQ_MHMC_VFIDX, info->vf_id) |
  3030. FIELD_PREP(IRDMA_CQPSQ_OPCODE,
  3031. IRDMA_CQP_OP_MANAGE_HMC_PM_FUNC_TABLE) |
  3032. FIELD_PREP(IRDMA_CQPSQ_MHMC_FREEPMFN, info->free_fcn) |
  3033. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3034. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3035. set_64bit_val(wqe, 24, hdr);
  3036. print_hex_dump_debug("WQE: MANAGE_HMC_PM_FUNC_TABLE WQE",
  3037. DUMP_PREFIX_OFFSET, 16, 8, wqe,
  3038. IRDMA_CQP_WQE_SIZE * 8, false);
  3039. if (post_sq)
  3040. irdma_sc_cqp_post_sq(cqp);
  3041. return 0;
  3042. }
  3043. /**
  3044. * irdma_sc_commit_fpm_val_done - wait for cqp eqe completion
  3045. * for fpm commit
  3046. * @cqp: struct for cqp hw
  3047. */
  3048. static int irdma_sc_commit_fpm_val_done(struct irdma_sc_cqp *cqp)
  3049. {
  3050. return irdma_sc_poll_for_cqp_op_done(cqp, IRDMA_CQP_OP_COMMIT_FPM_VAL,
  3051. NULL);
  3052. }
  3053. /**
  3054. * irdma_sc_commit_fpm_val - cqp wqe for commit fpm values
  3055. * @cqp: struct for cqp hw
  3056. * @scratch: u64 saved to be used during cqp completion
  3057. * @hmc_fn_id: hmc function id
  3058. * @commit_fpm_mem: Memory for fpm values
  3059. * @post_sq: flag for cqp db to ring
  3060. * @wait_type: poll ccq or cqp registers for cqp completion
  3061. */
  3062. static int irdma_sc_commit_fpm_val(struct irdma_sc_cqp *cqp, u64 scratch,
  3063. u8 hmc_fn_id,
  3064. struct irdma_dma_mem *commit_fpm_mem,
  3065. bool post_sq, u8 wait_type)
  3066. {
  3067. __le64 *wqe;
  3068. u64 hdr;
  3069. u32 tail, val, error;
  3070. int ret_code = 0;
  3071. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3072. if (!wqe)
  3073. return -ENOMEM;
  3074. set_64bit_val(wqe, 16, hmc_fn_id);
  3075. set_64bit_val(wqe, 32, commit_fpm_mem->pa);
  3076. hdr = FIELD_PREP(IRDMA_CQPSQ_BUFSIZE, IRDMA_COMMIT_FPM_BUF_SIZE) |
  3077. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_COMMIT_FPM_VAL) |
  3078. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3079. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3080. set_64bit_val(wqe, 24, hdr);
  3081. print_hex_dump_debug("WQE: COMMIT_FPM_VAL WQE", DUMP_PREFIX_OFFSET,
  3082. 16, 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3083. irdma_get_cqp_reg_info(cqp, &val, &tail, &error);
  3084. if (post_sq) {
  3085. irdma_sc_cqp_post_sq(cqp);
  3086. if (wait_type == IRDMA_CQP_WAIT_POLL_REGS)
  3087. ret_code = irdma_cqp_poll_registers(cqp, tail,
  3088. cqp->dev->hw_attrs.max_done_count);
  3089. else if (wait_type == IRDMA_CQP_WAIT_POLL_CQ)
  3090. ret_code = irdma_sc_commit_fpm_val_done(cqp);
  3091. }
  3092. return ret_code;
  3093. }
  3094. /**
  3095. * irdma_sc_query_fpm_val_done - poll for cqp wqe completion for
  3096. * query fpm
  3097. * @cqp: struct for cqp hw
  3098. */
  3099. static int irdma_sc_query_fpm_val_done(struct irdma_sc_cqp *cqp)
  3100. {
  3101. return irdma_sc_poll_for_cqp_op_done(cqp, IRDMA_CQP_OP_QUERY_FPM_VAL,
  3102. NULL);
  3103. }
  3104. /**
  3105. * irdma_sc_query_fpm_val - cqp wqe query fpm values
  3106. * @cqp: struct for cqp hw
  3107. * @scratch: u64 saved to be used during cqp completion
  3108. * @hmc_fn_id: hmc function id
  3109. * @query_fpm_mem: memory for return fpm values
  3110. * @post_sq: flag for cqp db to ring
  3111. * @wait_type: poll ccq or cqp registers for cqp completion
  3112. */
  3113. static int irdma_sc_query_fpm_val(struct irdma_sc_cqp *cqp, u64 scratch,
  3114. u8 hmc_fn_id,
  3115. struct irdma_dma_mem *query_fpm_mem,
  3116. bool post_sq, u8 wait_type)
  3117. {
  3118. __le64 *wqe;
  3119. u64 hdr;
  3120. u32 tail, val, error;
  3121. int ret_code = 0;
  3122. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3123. if (!wqe)
  3124. return -ENOMEM;
  3125. set_64bit_val(wqe, 16, hmc_fn_id);
  3126. set_64bit_val(wqe, 32, query_fpm_mem->pa);
  3127. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_QUERY_FPM_VAL) |
  3128. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3129. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3130. set_64bit_val(wqe, 24, hdr);
  3131. print_hex_dump_debug("WQE: QUERY_FPM WQE", DUMP_PREFIX_OFFSET, 16, 8,
  3132. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3133. irdma_get_cqp_reg_info(cqp, &val, &tail, &error);
  3134. if (post_sq) {
  3135. irdma_sc_cqp_post_sq(cqp);
  3136. if (wait_type == IRDMA_CQP_WAIT_POLL_REGS)
  3137. ret_code = irdma_cqp_poll_registers(cqp, tail,
  3138. cqp->dev->hw_attrs.max_done_count);
  3139. else if (wait_type == IRDMA_CQP_WAIT_POLL_CQ)
  3140. ret_code = irdma_sc_query_fpm_val_done(cqp);
  3141. }
  3142. return ret_code;
  3143. }
  3144. /**
  3145. * irdma_sc_ceq_init - initialize ceq
  3146. * @ceq: ceq sc structure
  3147. * @info: ceq initialization info
  3148. */
  3149. int irdma_sc_ceq_init(struct irdma_sc_ceq *ceq,
  3150. struct irdma_ceq_init_info *info)
  3151. {
  3152. u32 pble_obj_cnt;
  3153. if (info->elem_cnt < info->dev->hw_attrs.min_hw_ceq_size ||
  3154. info->elem_cnt > info->dev->hw_attrs.max_hw_ceq_size)
  3155. return -EINVAL;
  3156. if (info->ceq_id >= info->dev->hmc_fpm_misc.max_ceqs)
  3157. return -EINVAL;
  3158. pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  3159. if (info->virtual_map && info->first_pm_pbl_idx >= pble_obj_cnt)
  3160. return -EINVAL;
  3161. ceq->size = sizeof(*ceq);
  3162. ceq->ceqe_base = (struct irdma_ceqe *)info->ceqe_base;
  3163. ceq->ceq_id = info->ceq_id;
  3164. ceq->dev = info->dev;
  3165. ceq->elem_cnt = info->elem_cnt;
  3166. ceq->ceq_elem_pa = info->ceqe_pa;
  3167. ceq->virtual_map = info->virtual_map;
  3168. ceq->itr_no_expire = info->itr_no_expire;
  3169. ceq->reg_cq = info->reg_cq;
  3170. ceq->reg_cq_size = 0;
  3171. spin_lock_init(&ceq->req_cq_lock);
  3172. ceq->pbl_chunk_size = (ceq->virtual_map ? info->pbl_chunk_size : 0);
  3173. ceq->first_pm_pbl_idx = (ceq->virtual_map ? info->first_pm_pbl_idx : 0);
  3174. ceq->pbl_list = (ceq->virtual_map ? info->pbl_list : NULL);
  3175. ceq->tph_en = info->tph_en;
  3176. ceq->tph_val = info->tph_val;
  3177. ceq->vsi = info->vsi;
  3178. ceq->polarity = 1;
  3179. IRDMA_RING_INIT(ceq->ceq_ring, ceq->elem_cnt);
  3180. ceq->dev->ceq[info->ceq_id] = ceq;
  3181. return 0;
  3182. }
  3183. /**
  3184. * irdma_sc_ceq_create - create ceq wqe
  3185. * @ceq: ceq sc structure
  3186. * @scratch: u64 saved to be used during cqp completion
  3187. * @post_sq: flag for cqp db to ring
  3188. */
  3189. static int irdma_sc_ceq_create(struct irdma_sc_ceq *ceq, u64 scratch,
  3190. bool post_sq)
  3191. {
  3192. struct irdma_sc_cqp *cqp;
  3193. __le64 *wqe;
  3194. u64 hdr;
  3195. cqp = ceq->dev->cqp;
  3196. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3197. if (!wqe)
  3198. return -ENOMEM;
  3199. set_64bit_val(wqe, 16, ceq->elem_cnt);
  3200. set_64bit_val(wqe, 32,
  3201. (ceq->virtual_map ? 0 : ceq->ceq_elem_pa));
  3202. set_64bit_val(wqe, 48,
  3203. (ceq->virtual_map ? ceq->first_pm_pbl_idx : 0));
  3204. set_64bit_val(wqe, 56,
  3205. FIELD_PREP(IRDMA_CQPSQ_TPHVAL, ceq->tph_val) |
  3206. FIELD_PREP(IRDMA_CQPSQ_VSIIDX, ceq->vsi->vsi_idx));
  3207. hdr = FIELD_PREP(IRDMA_CQPSQ_CEQ_CEQID, ceq->ceq_id) |
  3208. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_CREATE_CEQ) |
  3209. FIELD_PREP(IRDMA_CQPSQ_CEQ_LPBLSIZE, ceq->pbl_chunk_size) |
  3210. FIELD_PREP(IRDMA_CQPSQ_CEQ_VMAP, ceq->virtual_map) |
  3211. FIELD_PREP(IRDMA_CQPSQ_CEQ_ITRNOEXPIRE, ceq->itr_no_expire) |
  3212. FIELD_PREP(IRDMA_CQPSQ_TPHEN, ceq->tph_en) |
  3213. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3214. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3215. set_64bit_val(wqe, 24, hdr);
  3216. print_hex_dump_debug("WQE: CEQ_CREATE WQE", DUMP_PREFIX_OFFSET, 16, 8,
  3217. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3218. if (post_sq)
  3219. irdma_sc_cqp_post_sq(cqp);
  3220. return 0;
  3221. }
  3222. /**
  3223. * irdma_sc_cceq_create_done - poll for control ceq wqe to complete
  3224. * @ceq: ceq sc structure
  3225. */
  3226. static int irdma_sc_cceq_create_done(struct irdma_sc_ceq *ceq)
  3227. {
  3228. struct irdma_sc_cqp *cqp;
  3229. cqp = ceq->dev->cqp;
  3230. return irdma_sc_poll_for_cqp_op_done(cqp, IRDMA_CQP_OP_CREATE_CEQ,
  3231. NULL);
  3232. }
  3233. /**
  3234. * irdma_sc_cceq_destroy_done - poll for destroy cceq to complete
  3235. * @ceq: ceq sc structure
  3236. */
  3237. int irdma_sc_cceq_destroy_done(struct irdma_sc_ceq *ceq)
  3238. {
  3239. struct irdma_sc_cqp *cqp;
  3240. if (ceq->reg_cq)
  3241. irdma_sc_remove_cq_ctx(ceq, ceq->dev->ccq);
  3242. cqp = ceq->dev->cqp;
  3243. cqp->process_cqp_sds = irdma_update_sds_noccq;
  3244. return irdma_sc_poll_for_cqp_op_done(cqp, IRDMA_CQP_OP_DESTROY_CEQ,
  3245. NULL);
  3246. }
  3247. /**
  3248. * irdma_sc_cceq_create - create cceq
  3249. * @ceq: ceq sc structure
  3250. * @scratch: u64 saved to be used during cqp completion
  3251. */
  3252. int irdma_sc_cceq_create(struct irdma_sc_ceq *ceq, u64 scratch)
  3253. {
  3254. int ret_code;
  3255. struct irdma_sc_dev *dev = ceq->dev;
  3256. dev->ccq->vsi = ceq->vsi;
  3257. if (ceq->reg_cq) {
  3258. ret_code = irdma_sc_add_cq_ctx(ceq, ceq->dev->ccq);
  3259. if (ret_code)
  3260. return ret_code;
  3261. }
  3262. ret_code = irdma_sc_ceq_create(ceq, scratch, true);
  3263. if (!ret_code)
  3264. return irdma_sc_cceq_create_done(ceq);
  3265. return ret_code;
  3266. }
  3267. /**
  3268. * irdma_sc_ceq_destroy - destroy ceq
  3269. * @ceq: ceq sc structure
  3270. * @scratch: u64 saved to be used during cqp completion
  3271. * @post_sq: flag for cqp db to ring
  3272. */
  3273. int irdma_sc_ceq_destroy(struct irdma_sc_ceq *ceq, u64 scratch, bool post_sq)
  3274. {
  3275. struct irdma_sc_cqp *cqp;
  3276. __le64 *wqe;
  3277. u64 hdr;
  3278. cqp = ceq->dev->cqp;
  3279. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3280. if (!wqe)
  3281. return -ENOMEM;
  3282. set_64bit_val(wqe, 16, ceq->elem_cnt);
  3283. set_64bit_val(wqe, 48, ceq->first_pm_pbl_idx);
  3284. hdr = ceq->ceq_id |
  3285. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_DESTROY_CEQ) |
  3286. FIELD_PREP(IRDMA_CQPSQ_CEQ_LPBLSIZE, ceq->pbl_chunk_size) |
  3287. FIELD_PREP(IRDMA_CQPSQ_CEQ_VMAP, ceq->virtual_map) |
  3288. FIELD_PREP(IRDMA_CQPSQ_TPHEN, ceq->tph_en) |
  3289. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3290. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3291. set_64bit_val(wqe, 24, hdr);
  3292. print_hex_dump_debug("WQE: CEQ_DESTROY WQE", DUMP_PREFIX_OFFSET, 16,
  3293. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3294. if (post_sq)
  3295. irdma_sc_cqp_post_sq(cqp);
  3296. return 0;
  3297. }
  3298. /**
  3299. * irdma_sc_process_ceq - process ceq
  3300. * @dev: sc device struct
  3301. * @ceq: ceq sc structure
  3302. *
  3303. * It is expected caller serializes this function with cleanup_ceqes()
  3304. * because these functions manipulate the same ceq
  3305. */
  3306. void *irdma_sc_process_ceq(struct irdma_sc_dev *dev, struct irdma_sc_ceq *ceq)
  3307. {
  3308. u64 temp;
  3309. __le64 *ceqe;
  3310. struct irdma_sc_cq *cq = NULL;
  3311. struct irdma_sc_cq *temp_cq;
  3312. u8 polarity;
  3313. u32 cq_idx;
  3314. unsigned long flags;
  3315. do {
  3316. cq_idx = 0;
  3317. ceqe = IRDMA_GET_CURRENT_CEQ_ELEM(ceq);
  3318. get_64bit_val(ceqe, 0, &temp);
  3319. polarity = (u8)FIELD_GET(IRDMA_CEQE_VALID, temp);
  3320. if (polarity != ceq->polarity)
  3321. return NULL;
  3322. temp_cq = (struct irdma_sc_cq *)(unsigned long)(temp << 1);
  3323. if (!temp_cq) {
  3324. cq_idx = IRDMA_INVALID_CQ_IDX;
  3325. IRDMA_RING_MOVE_TAIL(ceq->ceq_ring);
  3326. if (!IRDMA_RING_CURRENT_TAIL(ceq->ceq_ring))
  3327. ceq->polarity ^= 1;
  3328. continue;
  3329. }
  3330. cq = temp_cq;
  3331. if (ceq->reg_cq) {
  3332. spin_lock_irqsave(&ceq->req_cq_lock, flags);
  3333. cq_idx = irdma_sc_find_reg_cq(ceq, cq);
  3334. spin_unlock_irqrestore(&ceq->req_cq_lock, flags);
  3335. }
  3336. IRDMA_RING_MOVE_TAIL(ceq->ceq_ring);
  3337. if (!IRDMA_RING_CURRENT_TAIL(ceq->ceq_ring))
  3338. ceq->polarity ^= 1;
  3339. } while (cq_idx == IRDMA_INVALID_CQ_IDX);
  3340. if (cq)
  3341. irdma_sc_cq_ack(cq);
  3342. return cq;
  3343. }
  3344. /**
  3345. * irdma_sc_cleanup_ceqes - clear the valid ceqes ctx matching the cq
  3346. * @cq: cq for which the ceqes need to be cleaned up
  3347. * @ceq: ceq ptr
  3348. *
  3349. * The function is called after the cq is destroyed to cleanup
  3350. * its pending ceqe entries. It is expected caller serializes this
  3351. * function with process_ceq() in interrupt context.
  3352. */
  3353. void irdma_sc_cleanup_ceqes(struct irdma_sc_cq *cq, struct irdma_sc_ceq *ceq)
  3354. {
  3355. struct irdma_sc_cq *next_cq;
  3356. u8 ceq_polarity = ceq->polarity;
  3357. __le64 *ceqe;
  3358. u8 polarity;
  3359. u64 temp;
  3360. int next;
  3361. u32 i;
  3362. next = IRDMA_RING_GET_NEXT_TAIL(ceq->ceq_ring, 0);
  3363. for (i = 1; i <= IRDMA_RING_SIZE(*ceq); i++) {
  3364. ceqe = IRDMA_GET_CEQ_ELEM_AT_POS(ceq, next);
  3365. get_64bit_val(ceqe, 0, &temp);
  3366. polarity = (u8)FIELD_GET(IRDMA_CEQE_VALID, temp);
  3367. if (polarity != ceq_polarity)
  3368. return;
  3369. next_cq = (struct irdma_sc_cq *)(unsigned long)(temp << 1);
  3370. if (cq == next_cq)
  3371. set_64bit_val(ceqe, 0, temp & IRDMA_CEQE_VALID);
  3372. next = IRDMA_RING_GET_NEXT_TAIL(ceq->ceq_ring, i);
  3373. if (!next)
  3374. ceq_polarity ^= 1;
  3375. }
  3376. }
  3377. /**
  3378. * irdma_sc_aeq_init - initialize aeq
  3379. * @aeq: aeq structure ptr
  3380. * @info: aeq initialization info
  3381. */
  3382. int irdma_sc_aeq_init(struct irdma_sc_aeq *aeq,
  3383. struct irdma_aeq_init_info *info)
  3384. {
  3385. u32 pble_obj_cnt;
  3386. if (info->elem_cnt < info->dev->hw_attrs.min_hw_aeq_size ||
  3387. info->elem_cnt > info->dev->hw_attrs.max_hw_aeq_size)
  3388. return -EINVAL;
  3389. pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  3390. if (info->virtual_map && info->first_pm_pbl_idx >= pble_obj_cnt)
  3391. return -EINVAL;
  3392. aeq->size = sizeof(*aeq);
  3393. aeq->polarity = 1;
  3394. aeq->aeqe_base = (struct irdma_sc_aeqe *)info->aeqe_base;
  3395. aeq->dev = info->dev;
  3396. aeq->elem_cnt = info->elem_cnt;
  3397. aeq->aeq_elem_pa = info->aeq_elem_pa;
  3398. IRDMA_RING_INIT(aeq->aeq_ring, aeq->elem_cnt);
  3399. aeq->virtual_map = info->virtual_map;
  3400. aeq->pbl_list = (aeq->virtual_map ? info->pbl_list : NULL);
  3401. aeq->pbl_chunk_size = (aeq->virtual_map ? info->pbl_chunk_size : 0);
  3402. aeq->first_pm_pbl_idx = (aeq->virtual_map ? info->first_pm_pbl_idx : 0);
  3403. aeq->msix_idx = info->msix_idx;
  3404. info->dev->aeq = aeq;
  3405. return 0;
  3406. }
  3407. /**
  3408. * irdma_sc_aeq_create - create aeq
  3409. * @aeq: aeq structure ptr
  3410. * @scratch: u64 saved to be used during cqp completion
  3411. * @post_sq: flag for cqp db to ring
  3412. */
  3413. static int irdma_sc_aeq_create(struct irdma_sc_aeq *aeq, u64 scratch,
  3414. bool post_sq)
  3415. {
  3416. __le64 *wqe;
  3417. struct irdma_sc_cqp *cqp;
  3418. u64 hdr;
  3419. cqp = aeq->dev->cqp;
  3420. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3421. if (!wqe)
  3422. return -ENOMEM;
  3423. set_64bit_val(wqe, 16, aeq->elem_cnt);
  3424. set_64bit_val(wqe, 32,
  3425. (aeq->virtual_map ? 0 : aeq->aeq_elem_pa));
  3426. set_64bit_val(wqe, 48,
  3427. (aeq->virtual_map ? aeq->first_pm_pbl_idx : 0));
  3428. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_CREATE_AEQ) |
  3429. FIELD_PREP(IRDMA_CQPSQ_AEQ_LPBLSIZE, aeq->pbl_chunk_size) |
  3430. FIELD_PREP(IRDMA_CQPSQ_AEQ_VMAP, aeq->virtual_map) |
  3431. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3432. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3433. set_64bit_val(wqe, 24, hdr);
  3434. print_hex_dump_debug("WQE: AEQ_CREATE WQE", DUMP_PREFIX_OFFSET, 16, 8,
  3435. wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3436. if (post_sq)
  3437. irdma_sc_cqp_post_sq(cqp);
  3438. return 0;
  3439. }
  3440. /**
  3441. * irdma_sc_aeq_destroy - destroy aeq during close
  3442. * @aeq: aeq structure ptr
  3443. * @scratch: u64 saved to be used during cqp completion
  3444. * @post_sq: flag for cqp db to ring
  3445. */
  3446. static int irdma_sc_aeq_destroy(struct irdma_sc_aeq *aeq, u64 scratch,
  3447. bool post_sq)
  3448. {
  3449. __le64 *wqe;
  3450. struct irdma_sc_cqp *cqp;
  3451. struct irdma_sc_dev *dev;
  3452. u64 hdr;
  3453. dev = aeq->dev;
  3454. writel(0, dev->hw_regs[IRDMA_PFINT_AEQCTL]);
  3455. cqp = dev->cqp;
  3456. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3457. if (!wqe)
  3458. return -ENOMEM;
  3459. set_64bit_val(wqe, 16, aeq->elem_cnt);
  3460. set_64bit_val(wqe, 48, aeq->first_pm_pbl_idx);
  3461. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_DESTROY_AEQ) |
  3462. FIELD_PREP(IRDMA_CQPSQ_AEQ_LPBLSIZE, aeq->pbl_chunk_size) |
  3463. FIELD_PREP(IRDMA_CQPSQ_AEQ_VMAP, aeq->virtual_map) |
  3464. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3465. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3466. set_64bit_val(wqe, 24, hdr);
  3467. print_hex_dump_debug("WQE: AEQ_DESTROY WQE", DUMP_PREFIX_OFFSET, 16,
  3468. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3469. if (post_sq)
  3470. irdma_sc_cqp_post_sq(cqp);
  3471. return 0;
  3472. }
  3473. /**
  3474. * irdma_sc_get_next_aeqe - get next aeq entry
  3475. * @aeq: aeq structure ptr
  3476. * @info: aeqe info to be returned
  3477. */
  3478. int irdma_sc_get_next_aeqe(struct irdma_sc_aeq *aeq,
  3479. struct irdma_aeqe_info *info)
  3480. {
  3481. u64 temp, compl_ctx;
  3482. __le64 *aeqe;
  3483. u8 ae_src;
  3484. u8 polarity;
  3485. aeqe = IRDMA_GET_CURRENT_AEQ_ELEM(aeq);
  3486. get_64bit_val(aeqe, 8, &temp);
  3487. polarity = (u8)FIELD_GET(IRDMA_AEQE_VALID, temp);
  3488. if (aeq->polarity != polarity)
  3489. return -ENOENT;
  3490. /* Ensure AEQE contents are read after valid bit is checked */
  3491. dma_rmb();
  3492. get_64bit_val(aeqe, 0, &compl_ctx);
  3493. print_hex_dump_debug("WQE: AEQ_ENTRY WQE", DUMP_PREFIX_OFFSET, 16, 8,
  3494. aeqe, 16, false);
  3495. ae_src = (u8)FIELD_GET(IRDMA_AEQE_AESRC, temp);
  3496. info->wqe_idx = (u16)FIELD_GET(IRDMA_AEQE_WQDESCIDX, temp);
  3497. info->qp_cq_id = (u32)FIELD_GET(IRDMA_AEQE_QPCQID_LOW, temp) |
  3498. ((u32)FIELD_GET(IRDMA_AEQE_QPCQID_HI, temp) << 18);
  3499. info->ae_id = (u16)FIELD_GET(IRDMA_AEQE_AECODE, temp);
  3500. info->tcp_state = (u8)FIELD_GET(IRDMA_AEQE_TCPSTATE, temp);
  3501. info->iwarp_state = (u8)FIELD_GET(IRDMA_AEQE_IWSTATE, temp);
  3502. info->q2_data_written = (u8)FIELD_GET(IRDMA_AEQE_Q2DATA, temp);
  3503. info->aeqe_overflow = (bool)FIELD_GET(IRDMA_AEQE_OVERFLOW, temp);
  3504. info->ae_src = ae_src;
  3505. switch (info->ae_id) {
  3506. case IRDMA_AE_PRIV_OPERATION_DENIED:
  3507. case IRDMA_AE_AMP_INVALIDATE_TYPE1_MW:
  3508. case IRDMA_AE_AMP_MWBIND_ZERO_BASED_TYPE1_MW:
  3509. case IRDMA_AE_AMP_FASTREG_INVALID_PBL_HPS_CFG:
  3510. case IRDMA_AE_AMP_FASTREG_PBLE_MISMATCH:
  3511. case IRDMA_AE_UDA_XMIT_DGRAM_TOO_LONG:
  3512. case IRDMA_AE_UDA_XMIT_BAD_PD:
  3513. case IRDMA_AE_UDA_XMIT_DGRAM_TOO_SHORT:
  3514. case IRDMA_AE_BAD_CLOSE:
  3515. case IRDMA_AE_RDMA_READ_WHILE_ORD_ZERO:
  3516. case IRDMA_AE_STAG_ZERO_INVALID:
  3517. case IRDMA_AE_IB_RREQ_AND_Q1_FULL:
  3518. case IRDMA_AE_IB_INVALID_REQUEST:
  3519. case IRDMA_AE_WQE_UNEXPECTED_OPCODE:
  3520. case IRDMA_AE_IB_REMOTE_ACCESS_ERROR:
  3521. case IRDMA_AE_IB_REMOTE_OP_ERROR:
  3522. case IRDMA_AE_DDP_UBE_INVALID_DDP_VERSION:
  3523. case IRDMA_AE_DDP_UBE_INVALID_MO:
  3524. case IRDMA_AE_DDP_UBE_INVALID_QN:
  3525. case IRDMA_AE_DDP_NO_L_BIT:
  3526. case IRDMA_AE_RDMAP_ROE_INVALID_RDMAP_VERSION:
  3527. case IRDMA_AE_RDMAP_ROE_UNEXPECTED_OPCODE:
  3528. case IRDMA_AE_ROE_INVALID_RDMA_READ_REQUEST:
  3529. case IRDMA_AE_ROE_INVALID_RDMA_WRITE_OR_READ_RESP:
  3530. case IRDMA_AE_ROCE_RSP_LENGTH_ERROR:
  3531. case IRDMA_AE_INVALID_ARP_ENTRY:
  3532. case IRDMA_AE_INVALID_TCP_OPTION_RCVD:
  3533. case IRDMA_AE_STALE_ARP_ENTRY:
  3534. case IRDMA_AE_INVALID_AH_ENTRY:
  3535. case IRDMA_AE_LLP_RECEIVED_MPA_CRC_ERROR:
  3536. case IRDMA_AE_LLP_SEGMENT_TOO_SMALL:
  3537. case IRDMA_AE_LLP_TOO_MANY_RETRIES:
  3538. case IRDMA_AE_LLP_DOUBT_REACHABILITY:
  3539. case IRDMA_AE_LLP_CONNECTION_ESTABLISHED:
  3540. case IRDMA_AE_RESET_SENT:
  3541. case IRDMA_AE_TERMINATE_SENT:
  3542. case IRDMA_AE_RESET_NOT_SENT:
  3543. case IRDMA_AE_LCE_QP_CATASTROPHIC:
  3544. case IRDMA_AE_QP_SUSPEND_COMPLETE:
  3545. case IRDMA_AE_UDA_L4LEN_INVALID:
  3546. info->qp = true;
  3547. info->compl_ctx = compl_ctx;
  3548. break;
  3549. case IRDMA_AE_LCE_CQ_CATASTROPHIC:
  3550. info->cq = true;
  3551. info->compl_ctx = compl_ctx << 1;
  3552. ae_src = IRDMA_AE_SOURCE_RSVD;
  3553. break;
  3554. case IRDMA_AE_ROCE_EMPTY_MCG:
  3555. case IRDMA_AE_ROCE_BAD_MC_IP_ADDR:
  3556. case IRDMA_AE_ROCE_BAD_MC_QPID:
  3557. case IRDMA_AE_MCG_QP_PROTOCOL_MISMATCH:
  3558. fallthrough;
  3559. case IRDMA_AE_LLP_CONNECTION_RESET:
  3560. case IRDMA_AE_LLP_SYN_RECEIVED:
  3561. case IRDMA_AE_LLP_FIN_RECEIVED:
  3562. case IRDMA_AE_LLP_CLOSE_COMPLETE:
  3563. case IRDMA_AE_LLP_TERMINATE_RECEIVED:
  3564. case IRDMA_AE_RDMAP_ROE_BAD_LLP_CLOSE:
  3565. ae_src = IRDMA_AE_SOURCE_RSVD;
  3566. info->qp = true;
  3567. info->compl_ctx = compl_ctx;
  3568. break;
  3569. default:
  3570. break;
  3571. }
  3572. switch (ae_src) {
  3573. case IRDMA_AE_SOURCE_RQ:
  3574. case IRDMA_AE_SOURCE_RQ_0011:
  3575. info->qp = true;
  3576. info->rq = true;
  3577. info->compl_ctx = compl_ctx;
  3578. break;
  3579. case IRDMA_AE_SOURCE_CQ:
  3580. case IRDMA_AE_SOURCE_CQ_0110:
  3581. case IRDMA_AE_SOURCE_CQ_1010:
  3582. case IRDMA_AE_SOURCE_CQ_1110:
  3583. info->cq = true;
  3584. info->compl_ctx = compl_ctx << 1;
  3585. break;
  3586. case IRDMA_AE_SOURCE_SQ:
  3587. case IRDMA_AE_SOURCE_SQ_0111:
  3588. info->qp = true;
  3589. info->sq = true;
  3590. info->compl_ctx = compl_ctx;
  3591. break;
  3592. case IRDMA_AE_SOURCE_IN_RR_WR:
  3593. case IRDMA_AE_SOURCE_IN_RR_WR_1011:
  3594. info->qp = true;
  3595. info->compl_ctx = compl_ctx;
  3596. info->in_rdrsp_wr = true;
  3597. break;
  3598. case IRDMA_AE_SOURCE_OUT_RR:
  3599. case IRDMA_AE_SOURCE_OUT_RR_1111:
  3600. info->qp = true;
  3601. info->compl_ctx = compl_ctx;
  3602. info->out_rdrsp = true;
  3603. break;
  3604. case IRDMA_AE_SOURCE_RSVD:
  3605. default:
  3606. break;
  3607. }
  3608. IRDMA_RING_MOVE_TAIL(aeq->aeq_ring);
  3609. if (!IRDMA_RING_CURRENT_TAIL(aeq->aeq_ring))
  3610. aeq->polarity ^= 1;
  3611. return 0;
  3612. }
  3613. /**
  3614. * irdma_sc_repost_aeq_entries - repost completed aeq entries
  3615. * @dev: sc device struct
  3616. * @count: allocate count
  3617. */
  3618. void irdma_sc_repost_aeq_entries(struct irdma_sc_dev *dev, u32 count)
  3619. {
  3620. writel(count, dev->hw_regs[IRDMA_AEQALLOC]);
  3621. }
  3622. /**
  3623. * irdma_sc_ccq_init - initialize control cq
  3624. * @cq: sc's cq ctruct
  3625. * @info: info for control cq initialization
  3626. */
  3627. int irdma_sc_ccq_init(struct irdma_sc_cq *cq, struct irdma_ccq_init_info *info)
  3628. {
  3629. u32 pble_obj_cnt;
  3630. if (info->num_elem < info->dev->hw_attrs.uk_attrs.min_hw_cq_size ||
  3631. info->num_elem > info->dev->hw_attrs.uk_attrs.max_hw_cq_size)
  3632. return -EINVAL;
  3633. if (info->ceq_id >= info->dev->hmc_fpm_misc.max_ceqs)
  3634. return -EINVAL;
  3635. pble_obj_cnt = info->dev->hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt;
  3636. if (info->virtual_map && info->first_pm_pbl_idx >= pble_obj_cnt)
  3637. return -EINVAL;
  3638. cq->cq_pa = info->cq_pa;
  3639. cq->cq_uk.cq_base = info->cq_base;
  3640. cq->shadow_area_pa = info->shadow_area_pa;
  3641. cq->cq_uk.shadow_area = info->shadow_area;
  3642. cq->shadow_read_threshold = info->shadow_read_threshold;
  3643. cq->dev = info->dev;
  3644. cq->ceq_id = info->ceq_id;
  3645. cq->cq_uk.cq_size = info->num_elem;
  3646. cq->cq_type = IRDMA_CQ_TYPE_CQP;
  3647. cq->ceqe_mask = info->ceqe_mask;
  3648. IRDMA_RING_INIT(cq->cq_uk.cq_ring, info->num_elem);
  3649. cq->cq_uk.cq_id = 0; /* control cq is id 0 always */
  3650. cq->ceq_id_valid = info->ceq_id_valid;
  3651. cq->tph_en = info->tph_en;
  3652. cq->tph_val = info->tph_val;
  3653. cq->cq_uk.avoid_mem_cflct = info->avoid_mem_cflct;
  3654. cq->pbl_list = info->pbl_list;
  3655. cq->virtual_map = info->virtual_map;
  3656. cq->pbl_chunk_size = info->pbl_chunk_size;
  3657. cq->first_pm_pbl_idx = info->first_pm_pbl_idx;
  3658. cq->cq_uk.polarity = true;
  3659. cq->vsi = info->vsi;
  3660. cq->cq_uk.cq_ack_db = cq->dev->cq_ack_db;
  3661. /* Only applicable to CQs other than CCQ so initialize to zero */
  3662. cq->cq_uk.cqe_alloc_db = NULL;
  3663. info->dev->ccq = cq;
  3664. return 0;
  3665. }
  3666. /**
  3667. * irdma_sc_ccq_create_done - poll cqp for ccq create
  3668. * @ccq: ccq sc struct
  3669. */
  3670. static inline int irdma_sc_ccq_create_done(struct irdma_sc_cq *ccq)
  3671. {
  3672. struct irdma_sc_cqp *cqp;
  3673. cqp = ccq->dev->cqp;
  3674. return irdma_sc_poll_for_cqp_op_done(cqp, IRDMA_CQP_OP_CREATE_CQ, NULL);
  3675. }
  3676. /**
  3677. * irdma_sc_ccq_create - create control cq
  3678. * @ccq: ccq sc struct
  3679. * @scratch: u64 saved to be used during cqp completion
  3680. * @check_overflow: overlow flag for ccq
  3681. * @post_sq: flag for cqp db to ring
  3682. */
  3683. int irdma_sc_ccq_create(struct irdma_sc_cq *ccq, u64 scratch,
  3684. bool check_overflow, bool post_sq)
  3685. {
  3686. int ret_code;
  3687. ret_code = irdma_sc_cq_create(ccq, scratch, check_overflow, post_sq);
  3688. if (ret_code)
  3689. return ret_code;
  3690. if (post_sq) {
  3691. ret_code = irdma_sc_ccq_create_done(ccq);
  3692. if (ret_code)
  3693. return ret_code;
  3694. }
  3695. ccq->dev->cqp->process_cqp_sds = irdma_cqp_sds_cmd;
  3696. return 0;
  3697. }
  3698. /**
  3699. * irdma_sc_ccq_destroy - destroy ccq during close
  3700. * @ccq: ccq sc struct
  3701. * @scratch: u64 saved to be used during cqp completion
  3702. * @post_sq: flag for cqp db to ring
  3703. */
  3704. int irdma_sc_ccq_destroy(struct irdma_sc_cq *ccq, u64 scratch, bool post_sq)
  3705. {
  3706. struct irdma_sc_cqp *cqp;
  3707. __le64 *wqe;
  3708. u64 hdr;
  3709. int ret_code = 0;
  3710. u32 tail, val, error;
  3711. cqp = ccq->dev->cqp;
  3712. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3713. if (!wqe)
  3714. return -ENOMEM;
  3715. set_64bit_val(wqe, 0, ccq->cq_uk.cq_size);
  3716. set_64bit_val(wqe, 8, (uintptr_t)ccq >> 1);
  3717. set_64bit_val(wqe, 40, ccq->shadow_area_pa);
  3718. hdr = ccq->cq_uk.cq_id |
  3719. FLD_LS_64(ccq->dev, (ccq->ceq_id_valid ? ccq->ceq_id : 0),
  3720. IRDMA_CQPSQ_CQ_CEQID) |
  3721. FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_DESTROY_CQ) |
  3722. FIELD_PREP(IRDMA_CQPSQ_CQ_ENCEQEMASK, ccq->ceqe_mask) |
  3723. FIELD_PREP(IRDMA_CQPSQ_CQ_CEQIDVALID, ccq->ceq_id_valid) |
  3724. FIELD_PREP(IRDMA_CQPSQ_TPHEN, ccq->tph_en) |
  3725. FIELD_PREP(IRDMA_CQPSQ_CQ_AVOIDMEMCNFLCT, ccq->cq_uk.avoid_mem_cflct) |
  3726. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3727. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3728. set_64bit_val(wqe, 24, hdr);
  3729. print_hex_dump_debug("WQE: CCQ_DESTROY WQE", DUMP_PREFIX_OFFSET, 16,
  3730. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3731. irdma_get_cqp_reg_info(cqp, &val, &tail, &error);
  3732. if (post_sq) {
  3733. irdma_sc_cqp_post_sq(cqp);
  3734. ret_code = irdma_cqp_poll_registers(cqp, tail,
  3735. cqp->dev->hw_attrs.max_done_count);
  3736. }
  3737. cqp->process_cqp_sds = irdma_update_sds_noccq;
  3738. return ret_code;
  3739. }
  3740. /**
  3741. * irdma_sc_init_iw_hmc() - queries fpm values using cqp and populates hmc_info
  3742. * @dev : ptr to irdma_dev struct
  3743. * @hmc_fn_id: hmc function id
  3744. */
  3745. int irdma_sc_init_iw_hmc(struct irdma_sc_dev *dev, u8 hmc_fn_id)
  3746. {
  3747. struct irdma_hmc_info *hmc_info;
  3748. struct irdma_hmc_fpm_misc *hmc_fpm_misc;
  3749. struct irdma_dma_mem query_fpm_mem;
  3750. int ret_code = 0;
  3751. u8 wait_type;
  3752. hmc_info = dev->hmc_info;
  3753. hmc_fpm_misc = &dev->hmc_fpm_misc;
  3754. query_fpm_mem.pa = dev->fpm_query_buf_pa;
  3755. query_fpm_mem.va = dev->fpm_query_buf;
  3756. hmc_info->hmc_fn_id = hmc_fn_id;
  3757. wait_type = (u8)IRDMA_CQP_WAIT_POLL_REGS;
  3758. ret_code = irdma_sc_query_fpm_val(dev->cqp, 0, hmc_info->hmc_fn_id,
  3759. &query_fpm_mem, true, wait_type);
  3760. if (ret_code)
  3761. return ret_code;
  3762. /* parse the fpm_query_buf and fill hmc obj info */
  3763. ret_code = irdma_sc_parse_fpm_query_buf(dev, query_fpm_mem.va, hmc_info,
  3764. hmc_fpm_misc);
  3765. print_hex_dump_debug("HMC: QUERY FPM BUFFER", DUMP_PREFIX_OFFSET, 16,
  3766. 8, query_fpm_mem.va, IRDMA_QUERY_FPM_BUF_SIZE,
  3767. false);
  3768. return ret_code;
  3769. }
  3770. /**
  3771. * irdma_sc_cfg_iw_fpm() - commits hmc obj cnt values using cqp
  3772. * command and populates fpm base address in hmc_info
  3773. * @dev : ptr to irdma_dev struct
  3774. * @hmc_fn_id: hmc function id
  3775. */
  3776. static int irdma_sc_cfg_iw_fpm(struct irdma_sc_dev *dev, u8 hmc_fn_id)
  3777. {
  3778. struct irdma_hmc_info *hmc_info;
  3779. struct irdma_hmc_obj_info *obj_info;
  3780. __le64 *buf;
  3781. struct irdma_dma_mem commit_fpm_mem;
  3782. int ret_code = 0;
  3783. u8 wait_type;
  3784. hmc_info = dev->hmc_info;
  3785. obj_info = hmc_info->hmc_obj;
  3786. buf = dev->fpm_commit_buf;
  3787. set_64bit_val(buf, 0, (u64)obj_info[IRDMA_HMC_IW_QP].cnt);
  3788. set_64bit_val(buf, 8, (u64)obj_info[IRDMA_HMC_IW_CQ].cnt);
  3789. set_64bit_val(buf, 16, (u64)0); /* RSRVD */
  3790. set_64bit_val(buf, 24, (u64)obj_info[IRDMA_HMC_IW_HTE].cnt);
  3791. set_64bit_val(buf, 32, (u64)obj_info[IRDMA_HMC_IW_ARP].cnt);
  3792. set_64bit_val(buf, 40, (u64)0); /* RSVD */
  3793. set_64bit_val(buf, 48, (u64)obj_info[IRDMA_HMC_IW_MR].cnt);
  3794. set_64bit_val(buf, 56, (u64)obj_info[IRDMA_HMC_IW_XF].cnt);
  3795. set_64bit_val(buf, 64, (u64)obj_info[IRDMA_HMC_IW_XFFL].cnt);
  3796. set_64bit_val(buf, 72, (u64)obj_info[IRDMA_HMC_IW_Q1].cnt);
  3797. set_64bit_val(buf, 80, (u64)obj_info[IRDMA_HMC_IW_Q1FL].cnt);
  3798. set_64bit_val(buf, 88,
  3799. (u64)obj_info[IRDMA_HMC_IW_TIMER].cnt);
  3800. set_64bit_val(buf, 96,
  3801. (u64)obj_info[IRDMA_HMC_IW_FSIMC].cnt);
  3802. set_64bit_val(buf, 104,
  3803. (u64)obj_info[IRDMA_HMC_IW_FSIAV].cnt);
  3804. set_64bit_val(buf, 112,
  3805. (u64)obj_info[IRDMA_HMC_IW_PBLE].cnt);
  3806. set_64bit_val(buf, 120, (u64)0); /* RSVD */
  3807. set_64bit_val(buf, 128, (u64)obj_info[IRDMA_HMC_IW_RRF].cnt);
  3808. set_64bit_val(buf, 136,
  3809. (u64)obj_info[IRDMA_HMC_IW_RRFFL].cnt);
  3810. set_64bit_val(buf, 144, (u64)obj_info[IRDMA_HMC_IW_HDR].cnt);
  3811. set_64bit_val(buf, 152, (u64)obj_info[IRDMA_HMC_IW_MD].cnt);
  3812. set_64bit_val(buf, 160,
  3813. (u64)obj_info[IRDMA_HMC_IW_OOISC].cnt);
  3814. set_64bit_val(buf, 168,
  3815. (u64)obj_info[IRDMA_HMC_IW_OOISCFFL].cnt);
  3816. commit_fpm_mem.pa = dev->fpm_commit_buf_pa;
  3817. commit_fpm_mem.va = dev->fpm_commit_buf;
  3818. wait_type = (u8)IRDMA_CQP_WAIT_POLL_REGS;
  3819. print_hex_dump_debug("HMC: COMMIT FPM BUFFER", DUMP_PREFIX_OFFSET, 16,
  3820. 8, commit_fpm_mem.va, IRDMA_COMMIT_FPM_BUF_SIZE,
  3821. false);
  3822. ret_code = irdma_sc_commit_fpm_val(dev->cqp, 0, hmc_info->hmc_fn_id,
  3823. &commit_fpm_mem, true, wait_type);
  3824. if (!ret_code)
  3825. irdma_sc_parse_fpm_commit_buf(dev, dev->fpm_commit_buf,
  3826. hmc_info->hmc_obj,
  3827. &hmc_info->sd_table.sd_cnt);
  3828. print_hex_dump_debug("HMC: COMMIT FPM BUFFER", DUMP_PREFIX_OFFSET, 16,
  3829. 8, commit_fpm_mem.va, IRDMA_COMMIT_FPM_BUF_SIZE,
  3830. false);
  3831. return ret_code;
  3832. }
  3833. /**
  3834. * cqp_sds_wqe_fill - fill cqp wqe doe sd
  3835. * @cqp: struct for cqp hw
  3836. * @info: sd info for wqe
  3837. * @scratch: u64 saved to be used during cqp completion
  3838. */
  3839. static int cqp_sds_wqe_fill(struct irdma_sc_cqp *cqp,
  3840. struct irdma_update_sds_info *info, u64 scratch)
  3841. {
  3842. u64 data;
  3843. u64 hdr;
  3844. __le64 *wqe;
  3845. int mem_entries, wqe_entries;
  3846. struct irdma_dma_mem *sdbuf = &cqp->sdbuf;
  3847. u64 offset = 0;
  3848. u32 wqe_idx;
  3849. wqe = irdma_sc_cqp_get_next_send_wqe_idx(cqp, scratch, &wqe_idx);
  3850. if (!wqe)
  3851. return -ENOMEM;
  3852. wqe_entries = (info->cnt > 3) ? 3 : info->cnt;
  3853. mem_entries = info->cnt - wqe_entries;
  3854. if (mem_entries) {
  3855. offset = wqe_idx * IRDMA_UPDATE_SD_BUFF_SIZE;
  3856. memcpy(((char *)sdbuf->va + offset), &info->entry[3], mem_entries << 4);
  3857. data = (u64)sdbuf->pa + offset;
  3858. } else {
  3859. data = 0;
  3860. }
  3861. data |= FIELD_PREP(IRDMA_CQPSQ_UPESD_HMCFNID, info->hmc_fn_id);
  3862. set_64bit_val(wqe, 16, data);
  3863. switch (wqe_entries) {
  3864. case 3:
  3865. set_64bit_val(wqe, 48,
  3866. (FIELD_PREP(IRDMA_CQPSQ_UPESD_SDCMD, info->entry[2].cmd) |
  3867. FIELD_PREP(IRDMA_CQPSQ_UPESD_ENTRY_VALID, 1)));
  3868. set_64bit_val(wqe, 56, info->entry[2].data);
  3869. fallthrough;
  3870. case 2:
  3871. set_64bit_val(wqe, 32,
  3872. (FIELD_PREP(IRDMA_CQPSQ_UPESD_SDCMD, info->entry[1].cmd) |
  3873. FIELD_PREP(IRDMA_CQPSQ_UPESD_ENTRY_VALID, 1)));
  3874. set_64bit_val(wqe, 40, info->entry[1].data);
  3875. fallthrough;
  3876. case 1:
  3877. set_64bit_val(wqe, 0,
  3878. FIELD_PREP(IRDMA_CQPSQ_UPESD_SDCMD, info->entry[0].cmd));
  3879. set_64bit_val(wqe, 8, info->entry[0].data);
  3880. break;
  3881. default:
  3882. break;
  3883. }
  3884. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE, IRDMA_CQP_OP_UPDATE_PE_SDS) |
  3885. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity) |
  3886. FIELD_PREP(IRDMA_CQPSQ_UPESD_ENTRY_COUNT, mem_entries);
  3887. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3888. set_64bit_val(wqe, 24, hdr);
  3889. if (mem_entries)
  3890. print_hex_dump_debug("WQE: UPDATE_PE_SDS WQE Buffer",
  3891. DUMP_PREFIX_OFFSET, 16, 8,
  3892. (char *)sdbuf->va + offset,
  3893. mem_entries << 4, false);
  3894. print_hex_dump_debug("WQE: UPDATE_PE_SDS WQE", DUMP_PREFIX_OFFSET, 16,
  3895. 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  3896. return 0;
  3897. }
  3898. /**
  3899. * irdma_update_pe_sds - cqp wqe for sd
  3900. * @dev: ptr to irdma_dev struct
  3901. * @info: sd info for sd's
  3902. * @scratch: u64 saved to be used during cqp completion
  3903. */
  3904. static int irdma_update_pe_sds(struct irdma_sc_dev *dev,
  3905. struct irdma_update_sds_info *info, u64 scratch)
  3906. {
  3907. struct irdma_sc_cqp *cqp = dev->cqp;
  3908. int ret_code;
  3909. ret_code = cqp_sds_wqe_fill(cqp, info, scratch);
  3910. if (!ret_code)
  3911. irdma_sc_cqp_post_sq(cqp);
  3912. return ret_code;
  3913. }
  3914. /**
  3915. * irdma_update_sds_noccq - update sd before ccq created
  3916. * @dev: sc device struct
  3917. * @info: sd info for sd's
  3918. */
  3919. int irdma_update_sds_noccq(struct irdma_sc_dev *dev,
  3920. struct irdma_update_sds_info *info)
  3921. {
  3922. u32 error, val, tail;
  3923. struct irdma_sc_cqp *cqp = dev->cqp;
  3924. int ret_code;
  3925. ret_code = cqp_sds_wqe_fill(cqp, info, 0);
  3926. if (ret_code)
  3927. return ret_code;
  3928. irdma_get_cqp_reg_info(cqp, &val, &tail, &error);
  3929. irdma_sc_cqp_post_sq(cqp);
  3930. return irdma_cqp_poll_registers(cqp, tail,
  3931. cqp->dev->hw_attrs.max_done_count);
  3932. }
  3933. /**
  3934. * irdma_sc_static_hmc_pages_allocated - cqp wqe to allocate hmc pages
  3935. * @cqp: struct for cqp hw
  3936. * @scratch: u64 saved to be used during cqp completion
  3937. * @hmc_fn_id: hmc function id
  3938. * @post_sq: flag for cqp db to ring
  3939. * @poll_registers: flag to poll register for cqp completion
  3940. */
  3941. int irdma_sc_static_hmc_pages_allocated(struct irdma_sc_cqp *cqp, u64 scratch,
  3942. u8 hmc_fn_id, bool post_sq,
  3943. bool poll_registers)
  3944. {
  3945. u64 hdr;
  3946. __le64 *wqe;
  3947. u32 tail, val, error;
  3948. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  3949. if (!wqe)
  3950. return -ENOMEM;
  3951. set_64bit_val(wqe, 16,
  3952. FIELD_PREP(IRDMA_SHMC_PAGE_ALLOCATED_HMC_FN_ID, hmc_fn_id));
  3953. hdr = FIELD_PREP(IRDMA_CQPSQ_OPCODE,
  3954. IRDMA_CQP_OP_SHMC_PAGES_ALLOCATED) |
  3955. FIELD_PREP(IRDMA_CQPSQ_WQEVALID, cqp->polarity);
  3956. dma_wmb(); /* make sure WQE is written before valid bit is set */
  3957. set_64bit_val(wqe, 24, hdr);
  3958. print_hex_dump_debug("WQE: SHMC_PAGES_ALLOCATED WQE",
  3959. DUMP_PREFIX_OFFSET, 16, 8, wqe,
  3960. IRDMA_CQP_WQE_SIZE * 8, false);
  3961. irdma_get_cqp_reg_info(cqp, &val, &tail, &error);
  3962. if (post_sq) {
  3963. irdma_sc_cqp_post_sq(cqp);
  3964. if (poll_registers)
  3965. /* check for cqp sq tail update */
  3966. return irdma_cqp_poll_registers(cqp, tail,
  3967. cqp->dev->hw_attrs.max_done_count);
  3968. else
  3969. return irdma_sc_poll_for_cqp_op_done(cqp,
  3970. IRDMA_CQP_OP_SHMC_PAGES_ALLOCATED,
  3971. NULL);
  3972. }
  3973. return 0;
  3974. }
  3975. /**
  3976. * irdma_cqp_ring_full - check if cqp ring is full
  3977. * @cqp: struct for cqp hw
  3978. */
  3979. static bool irdma_cqp_ring_full(struct irdma_sc_cqp *cqp)
  3980. {
  3981. return IRDMA_RING_FULL_ERR(cqp->sq_ring);
  3982. }
  3983. /**
  3984. * irdma_est_sd - returns approximate number of SDs for HMC
  3985. * @dev: sc device struct
  3986. * @hmc_info: hmc structure, size and count for HMC objects
  3987. */
  3988. static u32 irdma_est_sd(struct irdma_sc_dev *dev,
  3989. struct irdma_hmc_info *hmc_info)
  3990. {
  3991. int i;
  3992. u64 size = 0;
  3993. u64 sd;
  3994. for (i = IRDMA_HMC_IW_QP; i < IRDMA_HMC_IW_MAX; i++)
  3995. if (i != IRDMA_HMC_IW_PBLE)
  3996. size += round_up(hmc_info->hmc_obj[i].cnt *
  3997. hmc_info->hmc_obj[i].size, 512);
  3998. size += round_up(hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt *
  3999. hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].size, 512);
  4000. if (size & 0x1FFFFF)
  4001. sd = (size >> 21) + 1; /* add 1 for remainder */
  4002. else
  4003. sd = size >> 21;
  4004. if (sd > 0xFFFFFFFF) {
  4005. ibdev_dbg(to_ibdev(dev), "HMC: sd overflow[%lld]\n", sd);
  4006. sd = 0xFFFFFFFF - 1;
  4007. }
  4008. return (u32)sd;
  4009. }
  4010. /**
  4011. * irdma_sc_query_rdma_features_done - poll cqp for query features done
  4012. * @cqp: struct for cqp hw
  4013. */
  4014. static int irdma_sc_query_rdma_features_done(struct irdma_sc_cqp *cqp)
  4015. {
  4016. return irdma_sc_poll_for_cqp_op_done(cqp,
  4017. IRDMA_CQP_OP_QUERY_RDMA_FEATURES,
  4018. NULL);
  4019. }
  4020. /**
  4021. * irdma_sc_query_rdma_features - query RDMA features and FW ver
  4022. * @cqp: struct for cqp hw
  4023. * @buf: buffer to hold query info
  4024. * @scratch: u64 saved to be used during cqp completion
  4025. */
  4026. static int irdma_sc_query_rdma_features(struct irdma_sc_cqp *cqp,
  4027. struct irdma_dma_mem *buf, u64 scratch)
  4028. {
  4029. __le64 *wqe;
  4030. u64 temp;
  4031. wqe = irdma_sc_cqp_get_next_send_wqe(cqp, scratch);
  4032. if (!wqe)
  4033. return -ENOMEM;
  4034. temp = buf->pa;
  4035. set_64bit_val(wqe, 32, temp);
  4036. temp = FIELD_PREP(IRDMA_CQPSQ_QUERY_RDMA_FEATURES_WQEVALID,
  4037. cqp->polarity) |
  4038. FIELD_PREP(IRDMA_CQPSQ_QUERY_RDMA_FEATURES_BUF_LEN, buf->size) |
  4039. FIELD_PREP(IRDMA_CQPSQ_UP_OP, IRDMA_CQP_OP_QUERY_RDMA_FEATURES);
  4040. dma_wmb(); /* make sure WQE is written before valid bit is set */
  4041. set_64bit_val(wqe, 24, temp);
  4042. print_hex_dump_debug("WQE: QUERY RDMA FEATURES", DUMP_PREFIX_OFFSET,
  4043. 16, 8, wqe, IRDMA_CQP_WQE_SIZE * 8, false);
  4044. irdma_sc_cqp_post_sq(cqp);
  4045. return 0;
  4046. }
  4047. /**
  4048. * irdma_get_rdma_features - get RDMA features
  4049. * @dev: sc device struct
  4050. */
  4051. int irdma_get_rdma_features(struct irdma_sc_dev *dev)
  4052. {
  4053. int ret_code;
  4054. struct irdma_dma_mem feat_buf;
  4055. u64 temp;
  4056. u16 byte_idx, feat_type, feat_cnt, feat_idx;
  4057. feat_buf.size = ALIGN(IRDMA_FEATURE_BUF_SIZE,
  4058. IRDMA_FEATURE_BUF_ALIGNMENT);
  4059. feat_buf.va = dma_alloc_coherent(dev->hw->device, feat_buf.size,
  4060. &feat_buf.pa, GFP_KERNEL);
  4061. if (!feat_buf.va)
  4062. return -ENOMEM;
  4063. ret_code = irdma_sc_query_rdma_features(dev->cqp, &feat_buf, 0);
  4064. if (!ret_code)
  4065. ret_code = irdma_sc_query_rdma_features_done(dev->cqp);
  4066. if (ret_code)
  4067. goto exit;
  4068. get_64bit_val(feat_buf.va, 0, &temp);
  4069. feat_cnt = (u16)FIELD_GET(IRDMA_FEATURE_CNT, temp);
  4070. if (feat_cnt < 2) {
  4071. ret_code = -EINVAL;
  4072. goto exit;
  4073. } else if (feat_cnt > IRDMA_MAX_FEATURES) {
  4074. ibdev_dbg(to_ibdev(dev),
  4075. "DEV: feature buf size insufficient, retrying with larger buffer\n");
  4076. dma_free_coherent(dev->hw->device, feat_buf.size, feat_buf.va,
  4077. feat_buf.pa);
  4078. feat_buf.va = NULL;
  4079. feat_buf.size = ALIGN(8 * feat_cnt,
  4080. IRDMA_FEATURE_BUF_ALIGNMENT);
  4081. feat_buf.va = dma_alloc_coherent(dev->hw->device,
  4082. feat_buf.size, &feat_buf.pa,
  4083. GFP_KERNEL);
  4084. if (!feat_buf.va)
  4085. return -ENOMEM;
  4086. ret_code = irdma_sc_query_rdma_features(dev->cqp, &feat_buf, 0);
  4087. if (!ret_code)
  4088. ret_code = irdma_sc_query_rdma_features_done(dev->cqp);
  4089. if (ret_code)
  4090. goto exit;
  4091. get_64bit_val(feat_buf.va, 0, &temp);
  4092. feat_cnt = (u16)FIELD_GET(IRDMA_FEATURE_CNT, temp);
  4093. if (feat_cnt < 2) {
  4094. ret_code = -EINVAL;
  4095. goto exit;
  4096. }
  4097. }
  4098. print_hex_dump_debug("WQE: QUERY RDMA FEATURES", DUMP_PREFIX_OFFSET,
  4099. 16, 8, feat_buf.va, feat_cnt * 8, false);
  4100. for (byte_idx = 0, feat_idx = 0; feat_idx < min(feat_cnt, (u16)IRDMA_MAX_FEATURES);
  4101. feat_idx++, byte_idx += 8) {
  4102. get_64bit_val(feat_buf.va, byte_idx, &temp);
  4103. feat_type = FIELD_GET(IRDMA_FEATURE_TYPE, temp);
  4104. if (feat_type >= IRDMA_MAX_FEATURES) {
  4105. ibdev_dbg(to_ibdev(dev),
  4106. "DEV: found unrecognized feature type %d\n",
  4107. feat_type);
  4108. continue;
  4109. }
  4110. dev->feature_info[feat_type] = temp;
  4111. }
  4112. exit:
  4113. dma_free_coherent(dev->hw->device, feat_buf.size, feat_buf.va,
  4114. feat_buf.pa);
  4115. feat_buf.va = NULL;
  4116. return ret_code;
  4117. }
  4118. static u32 irdma_q1_cnt(struct irdma_sc_dev *dev,
  4119. struct irdma_hmc_info *hmc_info, u32 qpwanted)
  4120. {
  4121. u32 q1_cnt;
  4122. if (dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1) {
  4123. q1_cnt = roundup_pow_of_two(dev->hw_attrs.max_hw_ird * 2 * qpwanted);
  4124. } else {
  4125. if (dev->cqp->protocol_used != IRDMA_IWARP_PROTOCOL_ONLY)
  4126. q1_cnt = roundup_pow_of_two(dev->hw_attrs.max_hw_ird * 2 * qpwanted + 512);
  4127. else
  4128. q1_cnt = dev->hw_attrs.max_hw_ird * 2 * qpwanted;
  4129. }
  4130. return q1_cnt;
  4131. }
  4132. static void cfg_fpm_value_gen_1(struct irdma_sc_dev *dev,
  4133. struct irdma_hmc_info *hmc_info, u32 qpwanted)
  4134. {
  4135. hmc_info->hmc_obj[IRDMA_HMC_IW_XF].cnt = roundup_pow_of_two(qpwanted * dev->hw_attrs.max_hw_wqes);
  4136. }
  4137. static void cfg_fpm_value_gen_2(struct irdma_sc_dev *dev,
  4138. struct irdma_hmc_info *hmc_info, u32 qpwanted)
  4139. {
  4140. struct irdma_hmc_fpm_misc *hmc_fpm_misc = &dev->hmc_fpm_misc;
  4141. hmc_info->hmc_obj[IRDMA_HMC_IW_XF].cnt =
  4142. 4 * hmc_fpm_misc->xf_block_size * qpwanted;
  4143. hmc_info->hmc_obj[IRDMA_HMC_IW_HDR].cnt = qpwanted;
  4144. if (hmc_info->hmc_obj[IRDMA_HMC_IW_RRF].max_cnt)
  4145. hmc_info->hmc_obj[IRDMA_HMC_IW_RRF].cnt = 32 * qpwanted;
  4146. if (hmc_info->hmc_obj[IRDMA_HMC_IW_RRFFL].max_cnt)
  4147. hmc_info->hmc_obj[IRDMA_HMC_IW_RRFFL].cnt =
  4148. hmc_info->hmc_obj[IRDMA_HMC_IW_RRF].cnt /
  4149. hmc_fpm_misc->rrf_block_size;
  4150. if (hmc_info->hmc_obj[IRDMA_HMC_IW_OOISC].max_cnt)
  4151. hmc_info->hmc_obj[IRDMA_HMC_IW_OOISC].cnt = 32 * qpwanted;
  4152. if (hmc_info->hmc_obj[IRDMA_HMC_IW_OOISCFFL].max_cnt)
  4153. hmc_info->hmc_obj[IRDMA_HMC_IW_OOISCFFL].cnt =
  4154. hmc_info->hmc_obj[IRDMA_HMC_IW_OOISC].cnt /
  4155. hmc_fpm_misc->ooiscf_block_size;
  4156. }
  4157. /**
  4158. * irdma_cfg_fpm_val - configure HMC objects
  4159. * @dev: sc device struct
  4160. * @qp_count: desired qp count
  4161. */
  4162. int irdma_cfg_fpm_val(struct irdma_sc_dev *dev, u32 qp_count)
  4163. {
  4164. struct irdma_virt_mem virt_mem;
  4165. u32 i, mem_size;
  4166. u32 qpwanted, mrwanted, pblewanted;
  4167. u32 powerof2, hte;
  4168. u32 sd_needed;
  4169. u32 sd_diff;
  4170. u32 loop_count = 0;
  4171. struct irdma_hmc_info *hmc_info;
  4172. struct irdma_hmc_fpm_misc *hmc_fpm_misc;
  4173. int ret_code = 0;
  4174. hmc_info = dev->hmc_info;
  4175. hmc_fpm_misc = &dev->hmc_fpm_misc;
  4176. ret_code = irdma_sc_init_iw_hmc(dev, dev->hmc_fn_id);
  4177. if (ret_code) {
  4178. ibdev_dbg(to_ibdev(dev),
  4179. "HMC: irdma_sc_init_iw_hmc returned error_code = %d\n",
  4180. ret_code);
  4181. return ret_code;
  4182. }
  4183. for (i = IRDMA_HMC_IW_QP; i < IRDMA_HMC_IW_MAX; i++)
  4184. hmc_info->hmc_obj[i].cnt = hmc_info->hmc_obj[i].max_cnt;
  4185. sd_needed = irdma_est_sd(dev, hmc_info);
  4186. ibdev_dbg(to_ibdev(dev),
  4187. "HMC: FW max resources sd_needed[%08d] first_sd_index[%04d]\n",
  4188. sd_needed, hmc_info->first_sd_index);
  4189. ibdev_dbg(to_ibdev(dev), "HMC: sd count %d where max sd is %d\n",
  4190. hmc_info->sd_table.sd_cnt, hmc_fpm_misc->max_sds);
  4191. qpwanted = min(qp_count, hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt);
  4192. powerof2 = 1;
  4193. while (powerof2 <= qpwanted)
  4194. powerof2 *= 2;
  4195. powerof2 /= 2;
  4196. qpwanted = powerof2;
  4197. mrwanted = hmc_info->hmc_obj[IRDMA_HMC_IW_MR].max_cnt;
  4198. pblewanted = hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].max_cnt;
  4199. ibdev_dbg(to_ibdev(dev),
  4200. "HMC: req_qp=%d max_sd=%d, max_qp = %d, max_cq=%d, max_mr=%d, max_pble=%d, mc=%d, av=%d\n",
  4201. qp_count, hmc_fpm_misc->max_sds,
  4202. hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt,
  4203. hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].max_cnt,
  4204. hmc_info->hmc_obj[IRDMA_HMC_IW_MR].max_cnt,
  4205. hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].max_cnt,
  4206. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].max_cnt,
  4207. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].max_cnt);
  4208. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].cnt =
  4209. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].max_cnt;
  4210. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].cnt =
  4211. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].max_cnt;
  4212. hmc_info->hmc_obj[IRDMA_HMC_IW_ARP].cnt =
  4213. hmc_info->hmc_obj[IRDMA_HMC_IW_ARP].max_cnt;
  4214. hmc_info->hmc_obj[IRDMA_HMC_IW_APBVT_ENTRY].cnt = 1;
  4215. while (irdma_q1_cnt(dev, hmc_info, qpwanted) > hmc_info->hmc_obj[IRDMA_HMC_IW_Q1].max_cnt)
  4216. qpwanted /= 2;
  4217. do {
  4218. ++loop_count;
  4219. hmc_info->hmc_obj[IRDMA_HMC_IW_QP].cnt = qpwanted;
  4220. hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].cnt =
  4221. min(2 * qpwanted, hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].cnt);
  4222. hmc_info->hmc_obj[IRDMA_HMC_IW_RESERVED].cnt = 0; /* Reserved */
  4223. hmc_info->hmc_obj[IRDMA_HMC_IW_MR].cnt = mrwanted;
  4224. hte = round_up(qpwanted + hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].cnt, 512);
  4225. powerof2 = 1;
  4226. while (powerof2 < hte)
  4227. powerof2 *= 2;
  4228. hmc_info->hmc_obj[IRDMA_HMC_IW_HTE].cnt =
  4229. powerof2 * hmc_fpm_misc->ht_multiplier;
  4230. if (dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1)
  4231. cfg_fpm_value_gen_1(dev, hmc_info, qpwanted);
  4232. else
  4233. cfg_fpm_value_gen_2(dev, hmc_info, qpwanted);
  4234. hmc_info->hmc_obj[IRDMA_HMC_IW_Q1].cnt = irdma_q1_cnt(dev, hmc_info, qpwanted);
  4235. hmc_info->hmc_obj[IRDMA_HMC_IW_XFFL].cnt =
  4236. hmc_info->hmc_obj[IRDMA_HMC_IW_XF].cnt / hmc_fpm_misc->xf_block_size;
  4237. hmc_info->hmc_obj[IRDMA_HMC_IW_Q1FL].cnt =
  4238. hmc_info->hmc_obj[IRDMA_HMC_IW_Q1].cnt / hmc_fpm_misc->q1_block_size;
  4239. hmc_info->hmc_obj[IRDMA_HMC_IW_TIMER].cnt =
  4240. (round_up(qpwanted, 512) / 512 + 1) * hmc_fpm_misc->timer_bucket;
  4241. hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt = pblewanted;
  4242. sd_needed = irdma_est_sd(dev, hmc_info);
  4243. ibdev_dbg(to_ibdev(dev),
  4244. "HMC: sd_needed = %d, hmc_fpm_misc->max_sds=%d, mrwanted=%d, pblewanted=%d qpwanted=%d\n",
  4245. sd_needed, hmc_fpm_misc->max_sds, mrwanted,
  4246. pblewanted, qpwanted);
  4247. /* Do not reduce resources further. All objects fit with max SDs */
  4248. if (sd_needed <= hmc_fpm_misc->max_sds)
  4249. break;
  4250. sd_diff = sd_needed - hmc_fpm_misc->max_sds;
  4251. if (sd_diff > 128) {
  4252. if (!(loop_count % 2) && qpwanted > 128) {
  4253. qpwanted /= 2;
  4254. } else {
  4255. mrwanted /= 2;
  4256. pblewanted /= 2;
  4257. }
  4258. continue;
  4259. }
  4260. if (dev->cqp->hmc_profile != IRDMA_HMC_PROFILE_FAVOR_VF &&
  4261. pblewanted > (512 * FPM_MULTIPLIER * sd_diff)) {
  4262. pblewanted -= 256 * FPM_MULTIPLIER * sd_diff;
  4263. continue;
  4264. } else if (pblewanted > (100 * FPM_MULTIPLIER)) {
  4265. pblewanted -= 10 * FPM_MULTIPLIER;
  4266. } else if (pblewanted > FPM_MULTIPLIER) {
  4267. pblewanted -= FPM_MULTIPLIER;
  4268. } else if (qpwanted <= 128) {
  4269. if (hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].cnt > 256)
  4270. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].cnt /= 2;
  4271. if (hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].cnt > 256)
  4272. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].cnt /= 2;
  4273. }
  4274. if (mrwanted > FPM_MULTIPLIER)
  4275. mrwanted -= FPM_MULTIPLIER;
  4276. if (!(loop_count % 10) && qpwanted > 128) {
  4277. qpwanted /= 2;
  4278. if (hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].cnt > 256)
  4279. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].cnt /= 2;
  4280. }
  4281. } while (loop_count < 2000);
  4282. if (sd_needed > hmc_fpm_misc->max_sds) {
  4283. ibdev_dbg(to_ibdev(dev),
  4284. "HMC: cfg_fpm failed loop_cnt=%d, sd_needed=%d, max sd count %d\n",
  4285. loop_count, sd_needed, hmc_info->sd_table.sd_cnt);
  4286. return -EINVAL;
  4287. }
  4288. if (loop_count > 1 && sd_needed < hmc_fpm_misc->max_sds) {
  4289. pblewanted += (hmc_fpm_misc->max_sds - sd_needed) * 256 *
  4290. FPM_MULTIPLIER;
  4291. hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt = pblewanted;
  4292. sd_needed = irdma_est_sd(dev, hmc_info);
  4293. }
  4294. ibdev_dbg(to_ibdev(dev),
  4295. "HMC: loop_cnt=%d, sd_needed=%d, qpcnt = %d, cqcnt=%d, mrcnt=%d, pblecnt=%d, mc=%d, ah=%d, max sd count %d, first sd index %d\n",
  4296. loop_count, sd_needed,
  4297. hmc_info->hmc_obj[IRDMA_HMC_IW_QP].cnt,
  4298. hmc_info->hmc_obj[IRDMA_HMC_IW_CQ].cnt,
  4299. hmc_info->hmc_obj[IRDMA_HMC_IW_MR].cnt,
  4300. hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].cnt,
  4301. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].cnt,
  4302. hmc_info->hmc_obj[IRDMA_HMC_IW_FSIAV].cnt,
  4303. hmc_info->sd_table.sd_cnt, hmc_info->first_sd_index);
  4304. ret_code = irdma_sc_cfg_iw_fpm(dev, dev->hmc_fn_id);
  4305. if (ret_code) {
  4306. ibdev_dbg(to_ibdev(dev),
  4307. "HMC: cfg_iw_fpm returned error_code[x%08X]\n",
  4308. readl(dev->hw_regs[IRDMA_CQPERRCODES]));
  4309. return ret_code;
  4310. }
  4311. mem_size = sizeof(struct irdma_hmc_sd_entry) *
  4312. (hmc_info->sd_table.sd_cnt + hmc_info->first_sd_index + 1);
  4313. virt_mem.size = mem_size;
  4314. virt_mem.va = kzalloc(virt_mem.size, GFP_KERNEL);
  4315. if (!virt_mem.va) {
  4316. ibdev_dbg(to_ibdev(dev),
  4317. "HMC: failed to allocate memory for sd_entry buffer\n");
  4318. return -ENOMEM;
  4319. }
  4320. hmc_info->sd_table.sd_entry = virt_mem.va;
  4321. return ret_code;
  4322. }
  4323. /**
  4324. * irdma_exec_cqp_cmd - execute cqp cmd when wqe are available
  4325. * @dev: rdma device
  4326. * @pcmdinfo: cqp command info
  4327. */
  4328. static int irdma_exec_cqp_cmd(struct irdma_sc_dev *dev,
  4329. struct cqp_cmds_info *pcmdinfo)
  4330. {
  4331. int status;
  4332. struct irdma_dma_mem val_mem;
  4333. bool alloc = false;
  4334. dev->cqp_cmd_stats[pcmdinfo->cqp_cmd]++;
  4335. switch (pcmdinfo->cqp_cmd) {
  4336. case IRDMA_OP_CEQ_DESTROY:
  4337. status = irdma_sc_ceq_destroy(pcmdinfo->in.u.ceq_destroy.ceq,
  4338. pcmdinfo->in.u.ceq_destroy.scratch,
  4339. pcmdinfo->post_sq);
  4340. break;
  4341. case IRDMA_OP_AEQ_DESTROY:
  4342. status = irdma_sc_aeq_destroy(pcmdinfo->in.u.aeq_destroy.aeq,
  4343. pcmdinfo->in.u.aeq_destroy.scratch,
  4344. pcmdinfo->post_sq);
  4345. break;
  4346. case IRDMA_OP_CEQ_CREATE:
  4347. status = irdma_sc_ceq_create(pcmdinfo->in.u.ceq_create.ceq,
  4348. pcmdinfo->in.u.ceq_create.scratch,
  4349. pcmdinfo->post_sq);
  4350. break;
  4351. case IRDMA_OP_AEQ_CREATE:
  4352. status = irdma_sc_aeq_create(pcmdinfo->in.u.aeq_create.aeq,
  4353. pcmdinfo->in.u.aeq_create.scratch,
  4354. pcmdinfo->post_sq);
  4355. break;
  4356. case IRDMA_OP_QP_UPLOAD_CONTEXT:
  4357. status = irdma_sc_qp_upload_context(pcmdinfo->in.u.qp_upload_context.dev,
  4358. &pcmdinfo->in.u.qp_upload_context.info,
  4359. pcmdinfo->in.u.qp_upload_context.scratch,
  4360. pcmdinfo->post_sq);
  4361. break;
  4362. case IRDMA_OP_CQ_CREATE:
  4363. status = irdma_sc_cq_create(pcmdinfo->in.u.cq_create.cq,
  4364. pcmdinfo->in.u.cq_create.scratch,
  4365. pcmdinfo->in.u.cq_create.check_overflow,
  4366. pcmdinfo->post_sq);
  4367. break;
  4368. case IRDMA_OP_CQ_MODIFY:
  4369. status = irdma_sc_cq_modify(pcmdinfo->in.u.cq_modify.cq,
  4370. &pcmdinfo->in.u.cq_modify.info,
  4371. pcmdinfo->in.u.cq_modify.scratch,
  4372. pcmdinfo->post_sq);
  4373. break;
  4374. case IRDMA_OP_CQ_DESTROY:
  4375. status = irdma_sc_cq_destroy(pcmdinfo->in.u.cq_destroy.cq,
  4376. pcmdinfo->in.u.cq_destroy.scratch,
  4377. pcmdinfo->post_sq);
  4378. break;
  4379. case IRDMA_OP_QP_FLUSH_WQES:
  4380. status = irdma_sc_qp_flush_wqes(pcmdinfo->in.u.qp_flush_wqes.qp,
  4381. &pcmdinfo->in.u.qp_flush_wqes.info,
  4382. pcmdinfo->in.u.qp_flush_wqes.scratch,
  4383. pcmdinfo->post_sq);
  4384. break;
  4385. case IRDMA_OP_GEN_AE:
  4386. status = irdma_sc_gen_ae(pcmdinfo->in.u.gen_ae.qp,
  4387. &pcmdinfo->in.u.gen_ae.info,
  4388. pcmdinfo->in.u.gen_ae.scratch,
  4389. pcmdinfo->post_sq);
  4390. break;
  4391. case IRDMA_OP_MANAGE_PUSH_PAGE:
  4392. status = irdma_sc_manage_push_page(pcmdinfo->in.u.manage_push_page.cqp,
  4393. &pcmdinfo->in.u.manage_push_page.info,
  4394. pcmdinfo->in.u.manage_push_page.scratch,
  4395. pcmdinfo->post_sq);
  4396. break;
  4397. case IRDMA_OP_UPDATE_PE_SDS:
  4398. status = irdma_update_pe_sds(pcmdinfo->in.u.update_pe_sds.dev,
  4399. &pcmdinfo->in.u.update_pe_sds.info,
  4400. pcmdinfo->in.u.update_pe_sds.scratch);
  4401. break;
  4402. case IRDMA_OP_MANAGE_HMC_PM_FUNC_TABLE:
  4403. /* switch to calling through the call table */
  4404. status =
  4405. irdma_sc_manage_hmc_pm_func_table(pcmdinfo->in.u.manage_hmc_pm.dev->cqp,
  4406. &pcmdinfo->in.u.manage_hmc_pm.info,
  4407. pcmdinfo->in.u.manage_hmc_pm.scratch,
  4408. true);
  4409. break;
  4410. case IRDMA_OP_SUSPEND:
  4411. status = irdma_sc_suspend_qp(pcmdinfo->in.u.suspend_resume.cqp,
  4412. pcmdinfo->in.u.suspend_resume.qp,
  4413. pcmdinfo->in.u.suspend_resume.scratch);
  4414. break;
  4415. case IRDMA_OP_RESUME:
  4416. status = irdma_sc_resume_qp(pcmdinfo->in.u.suspend_resume.cqp,
  4417. pcmdinfo->in.u.suspend_resume.qp,
  4418. pcmdinfo->in.u.suspend_resume.scratch);
  4419. break;
  4420. case IRDMA_OP_QUERY_FPM_VAL:
  4421. val_mem.pa = pcmdinfo->in.u.query_fpm_val.fpm_val_pa;
  4422. val_mem.va = pcmdinfo->in.u.query_fpm_val.fpm_val_va;
  4423. status = irdma_sc_query_fpm_val(pcmdinfo->in.u.query_fpm_val.cqp,
  4424. pcmdinfo->in.u.query_fpm_val.scratch,
  4425. pcmdinfo->in.u.query_fpm_val.hmc_fn_id,
  4426. &val_mem, true, IRDMA_CQP_WAIT_EVENT);
  4427. break;
  4428. case IRDMA_OP_COMMIT_FPM_VAL:
  4429. val_mem.pa = pcmdinfo->in.u.commit_fpm_val.fpm_val_pa;
  4430. val_mem.va = pcmdinfo->in.u.commit_fpm_val.fpm_val_va;
  4431. status = irdma_sc_commit_fpm_val(pcmdinfo->in.u.commit_fpm_val.cqp,
  4432. pcmdinfo->in.u.commit_fpm_val.scratch,
  4433. pcmdinfo->in.u.commit_fpm_val.hmc_fn_id,
  4434. &val_mem,
  4435. true,
  4436. IRDMA_CQP_WAIT_EVENT);
  4437. break;
  4438. case IRDMA_OP_STATS_ALLOCATE:
  4439. alloc = true;
  4440. fallthrough;
  4441. case IRDMA_OP_STATS_FREE:
  4442. status = irdma_sc_manage_stats_inst(pcmdinfo->in.u.stats_manage.cqp,
  4443. &pcmdinfo->in.u.stats_manage.info,
  4444. alloc,
  4445. pcmdinfo->in.u.stats_manage.scratch);
  4446. break;
  4447. case IRDMA_OP_STATS_GATHER:
  4448. status = irdma_sc_gather_stats(pcmdinfo->in.u.stats_gather.cqp,
  4449. &pcmdinfo->in.u.stats_gather.info,
  4450. pcmdinfo->in.u.stats_gather.scratch);
  4451. break;
  4452. case IRDMA_OP_WS_MODIFY_NODE:
  4453. status = irdma_sc_manage_ws_node(pcmdinfo->in.u.ws_node.cqp,
  4454. &pcmdinfo->in.u.ws_node.info,
  4455. IRDMA_MODIFY_NODE,
  4456. pcmdinfo->in.u.ws_node.scratch);
  4457. break;
  4458. case IRDMA_OP_WS_DELETE_NODE:
  4459. status = irdma_sc_manage_ws_node(pcmdinfo->in.u.ws_node.cqp,
  4460. &pcmdinfo->in.u.ws_node.info,
  4461. IRDMA_DEL_NODE,
  4462. pcmdinfo->in.u.ws_node.scratch);
  4463. break;
  4464. case IRDMA_OP_WS_ADD_NODE:
  4465. status = irdma_sc_manage_ws_node(pcmdinfo->in.u.ws_node.cqp,
  4466. &pcmdinfo->in.u.ws_node.info,
  4467. IRDMA_ADD_NODE,
  4468. pcmdinfo->in.u.ws_node.scratch);
  4469. break;
  4470. case IRDMA_OP_SET_UP_MAP:
  4471. status = irdma_sc_set_up_map(pcmdinfo->in.u.up_map.cqp,
  4472. &pcmdinfo->in.u.up_map.info,
  4473. pcmdinfo->in.u.up_map.scratch);
  4474. break;
  4475. case IRDMA_OP_QUERY_RDMA_FEATURES:
  4476. status = irdma_sc_query_rdma_features(pcmdinfo->in.u.query_rdma.cqp,
  4477. &pcmdinfo->in.u.query_rdma.query_buff_mem,
  4478. pcmdinfo->in.u.query_rdma.scratch);
  4479. break;
  4480. case IRDMA_OP_DELETE_ARP_CACHE_ENTRY:
  4481. status = irdma_sc_del_arp_cache_entry(pcmdinfo->in.u.del_arp_cache_entry.cqp,
  4482. pcmdinfo->in.u.del_arp_cache_entry.scratch,
  4483. pcmdinfo->in.u.del_arp_cache_entry.arp_index,
  4484. pcmdinfo->post_sq);
  4485. break;
  4486. case IRDMA_OP_MANAGE_APBVT_ENTRY:
  4487. status = irdma_sc_manage_apbvt_entry(pcmdinfo->in.u.manage_apbvt_entry.cqp,
  4488. &pcmdinfo->in.u.manage_apbvt_entry.info,
  4489. pcmdinfo->in.u.manage_apbvt_entry.scratch,
  4490. pcmdinfo->post_sq);
  4491. break;
  4492. case IRDMA_OP_MANAGE_QHASH_TABLE_ENTRY:
  4493. status = irdma_sc_manage_qhash_table_entry(pcmdinfo->in.u.manage_qhash_table_entry.cqp,
  4494. &pcmdinfo->in.u.manage_qhash_table_entry.info,
  4495. pcmdinfo->in.u.manage_qhash_table_entry.scratch,
  4496. pcmdinfo->post_sq);
  4497. break;
  4498. case IRDMA_OP_QP_MODIFY:
  4499. status = irdma_sc_qp_modify(pcmdinfo->in.u.qp_modify.qp,
  4500. &pcmdinfo->in.u.qp_modify.info,
  4501. pcmdinfo->in.u.qp_modify.scratch,
  4502. pcmdinfo->post_sq);
  4503. break;
  4504. case IRDMA_OP_QP_CREATE:
  4505. status = irdma_sc_qp_create(pcmdinfo->in.u.qp_create.qp,
  4506. &pcmdinfo->in.u.qp_create.info,
  4507. pcmdinfo->in.u.qp_create.scratch,
  4508. pcmdinfo->post_sq);
  4509. break;
  4510. case IRDMA_OP_QP_DESTROY:
  4511. status = irdma_sc_qp_destroy(pcmdinfo->in.u.qp_destroy.qp,
  4512. pcmdinfo->in.u.qp_destroy.scratch,
  4513. pcmdinfo->in.u.qp_destroy.remove_hash_idx,
  4514. pcmdinfo->in.u.qp_destroy.ignore_mw_bnd,
  4515. pcmdinfo->post_sq);
  4516. break;
  4517. case IRDMA_OP_ALLOC_STAG:
  4518. status = irdma_sc_alloc_stag(pcmdinfo->in.u.alloc_stag.dev,
  4519. &pcmdinfo->in.u.alloc_stag.info,
  4520. pcmdinfo->in.u.alloc_stag.scratch,
  4521. pcmdinfo->post_sq);
  4522. break;
  4523. case IRDMA_OP_MR_REG_NON_SHARED:
  4524. status = irdma_sc_mr_reg_non_shared(pcmdinfo->in.u.mr_reg_non_shared.dev,
  4525. &pcmdinfo->in.u.mr_reg_non_shared.info,
  4526. pcmdinfo->in.u.mr_reg_non_shared.scratch,
  4527. pcmdinfo->post_sq);
  4528. break;
  4529. case IRDMA_OP_DEALLOC_STAG:
  4530. status = irdma_sc_dealloc_stag(pcmdinfo->in.u.dealloc_stag.dev,
  4531. &pcmdinfo->in.u.dealloc_stag.info,
  4532. pcmdinfo->in.u.dealloc_stag.scratch,
  4533. pcmdinfo->post_sq);
  4534. break;
  4535. case IRDMA_OP_MW_ALLOC:
  4536. status = irdma_sc_mw_alloc(pcmdinfo->in.u.mw_alloc.dev,
  4537. &pcmdinfo->in.u.mw_alloc.info,
  4538. pcmdinfo->in.u.mw_alloc.scratch,
  4539. pcmdinfo->post_sq);
  4540. break;
  4541. case IRDMA_OP_ADD_ARP_CACHE_ENTRY:
  4542. status = irdma_sc_add_arp_cache_entry(pcmdinfo->in.u.add_arp_cache_entry.cqp,
  4543. &pcmdinfo->in.u.add_arp_cache_entry.info,
  4544. pcmdinfo->in.u.add_arp_cache_entry.scratch,
  4545. pcmdinfo->post_sq);
  4546. break;
  4547. case IRDMA_OP_ALLOC_LOCAL_MAC_ENTRY:
  4548. status = irdma_sc_alloc_local_mac_entry(pcmdinfo->in.u.alloc_local_mac_entry.cqp,
  4549. pcmdinfo->in.u.alloc_local_mac_entry.scratch,
  4550. pcmdinfo->post_sq);
  4551. break;
  4552. case IRDMA_OP_ADD_LOCAL_MAC_ENTRY:
  4553. status = irdma_sc_add_local_mac_entry(pcmdinfo->in.u.add_local_mac_entry.cqp,
  4554. &pcmdinfo->in.u.add_local_mac_entry.info,
  4555. pcmdinfo->in.u.add_local_mac_entry.scratch,
  4556. pcmdinfo->post_sq);
  4557. break;
  4558. case IRDMA_OP_DELETE_LOCAL_MAC_ENTRY:
  4559. status = irdma_sc_del_local_mac_entry(pcmdinfo->in.u.del_local_mac_entry.cqp,
  4560. pcmdinfo->in.u.del_local_mac_entry.scratch,
  4561. pcmdinfo->in.u.del_local_mac_entry.entry_idx,
  4562. pcmdinfo->in.u.del_local_mac_entry.ignore_ref_count,
  4563. pcmdinfo->post_sq);
  4564. break;
  4565. case IRDMA_OP_AH_CREATE:
  4566. status = irdma_sc_create_ah(pcmdinfo->in.u.ah_create.cqp,
  4567. &pcmdinfo->in.u.ah_create.info,
  4568. pcmdinfo->in.u.ah_create.scratch);
  4569. break;
  4570. case IRDMA_OP_AH_DESTROY:
  4571. status = irdma_sc_destroy_ah(pcmdinfo->in.u.ah_destroy.cqp,
  4572. &pcmdinfo->in.u.ah_destroy.info,
  4573. pcmdinfo->in.u.ah_destroy.scratch);
  4574. break;
  4575. case IRDMA_OP_MC_CREATE:
  4576. status = irdma_sc_create_mcast_grp(pcmdinfo->in.u.mc_create.cqp,
  4577. &pcmdinfo->in.u.mc_create.info,
  4578. pcmdinfo->in.u.mc_create.scratch);
  4579. break;
  4580. case IRDMA_OP_MC_DESTROY:
  4581. status = irdma_sc_destroy_mcast_grp(pcmdinfo->in.u.mc_destroy.cqp,
  4582. &pcmdinfo->in.u.mc_destroy.info,
  4583. pcmdinfo->in.u.mc_destroy.scratch);
  4584. break;
  4585. case IRDMA_OP_MC_MODIFY:
  4586. status = irdma_sc_modify_mcast_grp(pcmdinfo->in.u.mc_modify.cqp,
  4587. &pcmdinfo->in.u.mc_modify.info,
  4588. pcmdinfo->in.u.mc_modify.scratch);
  4589. break;
  4590. default:
  4591. status = -EOPNOTSUPP;
  4592. break;
  4593. }
  4594. return status;
  4595. }
  4596. /**
  4597. * irdma_process_cqp_cmd - process all cqp commands
  4598. * @dev: sc device struct
  4599. * @pcmdinfo: cqp command info
  4600. */
  4601. int irdma_process_cqp_cmd(struct irdma_sc_dev *dev,
  4602. struct cqp_cmds_info *pcmdinfo)
  4603. {
  4604. int status = 0;
  4605. unsigned long flags;
  4606. spin_lock_irqsave(&dev->cqp_lock, flags);
  4607. if (list_empty(&dev->cqp_cmd_head) && !irdma_cqp_ring_full(dev->cqp))
  4608. status = irdma_exec_cqp_cmd(dev, pcmdinfo);
  4609. else
  4610. list_add_tail(&pcmdinfo->cqp_cmd_entry, &dev->cqp_cmd_head);
  4611. spin_unlock_irqrestore(&dev->cqp_lock, flags);
  4612. return status;
  4613. }
  4614. /**
  4615. * irdma_process_bh - called from tasklet for cqp list
  4616. * @dev: sc device struct
  4617. */
  4618. int irdma_process_bh(struct irdma_sc_dev *dev)
  4619. {
  4620. int status = 0;
  4621. struct cqp_cmds_info *pcmdinfo;
  4622. unsigned long flags;
  4623. spin_lock_irqsave(&dev->cqp_lock, flags);
  4624. while (!list_empty(&dev->cqp_cmd_head) &&
  4625. !irdma_cqp_ring_full(dev->cqp)) {
  4626. pcmdinfo = (struct cqp_cmds_info *)irdma_remove_cqp_head(dev);
  4627. status = irdma_exec_cqp_cmd(dev, pcmdinfo);
  4628. if (status)
  4629. break;
  4630. }
  4631. spin_unlock_irqrestore(&dev->cqp_lock, flags);
  4632. return status;
  4633. }
  4634. /**
  4635. * irdma_cfg_aeq- Configure AEQ interrupt
  4636. * @dev: pointer to the device structure
  4637. * @idx: vector index
  4638. * @enable: True to enable, False disables
  4639. */
  4640. void irdma_cfg_aeq(struct irdma_sc_dev *dev, u32 idx, bool enable)
  4641. {
  4642. u32 reg_val;
  4643. reg_val = FIELD_PREP(IRDMA_PFINT_AEQCTL_CAUSE_ENA, enable) |
  4644. FIELD_PREP(IRDMA_PFINT_AEQCTL_MSIX_INDX, idx) |
  4645. FIELD_PREP(IRDMA_PFINT_AEQCTL_ITR_INDX, 3);
  4646. writel(reg_val, dev->hw_regs[IRDMA_PFINT_AEQCTL]);
  4647. }
  4648. /**
  4649. * sc_vsi_update_stats - Update statistics
  4650. * @vsi: sc_vsi instance to update
  4651. */
  4652. void sc_vsi_update_stats(struct irdma_sc_vsi *vsi)
  4653. {
  4654. struct irdma_gather_stats *gather_stats;
  4655. struct irdma_gather_stats *last_gather_stats;
  4656. gather_stats = vsi->pestat->gather_info.gather_stats_va;
  4657. last_gather_stats = vsi->pestat->gather_info.last_gather_stats_va;
  4658. irdma_update_stats(&vsi->pestat->hw_stats, gather_stats,
  4659. last_gather_stats, vsi->dev->hw_stats_map,
  4660. vsi->dev->hw_attrs.max_stat_idx);
  4661. }
  4662. /**
  4663. * irdma_wait_pe_ready - Check if firmware is ready
  4664. * @dev: provides access to registers
  4665. */
  4666. static int irdma_wait_pe_ready(struct irdma_sc_dev *dev)
  4667. {
  4668. u32 statuscpu0;
  4669. u32 statuscpu1;
  4670. u32 statuscpu2;
  4671. u32 retrycount = 0;
  4672. do {
  4673. statuscpu0 = readl(dev->hw_regs[IRDMA_GLPE_CPUSTATUS0]);
  4674. statuscpu1 = readl(dev->hw_regs[IRDMA_GLPE_CPUSTATUS1]);
  4675. statuscpu2 = readl(dev->hw_regs[IRDMA_GLPE_CPUSTATUS2]);
  4676. if (statuscpu0 == 0x80 && statuscpu1 == 0x80 &&
  4677. statuscpu2 == 0x80)
  4678. return 0;
  4679. mdelay(1000);
  4680. } while (retrycount++ < dev->hw_attrs.max_pe_ready_count);
  4681. return -1;
  4682. }
  4683. static inline void irdma_sc_init_hw(struct irdma_sc_dev *dev)
  4684. {
  4685. switch (dev->hw_attrs.uk_attrs.hw_rev) {
  4686. case IRDMA_GEN_1:
  4687. i40iw_init_hw(dev);
  4688. break;
  4689. case IRDMA_GEN_2:
  4690. icrdma_init_hw(dev);
  4691. break;
  4692. }
  4693. }
  4694. /**
  4695. * irdma_sc_dev_init - Initialize control part of device
  4696. * @ver: version
  4697. * @dev: Device pointer
  4698. * @info: Device init info
  4699. */
  4700. int irdma_sc_dev_init(enum irdma_vers ver, struct irdma_sc_dev *dev,
  4701. struct irdma_device_init_info *info)
  4702. {
  4703. u32 val;
  4704. int ret_code = 0;
  4705. u8 db_size;
  4706. INIT_LIST_HEAD(&dev->cqp_cmd_head); /* for CQP command backlog */
  4707. mutex_init(&dev->ws_mutex);
  4708. dev->hmc_fn_id = info->hmc_fn_id;
  4709. dev->fpm_query_buf_pa = info->fpm_query_buf_pa;
  4710. dev->fpm_query_buf = info->fpm_query_buf;
  4711. dev->fpm_commit_buf_pa = info->fpm_commit_buf_pa;
  4712. dev->fpm_commit_buf = info->fpm_commit_buf;
  4713. dev->hw = info->hw;
  4714. dev->hw->hw_addr = info->bar0;
  4715. /* Setup the hardware limits, hmc may limit further */
  4716. dev->hw_attrs.min_hw_qp_id = IRDMA_MIN_IW_QP_ID;
  4717. dev->hw_attrs.min_hw_aeq_size = IRDMA_MIN_AEQ_ENTRIES;
  4718. dev->hw_attrs.max_hw_aeq_size = IRDMA_MAX_AEQ_ENTRIES;
  4719. dev->hw_attrs.min_hw_ceq_size = IRDMA_MIN_CEQ_ENTRIES;
  4720. dev->hw_attrs.max_hw_ceq_size = IRDMA_MAX_CEQ_ENTRIES;
  4721. dev->hw_attrs.uk_attrs.min_hw_cq_size = IRDMA_MIN_CQ_SIZE;
  4722. dev->hw_attrs.uk_attrs.max_hw_cq_size = IRDMA_MAX_CQ_SIZE;
  4723. dev->hw_attrs.uk_attrs.max_hw_wq_frags = IRDMA_MAX_WQ_FRAGMENT_COUNT;
  4724. dev->hw_attrs.uk_attrs.max_hw_read_sges = IRDMA_MAX_SGE_RD;
  4725. dev->hw_attrs.max_hw_outbound_msg_size = IRDMA_MAX_OUTBOUND_MSG_SIZE;
  4726. dev->hw_attrs.max_mr_size = IRDMA_MAX_MR_SIZE;
  4727. dev->hw_attrs.max_hw_inbound_msg_size = IRDMA_MAX_INBOUND_MSG_SIZE;
  4728. dev->hw_attrs.max_hw_device_pages = IRDMA_MAX_PUSH_PAGE_COUNT;
  4729. dev->hw_attrs.uk_attrs.max_hw_inline = IRDMA_MAX_INLINE_DATA_SIZE;
  4730. dev->hw_attrs.max_hw_wqes = IRDMA_MAX_WQ_ENTRIES;
  4731. dev->hw_attrs.max_qp_wr = IRDMA_MAX_QP_WRS(IRDMA_MAX_QUANTA_PER_WR);
  4732. dev->hw_attrs.uk_attrs.max_hw_rq_quanta = IRDMA_QP_SW_MAX_RQ_QUANTA;
  4733. dev->hw_attrs.uk_attrs.max_hw_wq_quanta = IRDMA_QP_SW_MAX_WQ_QUANTA;
  4734. dev->hw_attrs.max_hw_pds = IRDMA_MAX_PDS;
  4735. dev->hw_attrs.max_hw_ena_vf_count = IRDMA_MAX_PE_ENA_VF_COUNT;
  4736. dev->hw_attrs.max_pe_ready_count = 14;
  4737. dev->hw_attrs.max_done_count = IRDMA_DONE_COUNT;
  4738. dev->hw_attrs.max_sleep_count = IRDMA_SLEEP_COUNT;
  4739. dev->hw_attrs.max_cqp_compl_wait_time_ms = CQP_COMPL_WAIT_TIME_MS;
  4740. dev->hw_attrs.uk_attrs.hw_rev = ver;
  4741. irdma_sc_init_hw(dev);
  4742. if (irdma_wait_pe_ready(dev))
  4743. return -ETIMEDOUT;
  4744. val = readl(dev->hw_regs[IRDMA_GLPCI_LBARCTRL]);
  4745. db_size = (u8)FIELD_GET(IRDMA_GLPCI_LBARCTRL_PE_DB_SIZE, val);
  4746. if (db_size != IRDMA_PE_DB_SIZE_4M && db_size != IRDMA_PE_DB_SIZE_8M) {
  4747. ibdev_dbg(to_ibdev(dev),
  4748. "DEV: RDMA PE doorbell is not enabled in CSR val 0x%x db_size=%d\n",
  4749. val, db_size);
  4750. return -ENODEV;
  4751. }
  4752. dev->db_addr = dev->hw->hw_addr + (uintptr_t)dev->hw_regs[IRDMA_DB_ADDR_OFFSET];
  4753. return ret_code;
  4754. }
  4755. /**
  4756. * irdma_stat_val - Extract HW counter value from statistics buffer
  4757. * @stats_val: pointer to statistics buffer
  4758. * @byteoff: byte offset of counter value in the buffer (8B-aligned)
  4759. * @bitoff: bit offset of counter value within 8B entry
  4760. * @bitmask: maximum counter value (e.g. 0xffffff for 24-bit counter)
  4761. */
  4762. static inline u64 irdma_stat_val(const u64 *stats_val, u16 byteoff, u8 bitoff,
  4763. u64 bitmask)
  4764. {
  4765. u16 idx = byteoff / sizeof(*stats_val);
  4766. return (stats_val[idx] >> bitoff) & bitmask;
  4767. }
  4768. /**
  4769. * irdma_stat_delta - Calculate counter delta
  4770. * @new_val: updated counter value
  4771. * @old_val: last counter value
  4772. * @max_val: maximum counter value (e.g. 0xffffff for 24-bit counter)
  4773. */
  4774. static inline u64 irdma_stat_delta(u64 new_val, u64 old_val, u64 max_val)
  4775. {
  4776. if (new_val >= old_val)
  4777. return new_val - old_val;
  4778. /* roll-over case */
  4779. return max_val - old_val + new_val + 1;
  4780. }
  4781. /**
  4782. * irdma_update_stats - Update statistics
  4783. * @hw_stats: hw_stats instance to update
  4784. * @gather_stats: updated stat counters
  4785. * @last_gather_stats: last stat counters
  4786. * @map: HW stat map (hw_stats => gather_stats)
  4787. * @max_stat_idx: number of HW stats
  4788. */
  4789. void irdma_update_stats(struct irdma_dev_hw_stats *hw_stats,
  4790. struct irdma_gather_stats *gather_stats,
  4791. struct irdma_gather_stats *last_gather_stats,
  4792. const struct irdma_hw_stat_map *map, u16 max_stat_idx)
  4793. {
  4794. u64 *stats_val = hw_stats->stats_val;
  4795. u16 i;
  4796. for (i = 0; i < max_stat_idx; i++) {
  4797. u64 new_val = irdma_stat_val(gather_stats->val, map[i].byteoff,
  4798. map[i].bitoff, map[i].bitmask);
  4799. u64 last_val = irdma_stat_val(last_gather_stats->val,
  4800. map[i].byteoff, map[i].bitoff,
  4801. map[i].bitmask);
  4802. stats_val[i] +=
  4803. irdma_stat_delta(new_val, last_val, map[i].bitmask);
  4804. }
  4805. memcpy(last_gather_stats, gather_stats, sizeof(*last_gather_stats));
  4806. }