i40iw_ctrl.c 139 KB

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