qed_sriov.c 141 KB

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