i40iw_ctrl.c 147 KB

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