i40iw_ctrl.c 150 KB

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