qed_sriov.c 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/etherdevice.h>
  33. #include <linux/crc32.h>
  34. #include <linux/vmalloc.h>
  35. #include <linux/qed/qed_iov_if.h>
  36. #include "qed_cxt.h"
  37. #include "qed_hsi.h"
  38. #include "qed_hw.h"
  39. #include "qed_init_ops.h"
  40. #include "qed_int.h"
  41. #include "qed_mcp.h"
  42. #include "qed_reg_addr.h"
  43. #include "qed_sp.h"
  44. #include "qed_sriov.h"
  45. #include "qed_vf.h"
  46. static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
  47. u8 opcode,
  48. __le16 echo,
  49. union event_ring_data *data, u8 fw_return_code);
  50. static u8 qed_vf_calculate_legacy(struct qed_vf_info *p_vf)
  51. {
  52. u8 legacy = 0;
  53. if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
  54. ETH_HSI_VER_NO_PKT_LEN_TUNN)
  55. legacy |= QED_QCID_LEGACY_VF_RX_PROD;
  56. if (!(p_vf->acquire.vfdev_info.capabilities &
  57. VFPF_ACQUIRE_CAP_QUEUE_QIDS))
  58. legacy |= QED_QCID_LEGACY_VF_CID;
  59. return legacy;
  60. }
  61. /* IOV ramrods */
  62. static int qed_sp_vf_start(struct qed_hwfn *p_hwfn, struct qed_vf_info *p_vf)
  63. {
  64. struct vf_start_ramrod_data *p_ramrod = NULL;
  65. struct qed_spq_entry *p_ent = NULL;
  66. struct qed_sp_init_data init_data;
  67. int rc = -EINVAL;
  68. u8 fp_minor;
  69. /* Get SPQ entry */
  70. memset(&init_data, 0, sizeof(init_data));
  71. init_data.cid = qed_spq_get_cid(p_hwfn);
  72. init_data.opaque_fid = p_vf->opaque_fid;
  73. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  74. rc = qed_sp_init_request(p_hwfn, &p_ent,
  75. COMMON_RAMROD_VF_START,
  76. PROTOCOLID_COMMON, &init_data);
  77. if (rc)
  78. return rc;
  79. p_ramrod = &p_ent->ramrod.vf_start;
  80. p_ramrod->vf_id = GET_FIELD(p_vf->concrete_fid, PXP_CONCRETE_FID_VFID);
  81. p_ramrod->opaque_fid = cpu_to_le16(p_vf->opaque_fid);
  82. switch (p_hwfn->hw_info.personality) {
  83. case QED_PCI_ETH:
  84. p_ramrod->personality = PERSONALITY_ETH;
  85. break;
  86. case QED_PCI_ETH_ROCE:
  87. p_ramrod->personality = PERSONALITY_RDMA_AND_ETH;
  88. break;
  89. default:
  90. DP_NOTICE(p_hwfn, "Unknown VF personality %d\n",
  91. p_hwfn->hw_info.personality);
  92. return -EINVAL;
  93. }
  94. fp_minor = p_vf->acquire.vfdev_info.eth_fp_hsi_minor;
  95. if (fp_minor > ETH_HSI_VER_MINOR &&
  96. fp_minor != ETH_HSI_VER_NO_PKT_LEN_TUNN) {
  97. DP_VERBOSE(p_hwfn,
  98. QED_MSG_IOV,
  99. "VF [%d] - Requested fp hsi %02x.%02x which is slightly newer than PF's %02x.%02x; Configuring PFs version\n",
  100. p_vf->abs_vf_id,
  101. ETH_HSI_VER_MAJOR,
  102. fp_minor, ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
  103. fp_minor = ETH_HSI_VER_MINOR;
  104. }
  105. p_ramrod->hsi_fp_ver.major_ver_arr[ETH_VER_KEY] = ETH_HSI_VER_MAJOR;
  106. p_ramrod->hsi_fp_ver.minor_ver_arr[ETH_VER_KEY] = fp_minor;
  107. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  108. "VF[%d] - Starting using HSI %02x.%02x\n",
  109. p_vf->abs_vf_id, ETH_HSI_VER_MAJOR, fp_minor);
  110. return qed_spq_post(p_hwfn, p_ent, NULL);
  111. }
  112. static int qed_sp_vf_stop(struct qed_hwfn *p_hwfn,
  113. u32 concrete_vfid, u16 opaque_vfid)
  114. {
  115. struct vf_stop_ramrod_data *p_ramrod = NULL;
  116. struct qed_spq_entry *p_ent = NULL;
  117. struct qed_sp_init_data init_data;
  118. int rc = -EINVAL;
  119. /* Get SPQ entry */
  120. memset(&init_data, 0, sizeof(init_data));
  121. init_data.cid = qed_spq_get_cid(p_hwfn);
  122. init_data.opaque_fid = opaque_vfid;
  123. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  124. rc = qed_sp_init_request(p_hwfn, &p_ent,
  125. COMMON_RAMROD_VF_STOP,
  126. PROTOCOLID_COMMON, &init_data);
  127. if (rc)
  128. return rc;
  129. p_ramrod = &p_ent->ramrod.vf_stop;
  130. p_ramrod->vf_id = GET_FIELD(concrete_vfid, PXP_CONCRETE_FID_VFID);
  131. return qed_spq_post(p_hwfn, p_ent, NULL);
  132. }
  133. static bool qed_iov_is_valid_vfid(struct qed_hwfn *p_hwfn,
  134. int rel_vf_id,
  135. bool b_enabled_only, bool b_non_malicious)
  136. {
  137. if (!p_hwfn->pf_iov_info) {
  138. DP_NOTICE(p_hwfn->cdev, "No iov info\n");
  139. return false;
  140. }
  141. if ((rel_vf_id >= p_hwfn->cdev->p_iov_info->total_vfs) ||
  142. (rel_vf_id < 0))
  143. return false;
  144. if ((!p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_init) &&
  145. b_enabled_only)
  146. return false;
  147. if ((p_hwfn->pf_iov_info->vfs_array[rel_vf_id].b_malicious) &&
  148. b_non_malicious)
  149. return false;
  150. return true;
  151. }
  152. static struct qed_vf_info *qed_iov_get_vf_info(struct qed_hwfn *p_hwfn,
  153. u16 relative_vf_id,
  154. bool b_enabled_only)
  155. {
  156. struct qed_vf_info *vf = NULL;
  157. if (!p_hwfn->pf_iov_info) {
  158. DP_NOTICE(p_hwfn->cdev, "No iov info\n");
  159. return NULL;
  160. }
  161. if (qed_iov_is_valid_vfid(p_hwfn, relative_vf_id,
  162. b_enabled_only, false))
  163. vf = &p_hwfn->pf_iov_info->vfs_array[relative_vf_id];
  164. else
  165. DP_ERR(p_hwfn, "qed_iov_get_vf_info: VF[%d] is not enabled\n",
  166. relative_vf_id);
  167. return vf;
  168. }
  169. static struct qed_queue_cid *
  170. qed_iov_get_vf_rx_queue_cid(struct qed_vf_queue *p_queue)
  171. {
  172. int i;
  173. for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
  174. if (p_queue->cids[i].p_cid && !p_queue->cids[i].b_is_tx)
  175. return p_queue->cids[i].p_cid;
  176. }
  177. return NULL;
  178. }
  179. enum qed_iov_validate_q_mode {
  180. QED_IOV_VALIDATE_Q_NA,
  181. QED_IOV_VALIDATE_Q_ENABLE,
  182. QED_IOV_VALIDATE_Q_DISABLE,
  183. };
  184. static bool qed_iov_validate_queue_mode(struct qed_hwfn *p_hwfn,
  185. struct qed_vf_info *p_vf,
  186. u16 qid,
  187. enum qed_iov_validate_q_mode mode,
  188. bool b_is_tx)
  189. {
  190. int i;
  191. if (mode == QED_IOV_VALIDATE_Q_NA)
  192. return true;
  193. for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
  194. struct qed_vf_queue_cid *p_qcid;
  195. p_qcid = &p_vf->vf_queues[qid].cids[i];
  196. if (!p_qcid->p_cid)
  197. continue;
  198. if (p_qcid->b_is_tx != b_is_tx)
  199. continue;
  200. return mode == QED_IOV_VALIDATE_Q_ENABLE;
  201. }
  202. /* In case we haven't found any valid cid, then its disabled */
  203. return mode == QED_IOV_VALIDATE_Q_DISABLE;
  204. }
  205. static bool qed_iov_validate_rxq(struct qed_hwfn *p_hwfn,
  206. struct qed_vf_info *p_vf,
  207. u16 rx_qid,
  208. enum qed_iov_validate_q_mode mode)
  209. {
  210. if (rx_qid >= p_vf->num_rxqs) {
  211. DP_VERBOSE(p_hwfn,
  212. QED_MSG_IOV,
  213. "VF[0x%02x] - can't touch Rx queue[%04x]; Only 0x%04x are allocated\n",
  214. p_vf->abs_vf_id, rx_qid, p_vf->num_rxqs);
  215. return false;
  216. }
  217. return qed_iov_validate_queue_mode(p_hwfn, p_vf, rx_qid, mode, false);
  218. }
  219. static bool qed_iov_validate_txq(struct qed_hwfn *p_hwfn,
  220. struct qed_vf_info *p_vf,
  221. u16 tx_qid,
  222. enum qed_iov_validate_q_mode mode)
  223. {
  224. if (tx_qid >= p_vf->num_txqs) {
  225. DP_VERBOSE(p_hwfn,
  226. QED_MSG_IOV,
  227. "VF[0x%02x] - can't touch Tx queue[%04x]; Only 0x%04x are allocated\n",
  228. p_vf->abs_vf_id, tx_qid, p_vf->num_txqs);
  229. return false;
  230. }
  231. return qed_iov_validate_queue_mode(p_hwfn, p_vf, tx_qid, mode, true);
  232. }
  233. static bool qed_iov_validate_sb(struct qed_hwfn *p_hwfn,
  234. struct qed_vf_info *p_vf, u16 sb_idx)
  235. {
  236. int i;
  237. for (i = 0; i < p_vf->num_sbs; i++)
  238. if (p_vf->igu_sbs[i] == sb_idx)
  239. return true;
  240. DP_VERBOSE(p_hwfn,
  241. QED_MSG_IOV,
  242. "VF[0%02x] - tried using sb_idx %04x which doesn't exist as one of its 0x%02x SBs\n",
  243. p_vf->abs_vf_id, sb_idx, p_vf->num_sbs);
  244. return false;
  245. }
  246. static bool qed_iov_validate_active_rxq(struct qed_hwfn *p_hwfn,
  247. struct qed_vf_info *p_vf)
  248. {
  249. u8 i;
  250. for (i = 0; i < p_vf->num_rxqs; i++)
  251. if (qed_iov_validate_queue_mode(p_hwfn, p_vf, i,
  252. QED_IOV_VALIDATE_Q_ENABLE,
  253. false))
  254. return true;
  255. return false;
  256. }
  257. static bool qed_iov_validate_active_txq(struct qed_hwfn *p_hwfn,
  258. struct qed_vf_info *p_vf)
  259. {
  260. u8 i;
  261. for (i = 0; i < p_vf->num_txqs; i++)
  262. if (qed_iov_validate_queue_mode(p_hwfn, p_vf, i,
  263. QED_IOV_VALIDATE_Q_ENABLE,
  264. true))
  265. return true;
  266. return false;
  267. }
  268. static int qed_iov_post_vf_bulletin(struct qed_hwfn *p_hwfn,
  269. int vfid, struct qed_ptt *p_ptt)
  270. {
  271. struct qed_bulletin_content *p_bulletin;
  272. int crc_size = sizeof(p_bulletin->crc);
  273. struct qed_dmae_params params;
  274. struct qed_vf_info *p_vf;
  275. p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  276. if (!p_vf)
  277. return -EINVAL;
  278. if (!p_vf->vf_bulletin)
  279. return -EINVAL;
  280. p_bulletin = p_vf->bulletin.p_virt;
  281. /* Increment bulletin board version and compute crc */
  282. p_bulletin->version++;
  283. p_bulletin->crc = crc32(0, (u8 *)p_bulletin + crc_size,
  284. p_vf->bulletin.size - crc_size);
  285. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  286. "Posting Bulletin 0x%08x to VF[%d] (CRC 0x%08x)\n",
  287. p_bulletin->version, p_vf->relative_vf_id, p_bulletin->crc);
  288. /* propagate bulletin board via dmae to vm memory */
  289. memset(&params, 0, sizeof(params));
  290. params.flags = QED_DMAE_FLAG_VF_DST;
  291. params.dst_vfid = p_vf->abs_vf_id;
  292. return qed_dmae_host2host(p_hwfn, p_ptt, p_vf->bulletin.phys,
  293. p_vf->vf_bulletin, p_vf->bulletin.size / 4,
  294. &params);
  295. }
  296. static int qed_iov_pci_cfg_info(struct qed_dev *cdev)
  297. {
  298. struct qed_hw_sriov_info *iov = cdev->p_iov_info;
  299. int pos = iov->pos;
  300. DP_VERBOSE(cdev, QED_MSG_IOV, "sriov ext pos %d\n", pos);
  301. pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
  302. pci_read_config_word(cdev->pdev,
  303. pos + PCI_SRIOV_TOTAL_VF, &iov->total_vfs);
  304. pci_read_config_word(cdev->pdev,
  305. pos + PCI_SRIOV_INITIAL_VF, &iov->initial_vfs);
  306. pci_read_config_word(cdev->pdev, pos + PCI_SRIOV_NUM_VF, &iov->num_vfs);
  307. if (iov->num_vfs) {
  308. DP_VERBOSE(cdev,
  309. QED_MSG_IOV,
  310. "Number of VFs are already set to non-zero value. Ignoring PCI configuration value\n");
  311. iov->num_vfs = 0;
  312. }
  313. pci_read_config_word(cdev->pdev,
  314. pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
  315. pci_read_config_word(cdev->pdev,
  316. pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
  317. pci_read_config_word(cdev->pdev,
  318. pos + PCI_SRIOV_VF_DID, &iov->vf_device_id);
  319. pci_read_config_dword(cdev->pdev,
  320. pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
  321. pci_read_config_dword(cdev->pdev, pos + PCI_SRIOV_CAP, &iov->cap);
  322. pci_read_config_byte(cdev->pdev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
  323. DP_VERBOSE(cdev,
  324. QED_MSG_IOV,
  325. "IOV info: nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
  326. iov->nres,
  327. iov->cap,
  328. iov->ctrl,
  329. iov->total_vfs,
  330. iov->initial_vfs,
  331. iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
  332. /* Some sanity checks */
  333. if (iov->num_vfs > NUM_OF_VFS(cdev) ||
  334. iov->total_vfs > NUM_OF_VFS(cdev)) {
  335. /* This can happen only due to a bug. In this case we set
  336. * num_vfs to zero to avoid memory corruption in the code that
  337. * assumes max number of vfs
  338. */
  339. DP_NOTICE(cdev,
  340. "IOV: Unexpected number of vfs set: %d setting num_vf to zero\n",
  341. iov->num_vfs);
  342. iov->num_vfs = 0;
  343. iov->total_vfs = 0;
  344. }
  345. return 0;
  346. }
  347. static void qed_iov_setup_vfdb(struct qed_hwfn *p_hwfn)
  348. {
  349. struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
  350. struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
  351. struct qed_bulletin_content *p_bulletin_virt;
  352. dma_addr_t req_p, rply_p, bulletin_p;
  353. union pfvf_tlvs *p_reply_virt_addr;
  354. union vfpf_tlvs *p_req_virt_addr;
  355. u8 idx = 0;
  356. memset(p_iov_info->vfs_array, 0, sizeof(p_iov_info->vfs_array));
  357. p_req_virt_addr = p_iov_info->mbx_msg_virt_addr;
  358. req_p = p_iov_info->mbx_msg_phys_addr;
  359. p_reply_virt_addr = p_iov_info->mbx_reply_virt_addr;
  360. rply_p = p_iov_info->mbx_reply_phys_addr;
  361. p_bulletin_virt = p_iov_info->p_bulletins;
  362. bulletin_p = p_iov_info->bulletins_phys;
  363. if (!p_req_virt_addr || !p_reply_virt_addr || !p_bulletin_virt) {
  364. DP_ERR(p_hwfn,
  365. "qed_iov_setup_vfdb called without allocating mem first\n");
  366. return;
  367. }
  368. for (idx = 0; idx < p_iov->total_vfs; idx++) {
  369. struct qed_vf_info *vf = &p_iov_info->vfs_array[idx];
  370. u32 concrete;
  371. vf->vf_mbx.req_virt = p_req_virt_addr + idx;
  372. vf->vf_mbx.req_phys = req_p + idx * sizeof(union vfpf_tlvs);
  373. vf->vf_mbx.reply_virt = p_reply_virt_addr + idx;
  374. vf->vf_mbx.reply_phys = rply_p + idx * sizeof(union pfvf_tlvs);
  375. vf->state = VF_STOPPED;
  376. vf->b_init = false;
  377. vf->bulletin.phys = idx *
  378. sizeof(struct qed_bulletin_content) +
  379. bulletin_p;
  380. vf->bulletin.p_virt = p_bulletin_virt + idx;
  381. vf->bulletin.size = sizeof(struct qed_bulletin_content);
  382. vf->relative_vf_id = idx;
  383. vf->abs_vf_id = idx + p_iov->first_vf_in_pf;
  384. concrete = qed_vfid_to_concrete(p_hwfn, vf->abs_vf_id);
  385. vf->concrete_fid = concrete;
  386. vf->opaque_fid = (p_hwfn->hw_info.opaque_fid & 0xff) |
  387. (vf->abs_vf_id << 8);
  388. vf->vport_id = idx + 1;
  389. vf->num_mac_filters = QED_ETH_VF_NUM_MAC_FILTERS;
  390. vf->num_vlan_filters = QED_ETH_VF_NUM_VLAN_FILTERS;
  391. }
  392. }
  393. static int qed_iov_allocate_vfdb(struct qed_hwfn *p_hwfn)
  394. {
  395. struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
  396. void **p_v_addr;
  397. u16 num_vfs = 0;
  398. num_vfs = p_hwfn->cdev->p_iov_info->total_vfs;
  399. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  400. "qed_iov_allocate_vfdb for %d VFs\n", num_vfs);
  401. /* Allocate PF Mailbox buffer (per-VF) */
  402. p_iov_info->mbx_msg_size = sizeof(union vfpf_tlvs) * num_vfs;
  403. p_v_addr = &p_iov_info->mbx_msg_virt_addr;
  404. *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  405. p_iov_info->mbx_msg_size,
  406. &p_iov_info->mbx_msg_phys_addr,
  407. GFP_KERNEL);
  408. if (!*p_v_addr)
  409. return -ENOMEM;
  410. /* Allocate PF Mailbox Reply buffer (per-VF) */
  411. p_iov_info->mbx_reply_size = sizeof(union pfvf_tlvs) * num_vfs;
  412. p_v_addr = &p_iov_info->mbx_reply_virt_addr;
  413. *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  414. p_iov_info->mbx_reply_size,
  415. &p_iov_info->mbx_reply_phys_addr,
  416. GFP_KERNEL);
  417. if (!*p_v_addr)
  418. return -ENOMEM;
  419. p_iov_info->bulletins_size = sizeof(struct qed_bulletin_content) *
  420. num_vfs;
  421. p_v_addr = &p_iov_info->p_bulletins;
  422. *p_v_addr = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  423. p_iov_info->bulletins_size,
  424. &p_iov_info->bulletins_phys,
  425. GFP_KERNEL);
  426. if (!*p_v_addr)
  427. return -ENOMEM;
  428. DP_VERBOSE(p_hwfn,
  429. QED_MSG_IOV,
  430. "PF's Requests mailbox [%p virt 0x%llx phys], Response mailbox [%p virt 0x%llx phys] Bulletins [%p virt 0x%llx phys]\n",
  431. p_iov_info->mbx_msg_virt_addr,
  432. (u64) p_iov_info->mbx_msg_phys_addr,
  433. p_iov_info->mbx_reply_virt_addr,
  434. (u64) p_iov_info->mbx_reply_phys_addr,
  435. p_iov_info->p_bulletins, (u64) p_iov_info->bulletins_phys);
  436. return 0;
  437. }
  438. static void qed_iov_free_vfdb(struct qed_hwfn *p_hwfn)
  439. {
  440. struct qed_pf_iov *p_iov_info = p_hwfn->pf_iov_info;
  441. if (p_hwfn->pf_iov_info->mbx_msg_virt_addr)
  442. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  443. p_iov_info->mbx_msg_size,
  444. p_iov_info->mbx_msg_virt_addr,
  445. p_iov_info->mbx_msg_phys_addr);
  446. if (p_hwfn->pf_iov_info->mbx_reply_virt_addr)
  447. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  448. p_iov_info->mbx_reply_size,
  449. p_iov_info->mbx_reply_virt_addr,
  450. p_iov_info->mbx_reply_phys_addr);
  451. if (p_iov_info->p_bulletins)
  452. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  453. p_iov_info->bulletins_size,
  454. p_iov_info->p_bulletins,
  455. p_iov_info->bulletins_phys);
  456. }
  457. int qed_iov_alloc(struct qed_hwfn *p_hwfn)
  458. {
  459. struct qed_pf_iov *p_sriov;
  460. if (!IS_PF_SRIOV(p_hwfn)) {
  461. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  462. "No SR-IOV - no need for IOV db\n");
  463. return 0;
  464. }
  465. p_sriov = kzalloc(sizeof(*p_sriov), GFP_KERNEL);
  466. if (!p_sriov)
  467. return -ENOMEM;
  468. p_hwfn->pf_iov_info = p_sriov;
  469. qed_spq_register_async_cb(p_hwfn, PROTOCOLID_COMMON,
  470. qed_sriov_eqe_event);
  471. return qed_iov_allocate_vfdb(p_hwfn);
  472. }
  473. void qed_iov_setup(struct qed_hwfn *p_hwfn)
  474. {
  475. if (!IS_PF_SRIOV(p_hwfn) || !IS_PF_SRIOV_ALLOC(p_hwfn))
  476. return;
  477. qed_iov_setup_vfdb(p_hwfn);
  478. }
  479. void qed_iov_free(struct qed_hwfn *p_hwfn)
  480. {
  481. qed_spq_unregister_async_cb(p_hwfn, PROTOCOLID_COMMON);
  482. if (IS_PF_SRIOV_ALLOC(p_hwfn)) {
  483. qed_iov_free_vfdb(p_hwfn);
  484. kfree(p_hwfn->pf_iov_info);
  485. }
  486. }
  487. void qed_iov_free_hw_info(struct qed_dev *cdev)
  488. {
  489. kfree(cdev->p_iov_info);
  490. cdev->p_iov_info = NULL;
  491. }
  492. int qed_iov_hw_info(struct qed_hwfn *p_hwfn)
  493. {
  494. struct qed_dev *cdev = p_hwfn->cdev;
  495. int pos;
  496. int rc;
  497. if (IS_VF(p_hwfn->cdev))
  498. return 0;
  499. /* Learn the PCI configuration */
  500. pos = pci_find_ext_capability(p_hwfn->cdev->pdev,
  501. PCI_EXT_CAP_ID_SRIOV);
  502. if (!pos) {
  503. DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No PCIe IOV support\n");
  504. return 0;
  505. }
  506. /* Allocate a new struct for IOV information */
  507. cdev->p_iov_info = kzalloc(sizeof(*cdev->p_iov_info), GFP_KERNEL);
  508. if (!cdev->p_iov_info)
  509. return -ENOMEM;
  510. cdev->p_iov_info->pos = pos;
  511. rc = qed_iov_pci_cfg_info(cdev);
  512. if (rc)
  513. return rc;
  514. /* We want PF IOV to be synonemous with the existance of p_iov_info;
  515. * In case the capability is published but there are no VFs, simply
  516. * de-allocate the struct.
  517. */
  518. if (!cdev->p_iov_info->total_vfs) {
  519. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  520. "IOV capabilities, but no VFs are published\n");
  521. kfree(cdev->p_iov_info);
  522. cdev->p_iov_info = NULL;
  523. return 0;
  524. }
  525. /* First VF index based on offset is tricky:
  526. * - If ARI is supported [likely], offset - (16 - pf_id) would
  527. * provide the number for eng0. 2nd engine Vfs would begin
  528. * after the first engine's VFs.
  529. * - If !ARI, VFs would start on next device.
  530. * so offset - (256 - pf_id) would provide the number.
  531. * Utilize the fact that (256 - pf_id) is achieved only by later
  532. * to differentiate between the two.
  533. */
  534. if (p_hwfn->cdev->p_iov_info->offset < (256 - p_hwfn->abs_pf_id)) {
  535. u32 first = p_hwfn->cdev->p_iov_info->offset +
  536. p_hwfn->abs_pf_id - 16;
  537. cdev->p_iov_info->first_vf_in_pf = first;
  538. if (QED_PATH_ID(p_hwfn))
  539. cdev->p_iov_info->first_vf_in_pf -= MAX_NUM_VFS_BB;
  540. } else {
  541. u32 first = p_hwfn->cdev->p_iov_info->offset +
  542. p_hwfn->abs_pf_id - 256;
  543. cdev->p_iov_info->first_vf_in_pf = first;
  544. }
  545. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  546. "First VF in hwfn 0x%08x\n",
  547. cdev->p_iov_info->first_vf_in_pf);
  548. return 0;
  549. }
  550. bool _qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn,
  551. int vfid, bool b_fail_malicious)
  552. {
  553. /* Check PF supports sriov */
  554. if (IS_VF(p_hwfn->cdev) || !IS_QED_SRIOV(p_hwfn->cdev) ||
  555. !IS_PF_SRIOV_ALLOC(p_hwfn))
  556. return false;
  557. /* Check VF validity */
  558. if (!qed_iov_is_valid_vfid(p_hwfn, vfid, true, b_fail_malicious))
  559. return false;
  560. return true;
  561. }
  562. bool qed_iov_pf_sanity_check(struct qed_hwfn *p_hwfn, int vfid)
  563. {
  564. return _qed_iov_pf_sanity_check(p_hwfn, vfid, true);
  565. }
  566. static void qed_iov_set_vf_to_disable(struct qed_dev *cdev,
  567. u16 rel_vf_id, u8 to_disable)
  568. {
  569. struct qed_vf_info *vf;
  570. int i;
  571. for_each_hwfn(cdev, i) {
  572. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  573. vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
  574. if (!vf)
  575. continue;
  576. vf->to_disable = to_disable;
  577. }
  578. }
  579. static void qed_iov_set_vfs_to_disable(struct qed_dev *cdev, u8 to_disable)
  580. {
  581. u16 i;
  582. if (!IS_QED_SRIOV(cdev))
  583. return;
  584. for (i = 0; i < cdev->p_iov_info->total_vfs; i++)
  585. qed_iov_set_vf_to_disable(cdev, i, to_disable);
  586. }
  587. static void qed_iov_vf_pglue_clear_err(struct qed_hwfn *p_hwfn,
  588. struct qed_ptt *p_ptt, u8 abs_vfid)
  589. {
  590. qed_wr(p_hwfn, p_ptt,
  591. PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR + (abs_vfid >> 5) * 4,
  592. 1 << (abs_vfid & 0x1f));
  593. }
  594. static void qed_iov_vf_igu_reset(struct qed_hwfn *p_hwfn,
  595. struct qed_ptt *p_ptt, struct qed_vf_info *vf)
  596. {
  597. int i;
  598. /* Set VF masks and configuration - pretend */
  599. qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
  600. qed_wr(p_hwfn, p_ptt, IGU_REG_STATISTIC_NUM_VF_MSG_SENT, 0);
  601. /* unpretend */
  602. qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
  603. /* iterate over all queues, clear sb consumer */
  604. for (i = 0; i < vf->num_sbs; i++)
  605. qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
  606. vf->igu_sbs[i],
  607. vf->opaque_fid, true);
  608. }
  609. static void qed_iov_vf_igu_set_int(struct qed_hwfn *p_hwfn,
  610. struct qed_ptt *p_ptt,
  611. struct qed_vf_info *vf, bool enable)
  612. {
  613. u32 igu_vf_conf;
  614. qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
  615. igu_vf_conf = qed_rd(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION);
  616. if (enable)
  617. igu_vf_conf |= IGU_VF_CONF_MSI_MSIX_EN;
  618. else
  619. igu_vf_conf &= ~IGU_VF_CONF_MSI_MSIX_EN;
  620. qed_wr(p_hwfn, p_ptt, IGU_REG_VF_CONFIGURATION, igu_vf_conf);
  621. /* unpretend */
  622. qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
  623. }
  624. static int
  625. qed_iov_enable_vf_access_msix(struct qed_hwfn *p_hwfn,
  626. struct qed_ptt *p_ptt, u8 abs_vf_id, u8 num_sbs)
  627. {
  628. u8 current_max = 0;
  629. int i;
  630. /* For AH onward, configuration is per-PF. Find maximum of all
  631. * the currently enabled child VFs, and set the number to be that.
  632. */
  633. if (!QED_IS_BB(p_hwfn->cdev)) {
  634. qed_for_each_vf(p_hwfn, i) {
  635. struct qed_vf_info *p_vf;
  636. p_vf = qed_iov_get_vf_info(p_hwfn, (u16)i, true);
  637. if (!p_vf)
  638. continue;
  639. current_max = max_t(u8, current_max, p_vf->num_sbs);
  640. }
  641. }
  642. if (num_sbs > current_max)
  643. return qed_mcp_config_vf_msix(p_hwfn, p_ptt,
  644. abs_vf_id, num_sbs);
  645. return 0;
  646. }
  647. static int qed_iov_enable_vf_access(struct qed_hwfn *p_hwfn,
  648. struct qed_ptt *p_ptt,
  649. struct qed_vf_info *vf)
  650. {
  651. u32 igu_vf_conf = IGU_VF_CONF_FUNC_EN;
  652. int rc;
  653. /* It's possible VF was previously considered malicious -
  654. * clear the indication even if we're only going to disable VF.
  655. */
  656. vf->b_malicious = false;
  657. if (vf->to_disable)
  658. return 0;
  659. DP_VERBOSE(p_hwfn,
  660. QED_MSG_IOV,
  661. "Enable internal access for vf %x [abs %x]\n",
  662. vf->abs_vf_id, QED_VF_ABS_ID(p_hwfn, vf));
  663. qed_iov_vf_pglue_clear_err(p_hwfn, p_ptt, QED_VF_ABS_ID(p_hwfn, vf));
  664. qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
  665. rc = qed_iov_enable_vf_access_msix(p_hwfn, p_ptt,
  666. vf->abs_vf_id, vf->num_sbs);
  667. if (rc)
  668. return rc;
  669. qed_fid_pretend(p_hwfn, p_ptt, (u16) vf->concrete_fid);
  670. SET_FIELD(igu_vf_conf, IGU_VF_CONF_PARENT, p_hwfn->rel_pf_id);
  671. STORE_RT_REG(p_hwfn, IGU_REG_VF_CONFIGURATION_RT_OFFSET, igu_vf_conf);
  672. qed_init_run(p_hwfn, p_ptt, PHASE_VF, vf->abs_vf_id,
  673. p_hwfn->hw_info.hw_mode);
  674. /* unpretend */
  675. qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
  676. vf->state = VF_FREE;
  677. return rc;
  678. }
  679. /**
  680. * @brief qed_iov_config_perm_table - configure the permission
  681. * zone table.
  682. * In E4, queue zone permission table size is 320x9. There
  683. * are 320 VF queues for single engine device (256 for dual
  684. * engine device), and each entry has the following format:
  685. * {Valid, VF[7:0]}
  686. * @param p_hwfn
  687. * @param p_ptt
  688. * @param vf
  689. * @param enable
  690. */
  691. static void qed_iov_config_perm_table(struct qed_hwfn *p_hwfn,
  692. struct qed_ptt *p_ptt,
  693. struct qed_vf_info *vf, u8 enable)
  694. {
  695. u32 reg_addr, val;
  696. u16 qzone_id = 0;
  697. int qid;
  698. for (qid = 0; qid < vf->num_rxqs; qid++) {
  699. qed_fw_l2_queue(p_hwfn, vf->vf_queues[qid].fw_rx_qid,
  700. &qzone_id);
  701. reg_addr = PSWHST_REG_ZONE_PERMISSION_TABLE + qzone_id * 4;
  702. val = enable ? (vf->abs_vf_id | BIT(8)) : 0;
  703. qed_wr(p_hwfn, p_ptt, reg_addr, val);
  704. }
  705. }
  706. static void qed_iov_enable_vf_traffic(struct qed_hwfn *p_hwfn,
  707. struct qed_ptt *p_ptt,
  708. struct qed_vf_info *vf)
  709. {
  710. /* Reset vf in IGU - interrupts are still disabled */
  711. qed_iov_vf_igu_reset(p_hwfn, p_ptt, vf);
  712. qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 1);
  713. /* Permission Table */
  714. qed_iov_config_perm_table(p_hwfn, p_ptt, vf, true);
  715. }
  716. static u8 qed_iov_alloc_vf_igu_sbs(struct qed_hwfn *p_hwfn,
  717. struct qed_ptt *p_ptt,
  718. struct qed_vf_info *vf, u16 num_rx_queues)
  719. {
  720. struct qed_igu_block *p_block;
  721. struct cau_sb_entry sb_entry;
  722. int qid = 0;
  723. u32 val = 0;
  724. if (num_rx_queues > p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov)
  725. num_rx_queues = p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov;
  726. p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov -= num_rx_queues;
  727. SET_FIELD(val, IGU_MAPPING_LINE_FUNCTION_NUMBER, vf->abs_vf_id);
  728. SET_FIELD(val, IGU_MAPPING_LINE_VALID, 1);
  729. SET_FIELD(val, IGU_MAPPING_LINE_PF_VALID, 0);
  730. for (qid = 0; qid < num_rx_queues; qid++) {
  731. p_block = qed_get_igu_free_sb(p_hwfn, false);
  732. vf->igu_sbs[qid] = p_block->igu_sb_id;
  733. p_block->status &= ~QED_IGU_STATUS_FREE;
  734. SET_FIELD(val, IGU_MAPPING_LINE_VECTOR_NUMBER, qid);
  735. qed_wr(p_hwfn, p_ptt,
  736. IGU_REG_MAPPING_MEMORY +
  737. sizeof(u32) * p_block->igu_sb_id, val);
  738. /* Configure igu sb in CAU which were marked valid */
  739. qed_init_cau_sb_entry(p_hwfn, &sb_entry,
  740. p_hwfn->rel_pf_id, vf->abs_vf_id, 1);
  741. qed_dmae_host2grc(p_hwfn, p_ptt,
  742. (u64)(uintptr_t)&sb_entry,
  743. CAU_REG_SB_VAR_MEMORY +
  744. p_block->igu_sb_id * sizeof(u64), 2, 0);
  745. }
  746. vf->num_sbs = (u8) num_rx_queues;
  747. return vf->num_sbs;
  748. }
  749. static void qed_iov_free_vf_igu_sbs(struct qed_hwfn *p_hwfn,
  750. struct qed_ptt *p_ptt,
  751. struct qed_vf_info *vf)
  752. {
  753. struct qed_igu_info *p_info = p_hwfn->hw_info.p_igu_info;
  754. int idx, igu_id;
  755. u32 addr, val;
  756. /* Invalidate igu CAM lines and mark them as free */
  757. for (idx = 0; idx < vf->num_sbs; idx++) {
  758. igu_id = vf->igu_sbs[idx];
  759. addr = IGU_REG_MAPPING_MEMORY + sizeof(u32) * igu_id;
  760. val = qed_rd(p_hwfn, p_ptt, addr);
  761. SET_FIELD(val, IGU_MAPPING_LINE_VALID, 0);
  762. qed_wr(p_hwfn, p_ptt, addr, val);
  763. p_info->entry[igu_id].status |= QED_IGU_STATUS_FREE;
  764. p_hwfn->hw_info.p_igu_info->usage.free_cnt_iov++;
  765. }
  766. vf->num_sbs = 0;
  767. }
  768. static void qed_iov_set_link(struct qed_hwfn *p_hwfn,
  769. u16 vfid,
  770. struct qed_mcp_link_params *params,
  771. struct qed_mcp_link_state *link,
  772. struct qed_mcp_link_capabilities *p_caps)
  773. {
  774. struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
  775. vfid,
  776. false);
  777. struct qed_bulletin_content *p_bulletin;
  778. if (!p_vf)
  779. return;
  780. p_bulletin = p_vf->bulletin.p_virt;
  781. p_bulletin->req_autoneg = params->speed.autoneg;
  782. p_bulletin->req_adv_speed = params->speed.advertised_speeds;
  783. p_bulletin->req_forced_speed = params->speed.forced_speed;
  784. p_bulletin->req_autoneg_pause = params->pause.autoneg;
  785. p_bulletin->req_forced_rx = params->pause.forced_rx;
  786. p_bulletin->req_forced_tx = params->pause.forced_tx;
  787. p_bulletin->req_loopback = params->loopback_mode;
  788. p_bulletin->link_up = link->link_up;
  789. p_bulletin->speed = link->speed;
  790. p_bulletin->full_duplex = link->full_duplex;
  791. p_bulletin->autoneg = link->an;
  792. p_bulletin->autoneg_complete = link->an_complete;
  793. p_bulletin->parallel_detection = link->parallel_detection;
  794. p_bulletin->pfc_enabled = link->pfc_enabled;
  795. p_bulletin->partner_adv_speed = link->partner_adv_speed;
  796. p_bulletin->partner_tx_flow_ctrl_en = link->partner_tx_flow_ctrl_en;
  797. p_bulletin->partner_rx_flow_ctrl_en = link->partner_rx_flow_ctrl_en;
  798. p_bulletin->partner_adv_pause = link->partner_adv_pause;
  799. p_bulletin->sfp_tx_fault = link->sfp_tx_fault;
  800. p_bulletin->capability_speed = p_caps->speed_capabilities;
  801. }
  802. static int qed_iov_init_hw_for_vf(struct qed_hwfn *p_hwfn,
  803. struct qed_ptt *p_ptt,
  804. struct qed_iov_vf_init_params *p_params)
  805. {
  806. struct qed_mcp_link_capabilities link_caps;
  807. struct qed_mcp_link_params link_params;
  808. struct qed_mcp_link_state link_state;
  809. u8 num_of_vf_avaiable_chains = 0;
  810. struct qed_vf_info *vf = NULL;
  811. u16 qid, num_irqs;
  812. int rc = 0;
  813. u32 cids;
  814. u8 i;
  815. vf = qed_iov_get_vf_info(p_hwfn, p_params->rel_vf_id, false);
  816. if (!vf) {
  817. DP_ERR(p_hwfn, "qed_iov_init_hw_for_vf : vf is NULL\n");
  818. return -EINVAL;
  819. }
  820. if (vf->b_init) {
  821. DP_NOTICE(p_hwfn, "VF[%d] is already active.\n",
  822. p_params->rel_vf_id);
  823. return -EINVAL;
  824. }
  825. /* Perform sanity checking on the requested queue_id */
  826. for (i = 0; i < p_params->num_queues; i++) {
  827. u16 min_vf_qzone = FEAT_NUM(p_hwfn, QED_PF_L2_QUE);
  828. u16 max_vf_qzone = min_vf_qzone +
  829. FEAT_NUM(p_hwfn, QED_VF_L2_QUE) - 1;
  830. qid = p_params->req_rx_queue[i];
  831. if (qid < min_vf_qzone || qid > max_vf_qzone) {
  832. DP_NOTICE(p_hwfn,
  833. "Can't enable Rx qid [%04x] for VF[%d]: qids [0x%04x,...,0x%04x] available\n",
  834. qid,
  835. p_params->rel_vf_id,
  836. min_vf_qzone, max_vf_qzone);
  837. return -EINVAL;
  838. }
  839. qid = p_params->req_tx_queue[i];
  840. if (qid > max_vf_qzone) {
  841. DP_NOTICE(p_hwfn,
  842. "Can't enable Tx qid [%04x] for VF[%d]: max qid 0x%04x\n",
  843. qid, p_params->rel_vf_id, max_vf_qzone);
  844. return -EINVAL;
  845. }
  846. /* If client *really* wants, Tx qid can be shared with PF */
  847. if (qid < min_vf_qzone)
  848. DP_VERBOSE(p_hwfn,
  849. QED_MSG_IOV,
  850. "VF[%d] is using PF qid [0x%04x] for Txq[0x%02x]\n",
  851. p_params->rel_vf_id, qid, i);
  852. }
  853. /* Limit number of queues according to number of CIDs */
  854. qed_cxt_get_proto_cid_count(p_hwfn, PROTOCOLID_ETH, &cids);
  855. DP_VERBOSE(p_hwfn,
  856. QED_MSG_IOV,
  857. "VF[%d] - requesting to initialize for 0x%04x queues [0x%04x CIDs available]\n",
  858. vf->relative_vf_id, p_params->num_queues, (u16)cids);
  859. num_irqs = min_t(u16, p_params->num_queues, ((u16)cids));
  860. num_of_vf_avaiable_chains = qed_iov_alloc_vf_igu_sbs(p_hwfn,
  861. p_ptt,
  862. vf, num_irqs);
  863. if (!num_of_vf_avaiable_chains) {
  864. DP_ERR(p_hwfn, "no available igu sbs\n");
  865. return -ENOMEM;
  866. }
  867. /* Choose queue number and index ranges */
  868. vf->num_rxqs = num_of_vf_avaiable_chains;
  869. vf->num_txqs = num_of_vf_avaiable_chains;
  870. for (i = 0; i < vf->num_rxqs; i++) {
  871. struct qed_vf_queue *p_queue = &vf->vf_queues[i];
  872. p_queue->fw_rx_qid = p_params->req_rx_queue[i];
  873. p_queue->fw_tx_qid = p_params->req_tx_queue[i];
  874. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  875. "VF[%d] - Q[%d] SB %04x, qid [Rx %04x Tx %04x]\n",
  876. vf->relative_vf_id, i, vf->igu_sbs[i],
  877. p_queue->fw_rx_qid, p_queue->fw_tx_qid);
  878. }
  879. /* Update the link configuration in bulletin */
  880. memcpy(&link_params, qed_mcp_get_link_params(p_hwfn),
  881. sizeof(link_params));
  882. memcpy(&link_state, qed_mcp_get_link_state(p_hwfn), sizeof(link_state));
  883. memcpy(&link_caps, qed_mcp_get_link_capabilities(p_hwfn),
  884. sizeof(link_caps));
  885. qed_iov_set_link(p_hwfn, p_params->rel_vf_id,
  886. &link_params, &link_state, &link_caps);
  887. rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, vf);
  888. if (!rc) {
  889. vf->b_init = true;
  890. if (IS_LEAD_HWFN(p_hwfn))
  891. p_hwfn->cdev->p_iov_info->num_vfs++;
  892. }
  893. return rc;
  894. }
  895. static int qed_iov_release_hw_for_vf(struct qed_hwfn *p_hwfn,
  896. struct qed_ptt *p_ptt, u16 rel_vf_id)
  897. {
  898. struct qed_mcp_link_capabilities caps;
  899. struct qed_mcp_link_params params;
  900. struct qed_mcp_link_state link;
  901. struct qed_vf_info *vf = NULL;
  902. vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
  903. if (!vf) {
  904. DP_ERR(p_hwfn, "qed_iov_release_hw_for_vf : vf is NULL\n");
  905. return -EINVAL;
  906. }
  907. if (vf->bulletin.p_virt)
  908. memset(vf->bulletin.p_virt, 0, sizeof(*vf->bulletin.p_virt));
  909. memset(&vf->p_vf_info, 0, sizeof(vf->p_vf_info));
  910. /* Get the link configuration back in bulletin so
  911. * that when VFs are re-enabled they get the actual
  912. * link configuration.
  913. */
  914. memcpy(&params, qed_mcp_get_link_params(p_hwfn), sizeof(params));
  915. memcpy(&link, qed_mcp_get_link_state(p_hwfn), sizeof(link));
  916. memcpy(&caps, qed_mcp_get_link_capabilities(p_hwfn), sizeof(caps));
  917. qed_iov_set_link(p_hwfn, rel_vf_id, &params, &link, &caps);
  918. /* Forget the VF's acquisition message */
  919. memset(&vf->acquire, 0, sizeof(vf->acquire));
  920. /* disablng interrupts and resetting permission table was done during
  921. * vf-close, however, we could get here without going through vf_close
  922. */
  923. /* Disable Interrupts for VF */
  924. qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
  925. /* Reset Permission table */
  926. qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
  927. vf->num_rxqs = 0;
  928. vf->num_txqs = 0;
  929. qed_iov_free_vf_igu_sbs(p_hwfn, p_ptt, vf);
  930. if (vf->b_init) {
  931. vf->b_init = false;
  932. if (IS_LEAD_HWFN(p_hwfn))
  933. p_hwfn->cdev->p_iov_info->num_vfs--;
  934. }
  935. return 0;
  936. }
  937. static bool qed_iov_tlv_supported(u16 tlvtype)
  938. {
  939. return CHANNEL_TLV_NONE < tlvtype && tlvtype < CHANNEL_TLV_MAX;
  940. }
  941. /* place a given tlv on the tlv buffer, continuing current tlv list */
  942. void *qed_add_tlv(struct qed_hwfn *p_hwfn, u8 **offset, u16 type, u16 length)
  943. {
  944. struct channel_tlv *tl = (struct channel_tlv *)*offset;
  945. tl->type = type;
  946. tl->length = length;
  947. /* Offset should keep pointing to next TLV (the end of the last) */
  948. *offset += length;
  949. /* Return a pointer to the start of the added tlv */
  950. return *offset - length;
  951. }
  952. /* list the types and lengths of the tlvs on the buffer */
  953. void qed_dp_tlv_list(struct qed_hwfn *p_hwfn, void *tlvs_list)
  954. {
  955. u16 i = 1, total_length = 0;
  956. struct channel_tlv *tlv;
  957. do {
  958. tlv = (struct channel_tlv *)((u8 *)tlvs_list + total_length);
  959. /* output tlv */
  960. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  961. "TLV number %d: type %d, length %d\n",
  962. i, tlv->type, tlv->length);
  963. if (tlv->type == CHANNEL_TLV_LIST_END)
  964. return;
  965. /* Validate entry - protect against malicious VFs */
  966. if (!tlv->length) {
  967. DP_NOTICE(p_hwfn, "TLV of length 0 found\n");
  968. return;
  969. }
  970. total_length += tlv->length;
  971. if (total_length >= sizeof(struct tlv_buffer_size)) {
  972. DP_NOTICE(p_hwfn, "TLV ==> Buffer overflow\n");
  973. return;
  974. }
  975. i++;
  976. } while (1);
  977. }
  978. static void qed_iov_send_response(struct qed_hwfn *p_hwfn,
  979. struct qed_ptt *p_ptt,
  980. struct qed_vf_info *p_vf,
  981. u16 length, u8 status)
  982. {
  983. struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
  984. struct qed_dmae_params params;
  985. u8 eng_vf_id;
  986. mbx->reply_virt->default_resp.hdr.status = status;
  987. qed_dp_tlv_list(p_hwfn, mbx->reply_virt);
  988. eng_vf_id = p_vf->abs_vf_id;
  989. memset(&params, 0, sizeof(struct qed_dmae_params));
  990. params.flags = QED_DMAE_FLAG_VF_DST;
  991. params.dst_vfid = eng_vf_id;
  992. qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys + sizeof(u64),
  993. mbx->req_virt->first_tlv.reply_address +
  994. sizeof(u64),
  995. (sizeof(union pfvf_tlvs) - sizeof(u64)) / 4,
  996. &params);
  997. /* Once PF copies the rc to the VF, the latter can continue
  998. * and send an additional message. So we have to make sure the
  999. * channel would be re-set to ready prior to that.
  1000. */
  1001. REG_WR(p_hwfn,
  1002. GTT_BAR0_MAP_REG_USDM_RAM +
  1003. USTORM_VF_PF_CHANNEL_READY_OFFSET(eng_vf_id), 1);
  1004. qed_dmae_host2host(p_hwfn, p_ptt, mbx->reply_phys,
  1005. mbx->req_virt->first_tlv.reply_address,
  1006. sizeof(u64) / 4, &params);
  1007. }
  1008. static u16 qed_iov_vport_to_tlv(struct qed_hwfn *p_hwfn,
  1009. enum qed_iov_vport_update_flag flag)
  1010. {
  1011. switch (flag) {
  1012. case QED_IOV_VP_UPDATE_ACTIVATE:
  1013. return CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
  1014. case QED_IOV_VP_UPDATE_VLAN_STRIP:
  1015. return CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
  1016. case QED_IOV_VP_UPDATE_TX_SWITCH:
  1017. return CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
  1018. case QED_IOV_VP_UPDATE_MCAST:
  1019. return CHANNEL_TLV_VPORT_UPDATE_MCAST;
  1020. case QED_IOV_VP_UPDATE_ACCEPT_PARAM:
  1021. return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
  1022. case QED_IOV_VP_UPDATE_RSS:
  1023. return CHANNEL_TLV_VPORT_UPDATE_RSS;
  1024. case QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN:
  1025. return CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
  1026. case QED_IOV_VP_UPDATE_SGE_TPA:
  1027. return CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
  1028. default:
  1029. return 0;
  1030. }
  1031. }
  1032. static u16 qed_iov_prep_vp_update_resp_tlvs(struct qed_hwfn *p_hwfn,
  1033. struct qed_vf_info *p_vf,
  1034. struct qed_iov_vf_mbx *p_mbx,
  1035. u8 status,
  1036. u16 tlvs_mask, u16 tlvs_accepted)
  1037. {
  1038. struct pfvf_def_resp_tlv *resp;
  1039. u16 size, total_len, i;
  1040. memset(p_mbx->reply_virt, 0, sizeof(union pfvf_tlvs));
  1041. p_mbx->offset = (u8 *)p_mbx->reply_virt;
  1042. size = sizeof(struct pfvf_def_resp_tlv);
  1043. total_len = size;
  1044. qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_VPORT_UPDATE, size);
  1045. /* Prepare response for all extended tlvs if they are found by PF */
  1046. for (i = 0; i < QED_IOV_VP_UPDATE_MAX; i++) {
  1047. if (!(tlvs_mask & BIT(i)))
  1048. continue;
  1049. resp = qed_add_tlv(p_hwfn, &p_mbx->offset,
  1050. qed_iov_vport_to_tlv(p_hwfn, i), size);
  1051. if (tlvs_accepted & BIT(i))
  1052. resp->hdr.status = status;
  1053. else
  1054. resp->hdr.status = PFVF_STATUS_NOT_SUPPORTED;
  1055. DP_VERBOSE(p_hwfn,
  1056. QED_MSG_IOV,
  1057. "VF[%d] - vport_update response: TLV %d, status %02x\n",
  1058. p_vf->relative_vf_id,
  1059. qed_iov_vport_to_tlv(p_hwfn, i), resp->hdr.status);
  1060. total_len += size;
  1061. }
  1062. qed_add_tlv(p_hwfn, &p_mbx->offset, CHANNEL_TLV_LIST_END,
  1063. sizeof(struct channel_list_end_tlv));
  1064. return total_len;
  1065. }
  1066. static void qed_iov_prepare_resp(struct qed_hwfn *p_hwfn,
  1067. struct qed_ptt *p_ptt,
  1068. struct qed_vf_info *vf_info,
  1069. u16 type, u16 length, u8 status)
  1070. {
  1071. struct qed_iov_vf_mbx *mbx = &vf_info->vf_mbx;
  1072. mbx->offset = (u8 *)mbx->reply_virt;
  1073. qed_add_tlv(p_hwfn, &mbx->offset, type, length);
  1074. qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
  1075. sizeof(struct channel_list_end_tlv));
  1076. qed_iov_send_response(p_hwfn, p_ptt, vf_info, length, status);
  1077. }
  1078. static struct
  1079. qed_public_vf_info *qed_iov_get_public_vf_info(struct qed_hwfn *p_hwfn,
  1080. u16 relative_vf_id,
  1081. bool b_enabled_only)
  1082. {
  1083. struct qed_vf_info *vf = NULL;
  1084. vf = qed_iov_get_vf_info(p_hwfn, relative_vf_id, b_enabled_only);
  1085. if (!vf)
  1086. return NULL;
  1087. return &vf->p_vf_info;
  1088. }
  1089. static void qed_iov_clean_vf(struct qed_hwfn *p_hwfn, u8 vfid)
  1090. {
  1091. struct qed_public_vf_info *vf_info;
  1092. vf_info = qed_iov_get_public_vf_info(p_hwfn, vfid, false);
  1093. if (!vf_info)
  1094. return;
  1095. /* Clear the VF mac */
  1096. eth_zero_addr(vf_info->mac);
  1097. vf_info->rx_accept_mode = 0;
  1098. vf_info->tx_accept_mode = 0;
  1099. }
  1100. static void qed_iov_vf_cleanup(struct qed_hwfn *p_hwfn,
  1101. struct qed_vf_info *p_vf)
  1102. {
  1103. u32 i, j;
  1104. p_vf->vf_bulletin = 0;
  1105. p_vf->vport_instance = 0;
  1106. p_vf->configured_features = 0;
  1107. /* If VF previously requested less resources, go back to default */
  1108. p_vf->num_rxqs = p_vf->num_sbs;
  1109. p_vf->num_txqs = p_vf->num_sbs;
  1110. p_vf->num_active_rxqs = 0;
  1111. for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
  1112. struct qed_vf_queue *p_queue = &p_vf->vf_queues[i];
  1113. for (j = 0; j < MAX_QUEUES_PER_QZONE; j++) {
  1114. if (!p_queue->cids[j].p_cid)
  1115. continue;
  1116. qed_eth_queue_cid_release(p_hwfn,
  1117. p_queue->cids[j].p_cid);
  1118. p_queue->cids[j].p_cid = NULL;
  1119. }
  1120. }
  1121. memset(&p_vf->shadow_config, 0, sizeof(p_vf->shadow_config));
  1122. memset(&p_vf->acquire, 0, sizeof(p_vf->acquire));
  1123. qed_iov_clean_vf(p_hwfn, p_vf->relative_vf_id);
  1124. }
  1125. /* Returns either 0, or log(size) */
  1126. static u32 qed_iov_vf_db_bar_size(struct qed_hwfn *p_hwfn,
  1127. struct qed_ptt *p_ptt)
  1128. {
  1129. u32 val = qed_rd(p_hwfn, p_ptt, PGLUE_B_REG_VF_BAR1_SIZE);
  1130. if (val)
  1131. return val + 11;
  1132. return 0;
  1133. }
  1134. static void
  1135. qed_iov_vf_mbx_acquire_resc_cids(struct qed_hwfn *p_hwfn,
  1136. struct qed_ptt *p_ptt,
  1137. struct qed_vf_info *p_vf,
  1138. struct vf_pf_resc_request *p_req,
  1139. struct pf_vf_resc *p_resp)
  1140. {
  1141. u8 num_vf_cons = p_hwfn->pf_params.eth_pf_params.num_vf_cons;
  1142. u8 db_size = qed_db_addr_vf(1, DQ_DEMS_LEGACY) -
  1143. qed_db_addr_vf(0, DQ_DEMS_LEGACY);
  1144. u32 bar_size;
  1145. p_resp->num_cids = min_t(u8, p_req->num_cids, num_vf_cons);
  1146. /* If VF didn't bother asking for QIDs than don't bother limiting
  1147. * number of CIDs. The VF doesn't care about the number, and this
  1148. * has the likely result of causing an additional acquisition.
  1149. */
  1150. if (!(p_vf->acquire.vfdev_info.capabilities &
  1151. VFPF_ACQUIRE_CAP_QUEUE_QIDS))
  1152. return;
  1153. /* If doorbell bar was mapped by VF, limit the VF CIDs to an amount
  1154. * that would make sure doorbells for all CIDs fall within the bar.
  1155. * If it doesn't, make sure regview window is sufficient.
  1156. */
  1157. if (p_vf->acquire.vfdev_info.capabilities &
  1158. VFPF_ACQUIRE_CAP_PHYSICAL_BAR) {
  1159. bar_size = qed_iov_vf_db_bar_size(p_hwfn, p_ptt);
  1160. if (bar_size)
  1161. bar_size = 1 << bar_size;
  1162. if (p_hwfn->cdev->num_hwfns > 1)
  1163. bar_size /= 2;
  1164. } else {
  1165. bar_size = PXP_VF_BAR0_DQ_LENGTH;
  1166. }
  1167. if (bar_size / db_size < 256)
  1168. p_resp->num_cids = min_t(u8, p_resp->num_cids,
  1169. (u8)(bar_size / db_size));
  1170. }
  1171. static u8 qed_iov_vf_mbx_acquire_resc(struct qed_hwfn *p_hwfn,
  1172. struct qed_ptt *p_ptt,
  1173. struct qed_vf_info *p_vf,
  1174. struct vf_pf_resc_request *p_req,
  1175. struct pf_vf_resc *p_resp)
  1176. {
  1177. u8 i;
  1178. /* Queue related information */
  1179. p_resp->num_rxqs = p_vf->num_rxqs;
  1180. p_resp->num_txqs = p_vf->num_txqs;
  1181. p_resp->num_sbs = p_vf->num_sbs;
  1182. for (i = 0; i < p_resp->num_sbs; i++) {
  1183. p_resp->hw_sbs[i].hw_sb_id = p_vf->igu_sbs[i];
  1184. p_resp->hw_sbs[i].sb_qid = 0;
  1185. }
  1186. /* These fields are filled for backward compatibility.
  1187. * Unused by modern vfs.
  1188. */
  1189. for (i = 0; i < p_resp->num_rxqs; i++) {
  1190. qed_fw_l2_queue(p_hwfn, p_vf->vf_queues[i].fw_rx_qid,
  1191. (u16 *)&p_resp->hw_qid[i]);
  1192. p_resp->cid[i] = i;
  1193. }
  1194. /* Filter related information */
  1195. p_resp->num_mac_filters = min_t(u8, p_vf->num_mac_filters,
  1196. p_req->num_mac_filters);
  1197. p_resp->num_vlan_filters = min_t(u8, p_vf->num_vlan_filters,
  1198. p_req->num_vlan_filters);
  1199. qed_iov_vf_mbx_acquire_resc_cids(p_hwfn, p_ptt, p_vf, p_req, p_resp);
  1200. /* This isn't really needed/enforced, but some legacy VFs might depend
  1201. * on the correct filling of this field.
  1202. */
  1203. p_resp->num_mc_filters = QED_MAX_MC_ADDRS;
  1204. /* Validate sufficient resources for VF */
  1205. if (p_resp->num_rxqs < p_req->num_rxqs ||
  1206. p_resp->num_txqs < p_req->num_txqs ||
  1207. p_resp->num_sbs < p_req->num_sbs ||
  1208. p_resp->num_mac_filters < p_req->num_mac_filters ||
  1209. p_resp->num_vlan_filters < p_req->num_vlan_filters ||
  1210. p_resp->num_mc_filters < p_req->num_mc_filters ||
  1211. p_resp->num_cids < p_req->num_cids) {
  1212. DP_VERBOSE(p_hwfn,
  1213. QED_MSG_IOV,
  1214. "VF[%d] - Insufficient resources: rxq [%02x/%02x] txq [%02x/%02x] sbs [%02x/%02x] mac [%02x/%02x] vlan [%02x/%02x] mc [%02x/%02x] cids [%02x/%02x]\n",
  1215. p_vf->abs_vf_id,
  1216. p_req->num_rxqs,
  1217. p_resp->num_rxqs,
  1218. p_req->num_rxqs,
  1219. p_resp->num_txqs,
  1220. p_req->num_sbs,
  1221. p_resp->num_sbs,
  1222. p_req->num_mac_filters,
  1223. p_resp->num_mac_filters,
  1224. p_req->num_vlan_filters,
  1225. p_resp->num_vlan_filters,
  1226. p_req->num_mc_filters,
  1227. p_resp->num_mc_filters,
  1228. p_req->num_cids, p_resp->num_cids);
  1229. /* Some legacy OSes are incapable of correctly handling this
  1230. * failure.
  1231. */
  1232. if ((p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
  1233. ETH_HSI_VER_NO_PKT_LEN_TUNN) &&
  1234. (p_vf->acquire.vfdev_info.os_type ==
  1235. VFPF_ACQUIRE_OS_WINDOWS))
  1236. return PFVF_STATUS_SUCCESS;
  1237. return PFVF_STATUS_NO_RESOURCE;
  1238. }
  1239. return PFVF_STATUS_SUCCESS;
  1240. }
  1241. static void qed_iov_vf_mbx_acquire_stats(struct qed_hwfn *p_hwfn,
  1242. struct pfvf_stats_info *p_stats)
  1243. {
  1244. p_stats->mstats.address = PXP_VF_BAR0_START_MSDM_ZONE_B +
  1245. offsetof(struct mstorm_vf_zone,
  1246. non_trigger.eth_queue_stat);
  1247. p_stats->mstats.len = sizeof(struct eth_mstorm_per_queue_stat);
  1248. p_stats->ustats.address = PXP_VF_BAR0_START_USDM_ZONE_B +
  1249. offsetof(struct ustorm_vf_zone,
  1250. non_trigger.eth_queue_stat);
  1251. p_stats->ustats.len = sizeof(struct eth_ustorm_per_queue_stat);
  1252. p_stats->pstats.address = PXP_VF_BAR0_START_PSDM_ZONE_B +
  1253. offsetof(struct pstorm_vf_zone,
  1254. non_trigger.eth_queue_stat);
  1255. p_stats->pstats.len = sizeof(struct eth_pstorm_per_queue_stat);
  1256. p_stats->tstats.address = 0;
  1257. p_stats->tstats.len = 0;
  1258. }
  1259. static void qed_iov_vf_mbx_acquire(struct qed_hwfn *p_hwfn,
  1260. struct qed_ptt *p_ptt,
  1261. struct qed_vf_info *vf)
  1262. {
  1263. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  1264. struct pfvf_acquire_resp_tlv *resp = &mbx->reply_virt->acquire_resp;
  1265. struct pf_vf_pfdev_info *pfdev_info = &resp->pfdev_info;
  1266. struct vfpf_acquire_tlv *req = &mbx->req_virt->acquire;
  1267. u8 vfpf_status = PFVF_STATUS_NOT_SUPPORTED;
  1268. struct pf_vf_resc *resc = &resp->resc;
  1269. int rc;
  1270. memset(resp, 0, sizeof(*resp));
  1271. /* Write the PF version so that VF would know which version
  1272. * is supported - might be later overriden. This guarantees that
  1273. * VF could recognize legacy PF based on lack of versions in reply.
  1274. */
  1275. pfdev_info->major_fp_hsi = ETH_HSI_VER_MAJOR;
  1276. pfdev_info->minor_fp_hsi = ETH_HSI_VER_MINOR;
  1277. if (vf->state != VF_FREE && vf->state != VF_STOPPED) {
  1278. DP_VERBOSE(p_hwfn,
  1279. QED_MSG_IOV,
  1280. "VF[%d] sent ACQUIRE but is already in state %d - fail request\n",
  1281. vf->abs_vf_id, vf->state);
  1282. goto out;
  1283. }
  1284. /* Validate FW compatibility */
  1285. if (req->vfdev_info.eth_fp_hsi_major != ETH_HSI_VER_MAJOR) {
  1286. if (req->vfdev_info.capabilities &
  1287. VFPF_ACQUIRE_CAP_PRE_FP_HSI) {
  1288. struct vf_pf_vfdev_info *p_vfdev = &req->vfdev_info;
  1289. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1290. "VF[%d] is pre-fastpath HSI\n",
  1291. vf->abs_vf_id);
  1292. p_vfdev->eth_fp_hsi_major = ETH_HSI_VER_MAJOR;
  1293. p_vfdev->eth_fp_hsi_minor = ETH_HSI_VER_NO_PKT_LEN_TUNN;
  1294. } else {
  1295. DP_INFO(p_hwfn,
  1296. "VF[%d] needs fastpath HSI %02x.%02x, which is incompatible with loaded FW's faspath HSI %02x.%02x\n",
  1297. vf->abs_vf_id,
  1298. req->vfdev_info.eth_fp_hsi_major,
  1299. req->vfdev_info.eth_fp_hsi_minor,
  1300. ETH_HSI_VER_MAJOR, ETH_HSI_VER_MINOR);
  1301. goto out;
  1302. }
  1303. }
  1304. /* On 100g PFs, prevent old VFs from loading */
  1305. if ((p_hwfn->cdev->num_hwfns > 1) &&
  1306. !(req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_100G)) {
  1307. DP_INFO(p_hwfn,
  1308. "VF[%d] is running an old driver that doesn't support 100g\n",
  1309. vf->abs_vf_id);
  1310. goto out;
  1311. }
  1312. /* Store the acquire message */
  1313. memcpy(&vf->acquire, req, sizeof(vf->acquire));
  1314. vf->opaque_fid = req->vfdev_info.opaque_fid;
  1315. vf->vf_bulletin = req->bulletin_addr;
  1316. vf->bulletin.size = (vf->bulletin.size < req->bulletin_size) ?
  1317. vf->bulletin.size : req->bulletin_size;
  1318. /* fill in pfdev info */
  1319. pfdev_info->chip_num = p_hwfn->cdev->chip_num;
  1320. pfdev_info->db_size = 0;
  1321. pfdev_info->indices_per_sb = PIS_PER_SB;
  1322. pfdev_info->capabilities = PFVF_ACQUIRE_CAP_DEFAULT_UNTAGGED |
  1323. PFVF_ACQUIRE_CAP_POST_FW_OVERRIDE;
  1324. if (p_hwfn->cdev->num_hwfns > 1)
  1325. pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_100G;
  1326. /* Share our ability to use multiple queue-ids only with VFs
  1327. * that request it.
  1328. */
  1329. if (req->vfdev_info.capabilities & VFPF_ACQUIRE_CAP_QUEUE_QIDS)
  1330. pfdev_info->capabilities |= PFVF_ACQUIRE_CAP_QUEUE_QIDS;
  1331. /* Share the sizes of the bars with VF */
  1332. resp->pfdev_info.bar_size = qed_iov_vf_db_bar_size(p_hwfn, p_ptt);
  1333. qed_iov_vf_mbx_acquire_stats(p_hwfn, &pfdev_info->stats_info);
  1334. memcpy(pfdev_info->port_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
  1335. pfdev_info->fw_major = FW_MAJOR_VERSION;
  1336. pfdev_info->fw_minor = FW_MINOR_VERSION;
  1337. pfdev_info->fw_rev = FW_REVISION_VERSION;
  1338. pfdev_info->fw_eng = FW_ENGINEERING_VERSION;
  1339. /* Incorrect when legacy, but doesn't matter as legacy isn't reading
  1340. * this field.
  1341. */
  1342. pfdev_info->minor_fp_hsi = min_t(u8, ETH_HSI_VER_MINOR,
  1343. req->vfdev_info.eth_fp_hsi_minor);
  1344. pfdev_info->os_type = VFPF_ACQUIRE_OS_LINUX;
  1345. qed_mcp_get_mfw_ver(p_hwfn, p_ptt, &pfdev_info->mfw_ver, NULL);
  1346. pfdev_info->dev_type = p_hwfn->cdev->type;
  1347. pfdev_info->chip_rev = p_hwfn->cdev->chip_rev;
  1348. /* Fill resources available to VF; Make sure there are enough to
  1349. * satisfy the VF's request.
  1350. */
  1351. vfpf_status = qed_iov_vf_mbx_acquire_resc(p_hwfn, p_ptt, vf,
  1352. &req->resc_request, resc);
  1353. if (vfpf_status != PFVF_STATUS_SUCCESS)
  1354. goto out;
  1355. /* Start the VF in FW */
  1356. rc = qed_sp_vf_start(p_hwfn, vf);
  1357. if (rc) {
  1358. DP_NOTICE(p_hwfn, "Failed to start VF[%02x]\n", vf->abs_vf_id);
  1359. vfpf_status = PFVF_STATUS_FAILURE;
  1360. goto out;
  1361. }
  1362. /* Fill agreed size of bulletin board in response */
  1363. resp->bulletin_size = vf->bulletin.size;
  1364. qed_iov_post_vf_bulletin(p_hwfn, vf->relative_vf_id, p_ptt);
  1365. DP_VERBOSE(p_hwfn,
  1366. QED_MSG_IOV,
  1367. "VF[%d] ACQUIRE_RESPONSE: pfdev_info- chip_num=0x%x, db_size=%d, idx_per_sb=%d, pf_cap=0x%llx\n"
  1368. "resources- n_rxq-%d, n_txq-%d, n_sbs-%d, n_macs-%d, n_vlans-%d\n",
  1369. vf->abs_vf_id,
  1370. resp->pfdev_info.chip_num,
  1371. resp->pfdev_info.db_size,
  1372. resp->pfdev_info.indices_per_sb,
  1373. resp->pfdev_info.capabilities,
  1374. resc->num_rxqs,
  1375. resc->num_txqs,
  1376. resc->num_sbs,
  1377. resc->num_mac_filters,
  1378. resc->num_vlan_filters);
  1379. vf->state = VF_ACQUIRED;
  1380. /* Prepare Response */
  1381. out:
  1382. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_ACQUIRE,
  1383. sizeof(struct pfvf_acquire_resp_tlv), vfpf_status);
  1384. }
  1385. static int __qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn,
  1386. struct qed_vf_info *p_vf, bool val)
  1387. {
  1388. struct qed_sp_vport_update_params params;
  1389. int rc;
  1390. if (val == p_vf->spoof_chk) {
  1391. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1392. "Spoofchk value[%d] is already configured\n", val);
  1393. return 0;
  1394. }
  1395. memset(&params, 0, sizeof(struct qed_sp_vport_update_params));
  1396. params.opaque_fid = p_vf->opaque_fid;
  1397. params.vport_id = p_vf->vport_id;
  1398. params.update_anti_spoofing_en_flg = 1;
  1399. params.anti_spoofing_en = val;
  1400. rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
  1401. if (!rc) {
  1402. p_vf->spoof_chk = val;
  1403. p_vf->req_spoofchk_val = p_vf->spoof_chk;
  1404. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1405. "Spoofchk val[%d] configured\n", val);
  1406. } else {
  1407. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1408. "Spoofchk configuration[val:%d] failed for VF[%d]\n",
  1409. val, p_vf->relative_vf_id);
  1410. }
  1411. return rc;
  1412. }
  1413. static int qed_iov_reconfigure_unicast_vlan(struct qed_hwfn *p_hwfn,
  1414. struct qed_vf_info *p_vf)
  1415. {
  1416. struct qed_filter_ucast filter;
  1417. int rc = 0;
  1418. int i;
  1419. memset(&filter, 0, sizeof(filter));
  1420. filter.is_rx_filter = 1;
  1421. filter.is_tx_filter = 1;
  1422. filter.vport_to_add_to = p_vf->vport_id;
  1423. filter.opcode = QED_FILTER_ADD;
  1424. /* Reconfigure vlans */
  1425. for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
  1426. if (!p_vf->shadow_config.vlans[i].used)
  1427. continue;
  1428. filter.type = QED_FILTER_VLAN;
  1429. filter.vlan = p_vf->shadow_config.vlans[i].vid;
  1430. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1431. "Reconfiguring VLAN [0x%04x] for VF [%04x]\n",
  1432. filter.vlan, p_vf->relative_vf_id);
  1433. rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
  1434. &filter, QED_SPQ_MODE_CB, NULL);
  1435. if (rc) {
  1436. DP_NOTICE(p_hwfn,
  1437. "Failed to configure VLAN [%04x] to VF [%04x]\n",
  1438. filter.vlan, p_vf->relative_vf_id);
  1439. break;
  1440. }
  1441. }
  1442. return rc;
  1443. }
  1444. static int
  1445. qed_iov_reconfigure_unicast_shadow(struct qed_hwfn *p_hwfn,
  1446. struct qed_vf_info *p_vf, u64 events)
  1447. {
  1448. int rc = 0;
  1449. if ((events & BIT(VLAN_ADDR_FORCED)) &&
  1450. !(p_vf->configured_features & (1 << VLAN_ADDR_FORCED)))
  1451. rc = qed_iov_reconfigure_unicast_vlan(p_hwfn, p_vf);
  1452. return rc;
  1453. }
  1454. static int qed_iov_configure_vport_forced(struct qed_hwfn *p_hwfn,
  1455. struct qed_vf_info *p_vf, u64 events)
  1456. {
  1457. int rc = 0;
  1458. struct qed_filter_ucast filter;
  1459. if (!p_vf->vport_instance)
  1460. return -EINVAL;
  1461. if (events & BIT(MAC_ADDR_FORCED)) {
  1462. /* Since there's no way [currently] of removing the MAC,
  1463. * we can always assume this means we need to force it.
  1464. */
  1465. memset(&filter, 0, sizeof(filter));
  1466. filter.type = QED_FILTER_MAC;
  1467. filter.opcode = QED_FILTER_REPLACE;
  1468. filter.is_rx_filter = 1;
  1469. filter.is_tx_filter = 1;
  1470. filter.vport_to_add_to = p_vf->vport_id;
  1471. ether_addr_copy(filter.mac, p_vf->bulletin.p_virt->mac);
  1472. rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
  1473. &filter, QED_SPQ_MODE_CB, NULL);
  1474. if (rc) {
  1475. DP_NOTICE(p_hwfn,
  1476. "PF failed to configure MAC for VF\n");
  1477. return rc;
  1478. }
  1479. p_vf->configured_features |= 1 << MAC_ADDR_FORCED;
  1480. }
  1481. if (events & BIT(VLAN_ADDR_FORCED)) {
  1482. struct qed_sp_vport_update_params vport_update;
  1483. u8 removal;
  1484. int i;
  1485. memset(&filter, 0, sizeof(filter));
  1486. filter.type = QED_FILTER_VLAN;
  1487. filter.is_rx_filter = 1;
  1488. filter.is_tx_filter = 1;
  1489. filter.vport_to_add_to = p_vf->vport_id;
  1490. filter.vlan = p_vf->bulletin.p_virt->pvid;
  1491. filter.opcode = filter.vlan ? QED_FILTER_REPLACE :
  1492. QED_FILTER_FLUSH;
  1493. /* Send the ramrod */
  1494. rc = qed_sp_eth_filter_ucast(p_hwfn, p_vf->opaque_fid,
  1495. &filter, QED_SPQ_MODE_CB, NULL);
  1496. if (rc) {
  1497. DP_NOTICE(p_hwfn,
  1498. "PF failed to configure VLAN for VF\n");
  1499. return rc;
  1500. }
  1501. /* Update the default-vlan & silent vlan stripping */
  1502. memset(&vport_update, 0, sizeof(vport_update));
  1503. vport_update.opaque_fid = p_vf->opaque_fid;
  1504. vport_update.vport_id = p_vf->vport_id;
  1505. vport_update.update_default_vlan_enable_flg = 1;
  1506. vport_update.default_vlan_enable_flg = filter.vlan ? 1 : 0;
  1507. vport_update.update_default_vlan_flg = 1;
  1508. vport_update.default_vlan = filter.vlan;
  1509. vport_update.update_inner_vlan_removal_flg = 1;
  1510. removal = filter.vlan ? 1
  1511. : p_vf->shadow_config.inner_vlan_removal;
  1512. vport_update.inner_vlan_removal_flg = removal;
  1513. vport_update.silent_vlan_removal_flg = filter.vlan ? 1 : 0;
  1514. rc = qed_sp_vport_update(p_hwfn,
  1515. &vport_update,
  1516. QED_SPQ_MODE_EBLOCK, NULL);
  1517. if (rc) {
  1518. DP_NOTICE(p_hwfn,
  1519. "PF failed to configure VF vport for vlan\n");
  1520. return rc;
  1521. }
  1522. /* Update all the Rx queues */
  1523. for (i = 0; i < QED_MAX_VF_CHAINS_PER_PF; i++) {
  1524. struct qed_vf_queue *p_queue = &p_vf->vf_queues[i];
  1525. struct qed_queue_cid *p_cid = NULL;
  1526. /* There can be at most 1 Rx queue on qzone. Find it */
  1527. p_cid = qed_iov_get_vf_rx_queue_cid(p_queue);
  1528. if (!p_cid)
  1529. continue;
  1530. rc = qed_sp_eth_rx_queues_update(p_hwfn,
  1531. (void **)&p_cid,
  1532. 1, 0, 1,
  1533. QED_SPQ_MODE_EBLOCK,
  1534. NULL);
  1535. if (rc) {
  1536. DP_NOTICE(p_hwfn,
  1537. "Failed to send Rx update fo queue[0x%04x]\n",
  1538. p_cid->rel.queue_id);
  1539. return rc;
  1540. }
  1541. }
  1542. if (filter.vlan)
  1543. p_vf->configured_features |= 1 << VLAN_ADDR_FORCED;
  1544. else
  1545. p_vf->configured_features &= ~BIT(VLAN_ADDR_FORCED);
  1546. }
  1547. /* If forced features are terminated, we need to configure the shadow
  1548. * configuration back again.
  1549. */
  1550. if (events)
  1551. qed_iov_reconfigure_unicast_shadow(p_hwfn, p_vf, events);
  1552. return rc;
  1553. }
  1554. static void qed_iov_vf_mbx_start_vport(struct qed_hwfn *p_hwfn,
  1555. struct qed_ptt *p_ptt,
  1556. struct qed_vf_info *vf)
  1557. {
  1558. struct qed_sp_vport_start_params params = { 0 };
  1559. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  1560. struct vfpf_vport_start_tlv *start;
  1561. u8 status = PFVF_STATUS_SUCCESS;
  1562. struct qed_vf_info *vf_info;
  1563. u64 *p_bitmap;
  1564. int sb_id;
  1565. int rc;
  1566. vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vf->relative_vf_id, true);
  1567. if (!vf_info) {
  1568. DP_NOTICE(p_hwfn->cdev,
  1569. "Failed to get VF info, invalid vfid [%d]\n",
  1570. vf->relative_vf_id);
  1571. return;
  1572. }
  1573. vf->state = VF_ENABLED;
  1574. start = &mbx->req_virt->start_vport;
  1575. qed_iov_enable_vf_traffic(p_hwfn, p_ptt, vf);
  1576. /* Initialize Status block in CAU */
  1577. for (sb_id = 0; sb_id < vf->num_sbs; sb_id++) {
  1578. if (!start->sb_addr[sb_id]) {
  1579. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1580. "VF[%d] did not fill the address of SB %d\n",
  1581. vf->relative_vf_id, sb_id);
  1582. break;
  1583. }
  1584. qed_int_cau_conf_sb(p_hwfn, p_ptt,
  1585. start->sb_addr[sb_id],
  1586. vf->igu_sbs[sb_id], vf->abs_vf_id, 1);
  1587. }
  1588. vf->mtu = start->mtu;
  1589. vf->shadow_config.inner_vlan_removal = start->inner_vlan_removal;
  1590. /* Take into consideration configuration forced by hypervisor;
  1591. * If none is configured, use the supplied VF values [for old
  1592. * vfs that would still be fine, since they passed '0' as padding].
  1593. */
  1594. p_bitmap = &vf_info->bulletin.p_virt->valid_bitmap;
  1595. if (!(*p_bitmap & BIT(VFPF_BULLETIN_UNTAGGED_DEFAULT_FORCED))) {
  1596. u8 vf_req = start->only_untagged;
  1597. vf_info->bulletin.p_virt->default_only_untagged = vf_req;
  1598. *p_bitmap |= 1 << VFPF_BULLETIN_UNTAGGED_DEFAULT;
  1599. }
  1600. params.tpa_mode = start->tpa_mode;
  1601. params.remove_inner_vlan = start->inner_vlan_removal;
  1602. params.tx_switching = true;
  1603. params.only_untagged = vf_info->bulletin.p_virt->default_only_untagged;
  1604. params.drop_ttl0 = false;
  1605. params.concrete_fid = vf->concrete_fid;
  1606. params.opaque_fid = vf->opaque_fid;
  1607. params.vport_id = vf->vport_id;
  1608. params.max_buffers_per_cqe = start->max_buffers_per_cqe;
  1609. params.mtu = vf->mtu;
  1610. params.check_mac = true;
  1611. rc = qed_sp_eth_vport_start(p_hwfn, &params);
  1612. if (rc) {
  1613. DP_ERR(p_hwfn,
  1614. "qed_iov_vf_mbx_start_vport returned error %d\n", rc);
  1615. status = PFVF_STATUS_FAILURE;
  1616. } else {
  1617. vf->vport_instance++;
  1618. /* Force configuration if needed on the newly opened vport */
  1619. qed_iov_configure_vport_forced(p_hwfn, vf, *p_bitmap);
  1620. __qed_iov_spoofchk_set(p_hwfn, vf, vf->req_spoofchk_val);
  1621. }
  1622. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_START,
  1623. sizeof(struct pfvf_def_resp_tlv), status);
  1624. }
  1625. static void qed_iov_vf_mbx_stop_vport(struct qed_hwfn *p_hwfn,
  1626. struct qed_ptt *p_ptt,
  1627. struct qed_vf_info *vf)
  1628. {
  1629. u8 status = PFVF_STATUS_SUCCESS;
  1630. int rc;
  1631. vf->vport_instance--;
  1632. vf->spoof_chk = false;
  1633. if ((qed_iov_validate_active_rxq(p_hwfn, vf)) ||
  1634. (qed_iov_validate_active_txq(p_hwfn, vf))) {
  1635. vf->b_malicious = true;
  1636. DP_NOTICE(p_hwfn,
  1637. "VF [%02x] - considered malicious; Unable to stop RX/TX queuess\n",
  1638. vf->abs_vf_id);
  1639. status = PFVF_STATUS_MALICIOUS;
  1640. goto out;
  1641. }
  1642. rc = qed_sp_vport_stop(p_hwfn, vf->opaque_fid, vf->vport_id);
  1643. if (rc) {
  1644. DP_ERR(p_hwfn, "qed_iov_vf_mbx_stop_vport returned error %d\n",
  1645. rc);
  1646. status = PFVF_STATUS_FAILURE;
  1647. }
  1648. /* Forget the configuration on the vport */
  1649. vf->configured_features = 0;
  1650. memset(&vf->shadow_config, 0, sizeof(vf->shadow_config));
  1651. out:
  1652. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_VPORT_TEARDOWN,
  1653. sizeof(struct pfvf_def_resp_tlv), status);
  1654. }
  1655. static void qed_iov_vf_mbx_start_rxq_resp(struct qed_hwfn *p_hwfn,
  1656. struct qed_ptt *p_ptt,
  1657. struct qed_vf_info *vf,
  1658. u8 status, bool b_legacy)
  1659. {
  1660. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  1661. struct pfvf_start_queue_resp_tlv *p_tlv;
  1662. struct vfpf_start_rxq_tlv *req;
  1663. u16 length;
  1664. mbx->offset = (u8 *)mbx->reply_virt;
  1665. /* Taking a bigger struct instead of adding a TLV to list was a
  1666. * mistake, but one which we're now stuck with, as some older
  1667. * clients assume the size of the previous response.
  1668. */
  1669. if (!b_legacy)
  1670. length = sizeof(*p_tlv);
  1671. else
  1672. length = sizeof(struct pfvf_def_resp_tlv);
  1673. p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_RXQ,
  1674. length);
  1675. qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
  1676. sizeof(struct channel_list_end_tlv));
  1677. /* Update the TLV with the response */
  1678. if ((status == PFVF_STATUS_SUCCESS) && !b_legacy) {
  1679. req = &mbx->req_virt->start_rxq;
  1680. p_tlv->offset = PXP_VF_BAR0_START_MSDM_ZONE_B +
  1681. offsetof(struct mstorm_vf_zone,
  1682. non_trigger.eth_rx_queue_producers) +
  1683. sizeof(struct eth_rx_prod_data) * req->rx_qid;
  1684. }
  1685. qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
  1686. }
  1687. static u8 qed_iov_vf_mbx_qid(struct qed_hwfn *p_hwfn,
  1688. struct qed_vf_info *p_vf, bool b_is_tx)
  1689. {
  1690. struct qed_iov_vf_mbx *p_mbx = &p_vf->vf_mbx;
  1691. struct vfpf_qid_tlv *p_qid_tlv;
  1692. /* Search for the qid if the VF published its going to provide it */
  1693. if (!(p_vf->acquire.vfdev_info.capabilities &
  1694. VFPF_ACQUIRE_CAP_QUEUE_QIDS)) {
  1695. if (b_is_tx)
  1696. return QED_IOV_LEGACY_QID_TX;
  1697. else
  1698. return QED_IOV_LEGACY_QID_RX;
  1699. }
  1700. p_qid_tlv = (struct vfpf_qid_tlv *)
  1701. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
  1702. CHANNEL_TLV_QID);
  1703. if (!p_qid_tlv) {
  1704. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1705. "VF[%2x]: Failed to provide qid\n",
  1706. p_vf->relative_vf_id);
  1707. return QED_IOV_QID_INVALID;
  1708. }
  1709. if (p_qid_tlv->qid >= MAX_QUEUES_PER_QZONE) {
  1710. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1711. "VF[%02x]: Provided qid out-of-bounds %02x\n",
  1712. p_vf->relative_vf_id, p_qid_tlv->qid);
  1713. return QED_IOV_QID_INVALID;
  1714. }
  1715. return p_qid_tlv->qid;
  1716. }
  1717. static void qed_iov_vf_mbx_start_rxq(struct qed_hwfn *p_hwfn,
  1718. struct qed_ptt *p_ptt,
  1719. struct qed_vf_info *vf)
  1720. {
  1721. struct qed_queue_start_common_params params;
  1722. struct qed_queue_cid_vf_params vf_params;
  1723. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  1724. u8 status = PFVF_STATUS_NO_RESOURCE;
  1725. u8 qid_usage_idx, vf_legacy = 0;
  1726. struct vfpf_start_rxq_tlv *req;
  1727. struct qed_vf_queue *p_queue;
  1728. struct qed_queue_cid *p_cid;
  1729. struct qed_sb_info sb_dummy;
  1730. int rc;
  1731. req = &mbx->req_virt->start_rxq;
  1732. if (!qed_iov_validate_rxq(p_hwfn, vf, req->rx_qid,
  1733. QED_IOV_VALIDATE_Q_DISABLE) ||
  1734. !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
  1735. goto out;
  1736. qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
  1737. if (qid_usage_idx == QED_IOV_QID_INVALID)
  1738. goto out;
  1739. p_queue = &vf->vf_queues[req->rx_qid];
  1740. if (p_queue->cids[qid_usage_idx].p_cid)
  1741. goto out;
  1742. vf_legacy = qed_vf_calculate_legacy(vf);
  1743. /* Acquire a new queue-cid */
  1744. memset(&params, 0, sizeof(params));
  1745. params.queue_id = p_queue->fw_rx_qid;
  1746. params.vport_id = vf->vport_id;
  1747. params.stats_id = vf->abs_vf_id + 0x10;
  1748. /* Since IGU index is passed via sb_info, construct a dummy one */
  1749. memset(&sb_dummy, 0, sizeof(sb_dummy));
  1750. sb_dummy.igu_sb_id = req->hw_sb;
  1751. params.p_sb = &sb_dummy;
  1752. params.sb_idx = req->sb_index;
  1753. memset(&vf_params, 0, sizeof(vf_params));
  1754. vf_params.vfid = vf->relative_vf_id;
  1755. vf_params.vf_qid = (u8)req->rx_qid;
  1756. vf_params.vf_legacy = vf_legacy;
  1757. vf_params.qid_usage_idx = qid_usage_idx;
  1758. p_cid = qed_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
  1759. &params, true, &vf_params);
  1760. if (!p_cid)
  1761. goto out;
  1762. /* Legacy VFs have their Producers in a different location, which they
  1763. * calculate on their own and clean the producer prior to this.
  1764. */
  1765. if (!(vf_legacy & QED_QCID_LEGACY_VF_RX_PROD))
  1766. REG_WR(p_hwfn,
  1767. GTT_BAR0_MAP_REG_MSDM_RAM +
  1768. MSTORM_ETH_VF_PRODS_OFFSET(vf->abs_vf_id, req->rx_qid),
  1769. 0);
  1770. rc = qed_eth_rxq_start_ramrod(p_hwfn, p_cid,
  1771. req->bd_max_bytes,
  1772. req->rxq_addr,
  1773. req->cqe_pbl_addr, req->cqe_pbl_size);
  1774. if (rc) {
  1775. status = PFVF_STATUS_FAILURE;
  1776. qed_eth_queue_cid_release(p_hwfn, p_cid);
  1777. } else {
  1778. p_queue->cids[qid_usage_idx].p_cid = p_cid;
  1779. p_queue->cids[qid_usage_idx].b_is_tx = false;
  1780. status = PFVF_STATUS_SUCCESS;
  1781. vf->num_active_rxqs++;
  1782. }
  1783. out:
  1784. qed_iov_vf_mbx_start_rxq_resp(p_hwfn, p_ptt, vf, status,
  1785. !!(vf_legacy &
  1786. QED_QCID_LEGACY_VF_RX_PROD));
  1787. }
  1788. static void
  1789. qed_iov_pf_update_tun_response(struct pfvf_update_tunn_param_tlv *p_resp,
  1790. struct qed_tunnel_info *p_tun,
  1791. u16 tunn_feature_mask)
  1792. {
  1793. p_resp->tunn_feature_mask = tunn_feature_mask;
  1794. p_resp->vxlan_mode = p_tun->vxlan.b_mode_enabled;
  1795. p_resp->l2geneve_mode = p_tun->l2_geneve.b_mode_enabled;
  1796. p_resp->ipgeneve_mode = p_tun->ip_geneve.b_mode_enabled;
  1797. p_resp->l2gre_mode = p_tun->l2_gre.b_mode_enabled;
  1798. p_resp->ipgre_mode = p_tun->l2_gre.b_mode_enabled;
  1799. p_resp->vxlan_clss = p_tun->vxlan.tun_cls;
  1800. p_resp->l2gre_clss = p_tun->l2_gre.tun_cls;
  1801. p_resp->ipgre_clss = p_tun->ip_gre.tun_cls;
  1802. p_resp->l2geneve_clss = p_tun->l2_geneve.tun_cls;
  1803. p_resp->ipgeneve_clss = p_tun->ip_geneve.tun_cls;
  1804. p_resp->geneve_udp_port = p_tun->geneve_port.port;
  1805. p_resp->vxlan_udp_port = p_tun->vxlan_port.port;
  1806. }
  1807. static void
  1808. __qed_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
  1809. struct qed_tunn_update_type *p_tun,
  1810. enum qed_tunn_mode mask, u8 tun_cls)
  1811. {
  1812. if (p_req->tun_mode_update_mask & BIT(mask)) {
  1813. p_tun->b_update_mode = true;
  1814. if (p_req->tunn_mode & BIT(mask))
  1815. p_tun->b_mode_enabled = true;
  1816. }
  1817. p_tun->tun_cls = tun_cls;
  1818. }
  1819. static void
  1820. qed_iov_pf_update_tun_param(struct vfpf_update_tunn_param_tlv *p_req,
  1821. struct qed_tunn_update_type *p_tun,
  1822. struct qed_tunn_update_udp_port *p_port,
  1823. enum qed_tunn_mode mask,
  1824. u8 tun_cls, u8 update_port, u16 port)
  1825. {
  1826. if (update_port) {
  1827. p_port->b_update_port = true;
  1828. p_port->port = port;
  1829. }
  1830. __qed_iov_pf_update_tun_param(p_req, p_tun, mask, tun_cls);
  1831. }
  1832. static bool
  1833. qed_iov_pf_validate_tunn_param(struct vfpf_update_tunn_param_tlv *p_req)
  1834. {
  1835. bool b_update_requested = false;
  1836. if (p_req->tun_mode_update_mask || p_req->update_tun_cls ||
  1837. p_req->update_geneve_port || p_req->update_vxlan_port)
  1838. b_update_requested = true;
  1839. return b_update_requested;
  1840. }
  1841. static void qed_pf_validate_tunn_mode(struct qed_tunn_update_type *tun, int *rc)
  1842. {
  1843. if (tun->b_update_mode && !tun->b_mode_enabled) {
  1844. tun->b_update_mode = false;
  1845. *rc = -EINVAL;
  1846. }
  1847. }
  1848. static int
  1849. qed_pf_validate_modify_tunn_config(struct qed_hwfn *p_hwfn,
  1850. u16 *tun_features, bool *update,
  1851. struct qed_tunnel_info *tun_src)
  1852. {
  1853. struct qed_eth_cb_ops *ops = p_hwfn->cdev->protocol_ops.eth;
  1854. struct qed_tunnel_info *tun = &p_hwfn->cdev->tunnel;
  1855. u16 bultn_vxlan_port, bultn_geneve_port;
  1856. void *cookie = p_hwfn->cdev->ops_cookie;
  1857. int i, rc = 0;
  1858. *tun_features = p_hwfn->cdev->tunn_feature_mask;
  1859. bultn_vxlan_port = tun->vxlan_port.port;
  1860. bultn_geneve_port = tun->geneve_port.port;
  1861. qed_pf_validate_tunn_mode(&tun_src->vxlan, &rc);
  1862. qed_pf_validate_tunn_mode(&tun_src->l2_geneve, &rc);
  1863. qed_pf_validate_tunn_mode(&tun_src->ip_geneve, &rc);
  1864. qed_pf_validate_tunn_mode(&tun_src->l2_gre, &rc);
  1865. qed_pf_validate_tunn_mode(&tun_src->ip_gre, &rc);
  1866. if ((tun_src->b_update_rx_cls || tun_src->b_update_tx_cls) &&
  1867. (tun_src->vxlan.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
  1868. tun_src->l2_geneve.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
  1869. tun_src->ip_geneve.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
  1870. tun_src->l2_gre.tun_cls != QED_TUNN_CLSS_MAC_VLAN ||
  1871. tun_src->ip_gre.tun_cls != QED_TUNN_CLSS_MAC_VLAN)) {
  1872. tun_src->b_update_rx_cls = false;
  1873. tun_src->b_update_tx_cls = false;
  1874. rc = -EINVAL;
  1875. }
  1876. if (tun_src->vxlan_port.b_update_port) {
  1877. if (tun_src->vxlan_port.port == tun->vxlan_port.port) {
  1878. tun_src->vxlan_port.b_update_port = false;
  1879. } else {
  1880. *update = true;
  1881. bultn_vxlan_port = tun_src->vxlan_port.port;
  1882. }
  1883. }
  1884. if (tun_src->geneve_port.b_update_port) {
  1885. if (tun_src->geneve_port.port == tun->geneve_port.port) {
  1886. tun_src->geneve_port.b_update_port = false;
  1887. } else {
  1888. *update = true;
  1889. bultn_geneve_port = tun_src->geneve_port.port;
  1890. }
  1891. }
  1892. qed_for_each_vf(p_hwfn, i) {
  1893. qed_iov_bulletin_set_udp_ports(p_hwfn, i, bultn_vxlan_port,
  1894. bultn_geneve_port);
  1895. }
  1896. qed_schedule_iov(p_hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
  1897. ops->ports_update(cookie, bultn_vxlan_port, bultn_geneve_port);
  1898. return rc;
  1899. }
  1900. static void qed_iov_vf_mbx_update_tunn_param(struct qed_hwfn *p_hwfn,
  1901. struct qed_ptt *p_ptt,
  1902. struct qed_vf_info *p_vf)
  1903. {
  1904. struct qed_tunnel_info *p_tun = &p_hwfn->cdev->tunnel;
  1905. struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
  1906. struct pfvf_update_tunn_param_tlv *p_resp;
  1907. struct vfpf_update_tunn_param_tlv *p_req;
  1908. u8 status = PFVF_STATUS_SUCCESS;
  1909. bool b_update_required = false;
  1910. struct qed_tunnel_info tunn;
  1911. u16 tunn_feature_mask = 0;
  1912. int i, rc = 0;
  1913. mbx->offset = (u8 *)mbx->reply_virt;
  1914. memset(&tunn, 0, sizeof(tunn));
  1915. p_req = &mbx->req_virt->tunn_param_update;
  1916. if (!qed_iov_pf_validate_tunn_param(p_req)) {
  1917. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  1918. "No tunnel update requested by VF\n");
  1919. status = PFVF_STATUS_FAILURE;
  1920. goto send_resp;
  1921. }
  1922. tunn.b_update_rx_cls = p_req->update_tun_cls;
  1923. tunn.b_update_tx_cls = p_req->update_tun_cls;
  1924. qed_iov_pf_update_tun_param(p_req, &tunn.vxlan, &tunn.vxlan_port,
  1925. QED_MODE_VXLAN_TUNN, p_req->vxlan_clss,
  1926. p_req->update_vxlan_port,
  1927. p_req->vxlan_port);
  1928. qed_iov_pf_update_tun_param(p_req, &tunn.l2_geneve, &tunn.geneve_port,
  1929. QED_MODE_L2GENEVE_TUNN,
  1930. p_req->l2geneve_clss,
  1931. p_req->update_geneve_port,
  1932. p_req->geneve_port);
  1933. __qed_iov_pf_update_tun_param(p_req, &tunn.ip_geneve,
  1934. QED_MODE_IPGENEVE_TUNN,
  1935. p_req->ipgeneve_clss);
  1936. __qed_iov_pf_update_tun_param(p_req, &tunn.l2_gre,
  1937. QED_MODE_L2GRE_TUNN, p_req->l2gre_clss);
  1938. __qed_iov_pf_update_tun_param(p_req, &tunn.ip_gre,
  1939. QED_MODE_IPGRE_TUNN, p_req->ipgre_clss);
  1940. /* If PF modifies VF's req then it should
  1941. * still return an error in case of partial configuration
  1942. * or modified configuration as opposed to requested one.
  1943. */
  1944. rc = qed_pf_validate_modify_tunn_config(p_hwfn, &tunn_feature_mask,
  1945. &b_update_required, &tunn);
  1946. if (rc)
  1947. status = PFVF_STATUS_FAILURE;
  1948. /* If QED client is willing to update anything ? */
  1949. if (b_update_required) {
  1950. u16 geneve_port;
  1951. rc = qed_sp_pf_update_tunn_cfg(p_hwfn, p_ptt, &tunn,
  1952. QED_SPQ_MODE_EBLOCK, NULL);
  1953. if (rc)
  1954. status = PFVF_STATUS_FAILURE;
  1955. geneve_port = p_tun->geneve_port.port;
  1956. qed_for_each_vf(p_hwfn, i) {
  1957. qed_iov_bulletin_set_udp_ports(p_hwfn, i,
  1958. p_tun->vxlan_port.port,
  1959. geneve_port);
  1960. }
  1961. }
  1962. send_resp:
  1963. p_resp = qed_add_tlv(p_hwfn, &mbx->offset,
  1964. CHANNEL_TLV_UPDATE_TUNN_PARAM, sizeof(*p_resp));
  1965. qed_iov_pf_update_tun_response(p_resp, p_tun, tunn_feature_mask);
  1966. qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
  1967. sizeof(struct channel_list_end_tlv));
  1968. qed_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
  1969. }
  1970. static void qed_iov_vf_mbx_start_txq_resp(struct qed_hwfn *p_hwfn,
  1971. struct qed_ptt *p_ptt,
  1972. struct qed_vf_info *p_vf,
  1973. u32 cid, u8 status)
  1974. {
  1975. struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
  1976. struct pfvf_start_queue_resp_tlv *p_tlv;
  1977. bool b_legacy = false;
  1978. u16 length;
  1979. mbx->offset = (u8 *)mbx->reply_virt;
  1980. /* Taking a bigger struct instead of adding a TLV to list was a
  1981. * mistake, but one which we're now stuck with, as some older
  1982. * clients assume the size of the previous response.
  1983. */
  1984. if (p_vf->acquire.vfdev_info.eth_fp_hsi_minor ==
  1985. ETH_HSI_VER_NO_PKT_LEN_TUNN)
  1986. b_legacy = true;
  1987. if (!b_legacy)
  1988. length = sizeof(*p_tlv);
  1989. else
  1990. length = sizeof(struct pfvf_def_resp_tlv);
  1991. p_tlv = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_START_TXQ,
  1992. length);
  1993. qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
  1994. sizeof(struct channel_list_end_tlv));
  1995. /* Update the TLV with the response */
  1996. if ((status == PFVF_STATUS_SUCCESS) && !b_legacy)
  1997. p_tlv->offset = qed_db_addr_vf(cid, DQ_DEMS_LEGACY);
  1998. qed_iov_send_response(p_hwfn, p_ptt, p_vf, length, status);
  1999. }
  2000. static void qed_iov_vf_mbx_start_txq(struct qed_hwfn *p_hwfn,
  2001. struct qed_ptt *p_ptt,
  2002. struct qed_vf_info *vf)
  2003. {
  2004. struct qed_queue_start_common_params params;
  2005. struct qed_queue_cid_vf_params vf_params;
  2006. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2007. u8 status = PFVF_STATUS_NO_RESOURCE;
  2008. struct vfpf_start_txq_tlv *req;
  2009. struct qed_vf_queue *p_queue;
  2010. struct qed_queue_cid *p_cid;
  2011. struct qed_sb_info sb_dummy;
  2012. u8 qid_usage_idx, vf_legacy;
  2013. u32 cid = 0;
  2014. int rc;
  2015. u16 pq;
  2016. memset(&params, 0, sizeof(params));
  2017. req = &mbx->req_virt->start_txq;
  2018. if (!qed_iov_validate_txq(p_hwfn, vf, req->tx_qid,
  2019. QED_IOV_VALIDATE_Q_NA) ||
  2020. !qed_iov_validate_sb(p_hwfn, vf, req->hw_sb))
  2021. goto out;
  2022. qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, true);
  2023. if (qid_usage_idx == QED_IOV_QID_INVALID)
  2024. goto out;
  2025. p_queue = &vf->vf_queues[req->tx_qid];
  2026. if (p_queue->cids[qid_usage_idx].p_cid)
  2027. goto out;
  2028. vf_legacy = qed_vf_calculate_legacy(vf);
  2029. /* Acquire a new queue-cid */
  2030. params.queue_id = p_queue->fw_tx_qid;
  2031. params.vport_id = vf->vport_id;
  2032. params.stats_id = vf->abs_vf_id + 0x10;
  2033. /* Since IGU index is passed via sb_info, construct a dummy one */
  2034. memset(&sb_dummy, 0, sizeof(sb_dummy));
  2035. sb_dummy.igu_sb_id = req->hw_sb;
  2036. params.p_sb = &sb_dummy;
  2037. params.sb_idx = req->sb_index;
  2038. memset(&vf_params, 0, sizeof(vf_params));
  2039. vf_params.vfid = vf->relative_vf_id;
  2040. vf_params.vf_qid = (u8)req->tx_qid;
  2041. vf_params.vf_legacy = vf_legacy;
  2042. vf_params.qid_usage_idx = qid_usage_idx;
  2043. p_cid = qed_eth_queue_to_cid(p_hwfn, vf->opaque_fid,
  2044. &params, false, &vf_params);
  2045. if (!p_cid)
  2046. goto out;
  2047. pq = qed_get_cm_pq_idx_vf(p_hwfn, vf->relative_vf_id);
  2048. rc = qed_eth_txq_start_ramrod(p_hwfn, p_cid,
  2049. req->pbl_addr, req->pbl_size, pq);
  2050. if (rc) {
  2051. status = PFVF_STATUS_FAILURE;
  2052. qed_eth_queue_cid_release(p_hwfn, p_cid);
  2053. } else {
  2054. status = PFVF_STATUS_SUCCESS;
  2055. p_queue->cids[qid_usage_idx].p_cid = p_cid;
  2056. p_queue->cids[qid_usage_idx].b_is_tx = true;
  2057. cid = p_cid->cid;
  2058. }
  2059. out:
  2060. qed_iov_vf_mbx_start_txq_resp(p_hwfn, p_ptt, vf, cid, status);
  2061. }
  2062. static int qed_iov_vf_stop_rxqs(struct qed_hwfn *p_hwfn,
  2063. struct qed_vf_info *vf,
  2064. u16 rxq_id,
  2065. u8 qid_usage_idx, bool cqe_completion)
  2066. {
  2067. struct qed_vf_queue *p_queue;
  2068. int rc = 0;
  2069. if (!qed_iov_validate_rxq(p_hwfn, vf, rxq_id, QED_IOV_VALIDATE_Q_NA)) {
  2070. DP_VERBOSE(p_hwfn,
  2071. QED_MSG_IOV,
  2072. "VF[%d] Tried Closing Rx 0x%04x.%02x which is inactive\n",
  2073. vf->relative_vf_id, rxq_id, qid_usage_idx);
  2074. return -EINVAL;
  2075. }
  2076. p_queue = &vf->vf_queues[rxq_id];
  2077. /* We've validated the index and the existence of the active RXQ -
  2078. * now we need to make sure that it's using the correct qid.
  2079. */
  2080. if (!p_queue->cids[qid_usage_idx].p_cid ||
  2081. p_queue->cids[qid_usage_idx].b_is_tx) {
  2082. struct qed_queue_cid *p_cid;
  2083. p_cid = qed_iov_get_vf_rx_queue_cid(p_queue);
  2084. DP_VERBOSE(p_hwfn,
  2085. QED_MSG_IOV,
  2086. "VF[%d] - Tried Closing Rx 0x%04x.%02x, but Rx is at %04x.%02x\n",
  2087. vf->relative_vf_id,
  2088. rxq_id, qid_usage_idx, rxq_id, p_cid->qid_usage_idx);
  2089. return -EINVAL;
  2090. }
  2091. /* Now that we know we have a valid Rx-queue - close it */
  2092. rc = qed_eth_rx_queue_stop(p_hwfn,
  2093. p_queue->cids[qid_usage_idx].p_cid,
  2094. false, cqe_completion);
  2095. if (rc)
  2096. return rc;
  2097. p_queue->cids[qid_usage_idx].p_cid = NULL;
  2098. vf->num_active_rxqs--;
  2099. return 0;
  2100. }
  2101. static int qed_iov_vf_stop_txqs(struct qed_hwfn *p_hwfn,
  2102. struct qed_vf_info *vf,
  2103. u16 txq_id, u8 qid_usage_idx)
  2104. {
  2105. struct qed_vf_queue *p_queue;
  2106. int rc = 0;
  2107. if (!qed_iov_validate_txq(p_hwfn, vf, txq_id, QED_IOV_VALIDATE_Q_NA))
  2108. return -EINVAL;
  2109. p_queue = &vf->vf_queues[txq_id];
  2110. if (!p_queue->cids[qid_usage_idx].p_cid ||
  2111. !p_queue->cids[qid_usage_idx].b_is_tx)
  2112. return -EINVAL;
  2113. rc = qed_eth_tx_queue_stop(p_hwfn, p_queue->cids[qid_usage_idx].p_cid);
  2114. if (rc)
  2115. return rc;
  2116. p_queue->cids[qid_usage_idx].p_cid = NULL;
  2117. return 0;
  2118. }
  2119. static void qed_iov_vf_mbx_stop_rxqs(struct qed_hwfn *p_hwfn,
  2120. struct qed_ptt *p_ptt,
  2121. struct qed_vf_info *vf)
  2122. {
  2123. u16 length = sizeof(struct pfvf_def_resp_tlv);
  2124. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2125. u8 status = PFVF_STATUS_FAILURE;
  2126. struct vfpf_stop_rxqs_tlv *req;
  2127. u8 qid_usage_idx;
  2128. int rc;
  2129. /* There has never been an official driver that used this interface
  2130. * for stopping multiple queues, and it is now considered deprecated.
  2131. * Validate this isn't used here.
  2132. */
  2133. req = &mbx->req_virt->stop_rxqs;
  2134. if (req->num_rxqs != 1) {
  2135. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2136. "Odd; VF[%d] tried stopping multiple Rx queues\n",
  2137. vf->relative_vf_id);
  2138. status = PFVF_STATUS_NOT_SUPPORTED;
  2139. goto out;
  2140. }
  2141. /* Find which qid-index is associated with the queue */
  2142. qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
  2143. if (qid_usage_idx == QED_IOV_QID_INVALID)
  2144. goto out;
  2145. rc = qed_iov_vf_stop_rxqs(p_hwfn, vf, req->rx_qid,
  2146. qid_usage_idx, req->cqe_completion);
  2147. if (!rc)
  2148. status = PFVF_STATUS_SUCCESS;
  2149. out:
  2150. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_RXQS,
  2151. length, status);
  2152. }
  2153. static void qed_iov_vf_mbx_stop_txqs(struct qed_hwfn *p_hwfn,
  2154. struct qed_ptt *p_ptt,
  2155. struct qed_vf_info *vf)
  2156. {
  2157. u16 length = sizeof(struct pfvf_def_resp_tlv);
  2158. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2159. u8 status = PFVF_STATUS_FAILURE;
  2160. struct vfpf_stop_txqs_tlv *req;
  2161. u8 qid_usage_idx;
  2162. int rc;
  2163. /* There has never been an official driver that used this interface
  2164. * for stopping multiple queues, and it is now considered deprecated.
  2165. * Validate this isn't used here.
  2166. */
  2167. req = &mbx->req_virt->stop_txqs;
  2168. if (req->num_txqs != 1) {
  2169. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2170. "Odd; VF[%d] tried stopping multiple Tx queues\n",
  2171. vf->relative_vf_id);
  2172. status = PFVF_STATUS_NOT_SUPPORTED;
  2173. goto out;
  2174. }
  2175. /* Find which qid-index is associated with the queue */
  2176. qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, true);
  2177. if (qid_usage_idx == QED_IOV_QID_INVALID)
  2178. goto out;
  2179. rc = qed_iov_vf_stop_txqs(p_hwfn, vf, req->tx_qid, qid_usage_idx);
  2180. if (!rc)
  2181. status = PFVF_STATUS_SUCCESS;
  2182. out:
  2183. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_STOP_TXQS,
  2184. length, status);
  2185. }
  2186. static void qed_iov_vf_mbx_update_rxqs(struct qed_hwfn *p_hwfn,
  2187. struct qed_ptt *p_ptt,
  2188. struct qed_vf_info *vf)
  2189. {
  2190. struct qed_queue_cid *handlers[QED_MAX_VF_CHAINS_PER_PF];
  2191. u16 length = sizeof(struct pfvf_def_resp_tlv);
  2192. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2193. struct vfpf_update_rxq_tlv *req;
  2194. u8 status = PFVF_STATUS_FAILURE;
  2195. u8 complete_event_flg;
  2196. u8 complete_cqe_flg;
  2197. u8 qid_usage_idx;
  2198. int rc;
  2199. u8 i;
  2200. req = &mbx->req_virt->update_rxq;
  2201. complete_cqe_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_CQE_FLAG);
  2202. complete_event_flg = !!(req->flags & VFPF_RXQ_UPD_COMPLETE_EVENT_FLAG);
  2203. qid_usage_idx = qed_iov_vf_mbx_qid(p_hwfn, vf, false);
  2204. if (qid_usage_idx == QED_IOV_QID_INVALID)
  2205. goto out;
  2206. /* There shouldn't exist a VF that uses queue-qids yet uses this
  2207. * API with multiple Rx queues. Validate this.
  2208. */
  2209. if ((vf->acquire.vfdev_info.capabilities &
  2210. VFPF_ACQUIRE_CAP_QUEUE_QIDS) && req->num_rxqs != 1) {
  2211. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2212. "VF[%d] supports QIDs but sends multiple queues\n",
  2213. vf->relative_vf_id);
  2214. goto out;
  2215. }
  2216. /* Validate inputs - for the legacy case this is still true since
  2217. * qid_usage_idx for each Rx queue would be LEGACY_QID_RX.
  2218. */
  2219. for (i = req->rx_qid; i < req->rx_qid + req->num_rxqs; i++) {
  2220. if (!qed_iov_validate_rxq(p_hwfn, vf, i,
  2221. QED_IOV_VALIDATE_Q_NA) ||
  2222. !vf->vf_queues[i].cids[qid_usage_idx].p_cid ||
  2223. vf->vf_queues[i].cids[qid_usage_idx].b_is_tx) {
  2224. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2225. "VF[%d]: Incorrect Rxqs [%04x, %02x]\n",
  2226. vf->relative_vf_id, req->rx_qid,
  2227. req->num_rxqs);
  2228. goto out;
  2229. }
  2230. }
  2231. /* Prepare the handlers */
  2232. for (i = 0; i < req->num_rxqs; i++) {
  2233. u16 qid = req->rx_qid + i;
  2234. handlers[i] = vf->vf_queues[qid].cids[qid_usage_idx].p_cid;
  2235. }
  2236. rc = qed_sp_eth_rx_queues_update(p_hwfn, (void **)&handlers,
  2237. req->num_rxqs,
  2238. complete_cqe_flg,
  2239. complete_event_flg,
  2240. QED_SPQ_MODE_EBLOCK, NULL);
  2241. if (rc)
  2242. goto out;
  2243. status = PFVF_STATUS_SUCCESS;
  2244. out:
  2245. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UPDATE_RXQ,
  2246. length, status);
  2247. }
  2248. void *qed_iov_search_list_tlvs(struct qed_hwfn *p_hwfn,
  2249. void *p_tlvs_list, u16 req_type)
  2250. {
  2251. struct channel_tlv *p_tlv = (struct channel_tlv *)p_tlvs_list;
  2252. int len = 0;
  2253. do {
  2254. if (!p_tlv->length) {
  2255. DP_NOTICE(p_hwfn, "Zero length TLV found\n");
  2256. return NULL;
  2257. }
  2258. if (p_tlv->type == req_type) {
  2259. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2260. "Extended tlv type %d, length %d found\n",
  2261. p_tlv->type, p_tlv->length);
  2262. return p_tlv;
  2263. }
  2264. len += p_tlv->length;
  2265. p_tlv = (struct channel_tlv *)((u8 *)p_tlv + p_tlv->length);
  2266. if ((len + p_tlv->length) > TLV_BUFFER_SIZE) {
  2267. DP_NOTICE(p_hwfn, "TLVs has overrun the buffer size\n");
  2268. return NULL;
  2269. }
  2270. } while (p_tlv->type != CHANNEL_TLV_LIST_END);
  2271. return NULL;
  2272. }
  2273. static void
  2274. qed_iov_vp_update_act_param(struct qed_hwfn *p_hwfn,
  2275. struct qed_sp_vport_update_params *p_data,
  2276. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2277. {
  2278. struct vfpf_vport_update_activate_tlv *p_act_tlv;
  2279. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACTIVATE;
  2280. p_act_tlv = (struct vfpf_vport_update_activate_tlv *)
  2281. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
  2282. if (!p_act_tlv)
  2283. return;
  2284. p_data->update_vport_active_rx_flg = p_act_tlv->update_rx;
  2285. p_data->vport_active_rx_flg = p_act_tlv->active_rx;
  2286. p_data->update_vport_active_tx_flg = p_act_tlv->update_tx;
  2287. p_data->vport_active_tx_flg = p_act_tlv->active_tx;
  2288. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACTIVATE;
  2289. }
  2290. static void
  2291. qed_iov_vp_update_vlan_param(struct qed_hwfn *p_hwfn,
  2292. struct qed_sp_vport_update_params *p_data,
  2293. struct qed_vf_info *p_vf,
  2294. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2295. {
  2296. struct vfpf_vport_update_vlan_strip_tlv *p_vlan_tlv;
  2297. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_VLAN_STRIP;
  2298. p_vlan_tlv = (struct vfpf_vport_update_vlan_strip_tlv *)
  2299. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
  2300. if (!p_vlan_tlv)
  2301. return;
  2302. p_vf->shadow_config.inner_vlan_removal = p_vlan_tlv->remove_vlan;
  2303. /* Ignore the VF request if we're forcing a vlan */
  2304. if (!(p_vf->configured_features & BIT(VLAN_ADDR_FORCED))) {
  2305. p_data->update_inner_vlan_removal_flg = 1;
  2306. p_data->inner_vlan_removal_flg = p_vlan_tlv->remove_vlan;
  2307. }
  2308. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_VLAN_STRIP;
  2309. }
  2310. static void
  2311. qed_iov_vp_update_tx_switch(struct qed_hwfn *p_hwfn,
  2312. struct qed_sp_vport_update_params *p_data,
  2313. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2314. {
  2315. struct vfpf_vport_update_tx_switch_tlv *p_tx_switch_tlv;
  2316. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_TX_SWITCH;
  2317. p_tx_switch_tlv = (struct vfpf_vport_update_tx_switch_tlv *)
  2318. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
  2319. tlv);
  2320. if (!p_tx_switch_tlv)
  2321. return;
  2322. p_data->update_tx_switching_flg = 1;
  2323. p_data->tx_switching_flg = p_tx_switch_tlv->tx_switching;
  2324. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_TX_SWITCH;
  2325. }
  2326. static void
  2327. qed_iov_vp_update_mcast_bin_param(struct qed_hwfn *p_hwfn,
  2328. struct qed_sp_vport_update_params *p_data,
  2329. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2330. {
  2331. struct vfpf_vport_update_mcast_bin_tlv *p_mcast_tlv;
  2332. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_MCAST;
  2333. p_mcast_tlv = (struct vfpf_vport_update_mcast_bin_tlv *)
  2334. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
  2335. if (!p_mcast_tlv)
  2336. return;
  2337. p_data->update_approx_mcast_flg = 1;
  2338. memcpy(p_data->bins, p_mcast_tlv->bins,
  2339. sizeof(unsigned long) * ETH_MULTICAST_MAC_BINS_IN_REGS);
  2340. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_MCAST;
  2341. }
  2342. static void
  2343. qed_iov_vp_update_accept_flag(struct qed_hwfn *p_hwfn,
  2344. struct qed_sp_vport_update_params *p_data,
  2345. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2346. {
  2347. struct qed_filter_accept_flags *p_flags = &p_data->accept_flags;
  2348. struct vfpf_vport_update_accept_param_tlv *p_accept_tlv;
  2349. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_PARAM;
  2350. p_accept_tlv = (struct vfpf_vport_update_accept_param_tlv *)
  2351. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
  2352. if (!p_accept_tlv)
  2353. return;
  2354. p_flags->update_rx_mode_config = p_accept_tlv->update_rx_mode;
  2355. p_flags->rx_accept_filter = p_accept_tlv->rx_accept_filter;
  2356. p_flags->update_tx_mode_config = p_accept_tlv->update_tx_mode;
  2357. p_flags->tx_accept_filter = p_accept_tlv->tx_accept_filter;
  2358. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_PARAM;
  2359. }
  2360. static void
  2361. qed_iov_vp_update_accept_any_vlan(struct qed_hwfn *p_hwfn,
  2362. struct qed_sp_vport_update_params *p_data,
  2363. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2364. {
  2365. struct vfpf_vport_update_accept_any_vlan_tlv *p_accept_any_vlan;
  2366. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_ACCEPT_ANY_VLAN;
  2367. p_accept_any_vlan = (struct vfpf_vport_update_accept_any_vlan_tlv *)
  2368. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt,
  2369. tlv);
  2370. if (!p_accept_any_vlan)
  2371. return;
  2372. p_data->accept_any_vlan = p_accept_any_vlan->accept_any_vlan;
  2373. p_data->update_accept_any_vlan_flg =
  2374. p_accept_any_vlan->update_accept_any_vlan_flg;
  2375. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_ACCEPT_ANY_VLAN;
  2376. }
  2377. static void
  2378. qed_iov_vp_update_rss_param(struct qed_hwfn *p_hwfn,
  2379. struct qed_vf_info *vf,
  2380. struct qed_sp_vport_update_params *p_data,
  2381. struct qed_rss_params *p_rss,
  2382. struct qed_iov_vf_mbx *p_mbx,
  2383. u16 *tlvs_mask, u16 *tlvs_accepted)
  2384. {
  2385. struct vfpf_vport_update_rss_tlv *p_rss_tlv;
  2386. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_RSS;
  2387. bool b_reject = false;
  2388. u16 table_size;
  2389. u16 i, q_idx;
  2390. p_rss_tlv = (struct vfpf_vport_update_rss_tlv *)
  2391. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
  2392. if (!p_rss_tlv) {
  2393. p_data->rss_params = NULL;
  2394. return;
  2395. }
  2396. memset(p_rss, 0, sizeof(struct qed_rss_params));
  2397. p_rss->update_rss_config = !!(p_rss_tlv->update_rss_flags &
  2398. VFPF_UPDATE_RSS_CONFIG_FLAG);
  2399. p_rss->update_rss_capabilities = !!(p_rss_tlv->update_rss_flags &
  2400. VFPF_UPDATE_RSS_CAPS_FLAG);
  2401. p_rss->update_rss_ind_table = !!(p_rss_tlv->update_rss_flags &
  2402. VFPF_UPDATE_RSS_IND_TABLE_FLAG);
  2403. p_rss->update_rss_key = !!(p_rss_tlv->update_rss_flags &
  2404. VFPF_UPDATE_RSS_KEY_FLAG);
  2405. p_rss->rss_enable = p_rss_tlv->rss_enable;
  2406. p_rss->rss_eng_id = vf->relative_vf_id + 1;
  2407. p_rss->rss_caps = p_rss_tlv->rss_caps;
  2408. p_rss->rss_table_size_log = p_rss_tlv->rss_table_size_log;
  2409. memcpy(p_rss->rss_key, p_rss_tlv->rss_key, sizeof(p_rss->rss_key));
  2410. table_size = min_t(u16, ARRAY_SIZE(p_rss->rss_ind_table),
  2411. (1 << p_rss_tlv->rss_table_size_log));
  2412. for (i = 0; i < table_size; i++) {
  2413. struct qed_queue_cid *p_cid;
  2414. q_idx = p_rss_tlv->rss_ind_table[i];
  2415. if (!qed_iov_validate_rxq(p_hwfn, vf, q_idx,
  2416. QED_IOV_VALIDATE_Q_ENABLE)) {
  2417. DP_VERBOSE(p_hwfn,
  2418. QED_MSG_IOV,
  2419. "VF[%d]: Omitting RSS due to wrong queue %04x\n",
  2420. vf->relative_vf_id, q_idx);
  2421. b_reject = true;
  2422. goto out;
  2423. }
  2424. p_cid = qed_iov_get_vf_rx_queue_cid(&vf->vf_queues[q_idx]);
  2425. p_rss->rss_ind_table[i] = p_cid;
  2426. }
  2427. p_data->rss_params = p_rss;
  2428. out:
  2429. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_RSS;
  2430. if (!b_reject)
  2431. *tlvs_accepted |= 1 << QED_IOV_VP_UPDATE_RSS;
  2432. }
  2433. static void
  2434. qed_iov_vp_update_sge_tpa_param(struct qed_hwfn *p_hwfn,
  2435. struct qed_vf_info *vf,
  2436. struct qed_sp_vport_update_params *p_data,
  2437. struct qed_sge_tpa_params *p_sge_tpa,
  2438. struct qed_iov_vf_mbx *p_mbx, u16 *tlvs_mask)
  2439. {
  2440. struct vfpf_vport_update_sge_tpa_tlv *p_sge_tpa_tlv;
  2441. u16 tlv = CHANNEL_TLV_VPORT_UPDATE_SGE_TPA;
  2442. p_sge_tpa_tlv = (struct vfpf_vport_update_sge_tpa_tlv *)
  2443. qed_iov_search_list_tlvs(p_hwfn, p_mbx->req_virt, tlv);
  2444. if (!p_sge_tpa_tlv) {
  2445. p_data->sge_tpa_params = NULL;
  2446. return;
  2447. }
  2448. memset(p_sge_tpa, 0, sizeof(struct qed_sge_tpa_params));
  2449. p_sge_tpa->update_tpa_en_flg =
  2450. !!(p_sge_tpa_tlv->update_sge_tpa_flags & VFPF_UPDATE_TPA_EN_FLAG);
  2451. p_sge_tpa->update_tpa_param_flg =
  2452. !!(p_sge_tpa_tlv->update_sge_tpa_flags &
  2453. VFPF_UPDATE_TPA_PARAM_FLAG);
  2454. p_sge_tpa->tpa_ipv4_en_flg =
  2455. !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV4_EN_FLAG);
  2456. p_sge_tpa->tpa_ipv6_en_flg =
  2457. !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_IPV6_EN_FLAG);
  2458. p_sge_tpa->tpa_pkt_split_flg =
  2459. !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_PKT_SPLIT_FLAG);
  2460. p_sge_tpa->tpa_hdr_data_split_flg =
  2461. !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_HDR_DATA_SPLIT_FLAG);
  2462. p_sge_tpa->tpa_gro_consistent_flg =
  2463. !!(p_sge_tpa_tlv->sge_tpa_flags & VFPF_TPA_GRO_CONSIST_FLAG);
  2464. p_sge_tpa->tpa_max_aggs_num = p_sge_tpa_tlv->tpa_max_aggs_num;
  2465. p_sge_tpa->tpa_max_size = p_sge_tpa_tlv->tpa_max_size;
  2466. p_sge_tpa->tpa_min_size_to_start = p_sge_tpa_tlv->tpa_min_size_to_start;
  2467. p_sge_tpa->tpa_min_size_to_cont = p_sge_tpa_tlv->tpa_min_size_to_cont;
  2468. p_sge_tpa->max_buffers_per_cqe = p_sge_tpa_tlv->max_buffers_per_cqe;
  2469. p_data->sge_tpa_params = p_sge_tpa;
  2470. *tlvs_mask |= 1 << QED_IOV_VP_UPDATE_SGE_TPA;
  2471. }
  2472. static int qed_iov_pre_update_vport(struct qed_hwfn *hwfn,
  2473. u8 vfid,
  2474. struct qed_sp_vport_update_params *params,
  2475. u16 *tlvs)
  2476. {
  2477. u8 mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
  2478. struct qed_filter_accept_flags *flags = &params->accept_flags;
  2479. struct qed_public_vf_info *vf_info;
  2480. /* Untrusted VFs can't even be trusted to know that fact.
  2481. * Simply indicate everything is configured fine, and trace
  2482. * configuration 'behind their back'.
  2483. */
  2484. if (!(*tlvs & BIT(QED_IOV_VP_UPDATE_ACCEPT_PARAM)))
  2485. return 0;
  2486. vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
  2487. if (flags->update_rx_mode_config) {
  2488. vf_info->rx_accept_mode = flags->rx_accept_filter;
  2489. if (!vf_info->is_trusted_configured)
  2490. flags->rx_accept_filter &= ~mask;
  2491. }
  2492. if (flags->update_tx_mode_config) {
  2493. vf_info->tx_accept_mode = flags->tx_accept_filter;
  2494. if (!vf_info->is_trusted_configured)
  2495. flags->tx_accept_filter &= ~mask;
  2496. }
  2497. return 0;
  2498. }
  2499. static void qed_iov_vf_mbx_vport_update(struct qed_hwfn *p_hwfn,
  2500. struct qed_ptt *p_ptt,
  2501. struct qed_vf_info *vf)
  2502. {
  2503. struct qed_rss_params *p_rss_params = NULL;
  2504. struct qed_sp_vport_update_params params;
  2505. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2506. struct qed_sge_tpa_params sge_tpa_params;
  2507. u16 tlvs_mask = 0, tlvs_accepted = 0;
  2508. u8 status = PFVF_STATUS_SUCCESS;
  2509. u16 length;
  2510. int rc;
  2511. /* Valiate PF can send such a request */
  2512. if (!vf->vport_instance) {
  2513. DP_VERBOSE(p_hwfn,
  2514. QED_MSG_IOV,
  2515. "No VPORT instance available for VF[%d], failing vport update\n",
  2516. vf->abs_vf_id);
  2517. status = PFVF_STATUS_FAILURE;
  2518. goto out;
  2519. }
  2520. p_rss_params = vzalloc(sizeof(*p_rss_params));
  2521. if (p_rss_params == NULL) {
  2522. status = PFVF_STATUS_FAILURE;
  2523. goto out;
  2524. }
  2525. memset(&params, 0, sizeof(params));
  2526. params.opaque_fid = vf->opaque_fid;
  2527. params.vport_id = vf->vport_id;
  2528. params.rss_params = NULL;
  2529. /* Search for extended tlvs list and update values
  2530. * from VF in struct qed_sp_vport_update_params.
  2531. */
  2532. qed_iov_vp_update_act_param(p_hwfn, &params, mbx, &tlvs_mask);
  2533. qed_iov_vp_update_vlan_param(p_hwfn, &params, vf, mbx, &tlvs_mask);
  2534. qed_iov_vp_update_tx_switch(p_hwfn, &params, mbx, &tlvs_mask);
  2535. qed_iov_vp_update_mcast_bin_param(p_hwfn, &params, mbx, &tlvs_mask);
  2536. qed_iov_vp_update_accept_flag(p_hwfn, &params, mbx, &tlvs_mask);
  2537. qed_iov_vp_update_accept_any_vlan(p_hwfn, &params, mbx, &tlvs_mask);
  2538. qed_iov_vp_update_sge_tpa_param(p_hwfn, vf, &params,
  2539. &sge_tpa_params, mbx, &tlvs_mask);
  2540. tlvs_accepted = tlvs_mask;
  2541. /* Some of the extended TLVs need to be validated first; In that case,
  2542. * they can update the mask without updating the accepted [so that
  2543. * PF could communicate to VF it has rejected request].
  2544. */
  2545. qed_iov_vp_update_rss_param(p_hwfn, vf, &params, p_rss_params,
  2546. mbx, &tlvs_mask, &tlvs_accepted);
  2547. if (qed_iov_pre_update_vport(p_hwfn, vf->relative_vf_id,
  2548. &params, &tlvs_accepted)) {
  2549. tlvs_accepted = 0;
  2550. status = PFVF_STATUS_NOT_SUPPORTED;
  2551. goto out;
  2552. }
  2553. if (!tlvs_accepted) {
  2554. if (tlvs_mask)
  2555. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2556. "Upper-layer prevents VF vport configuration\n");
  2557. else
  2558. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2559. "No feature tlvs found for vport update\n");
  2560. status = PFVF_STATUS_NOT_SUPPORTED;
  2561. goto out;
  2562. }
  2563. rc = qed_sp_vport_update(p_hwfn, &params, QED_SPQ_MODE_EBLOCK, NULL);
  2564. if (rc)
  2565. status = PFVF_STATUS_FAILURE;
  2566. out:
  2567. vfree(p_rss_params);
  2568. length = qed_iov_prep_vp_update_resp_tlvs(p_hwfn, vf, mbx, status,
  2569. tlvs_mask, tlvs_accepted);
  2570. qed_iov_send_response(p_hwfn, p_ptt, vf, length, status);
  2571. }
  2572. static int qed_iov_vf_update_vlan_shadow(struct qed_hwfn *p_hwfn,
  2573. struct qed_vf_info *p_vf,
  2574. struct qed_filter_ucast *p_params)
  2575. {
  2576. int i;
  2577. /* First remove entries and then add new ones */
  2578. if (p_params->opcode == QED_FILTER_REMOVE) {
  2579. for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
  2580. if (p_vf->shadow_config.vlans[i].used &&
  2581. p_vf->shadow_config.vlans[i].vid ==
  2582. p_params->vlan) {
  2583. p_vf->shadow_config.vlans[i].used = false;
  2584. break;
  2585. }
  2586. if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
  2587. DP_VERBOSE(p_hwfn,
  2588. QED_MSG_IOV,
  2589. "VF [%d] - Tries to remove a non-existing vlan\n",
  2590. p_vf->relative_vf_id);
  2591. return -EINVAL;
  2592. }
  2593. } else if (p_params->opcode == QED_FILTER_REPLACE ||
  2594. p_params->opcode == QED_FILTER_FLUSH) {
  2595. for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++)
  2596. p_vf->shadow_config.vlans[i].used = false;
  2597. }
  2598. /* In forced mode, we're willing to remove entries - but we don't add
  2599. * new ones.
  2600. */
  2601. if (p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED))
  2602. return 0;
  2603. if (p_params->opcode == QED_FILTER_ADD ||
  2604. p_params->opcode == QED_FILTER_REPLACE) {
  2605. for (i = 0; i < QED_ETH_VF_NUM_VLAN_FILTERS + 1; i++) {
  2606. if (p_vf->shadow_config.vlans[i].used)
  2607. continue;
  2608. p_vf->shadow_config.vlans[i].used = true;
  2609. p_vf->shadow_config.vlans[i].vid = p_params->vlan;
  2610. break;
  2611. }
  2612. if (i == QED_ETH_VF_NUM_VLAN_FILTERS + 1) {
  2613. DP_VERBOSE(p_hwfn,
  2614. QED_MSG_IOV,
  2615. "VF [%d] - Tries to configure more than %d vlan filters\n",
  2616. p_vf->relative_vf_id,
  2617. QED_ETH_VF_NUM_VLAN_FILTERS + 1);
  2618. return -EINVAL;
  2619. }
  2620. }
  2621. return 0;
  2622. }
  2623. static int qed_iov_vf_update_mac_shadow(struct qed_hwfn *p_hwfn,
  2624. struct qed_vf_info *p_vf,
  2625. struct qed_filter_ucast *p_params)
  2626. {
  2627. int i;
  2628. /* If we're in forced-mode, we don't allow any change */
  2629. if (p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED))
  2630. return 0;
  2631. /* First remove entries and then add new ones */
  2632. if (p_params->opcode == QED_FILTER_REMOVE) {
  2633. for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
  2634. if (ether_addr_equal(p_vf->shadow_config.macs[i],
  2635. p_params->mac)) {
  2636. eth_zero_addr(p_vf->shadow_config.macs[i]);
  2637. break;
  2638. }
  2639. }
  2640. if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
  2641. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2642. "MAC isn't configured\n");
  2643. return -EINVAL;
  2644. }
  2645. } else if (p_params->opcode == QED_FILTER_REPLACE ||
  2646. p_params->opcode == QED_FILTER_FLUSH) {
  2647. for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++)
  2648. eth_zero_addr(p_vf->shadow_config.macs[i]);
  2649. }
  2650. /* List the new MAC address */
  2651. if (p_params->opcode != QED_FILTER_ADD &&
  2652. p_params->opcode != QED_FILTER_REPLACE)
  2653. return 0;
  2654. for (i = 0; i < QED_ETH_VF_NUM_MAC_FILTERS; i++) {
  2655. if (is_zero_ether_addr(p_vf->shadow_config.macs[i])) {
  2656. ether_addr_copy(p_vf->shadow_config.macs[i],
  2657. p_params->mac);
  2658. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2659. "Added MAC at %d entry in shadow\n", i);
  2660. break;
  2661. }
  2662. }
  2663. if (i == QED_ETH_VF_NUM_MAC_FILTERS) {
  2664. DP_VERBOSE(p_hwfn, QED_MSG_IOV, "No available place for MAC\n");
  2665. return -EINVAL;
  2666. }
  2667. return 0;
  2668. }
  2669. static int
  2670. qed_iov_vf_update_unicast_shadow(struct qed_hwfn *p_hwfn,
  2671. struct qed_vf_info *p_vf,
  2672. struct qed_filter_ucast *p_params)
  2673. {
  2674. int rc = 0;
  2675. if (p_params->type == QED_FILTER_MAC) {
  2676. rc = qed_iov_vf_update_mac_shadow(p_hwfn, p_vf, p_params);
  2677. if (rc)
  2678. return rc;
  2679. }
  2680. if (p_params->type == QED_FILTER_VLAN)
  2681. rc = qed_iov_vf_update_vlan_shadow(p_hwfn, p_vf, p_params);
  2682. return rc;
  2683. }
  2684. static int qed_iov_chk_ucast(struct qed_hwfn *hwfn,
  2685. int vfid, struct qed_filter_ucast *params)
  2686. {
  2687. struct qed_public_vf_info *vf;
  2688. vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
  2689. if (!vf)
  2690. return -EINVAL;
  2691. /* No real decision to make; Store the configured MAC */
  2692. if (params->type == QED_FILTER_MAC ||
  2693. params->type == QED_FILTER_MAC_VLAN)
  2694. ether_addr_copy(vf->mac, params->mac);
  2695. return 0;
  2696. }
  2697. static void qed_iov_vf_mbx_ucast_filter(struct qed_hwfn *p_hwfn,
  2698. struct qed_ptt *p_ptt,
  2699. struct qed_vf_info *vf)
  2700. {
  2701. struct qed_bulletin_content *p_bulletin = vf->bulletin.p_virt;
  2702. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2703. struct vfpf_ucast_filter_tlv *req;
  2704. u8 status = PFVF_STATUS_SUCCESS;
  2705. struct qed_filter_ucast params;
  2706. int rc;
  2707. /* Prepare the unicast filter params */
  2708. memset(&params, 0, sizeof(struct qed_filter_ucast));
  2709. req = &mbx->req_virt->ucast_filter;
  2710. params.opcode = (enum qed_filter_opcode)req->opcode;
  2711. params.type = (enum qed_filter_ucast_type)req->type;
  2712. params.is_rx_filter = 1;
  2713. params.is_tx_filter = 1;
  2714. params.vport_to_remove_from = vf->vport_id;
  2715. params.vport_to_add_to = vf->vport_id;
  2716. memcpy(params.mac, req->mac, ETH_ALEN);
  2717. params.vlan = req->vlan;
  2718. DP_VERBOSE(p_hwfn,
  2719. QED_MSG_IOV,
  2720. "VF[%d]: opcode 0x%02x type 0x%02x [%s %s] [vport 0x%02x] MAC %02x:%02x:%02x:%02x:%02x:%02x, vlan 0x%04x\n",
  2721. vf->abs_vf_id, params.opcode, params.type,
  2722. params.is_rx_filter ? "RX" : "",
  2723. params.is_tx_filter ? "TX" : "",
  2724. params.vport_to_add_to,
  2725. params.mac[0], params.mac[1],
  2726. params.mac[2], params.mac[3],
  2727. params.mac[4], params.mac[5], params.vlan);
  2728. if (!vf->vport_instance) {
  2729. DP_VERBOSE(p_hwfn,
  2730. QED_MSG_IOV,
  2731. "No VPORT instance available for VF[%d], failing ucast MAC configuration\n",
  2732. vf->abs_vf_id);
  2733. status = PFVF_STATUS_FAILURE;
  2734. goto out;
  2735. }
  2736. /* Update shadow copy of the VF configuration */
  2737. if (qed_iov_vf_update_unicast_shadow(p_hwfn, vf, &params)) {
  2738. status = PFVF_STATUS_FAILURE;
  2739. goto out;
  2740. }
  2741. /* Determine if the unicast filtering is acceptible by PF */
  2742. if ((p_bulletin->valid_bitmap & BIT(VLAN_ADDR_FORCED)) &&
  2743. (params.type == QED_FILTER_VLAN ||
  2744. params.type == QED_FILTER_MAC_VLAN)) {
  2745. /* Once VLAN is forced or PVID is set, do not allow
  2746. * to add/replace any further VLANs.
  2747. */
  2748. if (params.opcode == QED_FILTER_ADD ||
  2749. params.opcode == QED_FILTER_REPLACE)
  2750. status = PFVF_STATUS_FORCED;
  2751. goto out;
  2752. }
  2753. if ((p_bulletin->valid_bitmap & BIT(MAC_ADDR_FORCED)) &&
  2754. (params.type == QED_FILTER_MAC ||
  2755. params.type == QED_FILTER_MAC_VLAN)) {
  2756. if (!ether_addr_equal(p_bulletin->mac, params.mac) ||
  2757. (params.opcode != QED_FILTER_ADD &&
  2758. params.opcode != QED_FILTER_REPLACE))
  2759. status = PFVF_STATUS_FORCED;
  2760. goto out;
  2761. }
  2762. rc = qed_iov_chk_ucast(p_hwfn, vf->relative_vf_id, &params);
  2763. if (rc) {
  2764. status = PFVF_STATUS_FAILURE;
  2765. goto out;
  2766. }
  2767. rc = qed_sp_eth_filter_ucast(p_hwfn, vf->opaque_fid, &params,
  2768. QED_SPQ_MODE_CB, NULL);
  2769. if (rc)
  2770. status = PFVF_STATUS_FAILURE;
  2771. out:
  2772. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_UCAST_FILTER,
  2773. sizeof(struct pfvf_def_resp_tlv), status);
  2774. }
  2775. static void qed_iov_vf_mbx_int_cleanup(struct qed_hwfn *p_hwfn,
  2776. struct qed_ptt *p_ptt,
  2777. struct qed_vf_info *vf)
  2778. {
  2779. int i;
  2780. /* Reset the SBs */
  2781. for (i = 0; i < vf->num_sbs; i++)
  2782. qed_int_igu_init_pure_rt_single(p_hwfn, p_ptt,
  2783. vf->igu_sbs[i],
  2784. vf->opaque_fid, false);
  2785. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_INT_CLEANUP,
  2786. sizeof(struct pfvf_def_resp_tlv),
  2787. PFVF_STATUS_SUCCESS);
  2788. }
  2789. static void qed_iov_vf_mbx_close(struct qed_hwfn *p_hwfn,
  2790. struct qed_ptt *p_ptt, struct qed_vf_info *vf)
  2791. {
  2792. u16 length = sizeof(struct pfvf_def_resp_tlv);
  2793. u8 status = PFVF_STATUS_SUCCESS;
  2794. /* Disable Interrupts for VF */
  2795. qed_iov_vf_igu_set_int(p_hwfn, p_ptt, vf, 0);
  2796. /* Reset Permission table */
  2797. qed_iov_config_perm_table(p_hwfn, p_ptt, vf, 0);
  2798. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_CLOSE,
  2799. length, status);
  2800. }
  2801. static void qed_iov_vf_mbx_release(struct qed_hwfn *p_hwfn,
  2802. struct qed_ptt *p_ptt,
  2803. struct qed_vf_info *p_vf)
  2804. {
  2805. u16 length = sizeof(struct pfvf_def_resp_tlv);
  2806. u8 status = PFVF_STATUS_SUCCESS;
  2807. int rc = 0;
  2808. qed_iov_vf_cleanup(p_hwfn, p_vf);
  2809. if (p_vf->state != VF_STOPPED && p_vf->state != VF_FREE) {
  2810. /* Stopping the VF */
  2811. rc = qed_sp_vf_stop(p_hwfn, p_vf->concrete_fid,
  2812. p_vf->opaque_fid);
  2813. if (rc) {
  2814. DP_ERR(p_hwfn, "qed_sp_vf_stop returned error %d\n",
  2815. rc);
  2816. status = PFVF_STATUS_FAILURE;
  2817. }
  2818. p_vf->state = VF_STOPPED;
  2819. }
  2820. qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf, CHANNEL_TLV_RELEASE,
  2821. length, status);
  2822. }
  2823. static void qed_iov_vf_pf_get_coalesce(struct qed_hwfn *p_hwfn,
  2824. struct qed_ptt *p_ptt,
  2825. struct qed_vf_info *p_vf)
  2826. {
  2827. struct qed_iov_vf_mbx *mbx = &p_vf->vf_mbx;
  2828. struct pfvf_read_coal_resp_tlv *p_resp;
  2829. struct vfpf_read_coal_req_tlv *req;
  2830. u8 status = PFVF_STATUS_FAILURE;
  2831. struct qed_vf_queue *p_queue;
  2832. struct qed_queue_cid *p_cid;
  2833. u16 coal = 0, qid, i;
  2834. bool b_is_rx;
  2835. int rc = 0;
  2836. mbx->offset = (u8 *)mbx->reply_virt;
  2837. req = &mbx->req_virt->read_coal_req;
  2838. qid = req->qid;
  2839. b_is_rx = req->is_rx ? true : false;
  2840. if (b_is_rx) {
  2841. if (!qed_iov_validate_rxq(p_hwfn, p_vf, qid,
  2842. QED_IOV_VALIDATE_Q_ENABLE)) {
  2843. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2844. "VF[%d]: Invalid Rx queue_id = %d\n",
  2845. p_vf->abs_vf_id, qid);
  2846. goto send_resp;
  2847. }
  2848. p_cid = qed_iov_get_vf_rx_queue_cid(&p_vf->vf_queues[qid]);
  2849. rc = qed_get_rxq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
  2850. if (rc)
  2851. goto send_resp;
  2852. } else {
  2853. if (!qed_iov_validate_txq(p_hwfn, p_vf, qid,
  2854. QED_IOV_VALIDATE_Q_ENABLE)) {
  2855. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2856. "VF[%d]: Invalid Tx queue_id = %d\n",
  2857. p_vf->abs_vf_id, qid);
  2858. goto send_resp;
  2859. }
  2860. for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
  2861. p_queue = &p_vf->vf_queues[qid];
  2862. if ((!p_queue->cids[i].p_cid) ||
  2863. (!p_queue->cids[i].b_is_tx))
  2864. continue;
  2865. p_cid = p_queue->cids[i].p_cid;
  2866. rc = qed_get_txq_coalesce(p_hwfn, p_ptt, p_cid, &coal);
  2867. if (rc)
  2868. goto send_resp;
  2869. break;
  2870. }
  2871. }
  2872. status = PFVF_STATUS_SUCCESS;
  2873. send_resp:
  2874. p_resp = qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_COALESCE_READ,
  2875. sizeof(*p_resp));
  2876. p_resp->coal = coal;
  2877. qed_add_tlv(p_hwfn, &mbx->offset, CHANNEL_TLV_LIST_END,
  2878. sizeof(struct channel_list_end_tlv));
  2879. qed_iov_send_response(p_hwfn, p_ptt, p_vf, sizeof(*p_resp), status);
  2880. }
  2881. static void qed_iov_vf_pf_set_coalesce(struct qed_hwfn *p_hwfn,
  2882. struct qed_ptt *p_ptt,
  2883. struct qed_vf_info *vf)
  2884. {
  2885. struct qed_iov_vf_mbx *mbx = &vf->vf_mbx;
  2886. struct vfpf_update_coalesce *req;
  2887. u8 status = PFVF_STATUS_FAILURE;
  2888. struct qed_queue_cid *p_cid;
  2889. u16 rx_coal, tx_coal;
  2890. int rc = 0, i;
  2891. u16 qid;
  2892. req = &mbx->req_virt->update_coalesce;
  2893. rx_coal = req->rx_coal;
  2894. tx_coal = req->tx_coal;
  2895. qid = req->qid;
  2896. if (!qed_iov_validate_rxq(p_hwfn, vf, qid,
  2897. QED_IOV_VALIDATE_Q_ENABLE) && rx_coal) {
  2898. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2899. "VF[%d]: Invalid Rx queue_id = %d\n",
  2900. vf->abs_vf_id, qid);
  2901. goto out;
  2902. }
  2903. if (!qed_iov_validate_txq(p_hwfn, vf, qid,
  2904. QED_IOV_VALIDATE_Q_ENABLE) && tx_coal) {
  2905. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  2906. "VF[%d]: Invalid Tx queue_id = %d\n",
  2907. vf->abs_vf_id, qid);
  2908. goto out;
  2909. }
  2910. DP_VERBOSE(p_hwfn,
  2911. QED_MSG_IOV,
  2912. "VF[%d]: Setting coalesce for VF rx_coal = %d, tx_coal = %d at queue = %d\n",
  2913. vf->abs_vf_id, rx_coal, tx_coal, qid);
  2914. if (rx_coal) {
  2915. p_cid = qed_iov_get_vf_rx_queue_cid(&vf->vf_queues[qid]);
  2916. rc = qed_set_rxq_coalesce(p_hwfn, p_ptt, rx_coal, p_cid);
  2917. if (rc) {
  2918. DP_VERBOSE(p_hwfn,
  2919. QED_MSG_IOV,
  2920. "VF[%d]: Unable to set rx queue = %d coalesce\n",
  2921. vf->abs_vf_id, vf->vf_queues[qid].fw_rx_qid);
  2922. goto out;
  2923. }
  2924. vf->rx_coal = rx_coal;
  2925. }
  2926. if (tx_coal) {
  2927. struct qed_vf_queue *p_queue = &vf->vf_queues[qid];
  2928. for (i = 0; i < MAX_QUEUES_PER_QZONE; i++) {
  2929. if (!p_queue->cids[i].p_cid)
  2930. continue;
  2931. if (!p_queue->cids[i].b_is_tx)
  2932. continue;
  2933. rc = qed_set_txq_coalesce(p_hwfn, p_ptt, tx_coal,
  2934. p_queue->cids[i].p_cid);
  2935. if (rc) {
  2936. DP_VERBOSE(p_hwfn,
  2937. QED_MSG_IOV,
  2938. "VF[%d]: Unable to set tx queue coalesce\n",
  2939. vf->abs_vf_id);
  2940. goto out;
  2941. }
  2942. }
  2943. vf->tx_coal = tx_coal;
  2944. }
  2945. status = PFVF_STATUS_SUCCESS;
  2946. out:
  2947. qed_iov_prepare_resp(p_hwfn, p_ptt, vf, CHANNEL_TLV_COALESCE_UPDATE,
  2948. sizeof(struct pfvf_def_resp_tlv), status);
  2949. }
  2950. static int
  2951. qed_iov_vf_flr_poll_dorq(struct qed_hwfn *p_hwfn,
  2952. struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
  2953. {
  2954. int cnt;
  2955. u32 val;
  2956. qed_fid_pretend(p_hwfn, p_ptt, (u16) p_vf->concrete_fid);
  2957. for (cnt = 0; cnt < 50; cnt++) {
  2958. val = qed_rd(p_hwfn, p_ptt, DORQ_REG_VF_USAGE_CNT);
  2959. if (!val)
  2960. break;
  2961. msleep(20);
  2962. }
  2963. qed_fid_pretend(p_hwfn, p_ptt, (u16) p_hwfn->hw_info.concrete_fid);
  2964. if (cnt == 50) {
  2965. DP_ERR(p_hwfn,
  2966. "VF[%d] - dorq failed to cleanup [usage 0x%08x]\n",
  2967. p_vf->abs_vf_id, val);
  2968. return -EBUSY;
  2969. }
  2970. return 0;
  2971. }
  2972. static int
  2973. qed_iov_vf_flr_poll_pbf(struct qed_hwfn *p_hwfn,
  2974. struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
  2975. {
  2976. u32 cons[MAX_NUM_VOQS], distance[MAX_NUM_VOQS];
  2977. int i, cnt;
  2978. /* Read initial consumers & producers */
  2979. for (i = 0; i < MAX_NUM_VOQS; i++) {
  2980. u32 prod;
  2981. cons[i] = qed_rd(p_hwfn, p_ptt,
  2982. PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
  2983. i * 0x40);
  2984. prod = qed_rd(p_hwfn, p_ptt,
  2985. PBF_REG_NUM_BLOCKS_ALLOCATED_PROD_VOQ0 +
  2986. i * 0x40);
  2987. distance[i] = prod - cons[i];
  2988. }
  2989. /* Wait for consumers to pass the producers */
  2990. i = 0;
  2991. for (cnt = 0; cnt < 50; cnt++) {
  2992. for (; i < MAX_NUM_VOQS; i++) {
  2993. u32 tmp;
  2994. tmp = qed_rd(p_hwfn, p_ptt,
  2995. PBF_REG_NUM_BLOCKS_ALLOCATED_CONS_VOQ0 +
  2996. i * 0x40);
  2997. if (distance[i] > tmp - cons[i])
  2998. break;
  2999. }
  3000. if (i == MAX_NUM_VOQS)
  3001. break;
  3002. msleep(20);
  3003. }
  3004. if (cnt == 50) {
  3005. DP_ERR(p_hwfn, "VF[%d] - pbf polling failed on VOQ %d\n",
  3006. p_vf->abs_vf_id, i);
  3007. return -EBUSY;
  3008. }
  3009. return 0;
  3010. }
  3011. static int qed_iov_vf_flr_poll(struct qed_hwfn *p_hwfn,
  3012. struct qed_vf_info *p_vf, struct qed_ptt *p_ptt)
  3013. {
  3014. int rc;
  3015. rc = qed_iov_vf_flr_poll_dorq(p_hwfn, p_vf, p_ptt);
  3016. if (rc)
  3017. return rc;
  3018. rc = qed_iov_vf_flr_poll_pbf(p_hwfn, p_vf, p_ptt);
  3019. if (rc)
  3020. return rc;
  3021. return 0;
  3022. }
  3023. static int
  3024. qed_iov_execute_vf_flr_cleanup(struct qed_hwfn *p_hwfn,
  3025. struct qed_ptt *p_ptt,
  3026. u16 rel_vf_id, u32 *ack_vfs)
  3027. {
  3028. struct qed_vf_info *p_vf;
  3029. int rc = 0;
  3030. p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, false);
  3031. if (!p_vf)
  3032. return 0;
  3033. if (p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &
  3034. (1ULL << (rel_vf_id % 64))) {
  3035. u16 vfid = p_vf->abs_vf_id;
  3036. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3037. "VF[%d] - Handling FLR\n", vfid);
  3038. qed_iov_vf_cleanup(p_hwfn, p_vf);
  3039. /* If VF isn't active, no need for anything but SW */
  3040. if (!p_vf->b_init)
  3041. goto cleanup;
  3042. rc = qed_iov_vf_flr_poll(p_hwfn, p_vf, p_ptt);
  3043. if (rc)
  3044. goto cleanup;
  3045. rc = qed_final_cleanup(p_hwfn, p_ptt, vfid, true);
  3046. if (rc) {
  3047. DP_ERR(p_hwfn, "Failed handle FLR of VF[%d]\n", vfid);
  3048. return rc;
  3049. }
  3050. /* Workaround to make VF-PF channel ready, as FW
  3051. * doesn't do that as a part of FLR.
  3052. */
  3053. REG_WR(p_hwfn,
  3054. GTT_BAR0_MAP_REG_USDM_RAM +
  3055. USTORM_VF_PF_CHANNEL_READY_OFFSET(vfid), 1);
  3056. /* VF_STOPPED has to be set only after final cleanup
  3057. * but prior to re-enabling the VF.
  3058. */
  3059. p_vf->state = VF_STOPPED;
  3060. rc = qed_iov_enable_vf_access(p_hwfn, p_ptt, p_vf);
  3061. if (rc) {
  3062. DP_ERR(p_hwfn, "Failed to re-enable VF[%d] acces\n",
  3063. vfid);
  3064. return rc;
  3065. }
  3066. cleanup:
  3067. /* Mark VF for ack and clean pending state */
  3068. if (p_vf->state == VF_RESET)
  3069. p_vf->state = VF_STOPPED;
  3070. ack_vfs[vfid / 32] |= BIT((vfid % 32));
  3071. p_hwfn->pf_iov_info->pending_flr[rel_vf_id / 64] &=
  3072. ~(1ULL << (rel_vf_id % 64));
  3073. p_vf->vf_mbx.b_pending_msg = false;
  3074. }
  3075. return rc;
  3076. }
  3077. static int
  3078. qed_iov_vf_flr_cleanup(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  3079. {
  3080. u32 ack_vfs[VF_MAX_STATIC / 32];
  3081. int rc = 0;
  3082. u16 i;
  3083. memset(ack_vfs, 0, sizeof(u32) * (VF_MAX_STATIC / 32));
  3084. /* Since BRB <-> PRS interface can't be tested as part of the flr
  3085. * polling due to HW limitations, simply sleep a bit. And since
  3086. * there's no need to wait per-vf, do it before looping.
  3087. */
  3088. msleep(100);
  3089. for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++)
  3090. qed_iov_execute_vf_flr_cleanup(p_hwfn, p_ptt, i, ack_vfs);
  3091. rc = qed_mcp_ack_vf_flr(p_hwfn, p_ptt, ack_vfs);
  3092. return rc;
  3093. }
  3094. bool qed_iov_mark_vf_flr(struct qed_hwfn *p_hwfn, u32 *p_disabled_vfs)
  3095. {
  3096. bool found = false;
  3097. u16 i;
  3098. DP_VERBOSE(p_hwfn, QED_MSG_IOV, "Marking FLR-ed VFs\n");
  3099. for (i = 0; i < (VF_MAX_STATIC / 32); i++)
  3100. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3101. "[%08x,...,%08x]: %08x\n",
  3102. i * 32, (i + 1) * 32 - 1, p_disabled_vfs[i]);
  3103. if (!p_hwfn->cdev->p_iov_info) {
  3104. DP_NOTICE(p_hwfn, "VF flr but no IOV\n");
  3105. return false;
  3106. }
  3107. /* Mark VFs */
  3108. for (i = 0; i < p_hwfn->cdev->p_iov_info->total_vfs; i++) {
  3109. struct qed_vf_info *p_vf;
  3110. u8 vfid;
  3111. p_vf = qed_iov_get_vf_info(p_hwfn, i, false);
  3112. if (!p_vf)
  3113. continue;
  3114. vfid = p_vf->abs_vf_id;
  3115. if (BIT((vfid % 32)) & p_disabled_vfs[vfid / 32]) {
  3116. u64 *p_flr = p_hwfn->pf_iov_info->pending_flr;
  3117. u16 rel_vf_id = p_vf->relative_vf_id;
  3118. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3119. "VF[%d] [rel %d] got FLR-ed\n",
  3120. vfid, rel_vf_id);
  3121. p_vf->state = VF_RESET;
  3122. /* No need to lock here, since pending_flr should
  3123. * only change here and before ACKing MFw. Since
  3124. * MFW will not trigger an additional attention for
  3125. * VF flr until ACKs, we're safe.
  3126. */
  3127. p_flr[rel_vf_id / 64] |= 1ULL << (rel_vf_id % 64);
  3128. found = true;
  3129. }
  3130. }
  3131. return found;
  3132. }
  3133. static void qed_iov_get_link(struct qed_hwfn *p_hwfn,
  3134. u16 vfid,
  3135. struct qed_mcp_link_params *p_params,
  3136. struct qed_mcp_link_state *p_link,
  3137. struct qed_mcp_link_capabilities *p_caps)
  3138. {
  3139. struct qed_vf_info *p_vf = qed_iov_get_vf_info(p_hwfn,
  3140. vfid,
  3141. false);
  3142. struct qed_bulletin_content *p_bulletin;
  3143. if (!p_vf)
  3144. return;
  3145. p_bulletin = p_vf->bulletin.p_virt;
  3146. if (p_params)
  3147. __qed_vf_get_link_params(p_hwfn, p_params, p_bulletin);
  3148. if (p_link)
  3149. __qed_vf_get_link_state(p_hwfn, p_link, p_bulletin);
  3150. if (p_caps)
  3151. __qed_vf_get_link_caps(p_hwfn, p_caps, p_bulletin);
  3152. }
  3153. static void qed_iov_process_mbx_req(struct qed_hwfn *p_hwfn,
  3154. struct qed_ptt *p_ptt, int vfid)
  3155. {
  3156. struct qed_iov_vf_mbx *mbx;
  3157. struct qed_vf_info *p_vf;
  3158. p_vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3159. if (!p_vf)
  3160. return;
  3161. mbx = &p_vf->vf_mbx;
  3162. /* qed_iov_process_mbx_request */
  3163. if (!mbx->b_pending_msg) {
  3164. DP_NOTICE(p_hwfn,
  3165. "VF[%02x]: Trying to process mailbox message when none is pending\n",
  3166. p_vf->abs_vf_id);
  3167. return;
  3168. }
  3169. mbx->b_pending_msg = false;
  3170. mbx->first_tlv = mbx->req_virt->first_tlv;
  3171. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3172. "VF[%02x]: Processing mailbox message [type %04x]\n",
  3173. p_vf->abs_vf_id, mbx->first_tlv.tl.type);
  3174. /* check if tlv type is known */
  3175. if (qed_iov_tlv_supported(mbx->first_tlv.tl.type) &&
  3176. !p_vf->b_malicious) {
  3177. switch (mbx->first_tlv.tl.type) {
  3178. case CHANNEL_TLV_ACQUIRE:
  3179. qed_iov_vf_mbx_acquire(p_hwfn, p_ptt, p_vf);
  3180. break;
  3181. case CHANNEL_TLV_VPORT_START:
  3182. qed_iov_vf_mbx_start_vport(p_hwfn, p_ptt, p_vf);
  3183. break;
  3184. case CHANNEL_TLV_VPORT_TEARDOWN:
  3185. qed_iov_vf_mbx_stop_vport(p_hwfn, p_ptt, p_vf);
  3186. break;
  3187. case CHANNEL_TLV_START_RXQ:
  3188. qed_iov_vf_mbx_start_rxq(p_hwfn, p_ptt, p_vf);
  3189. break;
  3190. case CHANNEL_TLV_START_TXQ:
  3191. qed_iov_vf_mbx_start_txq(p_hwfn, p_ptt, p_vf);
  3192. break;
  3193. case CHANNEL_TLV_STOP_RXQS:
  3194. qed_iov_vf_mbx_stop_rxqs(p_hwfn, p_ptt, p_vf);
  3195. break;
  3196. case CHANNEL_TLV_STOP_TXQS:
  3197. qed_iov_vf_mbx_stop_txqs(p_hwfn, p_ptt, p_vf);
  3198. break;
  3199. case CHANNEL_TLV_UPDATE_RXQ:
  3200. qed_iov_vf_mbx_update_rxqs(p_hwfn, p_ptt, p_vf);
  3201. break;
  3202. case CHANNEL_TLV_VPORT_UPDATE:
  3203. qed_iov_vf_mbx_vport_update(p_hwfn, p_ptt, p_vf);
  3204. break;
  3205. case CHANNEL_TLV_UCAST_FILTER:
  3206. qed_iov_vf_mbx_ucast_filter(p_hwfn, p_ptt, p_vf);
  3207. break;
  3208. case CHANNEL_TLV_CLOSE:
  3209. qed_iov_vf_mbx_close(p_hwfn, p_ptt, p_vf);
  3210. break;
  3211. case CHANNEL_TLV_INT_CLEANUP:
  3212. qed_iov_vf_mbx_int_cleanup(p_hwfn, p_ptt, p_vf);
  3213. break;
  3214. case CHANNEL_TLV_RELEASE:
  3215. qed_iov_vf_mbx_release(p_hwfn, p_ptt, p_vf);
  3216. break;
  3217. case CHANNEL_TLV_UPDATE_TUNN_PARAM:
  3218. qed_iov_vf_mbx_update_tunn_param(p_hwfn, p_ptt, p_vf);
  3219. break;
  3220. case CHANNEL_TLV_COALESCE_UPDATE:
  3221. qed_iov_vf_pf_set_coalesce(p_hwfn, p_ptt, p_vf);
  3222. break;
  3223. case CHANNEL_TLV_COALESCE_READ:
  3224. qed_iov_vf_pf_get_coalesce(p_hwfn, p_ptt, p_vf);
  3225. break;
  3226. }
  3227. } else if (qed_iov_tlv_supported(mbx->first_tlv.tl.type)) {
  3228. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3229. "VF [%02x] - considered malicious; Ignoring TLV [%04x]\n",
  3230. p_vf->abs_vf_id, mbx->first_tlv.tl.type);
  3231. qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
  3232. mbx->first_tlv.tl.type,
  3233. sizeof(struct pfvf_def_resp_tlv),
  3234. PFVF_STATUS_MALICIOUS);
  3235. } else {
  3236. /* unknown TLV - this may belong to a VF driver from the future
  3237. * - a version written after this PF driver was written, which
  3238. * supports features unknown as of yet. Too bad since we don't
  3239. * support them. Or this may be because someone wrote a crappy
  3240. * VF driver and is sending garbage over the channel.
  3241. */
  3242. DP_NOTICE(p_hwfn,
  3243. "VF[%02x]: unknown TLV. type %04x length %04x padding %08x reply address %llu\n",
  3244. p_vf->abs_vf_id,
  3245. mbx->first_tlv.tl.type,
  3246. mbx->first_tlv.tl.length,
  3247. mbx->first_tlv.padding, mbx->first_tlv.reply_address);
  3248. /* Try replying in case reply address matches the acquisition's
  3249. * posted address.
  3250. */
  3251. if (p_vf->acquire.first_tlv.reply_address &&
  3252. (mbx->first_tlv.reply_address ==
  3253. p_vf->acquire.first_tlv.reply_address)) {
  3254. qed_iov_prepare_resp(p_hwfn, p_ptt, p_vf,
  3255. mbx->first_tlv.tl.type,
  3256. sizeof(struct pfvf_def_resp_tlv),
  3257. PFVF_STATUS_NOT_SUPPORTED);
  3258. } else {
  3259. DP_VERBOSE(p_hwfn,
  3260. QED_MSG_IOV,
  3261. "VF[%02x]: Can't respond to TLV - no valid reply address\n",
  3262. p_vf->abs_vf_id);
  3263. }
  3264. }
  3265. }
  3266. void qed_iov_pf_get_pending_events(struct qed_hwfn *p_hwfn, u64 *events)
  3267. {
  3268. int i;
  3269. memset(events, 0, sizeof(u64) * QED_VF_ARRAY_LENGTH);
  3270. qed_for_each_vf(p_hwfn, i) {
  3271. struct qed_vf_info *p_vf;
  3272. p_vf = &p_hwfn->pf_iov_info->vfs_array[i];
  3273. if (p_vf->vf_mbx.b_pending_msg)
  3274. events[i / 64] |= 1ULL << (i % 64);
  3275. }
  3276. }
  3277. static struct qed_vf_info *qed_sriov_get_vf_from_absid(struct qed_hwfn *p_hwfn,
  3278. u16 abs_vfid)
  3279. {
  3280. u8 min = (u8) p_hwfn->cdev->p_iov_info->first_vf_in_pf;
  3281. if (!_qed_iov_pf_sanity_check(p_hwfn, (int)abs_vfid - min, false)) {
  3282. DP_VERBOSE(p_hwfn,
  3283. QED_MSG_IOV,
  3284. "Got indication for VF [abs 0x%08x] that cannot be handled by PF\n",
  3285. abs_vfid);
  3286. return NULL;
  3287. }
  3288. return &p_hwfn->pf_iov_info->vfs_array[(u8) abs_vfid - min];
  3289. }
  3290. static int qed_sriov_vfpf_msg(struct qed_hwfn *p_hwfn,
  3291. u16 abs_vfid, struct regpair *vf_msg)
  3292. {
  3293. struct qed_vf_info *p_vf = qed_sriov_get_vf_from_absid(p_hwfn,
  3294. abs_vfid);
  3295. if (!p_vf)
  3296. return 0;
  3297. /* List the physical address of the request so that handler
  3298. * could later on copy the message from it.
  3299. */
  3300. p_vf->vf_mbx.pending_req = (((u64)vf_msg->hi) << 32) | vf_msg->lo;
  3301. /* Mark the event and schedule the workqueue */
  3302. p_vf->vf_mbx.b_pending_msg = true;
  3303. qed_schedule_iov(p_hwfn, QED_IOV_WQ_MSG_FLAG);
  3304. return 0;
  3305. }
  3306. static void qed_sriov_vfpf_malicious(struct qed_hwfn *p_hwfn,
  3307. struct malicious_vf_eqe_data *p_data)
  3308. {
  3309. struct qed_vf_info *p_vf;
  3310. p_vf = qed_sriov_get_vf_from_absid(p_hwfn, p_data->vf_id);
  3311. if (!p_vf)
  3312. return;
  3313. if (!p_vf->b_malicious) {
  3314. DP_NOTICE(p_hwfn,
  3315. "VF [%d] - Malicious behavior [%02x]\n",
  3316. p_vf->abs_vf_id, p_data->err_id);
  3317. p_vf->b_malicious = true;
  3318. } else {
  3319. DP_INFO(p_hwfn,
  3320. "VF [%d] - Malicious behavior [%02x]\n",
  3321. p_vf->abs_vf_id, p_data->err_id);
  3322. }
  3323. }
  3324. static int qed_sriov_eqe_event(struct qed_hwfn *p_hwfn,
  3325. u8 opcode,
  3326. __le16 echo,
  3327. union event_ring_data *data, u8 fw_return_code)
  3328. {
  3329. switch (opcode) {
  3330. case COMMON_EVENT_VF_PF_CHANNEL:
  3331. return qed_sriov_vfpf_msg(p_hwfn, le16_to_cpu(echo),
  3332. &data->vf_pf_channel.msg_addr);
  3333. case COMMON_EVENT_MALICIOUS_VF:
  3334. qed_sriov_vfpf_malicious(p_hwfn, &data->malicious_vf);
  3335. return 0;
  3336. default:
  3337. DP_INFO(p_hwfn->cdev, "Unknown sriov eqe event 0x%02x\n",
  3338. opcode);
  3339. return -EINVAL;
  3340. }
  3341. }
  3342. u16 qed_iov_get_next_active_vf(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
  3343. {
  3344. struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
  3345. u16 i;
  3346. if (!p_iov)
  3347. goto out;
  3348. for (i = rel_vf_id; i < p_iov->total_vfs; i++)
  3349. if (qed_iov_is_valid_vfid(p_hwfn, rel_vf_id, true, false))
  3350. return i;
  3351. out:
  3352. return MAX_NUM_VFS;
  3353. }
  3354. static int qed_iov_copy_vf_msg(struct qed_hwfn *p_hwfn, struct qed_ptt *ptt,
  3355. int vfid)
  3356. {
  3357. struct qed_dmae_params params;
  3358. struct qed_vf_info *vf_info;
  3359. vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3360. if (!vf_info)
  3361. return -EINVAL;
  3362. memset(&params, 0, sizeof(struct qed_dmae_params));
  3363. params.flags = QED_DMAE_FLAG_VF_SRC | QED_DMAE_FLAG_COMPLETION_DST;
  3364. params.src_vfid = vf_info->abs_vf_id;
  3365. if (qed_dmae_host2host(p_hwfn, ptt,
  3366. vf_info->vf_mbx.pending_req,
  3367. vf_info->vf_mbx.req_phys,
  3368. sizeof(union vfpf_tlvs) / 4, &params)) {
  3369. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3370. "Failed to copy message from VF 0x%02x\n", vfid);
  3371. return -EIO;
  3372. }
  3373. return 0;
  3374. }
  3375. static void qed_iov_bulletin_set_forced_mac(struct qed_hwfn *p_hwfn,
  3376. u8 *mac, int vfid)
  3377. {
  3378. struct qed_vf_info *vf_info;
  3379. u64 feature;
  3380. vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
  3381. if (!vf_info) {
  3382. DP_NOTICE(p_hwfn->cdev,
  3383. "Can not set forced MAC, invalid vfid [%d]\n", vfid);
  3384. return;
  3385. }
  3386. if (vf_info->b_malicious) {
  3387. DP_NOTICE(p_hwfn->cdev,
  3388. "Can't set forced MAC to malicious VF [%d]\n", vfid);
  3389. return;
  3390. }
  3391. feature = 1 << MAC_ADDR_FORCED;
  3392. memcpy(vf_info->bulletin.p_virt->mac, mac, ETH_ALEN);
  3393. vf_info->bulletin.p_virt->valid_bitmap |= feature;
  3394. /* Forced MAC will disable MAC_ADDR */
  3395. vf_info->bulletin.p_virt->valid_bitmap &= ~BIT(VFPF_BULLETIN_MAC_ADDR);
  3396. qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
  3397. }
  3398. static void qed_iov_bulletin_set_forced_vlan(struct qed_hwfn *p_hwfn,
  3399. u16 pvid, int vfid)
  3400. {
  3401. struct qed_vf_info *vf_info;
  3402. u64 feature;
  3403. vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3404. if (!vf_info) {
  3405. DP_NOTICE(p_hwfn->cdev,
  3406. "Can not set forced MAC, invalid vfid [%d]\n", vfid);
  3407. return;
  3408. }
  3409. if (vf_info->b_malicious) {
  3410. DP_NOTICE(p_hwfn->cdev,
  3411. "Can't set forced vlan to malicious VF [%d]\n", vfid);
  3412. return;
  3413. }
  3414. feature = 1 << VLAN_ADDR_FORCED;
  3415. vf_info->bulletin.p_virt->pvid = pvid;
  3416. if (pvid)
  3417. vf_info->bulletin.p_virt->valid_bitmap |= feature;
  3418. else
  3419. vf_info->bulletin.p_virt->valid_bitmap &= ~feature;
  3420. qed_iov_configure_vport_forced(p_hwfn, vf_info, feature);
  3421. }
  3422. void qed_iov_bulletin_set_udp_ports(struct qed_hwfn *p_hwfn,
  3423. int vfid, u16 vxlan_port, u16 geneve_port)
  3424. {
  3425. struct qed_vf_info *vf_info;
  3426. vf_info = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
  3427. if (!vf_info) {
  3428. DP_NOTICE(p_hwfn->cdev,
  3429. "Can not set udp ports, invalid vfid [%d]\n", vfid);
  3430. return;
  3431. }
  3432. if (vf_info->b_malicious) {
  3433. DP_VERBOSE(p_hwfn, QED_MSG_IOV,
  3434. "Can not set udp ports to malicious VF [%d]\n",
  3435. vfid);
  3436. return;
  3437. }
  3438. vf_info->bulletin.p_virt->vxlan_udp_port = vxlan_port;
  3439. vf_info->bulletin.p_virt->geneve_udp_port = geneve_port;
  3440. }
  3441. static bool qed_iov_vf_has_vport_instance(struct qed_hwfn *p_hwfn, int vfid)
  3442. {
  3443. struct qed_vf_info *p_vf_info;
  3444. p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3445. if (!p_vf_info)
  3446. return false;
  3447. return !!p_vf_info->vport_instance;
  3448. }
  3449. static bool qed_iov_is_vf_stopped(struct qed_hwfn *p_hwfn, int vfid)
  3450. {
  3451. struct qed_vf_info *p_vf_info;
  3452. p_vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3453. if (!p_vf_info)
  3454. return true;
  3455. return p_vf_info->state == VF_STOPPED;
  3456. }
  3457. static bool qed_iov_spoofchk_get(struct qed_hwfn *p_hwfn, int vfid)
  3458. {
  3459. struct qed_vf_info *vf_info;
  3460. vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3461. if (!vf_info)
  3462. return false;
  3463. return vf_info->spoof_chk;
  3464. }
  3465. static int qed_iov_spoofchk_set(struct qed_hwfn *p_hwfn, int vfid, bool val)
  3466. {
  3467. struct qed_vf_info *vf;
  3468. int rc = -EINVAL;
  3469. if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
  3470. DP_NOTICE(p_hwfn,
  3471. "SR-IOV sanity check failed, can't set spoofchk\n");
  3472. goto out;
  3473. }
  3474. vf = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3475. if (!vf)
  3476. goto out;
  3477. if (!qed_iov_vf_has_vport_instance(p_hwfn, vfid)) {
  3478. /* After VF VPORT start PF will configure spoof check */
  3479. vf->req_spoofchk_val = val;
  3480. rc = 0;
  3481. goto out;
  3482. }
  3483. rc = __qed_iov_spoofchk_set(p_hwfn, vf, val);
  3484. out:
  3485. return rc;
  3486. }
  3487. static u8 *qed_iov_bulletin_get_forced_mac(struct qed_hwfn *p_hwfn,
  3488. u16 rel_vf_id)
  3489. {
  3490. struct qed_vf_info *p_vf;
  3491. p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
  3492. if (!p_vf || !p_vf->bulletin.p_virt)
  3493. return NULL;
  3494. if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(MAC_ADDR_FORCED)))
  3495. return NULL;
  3496. return p_vf->bulletin.p_virt->mac;
  3497. }
  3498. static u16
  3499. qed_iov_bulletin_get_forced_vlan(struct qed_hwfn *p_hwfn, u16 rel_vf_id)
  3500. {
  3501. struct qed_vf_info *p_vf;
  3502. p_vf = qed_iov_get_vf_info(p_hwfn, rel_vf_id, true);
  3503. if (!p_vf || !p_vf->bulletin.p_virt)
  3504. return 0;
  3505. if (!(p_vf->bulletin.p_virt->valid_bitmap & BIT(VLAN_ADDR_FORCED)))
  3506. return 0;
  3507. return p_vf->bulletin.p_virt->pvid;
  3508. }
  3509. static int qed_iov_configure_tx_rate(struct qed_hwfn *p_hwfn,
  3510. struct qed_ptt *p_ptt, int vfid, int val)
  3511. {
  3512. struct qed_vf_info *vf;
  3513. u8 abs_vp_id = 0;
  3514. int rc;
  3515. vf = qed_iov_get_vf_info(p_hwfn, (u16)vfid, true);
  3516. if (!vf)
  3517. return -EINVAL;
  3518. rc = qed_fw_vport(p_hwfn, vf->vport_id, &abs_vp_id);
  3519. if (rc)
  3520. return rc;
  3521. return qed_init_vport_rl(p_hwfn, p_ptt, abs_vp_id, (u32)val);
  3522. }
  3523. static int
  3524. qed_iov_configure_min_tx_rate(struct qed_dev *cdev, int vfid, u32 rate)
  3525. {
  3526. struct qed_vf_info *vf;
  3527. u8 vport_id;
  3528. int i;
  3529. for_each_hwfn(cdev, i) {
  3530. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3531. if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
  3532. DP_NOTICE(p_hwfn,
  3533. "SR-IOV sanity check failed, can't set min rate\n");
  3534. return -EINVAL;
  3535. }
  3536. }
  3537. vf = qed_iov_get_vf_info(QED_LEADING_HWFN(cdev), (u16)vfid, true);
  3538. vport_id = vf->vport_id;
  3539. return qed_configure_vport_wfq(cdev, vport_id, rate);
  3540. }
  3541. static int qed_iov_get_vf_min_rate(struct qed_hwfn *p_hwfn, int vfid)
  3542. {
  3543. struct qed_wfq_data *vf_vp_wfq;
  3544. struct qed_vf_info *vf_info;
  3545. vf_info = qed_iov_get_vf_info(p_hwfn, (u16) vfid, true);
  3546. if (!vf_info)
  3547. return 0;
  3548. vf_vp_wfq = &p_hwfn->qm_info.wfq_data[vf_info->vport_id];
  3549. if (vf_vp_wfq->configured)
  3550. return vf_vp_wfq->min_speed;
  3551. else
  3552. return 0;
  3553. }
  3554. /**
  3555. * qed_schedule_iov - schedules IOV task for VF and PF
  3556. * @hwfn: hardware function pointer
  3557. * @flag: IOV flag for VF/PF
  3558. */
  3559. void qed_schedule_iov(struct qed_hwfn *hwfn, enum qed_iov_wq_flag flag)
  3560. {
  3561. smp_mb__before_atomic();
  3562. set_bit(flag, &hwfn->iov_task_flags);
  3563. smp_mb__after_atomic();
  3564. DP_VERBOSE(hwfn, QED_MSG_IOV, "Scheduling iov task [Flag: %d]\n", flag);
  3565. queue_delayed_work(hwfn->iov_wq, &hwfn->iov_task, 0);
  3566. }
  3567. void qed_vf_start_iov_wq(struct qed_dev *cdev)
  3568. {
  3569. int i;
  3570. for_each_hwfn(cdev, i)
  3571. queue_delayed_work(cdev->hwfns[i].iov_wq,
  3572. &cdev->hwfns[i].iov_task, 0);
  3573. }
  3574. int qed_sriov_disable(struct qed_dev *cdev, bool pci_enabled)
  3575. {
  3576. int i, j;
  3577. for_each_hwfn(cdev, i)
  3578. if (cdev->hwfns[i].iov_wq)
  3579. flush_workqueue(cdev->hwfns[i].iov_wq);
  3580. /* Mark VFs for disablement */
  3581. qed_iov_set_vfs_to_disable(cdev, true);
  3582. if (cdev->p_iov_info && cdev->p_iov_info->num_vfs && pci_enabled)
  3583. pci_disable_sriov(cdev->pdev);
  3584. for_each_hwfn(cdev, i) {
  3585. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  3586. struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
  3587. /* Failure to acquire the ptt in 100g creates an odd error
  3588. * where the first engine has already relased IOV.
  3589. */
  3590. if (!ptt) {
  3591. DP_ERR(hwfn, "Failed to acquire ptt\n");
  3592. return -EBUSY;
  3593. }
  3594. /* Clean WFQ db and configure equal weight for all vports */
  3595. qed_clean_wfq_db(hwfn, ptt);
  3596. qed_for_each_vf(hwfn, j) {
  3597. int k;
  3598. if (!qed_iov_is_valid_vfid(hwfn, j, true, false))
  3599. continue;
  3600. /* Wait until VF is disabled before releasing */
  3601. for (k = 0; k < 100; k++) {
  3602. if (!qed_iov_is_vf_stopped(hwfn, j))
  3603. msleep(20);
  3604. else
  3605. break;
  3606. }
  3607. if (k < 100)
  3608. qed_iov_release_hw_for_vf(&cdev->hwfns[i],
  3609. ptt, j);
  3610. else
  3611. DP_ERR(hwfn,
  3612. "Timeout waiting for VF's FLR to end\n");
  3613. }
  3614. qed_ptt_release(hwfn, ptt);
  3615. }
  3616. qed_iov_set_vfs_to_disable(cdev, false);
  3617. return 0;
  3618. }
  3619. static void qed_sriov_enable_qid_config(struct qed_hwfn *hwfn,
  3620. u16 vfid,
  3621. struct qed_iov_vf_init_params *params)
  3622. {
  3623. u16 base, i;
  3624. /* Since we have an equal resource distribution per-VF, and we assume
  3625. * PF has acquired the QED_PF_L2_QUE first queues, we start setting
  3626. * sequentially from there.
  3627. */
  3628. base = FEAT_NUM(hwfn, QED_PF_L2_QUE) + vfid * params->num_queues;
  3629. params->rel_vf_id = vfid;
  3630. for (i = 0; i < params->num_queues; i++) {
  3631. params->req_rx_queue[i] = base + i;
  3632. params->req_tx_queue[i] = base + i;
  3633. }
  3634. }
  3635. static int qed_sriov_enable(struct qed_dev *cdev, int num)
  3636. {
  3637. struct qed_iov_vf_init_params params;
  3638. int i, j, rc;
  3639. if (num >= RESC_NUM(&cdev->hwfns[0], QED_VPORT)) {
  3640. DP_NOTICE(cdev, "Can start at most %d VFs\n",
  3641. RESC_NUM(&cdev->hwfns[0], QED_VPORT) - 1);
  3642. return -EINVAL;
  3643. }
  3644. memset(&params, 0, sizeof(params));
  3645. /* Initialize HW for VF access */
  3646. for_each_hwfn(cdev, j) {
  3647. struct qed_hwfn *hwfn = &cdev->hwfns[j];
  3648. struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
  3649. /* Make sure not to use more than 16 queues per VF */
  3650. params.num_queues = min_t(int,
  3651. FEAT_NUM(hwfn, QED_VF_L2_QUE) / num,
  3652. 16);
  3653. if (!ptt) {
  3654. DP_ERR(hwfn, "Failed to acquire ptt\n");
  3655. rc = -EBUSY;
  3656. goto err;
  3657. }
  3658. for (i = 0; i < num; i++) {
  3659. if (!qed_iov_is_valid_vfid(hwfn, i, false, true))
  3660. continue;
  3661. qed_sriov_enable_qid_config(hwfn, i, &params);
  3662. rc = qed_iov_init_hw_for_vf(hwfn, ptt, &params);
  3663. if (rc) {
  3664. DP_ERR(cdev, "Failed to enable VF[%d]\n", i);
  3665. qed_ptt_release(hwfn, ptt);
  3666. goto err;
  3667. }
  3668. }
  3669. qed_ptt_release(hwfn, ptt);
  3670. }
  3671. /* Enable SRIOV PCIe functions */
  3672. rc = pci_enable_sriov(cdev->pdev, num);
  3673. if (rc) {
  3674. DP_ERR(cdev, "Failed to enable sriov [%d]\n", rc);
  3675. goto err;
  3676. }
  3677. return num;
  3678. err:
  3679. qed_sriov_disable(cdev, false);
  3680. return rc;
  3681. }
  3682. static int qed_sriov_configure(struct qed_dev *cdev, int num_vfs_param)
  3683. {
  3684. if (!IS_QED_SRIOV(cdev)) {
  3685. DP_VERBOSE(cdev, QED_MSG_IOV, "SR-IOV is not supported\n");
  3686. return -EOPNOTSUPP;
  3687. }
  3688. if (num_vfs_param)
  3689. return qed_sriov_enable(cdev, num_vfs_param);
  3690. else
  3691. return qed_sriov_disable(cdev, true);
  3692. }
  3693. static int qed_sriov_pf_set_mac(struct qed_dev *cdev, u8 *mac, int vfid)
  3694. {
  3695. int i;
  3696. if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
  3697. DP_VERBOSE(cdev, QED_MSG_IOV,
  3698. "Cannot set a VF MAC; Sriov is not enabled\n");
  3699. return -EINVAL;
  3700. }
  3701. if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
  3702. DP_VERBOSE(cdev, QED_MSG_IOV,
  3703. "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
  3704. return -EINVAL;
  3705. }
  3706. for_each_hwfn(cdev, i) {
  3707. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  3708. struct qed_public_vf_info *vf_info;
  3709. vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
  3710. if (!vf_info)
  3711. continue;
  3712. /* Set the forced MAC, and schedule the IOV task */
  3713. ether_addr_copy(vf_info->forced_mac, mac);
  3714. qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
  3715. }
  3716. return 0;
  3717. }
  3718. static int qed_sriov_pf_set_vlan(struct qed_dev *cdev, u16 vid, int vfid)
  3719. {
  3720. int i;
  3721. if (!IS_QED_SRIOV(cdev) || !IS_PF_SRIOV_ALLOC(&cdev->hwfns[0])) {
  3722. DP_VERBOSE(cdev, QED_MSG_IOV,
  3723. "Cannot set a VF MAC; Sriov is not enabled\n");
  3724. return -EINVAL;
  3725. }
  3726. if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vfid, true, true)) {
  3727. DP_VERBOSE(cdev, QED_MSG_IOV,
  3728. "Cannot set VF[%d] MAC (VF is not active)\n", vfid);
  3729. return -EINVAL;
  3730. }
  3731. for_each_hwfn(cdev, i) {
  3732. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  3733. struct qed_public_vf_info *vf_info;
  3734. vf_info = qed_iov_get_public_vf_info(hwfn, vfid, true);
  3735. if (!vf_info)
  3736. continue;
  3737. /* Set the forced vlan, and schedule the IOV task */
  3738. vf_info->forced_vlan = vid;
  3739. qed_schedule_iov(hwfn, QED_IOV_WQ_SET_UNICAST_FILTER_FLAG);
  3740. }
  3741. return 0;
  3742. }
  3743. static int qed_get_vf_config(struct qed_dev *cdev,
  3744. int vf_id, struct ifla_vf_info *ivi)
  3745. {
  3746. struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
  3747. struct qed_public_vf_info *vf_info;
  3748. struct qed_mcp_link_state link;
  3749. u32 tx_rate;
  3750. /* Sanitize request */
  3751. if (IS_VF(cdev))
  3752. return -EINVAL;
  3753. if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, false)) {
  3754. DP_VERBOSE(cdev, QED_MSG_IOV,
  3755. "VF index [%d] isn't active\n", vf_id);
  3756. return -EINVAL;
  3757. }
  3758. vf_info = qed_iov_get_public_vf_info(hwfn, vf_id, true);
  3759. qed_iov_get_link(hwfn, vf_id, NULL, &link, NULL);
  3760. /* Fill information about VF */
  3761. ivi->vf = vf_id;
  3762. if (is_valid_ether_addr(vf_info->forced_mac))
  3763. ether_addr_copy(ivi->mac, vf_info->forced_mac);
  3764. else
  3765. ether_addr_copy(ivi->mac, vf_info->mac);
  3766. ivi->vlan = vf_info->forced_vlan;
  3767. ivi->spoofchk = qed_iov_spoofchk_get(hwfn, vf_id);
  3768. ivi->linkstate = vf_info->link_state;
  3769. tx_rate = vf_info->tx_rate;
  3770. ivi->max_tx_rate = tx_rate ? tx_rate : link.speed;
  3771. ivi->min_tx_rate = qed_iov_get_vf_min_rate(hwfn, vf_id);
  3772. return 0;
  3773. }
  3774. void qed_inform_vf_link_state(struct qed_hwfn *hwfn)
  3775. {
  3776. struct qed_hwfn *lead_hwfn = QED_LEADING_HWFN(hwfn->cdev);
  3777. struct qed_mcp_link_capabilities caps;
  3778. struct qed_mcp_link_params params;
  3779. struct qed_mcp_link_state link;
  3780. int i;
  3781. if (!hwfn->pf_iov_info)
  3782. return;
  3783. /* Update bulletin of all future possible VFs with link configuration */
  3784. for (i = 0; i < hwfn->cdev->p_iov_info->total_vfs; i++) {
  3785. struct qed_public_vf_info *vf_info;
  3786. vf_info = qed_iov_get_public_vf_info(hwfn, i, false);
  3787. if (!vf_info)
  3788. continue;
  3789. /* Only hwfn0 is actually interested in the link speed.
  3790. * But since only it would receive an MFW indication of link,
  3791. * need to take configuration from it - otherwise things like
  3792. * rate limiting for hwfn1 VF would not work.
  3793. */
  3794. memcpy(&params, qed_mcp_get_link_params(lead_hwfn),
  3795. sizeof(params));
  3796. memcpy(&link, qed_mcp_get_link_state(lead_hwfn), sizeof(link));
  3797. memcpy(&caps, qed_mcp_get_link_capabilities(lead_hwfn),
  3798. sizeof(caps));
  3799. /* Modify link according to the VF's configured link state */
  3800. switch (vf_info->link_state) {
  3801. case IFLA_VF_LINK_STATE_DISABLE:
  3802. link.link_up = false;
  3803. break;
  3804. case IFLA_VF_LINK_STATE_ENABLE:
  3805. link.link_up = true;
  3806. /* Set speed according to maximum supported by HW.
  3807. * that is 40G for regular devices and 100G for CMT
  3808. * mode devices.
  3809. */
  3810. link.speed = (hwfn->cdev->num_hwfns > 1) ?
  3811. 100000 : 40000;
  3812. default:
  3813. /* In auto mode pass PF link image to VF */
  3814. break;
  3815. }
  3816. if (link.link_up && vf_info->tx_rate) {
  3817. struct qed_ptt *ptt;
  3818. int rate;
  3819. rate = min_t(int, vf_info->tx_rate, link.speed);
  3820. ptt = qed_ptt_acquire(hwfn);
  3821. if (!ptt) {
  3822. DP_NOTICE(hwfn, "Failed to acquire PTT\n");
  3823. return;
  3824. }
  3825. if (!qed_iov_configure_tx_rate(hwfn, ptt, i, rate)) {
  3826. vf_info->tx_rate = rate;
  3827. link.speed = rate;
  3828. }
  3829. qed_ptt_release(hwfn, ptt);
  3830. }
  3831. qed_iov_set_link(hwfn, i, &params, &link, &caps);
  3832. }
  3833. qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
  3834. }
  3835. static int qed_set_vf_link_state(struct qed_dev *cdev,
  3836. int vf_id, int link_state)
  3837. {
  3838. int i;
  3839. /* Sanitize request */
  3840. if (IS_VF(cdev))
  3841. return -EINVAL;
  3842. if (!qed_iov_is_valid_vfid(&cdev->hwfns[0], vf_id, true, true)) {
  3843. DP_VERBOSE(cdev, QED_MSG_IOV,
  3844. "VF index [%d] isn't active\n", vf_id);
  3845. return -EINVAL;
  3846. }
  3847. /* Handle configuration of link state */
  3848. for_each_hwfn(cdev, i) {
  3849. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  3850. struct qed_public_vf_info *vf;
  3851. vf = qed_iov_get_public_vf_info(hwfn, vf_id, true);
  3852. if (!vf)
  3853. continue;
  3854. if (vf->link_state == link_state)
  3855. continue;
  3856. vf->link_state = link_state;
  3857. qed_inform_vf_link_state(&cdev->hwfns[i]);
  3858. }
  3859. return 0;
  3860. }
  3861. static int qed_spoof_configure(struct qed_dev *cdev, int vfid, bool val)
  3862. {
  3863. int i, rc = -EINVAL;
  3864. for_each_hwfn(cdev, i) {
  3865. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3866. rc = qed_iov_spoofchk_set(p_hwfn, vfid, val);
  3867. if (rc)
  3868. break;
  3869. }
  3870. return rc;
  3871. }
  3872. static int qed_configure_max_vf_rate(struct qed_dev *cdev, int vfid, int rate)
  3873. {
  3874. int i;
  3875. for_each_hwfn(cdev, i) {
  3876. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  3877. struct qed_public_vf_info *vf;
  3878. if (!qed_iov_pf_sanity_check(p_hwfn, vfid)) {
  3879. DP_NOTICE(p_hwfn,
  3880. "SR-IOV sanity check failed, can't set tx rate\n");
  3881. return -EINVAL;
  3882. }
  3883. vf = qed_iov_get_public_vf_info(p_hwfn, vfid, true);
  3884. vf->tx_rate = rate;
  3885. qed_inform_vf_link_state(p_hwfn);
  3886. }
  3887. return 0;
  3888. }
  3889. static int qed_set_vf_rate(struct qed_dev *cdev,
  3890. int vfid, u32 min_rate, u32 max_rate)
  3891. {
  3892. int rc_min = 0, rc_max = 0;
  3893. if (max_rate)
  3894. rc_max = qed_configure_max_vf_rate(cdev, vfid, max_rate);
  3895. if (min_rate)
  3896. rc_min = qed_iov_configure_min_tx_rate(cdev, vfid, min_rate);
  3897. if (rc_max | rc_min)
  3898. return -EINVAL;
  3899. return 0;
  3900. }
  3901. static int qed_set_vf_trust(struct qed_dev *cdev, int vfid, bool trust)
  3902. {
  3903. int i;
  3904. for_each_hwfn(cdev, i) {
  3905. struct qed_hwfn *hwfn = &cdev->hwfns[i];
  3906. struct qed_public_vf_info *vf;
  3907. if (!qed_iov_pf_sanity_check(hwfn, vfid)) {
  3908. DP_NOTICE(hwfn,
  3909. "SR-IOV sanity check failed, can't set trust\n");
  3910. return -EINVAL;
  3911. }
  3912. vf = qed_iov_get_public_vf_info(hwfn, vfid, true);
  3913. if (vf->is_trusted_request == trust)
  3914. return 0;
  3915. vf->is_trusted_request = trust;
  3916. qed_schedule_iov(hwfn, QED_IOV_WQ_TRUST_FLAG);
  3917. }
  3918. return 0;
  3919. }
  3920. static void qed_handle_vf_msg(struct qed_hwfn *hwfn)
  3921. {
  3922. u64 events[QED_VF_ARRAY_LENGTH];
  3923. struct qed_ptt *ptt;
  3924. int i;
  3925. ptt = qed_ptt_acquire(hwfn);
  3926. if (!ptt) {
  3927. DP_VERBOSE(hwfn, QED_MSG_IOV,
  3928. "Can't acquire PTT; re-scheduling\n");
  3929. qed_schedule_iov(hwfn, QED_IOV_WQ_MSG_FLAG);
  3930. return;
  3931. }
  3932. qed_iov_pf_get_pending_events(hwfn, events);
  3933. DP_VERBOSE(hwfn, QED_MSG_IOV,
  3934. "Event mask of VF events: 0x%llx 0x%llx 0x%llx\n",
  3935. events[0], events[1], events[2]);
  3936. qed_for_each_vf(hwfn, i) {
  3937. /* Skip VFs with no pending messages */
  3938. if (!(events[i / 64] & (1ULL << (i % 64))))
  3939. continue;
  3940. DP_VERBOSE(hwfn, QED_MSG_IOV,
  3941. "Handling VF message from VF 0x%02x [Abs 0x%02x]\n",
  3942. i, hwfn->cdev->p_iov_info->first_vf_in_pf + i);
  3943. /* Copy VF's message to PF's request buffer for that VF */
  3944. if (qed_iov_copy_vf_msg(hwfn, ptt, i))
  3945. continue;
  3946. qed_iov_process_mbx_req(hwfn, ptt, i);
  3947. }
  3948. qed_ptt_release(hwfn, ptt);
  3949. }
  3950. static void qed_handle_pf_set_vf_unicast(struct qed_hwfn *hwfn)
  3951. {
  3952. int i;
  3953. qed_for_each_vf(hwfn, i) {
  3954. struct qed_public_vf_info *info;
  3955. bool update = false;
  3956. u8 *mac;
  3957. info = qed_iov_get_public_vf_info(hwfn, i, true);
  3958. if (!info)
  3959. continue;
  3960. /* Update data on bulletin board */
  3961. mac = qed_iov_bulletin_get_forced_mac(hwfn, i);
  3962. if (is_valid_ether_addr(info->forced_mac) &&
  3963. (!mac || !ether_addr_equal(mac, info->forced_mac))) {
  3964. DP_VERBOSE(hwfn,
  3965. QED_MSG_IOV,
  3966. "Handling PF setting of VF MAC to VF 0x%02x [Abs 0x%02x]\n",
  3967. i,
  3968. hwfn->cdev->p_iov_info->first_vf_in_pf + i);
  3969. /* Update bulletin board with forced MAC */
  3970. qed_iov_bulletin_set_forced_mac(hwfn,
  3971. info->forced_mac, i);
  3972. update = true;
  3973. }
  3974. if (qed_iov_bulletin_get_forced_vlan(hwfn, i) ^
  3975. info->forced_vlan) {
  3976. DP_VERBOSE(hwfn,
  3977. QED_MSG_IOV,
  3978. "Handling PF setting of pvid [0x%04x] to VF 0x%02x [Abs 0x%02x]\n",
  3979. info->forced_vlan,
  3980. i,
  3981. hwfn->cdev->p_iov_info->first_vf_in_pf + i);
  3982. qed_iov_bulletin_set_forced_vlan(hwfn,
  3983. info->forced_vlan, i);
  3984. update = true;
  3985. }
  3986. if (update)
  3987. qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
  3988. }
  3989. }
  3990. static void qed_handle_bulletin_post(struct qed_hwfn *hwfn)
  3991. {
  3992. struct qed_ptt *ptt;
  3993. int i;
  3994. ptt = qed_ptt_acquire(hwfn);
  3995. if (!ptt) {
  3996. DP_NOTICE(hwfn, "Failed allocating a ptt entry\n");
  3997. qed_schedule_iov(hwfn, QED_IOV_WQ_BULLETIN_UPDATE_FLAG);
  3998. return;
  3999. }
  4000. qed_for_each_vf(hwfn, i)
  4001. qed_iov_post_vf_bulletin(hwfn, i, ptt);
  4002. qed_ptt_release(hwfn, ptt);
  4003. }
  4004. static void qed_iov_handle_trust_change(struct qed_hwfn *hwfn)
  4005. {
  4006. struct qed_sp_vport_update_params params;
  4007. struct qed_filter_accept_flags *flags;
  4008. struct qed_public_vf_info *vf_info;
  4009. struct qed_vf_info *vf;
  4010. u8 mask;
  4011. int i;
  4012. mask = QED_ACCEPT_UCAST_UNMATCHED | QED_ACCEPT_MCAST_UNMATCHED;
  4013. flags = &params.accept_flags;
  4014. qed_for_each_vf(hwfn, i) {
  4015. /* Need to make sure current requested configuration didn't
  4016. * flip so that we'll end up configuring something that's not
  4017. * needed.
  4018. */
  4019. vf_info = qed_iov_get_public_vf_info(hwfn, i, true);
  4020. if (vf_info->is_trusted_configured ==
  4021. vf_info->is_trusted_request)
  4022. continue;
  4023. vf_info->is_trusted_configured = vf_info->is_trusted_request;
  4024. /* Validate that the VF has a configured vport */
  4025. vf = qed_iov_get_vf_info(hwfn, i, true);
  4026. if (!vf->vport_instance)
  4027. continue;
  4028. memset(&params, 0, sizeof(params));
  4029. params.opaque_fid = vf->opaque_fid;
  4030. params.vport_id = vf->vport_id;
  4031. if (vf_info->rx_accept_mode & mask) {
  4032. flags->update_rx_mode_config = 1;
  4033. flags->rx_accept_filter = vf_info->rx_accept_mode;
  4034. }
  4035. if (vf_info->tx_accept_mode & mask) {
  4036. flags->update_tx_mode_config = 1;
  4037. flags->tx_accept_filter = vf_info->tx_accept_mode;
  4038. }
  4039. /* Remove if needed; Otherwise this would set the mask */
  4040. if (!vf_info->is_trusted_configured) {
  4041. flags->rx_accept_filter &= ~mask;
  4042. flags->tx_accept_filter &= ~mask;
  4043. }
  4044. if (flags->update_rx_mode_config ||
  4045. flags->update_tx_mode_config)
  4046. qed_sp_vport_update(hwfn, &params,
  4047. QED_SPQ_MODE_EBLOCK, NULL);
  4048. }
  4049. }
  4050. static void qed_iov_pf_task(struct work_struct *work)
  4051. {
  4052. struct qed_hwfn *hwfn = container_of(work, struct qed_hwfn,
  4053. iov_task.work);
  4054. int rc;
  4055. if (test_and_clear_bit(QED_IOV_WQ_STOP_WQ_FLAG, &hwfn->iov_task_flags))
  4056. return;
  4057. if (test_and_clear_bit(QED_IOV_WQ_FLR_FLAG, &hwfn->iov_task_flags)) {
  4058. struct qed_ptt *ptt = qed_ptt_acquire(hwfn);
  4059. if (!ptt) {
  4060. qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
  4061. return;
  4062. }
  4063. rc = qed_iov_vf_flr_cleanup(hwfn, ptt);
  4064. if (rc)
  4065. qed_schedule_iov(hwfn, QED_IOV_WQ_FLR_FLAG);
  4066. qed_ptt_release(hwfn, ptt);
  4067. }
  4068. if (test_and_clear_bit(QED_IOV_WQ_MSG_FLAG, &hwfn->iov_task_flags))
  4069. qed_handle_vf_msg(hwfn);
  4070. if (test_and_clear_bit(QED_IOV_WQ_SET_UNICAST_FILTER_FLAG,
  4071. &hwfn->iov_task_flags))
  4072. qed_handle_pf_set_vf_unicast(hwfn);
  4073. if (test_and_clear_bit(QED_IOV_WQ_BULLETIN_UPDATE_FLAG,
  4074. &hwfn->iov_task_flags))
  4075. qed_handle_bulletin_post(hwfn);
  4076. if (test_and_clear_bit(QED_IOV_WQ_TRUST_FLAG, &hwfn->iov_task_flags))
  4077. qed_iov_handle_trust_change(hwfn);
  4078. }
  4079. void qed_iov_wq_stop(struct qed_dev *cdev, bool schedule_first)
  4080. {
  4081. int i;
  4082. for_each_hwfn(cdev, i) {
  4083. if (!cdev->hwfns[i].iov_wq)
  4084. continue;
  4085. if (schedule_first) {
  4086. qed_schedule_iov(&cdev->hwfns[i],
  4087. QED_IOV_WQ_STOP_WQ_FLAG);
  4088. cancel_delayed_work_sync(&cdev->hwfns[i].iov_task);
  4089. }
  4090. flush_workqueue(cdev->hwfns[i].iov_wq);
  4091. destroy_workqueue(cdev->hwfns[i].iov_wq);
  4092. }
  4093. }
  4094. int qed_iov_wq_start(struct qed_dev *cdev)
  4095. {
  4096. char name[NAME_SIZE];
  4097. int i;
  4098. for_each_hwfn(cdev, i) {
  4099. struct qed_hwfn *p_hwfn = &cdev->hwfns[i];
  4100. /* PFs needs a dedicated workqueue only if they support IOV.
  4101. * VFs always require one.
  4102. */
  4103. if (IS_PF(p_hwfn->cdev) && !IS_PF_SRIOV(p_hwfn))
  4104. continue;
  4105. snprintf(name, NAME_SIZE, "iov-%02x:%02x.%02x",
  4106. cdev->pdev->bus->number,
  4107. PCI_SLOT(cdev->pdev->devfn), p_hwfn->abs_pf_id);
  4108. p_hwfn->iov_wq = create_singlethread_workqueue(name);
  4109. if (!p_hwfn->iov_wq) {
  4110. DP_NOTICE(p_hwfn, "Cannot create iov workqueue\n");
  4111. return -ENOMEM;
  4112. }
  4113. if (IS_PF(cdev))
  4114. INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_pf_task);
  4115. else
  4116. INIT_DELAYED_WORK(&p_hwfn->iov_task, qed_iov_vf_task);
  4117. }
  4118. return 0;
  4119. }
  4120. const struct qed_iov_hv_ops qed_iov_ops_pass = {
  4121. .configure = &qed_sriov_configure,
  4122. .set_mac = &qed_sriov_pf_set_mac,
  4123. .set_vlan = &qed_sriov_pf_set_vlan,
  4124. .get_config = &qed_get_vf_config,
  4125. .set_link_state = &qed_set_vf_link_state,
  4126. .set_spoof = &qed_spoof_configure,
  4127. .set_rate = &qed_set_vf_rate,
  4128. .set_trust = &qed_set_vf_trust,
  4129. };