i40iw_ctrl.c 148 KB

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