i40iw_ctrl.c 148 KB

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