i40e_virtchnl_pf.c 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include "i40e.h"
  4. /*********************notification routines***********************/
  5. /**
  6. * i40e_vc_vf_broadcast
  7. * @pf: pointer to the PF structure
  8. * @v_opcode: operation code
  9. * @v_retval: return value
  10. * @msg: pointer to the msg buffer
  11. * @msglen: msg length
  12. *
  13. * send a message to all VFs on a given PF
  14. **/
  15. static void i40e_vc_vf_broadcast(struct i40e_pf *pf,
  16. enum virtchnl_ops v_opcode,
  17. i40e_status v_retval, u8 *msg,
  18. u16 msglen)
  19. {
  20. struct i40e_hw *hw = &pf->hw;
  21. struct i40e_vf *vf = pf->vf;
  22. int i;
  23. for (i = 0; i < pf->num_alloc_vfs; i++, vf++) {
  24. int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
  25. /* Not all vfs are enabled so skip the ones that are not */
  26. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) &&
  27. !test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
  28. continue;
  29. /* Ignore return value on purpose - a given VF may fail, but
  30. * we need to keep going and send to all of them
  31. */
  32. i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
  33. msg, msglen, NULL);
  34. }
  35. }
  36. /**
  37. * i40e_vc_notify_vf_link_state
  38. * @vf: pointer to the VF structure
  39. *
  40. * send a link status message to a single VF
  41. **/
  42. static void i40e_vc_notify_vf_link_state(struct i40e_vf *vf)
  43. {
  44. struct virtchnl_pf_event pfe;
  45. struct i40e_pf *pf = vf->pf;
  46. struct i40e_hw *hw = &pf->hw;
  47. struct i40e_link_status *ls = &pf->hw.phy.link_info;
  48. int abs_vf_id = vf->vf_id + (int)hw->func_caps.vf_base_id;
  49. pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
  50. pfe.severity = PF_EVENT_SEVERITY_INFO;
  51. if (vf->link_forced) {
  52. pfe.event_data.link_event.link_status = vf->link_up;
  53. pfe.event_data.link_event.link_speed =
  54. (vf->link_up ? VIRTCHNL_LINK_SPEED_40GB : 0);
  55. } else {
  56. pfe.event_data.link_event.link_status =
  57. ls->link_info & I40E_AQ_LINK_UP;
  58. pfe.event_data.link_event.link_speed =
  59. i40e_virtchnl_link_speed(ls->link_speed);
  60. }
  61. i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT,
  62. 0, (u8 *)&pfe, sizeof(pfe), NULL);
  63. }
  64. /**
  65. * i40e_vc_notify_link_state
  66. * @pf: pointer to the PF structure
  67. *
  68. * send a link status message to all VFs on a given PF
  69. **/
  70. void i40e_vc_notify_link_state(struct i40e_pf *pf)
  71. {
  72. int i;
  73. for (i = 0; i < pf->num_alloc_vfs; i++)
  74. i40e_vc_notify_vf_link_state(&pf->vf[i]);
  75. }
  76. /**
  77. * i40e_vc_notify_reset
  78. * @pf: pointer to the PF structure
  79. *
  80. * indicate a pending reset to all VFs on a given PF
  81. **/
  82. void i40e_vc_notify_reset(struct i40e_pf *pf)
  83. {
  84. struct virtchnl_pf_event pfe;
  85. pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
  86. pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
  87. i40e_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, 0,
  88. (u8 *)&pfe, sizeof(struct virtchnl_pf_event));
  89. }
  90. /**
  91. * i40e_vc_notify_vf_reset
  92. * @vf: pointer to the VF structure
  93. *
  94. * indicate a pending reset to the given VF
  95. **/
  96. void i40e_vc_notify_vf_reset(struct i40e_vf *vf)
  97. {
  98. struct virtchnl_pf_event pfe;
  99. int abs_vf_id;
  100. /* validate the request */
  101. if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
  102. return;
  103. /* verify if the VF is in either init or active before proceeding */
  104. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states) &&
  105. !test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
  106. return;
  107. abs_vf_id = vf->vf_id + (int)vf->pf->hw.func_caps.vf_base_id;
  108. pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
  109. pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
  110. i40e_aq_send_msg_to_vf(&vf->pf->hw, abs_vf_id, VIRTCHNL_OP_EVENT,
  111. 0, (u8 *)&pfe,
  112. sizeof(struct virtchnl_pf_event), NULL);
  113. }
  114. /***********************misc routines*****************************/
  115. /**
  116. * i40e_vc_disable_vf
  117. * @vf: pointer to the VF info
  118. *
  119. * Disable the VF through a SW reset.
  120. **/
  121. static inline void i40e_vc_disable_vf(struct i40e_vf *vf)
  122. {
  123. int i;
  124. i40e_vc_notify_vf_reset(vf);
  125. /* We want to ensure that an actual reset occurs initiated after this
  126. * function was called. However, we do not want to wait forever, so
  127. * we'll give a reasonable time and print a message if we failed to
  128. * ensure a reset.
  129. */
  130. for (i = 0; i < 20; i++) {
  131. if (i40e_reset_vf(vf, false))
  132. return;
  133. usleep_range(10000, 20000);
  134. }
  135. dev_warn(&vf->pf->pdev->dev,
  136. "Failed to initiate reset for VF %d after 200 milliseconds\n",
  137. vf->vf_id);
  138. }
  139. /**
  140. * i40e_vc_isvalid_vsi_id
  141. * @vf: pointer to the VF info
  142. * @vsi_id: VF relative VSI id
  143. *
  144. * check for the valid VSI id
  145. **/
  146. static inline bool i40e_vc_isvalid_vsi_id(struct i40e_vf *vf, u16 vsi_id)
  147. {
  148. struct i40e_pf *pf = vf->pf;
  149. struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
  150. return (vsi && (vsi->vf_id == vf->vf_id));
  151. }
  152. /**
  153. * i40e_vc_isvalid_queue_id
  154. * @vf: pointer to the VF info
  155. * @vsi_id: vsi id
  156. * @qid: vsi relative queue id
  157. *
  158. * check for the valid queue id
  159. **/
  160. static inline bool i40e_vc_isvalid_queue_id(struct i40e_vf *vf, u16 vsi_id,
  161. u8 qid)
  162. {
  163. struct i40e_pf *pf = vf->pf;
  164. struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
  165. return (vsi && (qid < vsi->alloc_queue_pairs));
  166. }
  167. /**
  168. * i40e_vc_isvalid_vector_id
  169. * @vf: pointer to the VF info
  170. * @vector_id: VF relative vector id
  171. *
  172. * check for the valid vector id
  173. **/
  174. static inline bool i40e_vc_isvalid_vector_id(struct i40e_vf *vf, u8 vector_id)
  175. {
  176. struct i40e_pf *pf = vf->pf;
  177. return vector_id < pf->hw.func_caps.num_msix_vectors_vf;
  178. }
  179. /***********************vf resource mgmt routines*****************/
  180. /**
  181. * i40e_vc_get_pf_queue_id
  182. * @vf: pointer to the VF info
  183. * @vsi_id: id of VSI as provided by the FW
  184. * @vsi_queue_id: vsi relative queue id
  185. *
  186. * return PF relative queue id
  187. **/
  188. static u16 i40e_vc_get_pf_queue_id(struct i40e_vf *vf, u16 vsi_id,
  189. u8 vsi_queue_id)
  190. {
  191. struct i40e_pf *pf = vf->pf;
  192. struct i40e_vsi *vsi = i40e_find_vsi_from_id(pf, vsi_id);
  193. u16 pf_queue_id = I40E_QUEUE_END_OF_LIST;
  194. if (!vsi)
  195. return pf_queue_id;
  196. if (le16_to_cpu(vsi->info.mapping_flags) &
  197. I40E_AQ_VSI_QUE_MAP_NONCONTIG)
  198. pf_queue_id =
  199. le16_to_cpu(vsi->info.queue_mapping[vsi_queue_id]);
  200. else
  201. pf_queue_id = le16_to_cpu(vsi->info.queue_mapping[0]) +
  202. vsi_queue_id;
  203. return pf_queue_id;
  204. }
  205. /**
  206. * i40e_get_real_pf_qid
  207. * @vf: pointer to the VF info
  208. * @vsi_id: vsi id
  209. * @queue_id: queue number
  210. *
  211. * wrapper function to get pf_queue_id handling ADq code as well
  212. **/
  213. static u16 i40e_get_real_pf_qid(struct i40e_vf *vf, u16 vsi_id, u16 queue_id)
  214. {
  215. int i;
  216. if (vf->adq_enabled) {
  217. /* Although VF considers all the queues(can be 1 to 16) as its
  218. * own but they may actually belong to different VSIs(up to 4).
  219. * We need to find which queues belongs to which VSI.
  220. */
  221. for (i = 0; i < vf->num_tc; i++) {
  222. if (queue_id < vf->ch[i].num_qps) {
  223. vsi_id = vf->ch[i].vsi_id;
  224. break;
  225. }
  226. /* find right queue id which is relative to a
  227. * given VSI.
  228. */
  229. queue_id -= vf->ch[i].num_qps;
  230. }
  231. }
  232. return i40e_vc_get_pf_queue_id(vf, vsi_id, queue_id);
  233. }
  234. /**
  235. * i40e_config_irq_link_list
  236. * @vf: pointer to the VF info
  237. * @vsi_id: id of VSI as given by the FW
  238. * @vecmap: irq map info
  239. *
  240. * configure irq link list from the map
  241. **/
  242. static void i40e_config_irq_link_list(struct i40e_vf *vf, u16 vsi_id,
  243. struct virtchnl_vector_map *vecmap)
  244. {
  245. unsigned long linklistmap = 0, tempmap;
  246. struct i40e_pf *pf = vf->pf;
  247. struct i40e_hw *hw = &pf->hw;
  248. u16 vsi_queue_id, pf_queue_id;
  249. enum i40e_queue_type qtype;
  250. u16 next_q, vector_id, size;
  251. u32 reg, reg_idx;
  252. u16 itr_idx = 0;
  253. vector_id = vecmap->vector_id;
  254. /* setup the head */
  255. if (0 == vector_id)
  256. reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
  257. else
  258. reg_idx = I40E_VPINT_LNKLSTN(
  259. ((pf->hw.func_caps.num_msix_vectors_vf - 1) * vf->vf_id) +
  260. (vector_id - 1));
  261. if (vecmap->rxq_map == 0 && vecmap->txq_map == 0) {
  262. /* Special case - No queues mapped on this vector */
  263. wr32(hw, reg_idx, I40E_VPINT_LNKLST0_FIRSTQ_INDX_MASK);
  264. goto irq_list_done;
  265. }
  266. tempmap = vecmap->rxq_map;
  267. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  268. linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
  269. vsi_queue_id));
  270. }
  271. tempmap = vecmap->txq_map;
  272. for_each_set_bit(vsi_queue_id, &tempmap, I40E_MAX_VSI_QP) {
  273. linklistmap |= (BIT(I40E_VIRTCHNL_SUPPORTED_QTYPES *
  274. vsi_queue_id + 1));
  275. }
  276. size = I40E_MAX_VSI_QP * I40E_VIRTCHNL_SUPPORTED_QTYPES;
  277. next_q = find_first_bit(&linklistmap, size);
  278. if (unlikely(next_q == size))
  279. goto irq_list_done;
  280. vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
  281. qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
  282. pf_queue_id = i40e_get_real_pf_qid(vf, vsi_id, vsi_queue_id);
  283. reg = ((qtype << I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT) | pf_queue_id);
  284. wr32(hw, reg_idx, reg);
  285. while (next_q < size) {
  286. switch (qtype) {
  287. case I40E_QUEUE_TYPE_RX:
  288. reg_idx = I40E_QINT_RQCTL(pf_queue_id);
  289. itr_idx = vecmap->rxitr_idx;
  290. break;
  291. case I40E_QUEUE_TYPE_TX:
  292. reg_idx = I40E_QINT_TQCTL(pf_queue_id);
  293. itr_idx = vecmap->txitr_idx;
  294. break;
  295. default:
  296. break;
  297. }
  298. next_q = find_next_bit(&linklistmap, size, next_q + 1);
  299. if (next_q < size) {
  300. vsi_queue_id = next_q / I40E_VIRTCHNL_SUPPORTED_QTYPES;
  301. qtype = next_q % I40E_VIRTCHNL_SUPPORTED_QTYPES;
  302. pf_queue_id = i40e_get_real_pf_qid(vf,
  303. vsi_id,
  304. vsi_queue_id);
  305. } else {
  306. pf_queue_id = I40E_QUEUE_END_OF_LIST;
  307. qtype = 0;
  308. }
  309. /* format for the RQCTL & TQCTL regs is same */
  310. reg = (vector_id) |
  311. (qtype << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT) |
  312. (pf_queue_id << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT) |
  313. BIT(I40E_QINT_RQCTL_CAUSE_ENA_SHIFT) |
  314. (itr_idx << I40E_QINT_RQCTL_ITR_INDX_SHIFT);
  315. wr32(hw, reg_idx, reg);
  316. }
  317. /* if the vf is running in polling mode and using interrupt zero,
  318. * need to disable auto-mask on enabling zero interrupt for VFs.
  319. */
  320. if ((vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING) &&
  321. (vector_id == 0)) {
  322. reg = rd32(hw, I40E_GLINT_CTL);
  323. if (!(reg & I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK)) {
  324. reg |= I40E_GLINT_CTL_DIS_AUTOMASK_VF0_MASK;
  325. wr32(hw, I40E_GLINT_CTL, reg);
  326. }
  327. }
  328. irq_list_done:
  329. i40e_flush(hw);
  330. }
  331. /**
  332. * i40e_release_iwarp_qvlist
  333. * @vf: pointer to the VF.
  334. *
  335. **/
  336. static void i40e_release_iwarp_qvlist(struct i40e_vf *vf)
  337. {
  338. struct i40e_pf *pf = vf->pf;
  339. struct virtchnl_iwarp_qvlist_info *qvlist_info = vf->qvlist_info;
  340. u32 msix_vf;
  341. u32 i;
  342. if (!vf->qvlist_info)
  343. return;
  344. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  345. for (i = 0; i < qvlist_info->num_vectors; i++) {
  346. struct virtchnl_iwarp_qv_info *qv_info;
  347. u32 next_q_index, next_q_type;
  348. struct i40e_hw *hw = &pf->hw;
  349. u32 v_idx, reg_idx, reg;
  350. qv_info = &qvlist_info->qv_info[i];
  351. if (!qv_info)
  352. continue;
  353. v_idx = qv_info->v_idx;
  354. if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
  355. /* Figure out the queue after CEQ and make that the
  356. * first queue.
  357. */
  358. reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
  359. reg = rd32(hw, I40E_VPINT_CEQCTL(reg_idx));
  360. next_q_index = (reg & I40E_VPINT_CEQCTL_NEXTQ_INDX_MASK)
  361. >> I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT;
  362. next_q_type = (reg & I40E_VPINT_CEQCTL_NEXTQ_TYPE_MASK)
  363. >> I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT;
  364. reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
  365. reg = (next_q_index &
  366. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  367. (next_q_type <<
  368. I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  369. wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
  370. }
  371. }
  372. kfree(vf->qvlist_info);
  373. vf->qvlist_info = NULL;
  374. }
  375. /**
  376. * i40e_config_iwarp_qvlist
  377. * @vf: pointer to the VF info
  378. * @qvlist_info: queue and vector list
  379. *
  380. * Return 0 on success or < 0 on error
  381. **/
  382. static int i40e_config_iwarp_qvlist(struct i40e_vf *vf,
  383. struct virtchnl_iwarp_qvlist_info *qvlist_info)
  384. {
  385. struct i40e_pf *pf = vf->pf;
  386. struct i40e_hw *hw = &pf->hw;
  387. struct virtchnl_iwarp_qv_info *qv_info;
  388. u32 v_idx, i, reg_idx, reg;
  389. u32 next_q_idx, next_q_type;
  390. u32 msix_vf, size;
  391. size = sizeof(struct virtchnl_iwarp_qvlist_info) +
  392. (sizeof(struct virtchnl_iwarp_qv_info) *
  393. (qvlist_info->num_vectors - 1));
  394. vf->qvlist_info = kzalloc(size, GFP_KERNEL);
  395. if (!vf->qvlist_info)
  396. return -ENOMEM;
  397. vf->qvlist_info->num_vectors = qvlist_info->num_vectors;
  398. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  399. for (i = 0; i < qvlist_info->num_vectors; i++) {
  400. qv_info = &qvlist_info->qv_info[i];
  401. if (!qv_info)
  402. continue;
  403. v_idx = qv_info->v_idx;
  404. /* Validate vector id belongs to this vf */
  405. if (!i40e_vc_isvalid_vector_id(vf, v_idx))
  406. goto err;
  407. vf->qvlist_info->qv_info[i] = *qv_info;
  408. reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
  409. /* We might be sharing the interrupt, so get the first queue
  410. * index and type, push it down the list by adding the new
  411. * queue on top. Also link it with the new queue in CEQCTL.
  412. */
  413. reg = rd32(hw, I40E_VPINT_LNKLSTN(reg_idx));
  414. next_q_idx = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) >>
  415. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_SHIFT);
  416. next_q_type = ((reg & I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK) >>
  417. I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  418. if (qv_info->ceq_idx != I40E_QUEUE_INVALID_IDX) {
  419. reg_idx = (msix_vf - 1) * vf->vf_id + qv_info->ceq_idx;
  420. reg = (I40E_VPINT_CEQCTL_CAUSE_ENA_MASK |
  421. (v_idx << I40E_VPINT_CEQCTL_MSIX_INDX_SHIFT) |
  422. (qv_info->itr_idx << I40E_VPINT_CEQCTL_ITR_INDX_SHIFT) |
  423. (next_q_type << I40E_VPINT_CEQCTL_NEXTQ_TYPE_SHIFT) |
  424. (next_q_idx << I40E_VPINT_CEQCTL_NEXTQ_INDX_SHIFT));
  425. wr32(hw, I40E_VPINT_CEQCTL(reg_idx), reg);
  426. reg_idx = ((msix_vf - 1) * vf->vf_id) + (v_idx - 1);
  427. reg = (qv_info->ceq_idx &
  428. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK) |
  429. (I40E_QUEUE_TYPE_PE_CEQ <<
  430. I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_SHIFT);
  431. wr32(hw, I40E_VPINT_LNKLSTN(reg_idx), reg);
  432. }
  433. if (qv_info->aeq_idx != I40E_QUEUE_INVALID_IDX) {
  434. reg = (I40E_VPINT_AEQCTL_CAUSE_ENA_MASK |
  435. (v_idx << I40E_VPINT_AEQCTL_MSIX_INDX_SHIFT) |
  436. (qv_info->itr_idx << I40E_VPINT_AEQCTL_ITR_INDX_SHIFT));
  437. wr32(hw, I40E_VPINT_AEQCTL(vf->vf_id), reg);
  438. }
  439. }
  440. return 0;
  441. err:
  442. kfree(vf->qvlist_info);
  443. vf->qvlist_info = NULL;
  444. return -EINVAL;
  445. }
  446. /**
  447. * i40e_config_vsi_tx_queue
  448. * @vf: pointer to the VF info
  449. * @vsi_id: id of VSI as provided by the FW
  450. * @vsi_queue_id: vsi relative queue index
  451. * @info: config. info
  452. *
  453. * configure tx queue
  454. **/
  455. static int i40e_config_vsi_tx_queue(struct i40e_vf *vf, u16 vsi_id,
  456. u16 vsi_queue_id,
  457. struct virtchnl_txq_info *info)
  458. {
  459. struct i40e_pf *pf = vf->pf;
  460. struct i40e_hw *hw = &pf->hw;
  461. struct i40e_hmc_obj_txq tx_ctx;
  462. struct i40e_vsi *vsi;
  463. u16 pf_queue_id;
  464. u32 qtx_ctl;
  465. int ret = 0;
  466. if (!i40e_vc_isvalid_vsi_id(vf, info->vsi_id)) {
  467. ret = -ENOENT;
  468. goto error_context;
  469. }
  470. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  471. vsi = i40e_find_vsi_from_id(pf, vsi_id);
  472. if (!vsi) {
  473. ret = -ENOENT;
  474. goto error_context;
  475. }
  476. /* clear the context structure first */
  477. memset(&tx_ctx, 0, sizeof(struct i40e_hmc_obj_txq));
  478. /* only set the required fields */
  479. tx_ctx.base = info->dma_ring_addr / 128;
  480. tx_ctx.qlen = info->ring_len;
  481. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[0]);
  482. tx_ctx.rdylist_act = 0;
  483. tx_ctx.head_wb_ena = info->headwb_enabled;
  484. tx_ctx.head_wb_addr = info->dma_headwb_addr;
  485. /* clear the context in the HMC */
  486. ret = i40e_clear_lan_tx_queue_context(hw, pf_queue_id);
  487. if (ret) {
  488. dev_err(&pf->pdev->dev,
  489. "Failed to clear VF LAN Tx queue context %d, error: %d\n",
  490. pf_queue_id, ret);
  491. ret = -ENOENT;
  492. goto error_context;
  493. }
  494. /* set the context in the HMC */
  495. ret = i40e_set_lan_tx_queue_context(hw, pf_queue_id, &tx_ctx);
  496. if (ret) {
  497. dev_err(&pf->pdev->dev,
  498. "Failed to set VF LAN Tx queue context %d error: %d\n",
  499. pf_queue_id, ret);
  500. ret = -ENOENT;
  501. goto error_context;
  502. }
  503. /* associate this queue with the PCI VF function */
  504. qtx_ctl = I40E_QTX_CTL_VF_QUEUE;
  505. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT)
  506. & I40E_QTX_CTL_PF_INDX_MASK);
  507. qtx_ctl |= (((vf->vf_id + hw->func_caps.vf_base_id)
  508. << I40E_QTX_CTL_VFVM_INDX_SHIFT)
  509. & I40E_QTX_CTL_VFVM_INDX_MASK);
  510. wr32(hw, I40E_QTX_CTL(pf_queue_id), qtx_ctl);
  511. i40e_flush(hw);
  512. error_context:
  513. return ret;
  514. }
  515. /**
  516. * i40e_config_vsi_rx_queue
  517. * @vf: pointer to the VF info
  518. * @vsi_id: id of VSI as provided by the FW
  519. * @vsi_queue_id: vsi relative queue index
  520. * @info: config. info
  521. *
  522. * configure rx queue
  523. **/
  524. static int i40e_config_vsi_rx_queue(struct i40e_vf *vf, u16 vsi_id,
  525. u16 vsi_queue_id,
  526. struct virtchnl_rxq_info *info)
  527. {
  528. struct i40e_pf *pf = vf->pf;
  529. struct i40e_hw *hw = &pf->hw;
  530. struct i40e_hmc_obj_rxq rx_ctx;
  531. u16 pf_queue_id;
  532. int ret = 0;
  533. pf_queue_id = i40e_vc_get_pf_queue_id(vf, vsi_id, vsi_queue_id);
  534. /* clear the context structure first */
  535. memset(&rx_ctx, 0, sizeof(struct i40e_hmc_obj_rxq));
  536. /* only set the required fields */
  537. rx_ctx.base = info->dma_ring_addr / 128;
  538. rx_ctx.qlen = info->ring_len;
  539. if (info->splithdr_enabled) {
  540. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  541. I40E_RX_SPLIT_IP |
  542. I40E_RX_SPLIT_TCP_UDP |
  543. I40E_RX_SPLIT_SCTP;
  544. /* header length validation */
  545. if (info->hdr_size > ((2 * 1024) - 64)) {
  546. ret = -EINVAL;
  547. goto error_param;
  548. }
  549. rx_ctx.hbuff = info->hdr_size >> I40E_RXQ_CTX_HBUFF_SHIFT;
  550. /* set split mode 10b */
  551. rx_ctx.dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  552. }
  553. /* databuffer length validation */
  554. if (info->databuffer_size > ((16 * 1024) - 128)) {
  555. ret = -EINVAL;
  556. goto error_param;
  557. }
  558. rx_ctx.dbuff = info->databuffer_size >> I40E_RXQ_CTX_DBUFF_SHIFT;
  559. /* max pkt. length validation */
  560. if (info->max_pkt_size >= (16 * 1024) || info->max_pkt_size < 64) {
  561. ret = -EINVAL;
  562. goto error_param;
  563. }
  564. rx_ctx.rxmax = info->max_pkt_size;
  565. /* enable 32bytes desc always */
  566. rx_ctx.dsize = 1;
  567. /* default values */
  568. rx_ctx.lrxqthresh = 1;
  569. rx_ctx.crcstrip = 1;
  570. rx_ctx.prefena = 1;
  571. rx_ctx.l2tsel = 1;
  572. /* clear the context in the HMC */
  573. ret = i40e_clear_lan_rx_queue_context(hw, pf_queue_id);
  574. if (ret) {
  575. dev_err(&pf->pdev->dev,
  576. "Failed to clear VF LAN Rx queue context %d, error: %d\n",
  577. pf_queue_id, ret);
  578. ret = -ENOENT;
  579. goto error_param;
  580. }
  581. /* set the context in the HMC */
  582. ret = i40e_set_lan_rx_queue_context(hw, pf_queue_id, &rx_ctx);
  583. if (ret) {
  584. dev_err(&pf->pdev->dev,
  585. "Failed to set VF LAN Rx queue context %d error: %d\n",
  586. pf_queue_id, ret);
  587. ret = -ENOENT;
  588. goto error_param;
  589. }
  590. error_param:
  591. return ret;
  592. }
  593. /**
  594. * i40e_alloc_vsi_res
  595. * @vf: pointer to the VF info
  596. * @idx: VSI index, applies only for ADq mode, zero otherwise
  597. *
  598. * alloc VF vsi context & resources
  599. **/
  600. static int i40e_alloc_vsi_res(struct i40e_vf *vf, u8 idx)
  601. {
  602. struct i40e_mac_filter *f = NULL;
  603. struct i40e_pf *pf = vf->pf;
  604. struct i40e_vsi *vsi;
  605. u64 max_tx_rate = 0;
  606. int ret = 0;
  607. vsi = i40e_vsi_setup(pf, I40E_VSI_SRIOV, pf->vsi[pf->lan_vsi]->seid,
  608. vf->vf_id);
  609. if (!vsi) {
  610. dev_err(&pf->pdev->dev,
  611. "add vsi failed for VF %d, aq_err %d\n",
  612. vf->vf_id, pf->hw.aq.asq_last_status);
  613. ret = -ENOENT;
  614. goto error_alloc_vsi_res;
  615. }
  616. if (!idx) {
  617. u64 hena = i40e_pf_get_default_rss_hena(pf);
  618. u8 broadcast[ETH_ALEN];
  619. vf->lan_vsi_idx = vsi->idx;
  620. vf->lan_vsi_id = vsi->id;
  621. /* If the port VLAN has been configured and then the
  622. * VF driver was removed then the VSI port VLAN
  623. * configuration was destroyed. Check if there is
  624. * a port VLAN and restore the VSI configuration if
  625. * needed.
  626. */
  627. if (vf->port_vlan_id)
  628. i40e_vsi_add_pvid(vsi, vf->port_vlan_id);
  629. spin_lock_bh(&vsi->mac_filter_hash_lock);
  630. if (is_valid_ether_addr(vf->default_lan_addr.addr)) {
  631. f = i40e_add_mac_filter(vsi,
  632. vf->default_lan_addr.addr);
  633. if (!f)
  634. dev_info(&pf->pdev->dev,
  635. "Could not add MAC filter %pM for VF %d\n",
  636. vf->default_lan_addr.addr, vf->vf_id);
  637. }
  638. eth_broadcast_addr(broadcast);
  639. f = i40e_add_mac_filter(vsi, broadcast);
  640. if (!f)
  641. dev_info(&pf->pdev->dev,
  642. "Could not allocate VF broadcast filter\n");
  643. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  644. wr32(&pf->hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)hena);
  645. wr32(&pf->hw, I40E_VFQF_HENA1(1, vf->vf_id), (u32)(hena >> 32));
  646. /* program mac filter only for VF VSI */
  647. ret = i40e_sync_vsi_filters(vsi);
  648. if (ret)
  649. dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
  650. }
  651. /* storing VSI index and id for ADq and don't apply the mac filter */
  652. if (vf->adq_enabled) {
  653. vf->ch[idx].vsi_idx = vsi->idx;
  654. vf->ch[idx].vsi_id = vsi->id;
  655. }
  656. /* Set VF bandwidth if specified */
  657. if (vf->tx_rate) {
  658. max_tx_rate = vf->tx_rate;
  659. } else if (vf->ch[idx].max_tx_rate) {
  660. max_tx_rate = vf->ch[idx].max_tx_rate;
  661. }
  662. if (max_tx_rate) {
  663. max_tx_rate = div_u64(max_tx_rate, I40E_BW_CREDIT_DIVISOR);
  664. ret = i40e_aq_config_vsi_bw_limit(&pf->hw, vsi->seid,
  665. max_tx_rate, 0, NULL);
  666. if (ret)
  667. dev_err(&pf->pdev->dev, "Unable to set tx rate, VF %d, error code %d.\n",
  668. vf->vf_id, ret);
  669. }
  670. error_alloc_vsi_res:
  671. return ret;
  672. }
  673. /**
  674. * i40e_map_pf_queues_to_vsi
  675. * @vf: pointer to the VF info
  676. *
  677. * PF maps LQPs to a VF by programming VSILAN_QTABLE & VPLAN_QTABLE. This
  678. * function takes care of first part VSILAN_QTABLE, mapping pf queues to VSI.
  679. **/
  680. static void i40e_map_pf_queues_to_vsi(struct i40e_vf *vf)
  681. {
  682. struct i40e_pf *pf = vf->pf;
  683. struct i40e_hw *hw = &pf->hw;
  684. u32 reg, num_tc = 1; /* VF has at least one traffic class */
  685. u16 vsi_id, qps;
  686. int i, j;
  687. if (vf->adq_enabled)
  688. num_tc = vf->num_tc;
  689. for (i = 0; i < num_tc; i++) {
  690. if (vf->adq_enabled) {
  691. qps = vf->ch[i].num_qps;
  692. vsi_id = vf->ch[i].vsi_id;
  693. } else {
  694. qps = pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
  695. vsi_id = vf->lan_vsi_id;
  696. }
  697. for (j = 0; j < 7; j++) {
  698. if (j * 2 >= qps) {
  699. /* end of list */
  700. reg = 0x07FF07FF;
  701. } else {
  702. u16 qid = i40e_vc_get_pf_queue_id(vf,
  703. vsi_id,
  704. j * 2);
  705. reg = qid;
  706. qid = i40e_vc_get_pf_queue_id(vf, vsi_id,
  707. (j * 2) + 1);
  708. reg |= qid << 16;
  709. }
  710. i40e_write_rx_ctl(hw,
  711. I40E_VSILAN_QTABLE(j, vsi_id),
  712. reg);
  713. }
  714. }
  715. }
  716. /**
  717. * i40e_map_pf_to_vf_queues
  718. * @vf: pointer to the VF info
  719. *
  720. * PF maps LQPs to a VF by programming VSILAN_QTABLE & VPLAN_QTABLE. This
  721. * function takes care of the second part VPLAN_QTABLE & completes VF mappings.
  722. **/
  723. static void i40e_map_pf_to_vf_queues(struct i40e_vf *vf)
  724. {
  725. struct i40e_pf *pf = vf->pf;
  726. struct i40e_hw *hw = &pf->hw;
  727. u32 reg, total_qps = 0;
  728. u32 qps, num_tc = 1; /* VF has at least one traffic class */
  729. u16 vsi_id, qid;
  730. int i, j;
  731. if (vf->adq_enabled)
  732. num_tc = vf->num_tc;
  733. for (i = 0; i < num_tc; i++) {
  734. if (vf->adq_enabled) {
  735. qps = vf->ch[i].num_qps;
  736. vsi_id = vf->ch[i].vsi_id;
  737. } else {
  738. qps = pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
  739. vsi_id = vf->lan_vsi_id;
  740. }
  741. for (j = 0; j < qps; j++) {
  742. qid = i40e_vc_get_pf_queue_id(vf, vsi_id, j);
  743. reg = (qid & I40E_VPLAN_QTABLE_QINDEX_MASK);
  744. wr32(hw, I40E_VPLAN_QTABLE(total_qps, vf->vf_id),
  745. reg);
  746. total_qps++;
  747. }
  748. }
  749. }
  750. /**
  751. * i40e_enable_vf_mappings
  752. * @vf: pointer to the VF info
  753. *
  754. * enable VF mappings
  755. **/
  756. static void i40e_enable_vf_mappings(struct i40e_vf *vf)
  757. {
  758. struct i40e_pf *pf = vf->pf;
  759. struct i40e_hw *hw = &pf->hw;
  760. u32 reg;
  761. /* Tell the hardware we're using noncontiguous mapping. HW requires
  762. * that VF queues be mapped using this method, even when they are
  763. * contiguous in real life
  764. */
  765. i40e_write_rx_ctl(hw, I40E_VSILAN_QBASE(vf->lan_vsi_id),
  766. I40E_VSILAN_QBASE_VSIQTABLE_ENA_MASK);
  767. /* enable VF vplan_qtable mappings */
  768. reg = I40E_VPLAN_MAPENA_TXRX_ENA_MASK;
  769. wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), reg);
  770. i40e_map_pf_to_vf_queues(vf);
  771. i40e_map_pf_queues_to_vsi(vf);
  772. i40e_flush(hw);
  773. }
  774. /**
  775. * i40e_disable_vf_mappings
  776. * @vf: pointer to the VF info
  777. *
  778. * disable VF mappings
  779. **/
  780. static void i40e_disable_vf_mappings(struct i40e_vf *vf)
  781. {
  782. struct i40e_pf *pf = vf->pf;
  783. struct i40e_hw *hw = &pf->hw;
  784. int i;
  785. /* disable qp mappings */
  786. wr32(hw, I40E_VPLAN_MAPENA(vf->vf_id), 0);
  787. for (i = 0; i < I40E_MAX_VSI_QP; i++)
  788. wr32(hw, I40E_VPLAN_QTABLE(i, vf->vf_id),
  789. I40E_QUEUE_END_OF_LIST);
  790. i40e_flush(hw);
  791. }
  792. /**
  793. * i40e_free_vf_res
  794. * @vf: pointer to the VF info
  795. *
  796. * free VF resources
  797. **/
  798. static void i40e_free_vf_res(struct i40e_vf *vf)
  799. {
  800. struct i40e_pf *pf = vf->pf;
  801. struct i40e_hw *hw = &pf->hw;
  802. u32 reg_idx, reg;
  803. int i, j, msix_vf;
  804. /* Start by disabling VF's configuration API to prevent the OS from
  805. * accessing the VF's VSI after it's freed / invalidated.
  806. */
  807. clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
  808. /* It's possible the VF had requeuested more queues than the default so
  809. * do the accounting here when we're about to free them.
  810. */
  811. if (vf->num_queue_pairs > I40E_DEFAULT_QUEUES_PER_VF) {
  812. pf->queues_left += vf->num_queue_pairs -
  813. I40E_DEFAULT_QUEUES_PER_VF;
  814. }
  815. /* free vsi & disconnect it from the parent uplink */
  816. if (vf->lan_vsi_idx) {
  817. i40e_vsi_release(pf->vsi[vf->lan_vsi_idx]);
  818. vf->lan_vsi_idx = 0;
  819. vf->lan_vsi_id = 0;
  820. vf->num_mac = 0;
  821. }
  822. /* do the accounting and remove additional ADq VSI's */
  823. if (vf->adq_enabled && vf->ch[0].vsi_idx) {
  824. for (j = 0; j < vf->num_tc; j++) {
  825. /* At this point VSI0 is already released so don't
  826. * release it again and only clear their values in
  827. * structure variables
  828. */
  829. if (j)
  830. i40e_vsi_release(pf->vsi[vf->ch[j].vsi_idx]);
  831. vf->ch[j].vsi_idx = 0;
  832. vf->ch[j].vsi_id = 0;
  833. }
  834. }
  835. msix_vf = pf->hw.func_caps.num_msix_vectors_vf;
  836. /* disable interrupts so the VF starts in a known state */
  837. for (i = 0; i < msix_vf; i++) {
  838. /* format is same for both registers */
  839. if (0 == i)
  840. reg_idx = I40E_VFINT_DYN_CTL0(vf->vf_id);
  841. else
  842. reg_idx = I40E_VFINT_DYN_CTLN(((msix_vf - 1) *
  843. (vf->vf_id))
  844. + (i - 1));
  845. wr32(hw, reg_idx, I40E_VFINT_DYN_CTLN_CLEARPBA_MASK);
  846. i40e_flush(hw);
  847. }
  848. /* clear the irq settings */
  849. for (i = 0; i < msix_vf; i++) {
  850. /* format is same for both registers */
  851. if (0 == i)
  852. reg_idx = I40E_VPINT_LNKLST0(vf->vf_id);
  853. else
  854. reg_idx = I40E_VPINT_LNKLSTN(((msix_vf - 1) *
  855. (vf->vf_id))
  856. + (i - 1));
  857. reg = (I40E_VPINT_LNKLSTN_FIRSTQ_TYPE_MASK |
  858. I40E_VPINT_LNKLSTN_FIRSTQ_INDX_MASK);
  859. wr32(hw, reg_idx, reg);
  860. i40e_flush(hw);
  861. }
  862. /* reset some of the state variables keeping track of the resources */
  863. vf->num_queue_pairs = 0;
  864. clear_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
  865. clear_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
  866. }
  867. /**
  868. * i40e_alloc_vf_res
  869. * @vf: pointer to the VF info
  870. *
  871. * allocate VF resources
  872. **/
  873. static int i40e_alloc_vf_res(struct i40e_vf *vf)
  874. {
  875. struct i40e_pf *pf = vf->pf;
  876. int total_queue_pairs = 0;
  877. int ret, idx;
  878. if (vf->num_req_queues &&
  879. vf->num_req_queues <= pf->queues_left + I40E_DEFAULT_QUEUES_PER_VF)
  880. pf->num_vf_qps = vf->num_req_queues;
  881. else
  882. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  883. /* allocate hw vsi context & associated resources */
  884. ret = i40e_alloc_vsi_res(vf, 0);
  885. if (ret)
  886. goto error_alloc;
  887. total_queue_pairs += pf->vsi[vf->lan_vsi_idx]->alloc_queue_pairs;
  888. /* allocate additional VSIs based on tc information for ADq */
  889. if (vf->adq_enabled) {
  890. if (pf->queues_left >=
  891. (I40E_MAX_VF_QUEUES - I40E_DEFAULT_QUEUES_PER_VF)) {
  892. /* TC 0 always belongs to VF VSI */
  893. for (idx = 1; idx < vf->num_tc; idx++) {
  894. ret = i40e_alloc_vsi_res(vf, idx);
  895. if (ret)
  896. goto error_alloc;
  897. }
  898. /* send correct number of queues */
  899. total_queue_pairs = I40E_MAX_VF_QUEUES;
  900. } else {
  901. dev_info(&pf->pdev->dev, "VF %d: Not enough queues to allocate, disabling ADq\n",
  902. vf->vf_id);
  903. vf->adq_enabled = false;
  904. }
  905. }
  906. /* We account for each VF to get a default number of queue pairs. If
  907. * the VF has now requested more, we need to account for that to make
  908. * certain we never request more queues than we actually have left in
  909. * HW.
  910. */
  911. if (total_queue_pairs > I40E_DEFAULT_QUEUES_PER_VF)
  912. pf->queues_left -=
  913. total_queue_pairs - I40E_DEFAULT_QUEUES_PER_VF;
  914. if (vf->trusted)
  915. set_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
  916. else
  917. clear_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps);
  918. /* store the total qps number for the runtime
  919. * VF req validation
  920. */
  921. vf->num_queue_pairs = total_queue_pairs;
  922. /* VF is now completely initialized */
  923. set_bit(I40E_VF_STATE_INIT, &vf->vf_states);
  924. error_alloc:
  925. if (ret)
  926. i40e_free_vf_res(vf);
  927. return ret;
  928. }
  929. #define VF_DEVICE_STATUS 0xAA
  930. #define VF_TRANS_PENDING_MASK 0x20
  931. /**
  932. * i40e_quiesce_vf_pci
  933. * @vf: pointer to the VF structure
  934. *
  935. * Wait for VF PCI transactions to be cleared after reset. Returns -EIO
  936. * if the transactions never clear.
  937. **/
  938. static int i40e_quiesce_vf_pci(struct i40e_vf *vf)
  939. {
  940. struct i40e_pf *pf = vf->pf;
  941. struct i40e_hw *hw = &pf->hw;
  942. int vf_abs_id, i;
  943. u32 reg;
  944. vf_abs_id = vf->vf_id + hw->func_caps.vf_base_id;
  945. wr32(hw, I40E_PF_PCI_CIAA,
  946. VF_DEVICE_STATUS | (vf_abs_id << I40E_PF_PCI_CIAA_VF_NUM_SHIFT));
  947. for (i = 0; i < 100; i++) {
  948. reg = rd32(hw, I40E_PF_PCI_CIAD);
  949. if ((reg & VF_TRANS_PENDING_MASK) == 0)
  950. return 0;
  951. udelay(1);
  952. }
  953. return -EIO;
  954. }
  955. /**
  956. * i40e_trigger_vf_reset
  957. * @vf: pointer to the VF structure
  958. * @flr: VFLR was issued or not
  959. *
  960. * Trigger hardware to start a reset for a particular VF. Expects the caller
  961. * to wait the proper amount of time to allow hardware to reset the VF before
  962. * it cleans up and restores VF functionality.
  963. **/
  964. static void i40e_trigger_vf_reset(struct i40e_vf *vf, bool flr)
  965. {
  966. struct i40e_pf *pf = vf->pf;
  967. struct i40e_hw *hw = &pf->hw;
  968. u32 reg, reg_idx, bit_idx;
  969. /* warn the VF */
  970. clear_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
  971. /* Disable VF's configuration API during reset. The flag is re-enabled
  972. * in i40e_alloc_vf_res(), when it's safe again to access VF's VSI.
  973. * It's normally disabled in i40e_free_vf_res(), but it's safer
  974. * to do it earlier to give some time to finish to any VF config
  975. * functions that may still be running at this point.
  976. */
  977. clear_bit(I40E_VF_STATE_INIT, &vf->vf_states);
  978. /* In the case of a VFLR, the HW has already reset the VF and we
  979. * just need to clean up, so don't hit the VFRTRIG register.
  980. */
  981. if (!flr) {
  982. /* reset VF using VPGEN_VFRTRIG reg */
  983. reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
  984. reg |= I40E_VPGEN_VFRTRIG_VFSWR_MASK;
  985. wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
  986. i40e_flush(hw);
  987. }
  988. /* clear the VFLR bit in GLGEN_VFLRSTAT */
  989. reg_idx = (hw->func_caps.vf_base_id + vf->vf_id) / 32;
  990. bit_idx = (hw->func_caps.vf_base_id + vf->vf_id) % 32;
  991. wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
  992. i40e_flush(hw);
  993. if (i40e_quiesce_vf_pci(vf))
  994. dev_err(&pf->pdev->dev, "VF %d PCI transactions stuck\n",
  995. vf->vf_id);
  996. }
  997. /**
  998. * i40e_cleanup_reset_vf
  999. * @vf: pointer to the VF structure
  1000. *
  1001. * Cleanup a VF after the hardware reset is finished. Expects the caller to
  1002. * have verified whether the reset is finished properly, and ensure the
  1003. * minimum amount of wait time has passed.
  1004. **/
  1005. static void i40e_cleanup_reset_vf(struct i40e_vf *vf)
  1006. {
  1007. struct i40e_pf *pf = vf->pf;
  1008. struct i40e_hw *hw = &pf->hw;
  1009. u32 reg;
  1010. /* free VF resources to begin resetting the VSI state */
  1011. i40e_free_vf_res(vf);
  1012. /* Enable hardware by clearing the reset bit in the VPGEN_VFRTRIG reg.
  1013. * By doing this we allow HW to access VF memory at any point. If we
  1014. * did it any sooner, HW could access memory while it was being freed
  1015. * in i40e_free_vf_res(), causing an IOMMU fault.
  1016. *
  1017. * On the other hand, this needs to be done ASAP, because the VF driver
  1018. * is waiting for this to happen and may report a timeout. It's
  1019. * harmless, but it gets logged into Guest OS kernel log, so best avoid
  1020. * it.
  1021. */
  1022. reg = rd32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id));
  1023. reg &= ~I40E_VPGEN_VFRTRIG_VFSWR_MASK;
  1024. wr32(hw, I40E_VPGEN_VFRTRIG(vf->vf_id), reg);
  1025. /* reallocate VF resources to finish resetting the VSI state */
  1026. if (!i40e_alloc_vf_res(vf)) {
  1027. int abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  1028. i40e_enable_vf_mappings(vf);
  1029. set_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
  1030. clear_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
  1031. /* Do not notify the client during VF init */
  1032. if (!test_and_clear_bit(I40E_VF_STATE_PRE_ENABLE,
  1033. &vf->vf_states))
  1034. i40e_notify_client_of_vf_reset(pf, abs_vf_id);
  1035. vf->num_vlan = 0;
  1036. }
  1037. /* Tell the VF driver the reset is done. This needs to be done only
  1038. * after VF has been fully initialized, because the VF driver may
  1039. * request resources immediately after setting this flag.
  1040. */
  1041. wr32(hw, I40E_VFGEN_RSTAT1(vf->vf_id), VIRTCHNL_VFR_VFACTIVE);
  1042. }
  1043. /**
  1044. * i40e_reset_vf
  1045. * @vf: pointer to the VF structure
  1046. * @flr: VFLR was issued or not
  1047. *
  1048. * Returns true if the VF is reset, false otherwise.
  1049. **/
  1050. bool i40e_reset_vf(struct i40e_vf *vf, bool flr)
  1051. {
  1052. struct i40e_pf *pf = vf->pf;
  1053. struct i40e_hw *hw = &pf->hw;
  1054. bool rsd = false;
  1055. u32 reg;
  1056. int i;
  1057. /* If the VFs have been disabled, this means something else is
  1058. * resetting the VF, so we shouldn't continue.
  1059. */
  1060. if (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
  1061. return false;
  1062. i40e_trigger_vf_reset(vf, flr);
  1063. /* poll VPGEN_VFRSTAT reg to make sure
  1064. * that reset is complete
  1065. */
  1066. for (i = 0; i < 10; i++) {
  1067. /* VF reset requires driver to first reset the VF and then
  1068. * poll the status register to make sure that the reset
  1069. * completed successfully. Due to internal HW FIFO flushes,
  1070. * we must wait 10ms before the register will be valid.
  1071. */
  1072. usleep_range(10000, 20000);
  1073. reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
  1074. if (reg & I40E_VPGEN_VFRSTAT_VFRD_MASK) {
  1075. rsd = true;
  1076. break;
  1077. }
  1078. }
  1079. if (flr)
  1080. usleep_range(10000, 20000);
  1081. if (!rsd)
  1082. dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
  1083. vf->vf_id);
  1084. usleep_range(10000, 20000);
  1085. /* On initial reset, we don't have any queues to disable */
  1086. if (vf->lan_vsi_idx != 0)
  1087. i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
  1088. i40e_cleanup_reset_vf(vf);
  1089. i40e_flush(hw);
  1090. clear_bit(__I40E_VF_DISABLE, pf->state);
  1091. return true;
  1092. }
  1093. /**
  1094. * i40e_reset_all_vfs
  1095. * @pf: pointer to the PF structure
  1096. * @flr: VFLR was issued or not
  1097. *
  1098. * Reset all allocated VFs in one go. First, tell the hardware to reset each
  1099. * VF, then do all the waiting in one chunk, and finally finish restoring each
  1100. * VF after the wait. This is useful during PF routines which need to reset
  1101. * all VFs, as otherwise it must perform these resets in a serialized fashion.
  1102. *
  1103. * Returns true if any VFs were reset, and false otherwise.
  1104. **/
  1105. bool i40e_reset_all_vfs(struct i40e_pf *pf, bool flr)
  1106. {
  1107. struct i40e_hw *hw = &pf->hw;
  1108. struct i40e_vf *vf;
  1109. int i, v;
  1110. u32 reg;
  1111. /* If we don't have any VFs, then there is nothing to reset */
  1112. if (!pf->num_alloc_vfs)
  1113. return false;
  1114. /* If VFs have been disabled, there is no need to reset */
  1115. if (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
  1116. return false;
  1117. /* Begin reset on all VFs at once */
  1118. for (v = 0; v < pf->num_alloc_vfs; v++)
  1119. i40e_trigger_vf_reset(&pf->vf[v], flr);
  1120. /* HW requires some time to make sure it can flush the FIFO for a VF
  1121. * when it resets it. Poll the VPGEN_VFRSTAT register for each VF in
  1122. * sequence to make sure that it has completed. We'll keep track of
  1123. * the VFs using a simple iterator that increments once that VF has
  1124. * finished resetting.
  1125. */
  1126. for (i = 0, v = 0; i < 10 && v < pf->num_alloc_vfs; i++) {
  1127. usleep_range(10000, 20000);
  1128. /* Check each VF in sequence, beginning with the VF to fail
  1129. * the previous check.
  1130. */
  1131. while (v < pf->num_alloc_vfs) {
  1132. vf = &pf->vf[v];
  1133. reg = rd32(hw, I40E_VPGEN_VFRSTAT(vf->vf_id));
  1134. if (!(reg & I40E_VPGEN_VFRSTAT_VFRD_MASK))
  1135. break;
  1136. /* If the current VF has finished resetting, move on
  1137. * to the next VF in sequence.
  1138. */
  1139. v++;
  1140. }
  1141. }
  1142. if (flr)
  1143. usleep_range(10000, 20000);
  1144. /* Display a warning if at least one VF didn't manage to reset in
  1145. * time, but continue on with the operation.
  1146. */
  1147. if (v < pf->num_alloc_vfs)
  1148. dev_err(&pf->pdev->dev, "VF reset check timeout on VF %d\n",
  1149. pf->vf[v].vf_id);
  1150. usleep_range(10000, 20000);
  1151. /* Begin disabling all the rings associated with VFs, but do not wait
  1152. * between each VF.
  1153. */
  1154. for (v = 0; v < pf->num_alloc_vfs; v++) {
  1155. /* On initial reset, we don't have any queues to disable */
  1156. if (pf->vf[v].lan_vsi_idx == 0)
  1157. continue;
  1158. i40e_vsi_stop_rings_no_wait(pf->vsi[pf->vf[v].lan_vsi_idx]);
  1159. }
  1160. /* Now that we've notified HW to disable all of the VF rings, wait
  1161. * until they finish.
  1162. */
  1163. for (v = 0; v < pf->num_alloc_vfs; v++) {
  1164. /* On initial reset, we don't have any queues to disable */
  1165. if (pf->vf[v].lan_vsi_idx == 0)
  1166. continue;
  1167. i40e_vsi_wait_queues_disabled(pf->vsi[pf->vf[v].lan_vsi_idx]);
  1168. }
  1169. /* Hw may need up to 50ms to finish disabling the RX queues. We
  1170. * minimize the wait by delaying only once for all VFs.
  1171. */
  1172. mdelay(50);
  1173. /* Finish the reset on each VF */
  1174. for (v = 0; v < pf->num_alloc_vfs; v++)
  1175. i40e_cleanup_reset_vf(&pf->vf[v]);
  1176. i40e_flush(hw);
  1177. clear_bit(__I40E_VF_DISABLE, pf->state);
  1178. return true;
  1179. }
  1180. /**
  1181. * i40e_free_vfs
  1182. * @pf: pointer to the PF structure
  1183. *
  1184. * free VF resources
  1185. **/
  1186. void i40e_free_vfs(struct i40e_pf *pf)
  1187. {
  1188. struct i40e_hw *hw = &pf->hw;
  1189. u32 reg_idx, bit_idx;
  1190. int i, tmp, vf_id;
  1191. if (!pf->vf)
  1192. return;
  1193. while (test_and_set_bit(__I40E_VF_DISABLE, pf->state))
  1194. usleep_range(1000, 2000);
  1195. i40e_notify_client_of_vf_enable(pf, 0);
  1196. /* Amortize wait time by stopping all VFs at the same time */
  1197. for (i = 0; i < pf->num_alloc_vfs; i++) {
  1198. if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
  1199. continue;
  1200. i40e_vsi_stop_rings_no_wait(pf->vsi[pf->vf[i].lan_vsi_idx]);
  1201. }
  1202. for (i = 0; i < pf->num_alloc_vfs; i++) {
  1203. if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
  1204. continue;
  1205. i40e_vsi_wait_queues_disabled(pf->vsi[pf->vf[i].lan_vsi_idx]);
  1206. }
  1207. /* Disable IOV before freeing resources. This lets any VF drivers
  1208. * running in the host get themselves cleaned up before we yank
  1209. * the carpet out from underneath their feet.
  1210. */
  1211. if (!pci_vfs_assigned(pf->pdev))
  1212. pci_disable_sriov(pf->pdev);
  1213. else
  1214. dev_warn(&pf->pdev->dev, "VFs are assigned - not disabling SR-IOV\n");
  1215. /* free up VF resources */
  1216. tmp = pf->num_alloc_vfs;
  1217. pf->num_alloc_vfs = 0;
  1218. for (i = 0; i < tmp; i++) {
  1219. if (test_bit(I40E_VF_STATE_INIT, &pf->vf[i].vf_states))
  1220. i40e_free_vf_res(&pf->vf[i]);
  1221. /* disable qp mappings */
  1222. i40e_disable_vf_mappings(&pf->vf[i]);
  1223. }
  1224. kfree(pf->vf);
  1225. pf->vf = NULL;
  1226. /* This check is for when the driver is unloaded while VFs are
  1227. * assigned. Setting the number of VFs to 0 through sysfs is caught
  1228. * before this function ever gets called.
  1229. */
  1230. if (!pci_vfs_assigned(pf->pdev)) {
  1231. /* Acknowledge VFLR for all VFS. Without this, VFs will fail to
  1232. * work correctly when SR-IOV gets re-enabled.
  1233. */
  1234. for (vf_id = 0; vf_id < tmp; vf_id++) {
  1235. reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
  1236. bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
  1237. wr32(hw, I40E_GLGEN_VFLRSTAT(reg_idx), BIT(bit_idx));
  1238. }
  1239. }
  1240. clear_bit(__I40E_VF_DISABLE, pf->state);
  1241. }
  1242. #ifdef CONFIG_PCI_IOV
  1243. /**
  1244. * i40e_alloc_vfs
  1245. * @pf: pointer to the PF structure
  1246. * @num_alloc_vfs: number of VFs to allocate
  1247. *
  1248. * allocate VF resources
  1249. **/
  1250. int i40e_alloc_vfs(struct i40e_pf *pf, u16 num_alloc_vfs)
  1251. {
  1252. struct i40e_vf *vfs;
  1253. int i, ret = 0;
  1254. /* Disable interrupt 0 so we don't try to handle the VFLR. */
  1255. i40e_irq_dynamic_disable_icr0(pf);
  1256. /* Check to see if we're just allocating resources for extant VFs */
  1257. if (pci_num_vf(pf->pdev) != num_alloc_vfs) {
  1258. ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
  1259. if (ret) {
  1260. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  1261. pf->num_alloc_vfs = 0;
  1262. goto err_iov;
  1263. }
  1264. }
  1265. /* allocate memory */
  1266. vfs = kcalloc(num_alloc_vfs, sizeof(struct i40e_vf), GFP_KERNEL);
  1267. if (!vfs) {
  1268. ret = -ENOMEM;
  1269. goto err_alloc;
  1270. }
  1271. pf->vf = vfs;
  1272. /* apply default profile */
  1273. for (i = 0; i < num_alloc_vfs; i++) {
  1274. vfs[i].pf = pf;
  1275. vfs[i].parent_type = I40E_SWITCH_ELEMENT_TYPE_VEB;
  1276. vfs[i].vf_id = i;
  1277. /* assign default capabilities */
  1278. set_bit(I40E_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
  1279. vfs[i].spoofchk = true;
  1280. set_bit(I40E_VF_STATE_PRE_ENABLE, &vfs[i].vf_states);
  1281. }
  1282. pf->num_alloc_vfs = num_alloc_vfs;
  1283. /* VF resources get allocated during reset */
  1284. i40e_reset_all_vfs(pf, false);
  1285. i40e_notify_client_of_vf_enable(pf, num_alloc_vfs);
  1286. err_alloc:
  1287. if (ret)
  1288. i40e_free_vfs(pf);
  1289. err_iov:
  1290. /* Re-enable interrupt 0. */
  1291. i40e_irq_dynamic_enable_icr0(pf);
  1292. return ret;
  1293. }
  1294. #endif
  1295. /**
  1296. * i40e_pci_sriov_enable
  1297. * @pdev: pointer to a pci_dev structure
  1298. * @num_vfs: number of VFs to allocate
  1299. *
  1300. * Enable or change the number of VFs
  1301. **/
  1302. static int i40e_pci_sriov_enable(struct pci_dev *pdev, int num_vfs)
  1303. {
  1304. #ifdef CONFIG_PCI_IOV
  1305. struct i40e_pf *pf = pci_get_drvdata(pdev);
  1306. int pre_existing_vfs = pci_num_vf(pdev);
  1307. int err = 0;
  1308. if (test_bit(__I40E_TESTING, pf->state)) {
  1309. dev_warn(&pdev->dev,
  1310. "Cannot enable SR-IOV virtual functions while the device is undergoing diagnostic testing\n");
  1311. err = -EPERM;
  1312. goto err_out;
  1313. }
  1314. if (pre_existing_vfs && pre_existing_vfs != num_vfs)
  1315. i40e_free_vfs(pf);
  1316. else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
  1317. goto out;
  1318. if (num_vfs > pf->num_req_vfs) {
  1319. dev_warn(&pdev->dev, "Unable to enable %d VFs. Limited to %d VFs due to device resource constraints.\n",
  1320. num_vfs, pf->num_req_vfs);
  1321. err = -EPERM;
  1322. goto err_out;
  1323. }
  1324. dev_info(&pdev->dev, "Allocating %d VFs.\n", num_vfs);
  1325. err = i40e_alloc_vfs(pf, num_vfs);
  1326. if (err) {
  1327. dev_warn(&pdev->dev, "Failed to enable SR-IOV: %d\n", err);
  1328. goto err_out;
  1329. }
  1330. out:
  1331. return num_vfs;
  1332. err_out:
  1333. return err;
  1334. #endif
  1335. return 0;
  1336. }
  1337. /**
  1338. * i40e_pci_sriov_configure
  1339. * @pdev: pointer to a pci_dev structure
  1340. * @num_vfs: number of VFs to allocate
  1341. *
  1342. * Enable or change the number of VFs. Called when the user updates the number
  1343. * of VFs in sysfs.
  1344. **/
  1345. int i40e_pci_sriov_configure(struct pci_dev *pdev, int num_vfs)
  1346. {
  1347. struct i40e_pf *pf = pci_get_drvdata(pdev);
  1348. if (num_vfs) {
  1349. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  1350. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  1351. i40e_do_reset_safe(pf, I40E_PF_RESET_FLAG);
  1352. }
  1353. return i40e_pci_sriov_enable(pdev, num_vfs);
  1354. }
  1355. if (!pci_vfs_assigned(pf->pdev)) {
  1356. i40e_free_vfs(pf);
  1357. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  1358. i40e_do_reset_safe(pf, I40E_PF_RESET_FLAG);
  1359. } else {
  1360. dev_warn(&pdev->dev, "Unable to free VFs because some are assigned to VMs.\n");
  1361. return -EINVAL;
  1362. }
  1363. return 0;
  1364. }
  1365. /***********************virtual channel routines******************/
  1366. /**
  1367. * i40e_vc_send_msg_to_vf
  1368. * @vf: pointer to the VF info
  1369. * @v_opcode: virtual channel opcode
  1370. * @v_retval: virtual channel return value
  1371. * @msg: pointer to the msg buffer
  1372. * @msglen: msg length
  1373. *
  1374. * send msg to VF
  1375. **/
  1376. static int i40e_vc_send_msg_to_vf(struct i40e_vf *vf, u32 v_opcode,
  1377. u32 v_retval, u8 *msg, u16 msglen)
  1378. {
  1379. struct i40e_pf *pf;
  1380. struct i40e_hw *hw;
  1381. int abs_vf_id;
  1382. i40e_status aq_ret;
  1383. /* validate the request */
  1384. if (!vf || vf->vf_id >= vf->pf->num_alloc_vfs)
  1385. return -EINVAL;
  1386. pf = vf->pf;
  1387. hw = &pf->hw;
  1388. abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  1389. /* single place to detect unsuccessful return values */
  1390. if (v_retval) {
  1391. vf->num_invalid_msgs++;
  1392. dev_info(&pf->pdev->dev, "VF %d failed opcode %d, retval: %d\n",
  1393. vf->vf_id, v_opcode, v_retval);
  1394. if (vf->num_invalid_msgs >
  1395. I40E_DEFAULT_NUM_INVALID_MSGS_ALLOWED) {
  1396. dev_err(&pf->pdev->dev,
  1397. "Number of invalid messages exceeded for VF %d\n",
  1398. vf->vf_id);
  1399. dev_err(&pf->pdev->dev, "Use PF Control I/F to enable the VF\n");
  1400. set_bit(I40E_VF_STATE_DISABLED, &vf->vf_states);
  1401. }
  1402. } else {
  1403. vf->num_valid_msgs++;
  1404. /* reset the invalid counter, if a valid message is received. */
  1405. vf->num_invalid_msgs = 0;
  1406. }
  1407. aq_ret = i40e_aq_send_msg_to_vf(hw, abs_vf_id, v_opcode, v_retval,
  1408. msg, msglen, NULL);
  1409. if (aq_ret) {
  1410. dev_info(&pf->pdev->dev,
  1411. "Unable to send the message to VF %d aq_err %d\n",
  1412. vf->vf_id, pf->hw.aq.asq_last_status);
  1413. return -EIO;
  1414. }
  1415. return 0;
  1416. }
  1417. /**
  1418. * i40e_vc_send_resp_to_vf
  1419. * @vf: pointer to the VF info
  1420. * @opcode: operation code
  1421. * @retval: return value
  1422. *
  1423. * send resp msg to VF
  1424. **/
  1425. static int i40e_vc_send_resp_to_vf(struct i40e_vf *vf,
  1426. enum virtchnl_ops opcode,
  1427. i40e_status retval)
  1428. {
  1429. return i40e_vc_send_msg_to_vf(vf, opcode, retval, NULL, 0);
  1430. }
  1431. /**
  1432. * i40e_vc_get_version_msg
  1433. * @vf: pointer to the VF info
  1434. * @msg: pointer to the msg buffer
  1435. *
  1436. * called from the VF to request the API version used by the PF
  1437. **/
  1438. static int i40e_vc_get_version_msg(struct i40e_vf *vf, u8 *msg)
  1439. {
  1440. struct virtchnl_version_info info = {
  1441. VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
  1442. };
  1443. vf->vf_ver = *(struct virtchnl_version_info *)msg;
  1444. /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
  1445. if (VF_IS_V10(&vf->vf_ver))
  1446. info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
  1447. return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
  1448. I40E_SUCCESS, (u8 *)&info,
  1449. sizeof(struct virtchnl_version_info));
  1450. }
  1451. /**
  1452. * i40e_del_qch - delete all the additional VSIs created as a part of ADq
  1453. * @vf: pointer to VF structure
  1454. **/
  1455. static void i40e_del_qch(struct i40e_vf *vf)
  1456. {
  1457. struct i40e_pf *pf = vf->pf;
  1458. int i;
  1459. /* first element in the array belongs to primary VF VSI and we shouldn't
  1460. * delete it. We should however delete the rest of the VSIs created
  1461. */
  1462. for (i = 1; i < vf->num_tc; i++) {
  1463. if (vf->ch[i].vsi_idx) {
  1464. i40e_vsi_release(pf->vsi[vf->ch[i].vsi_idx]);
  1465. vf->ch[i].vsi_idx = 0;
  1466. vf->ch[i].vsi_id = 0;
  1467. }
  1468. }
  1469. }
  1470. /**
  1471. * i40e_vc_get_vf_resources_msg
  1472. * @vf: pointer to the VF info
  1473. * @msg: pointer to the msg buffer
  1474. *
  1475. * called from the VF to request its resources
  1476. **/
  1477. static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
  1478. {
  1479. struct virtchnl_vf_resource *vfres = NULL;
  1480. struct i40e_pf *pf = vf->pf;
  1481. i40e_status aq_ret = 0;
  1482. struct i40e_vsi *vsi;
  1483. int num_vsis = 1;
  1484. int len = 0;
  1485. int ret;
  1486. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
  1487. aq_ret = I40E_ERR_PARAM;
  1488. goto err;
  1489. }
  1490. len = (sizeof(struct virtchnl_vf_resource) +
  1491. sizeof(struct virtchnl_vsi_resource) * num_vsis);
  1492. vfres = kzalloc(len, GFP_KERNEL);
  1493. if (!vfres) {
  1494. aq_ret = I40E_ERR_NO_MEMORY;
  1495. len = 0;
  1496. goto err;
  1497. }
  1498. if (VF_IS_V11(&vf->vf_ver))
  1499. vf->driver_caps = *(u32 *)msg;
  1500. else
  1501. vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
  1502. VIRTCHNL_VF_OFFLOAD_RSS_REG |
  1503. VIRTCHNL_VF_OFFLOAD_VLAN;
  1504. vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
  1505. vsi = pf->vsi[vf->lan_vsi_idx];
  1506. if (!vsi->info.pvid)
  1507. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_VLAN;
  1508. if (i40e_vf_client_capable(pf, vf->vf_id) &&
  1509. (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_IWARP)) {
  1510. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_IWARP;
  1511. set_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states);
  1512. } else {
  1513. clear_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states);
  1514. }
  1515. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF) {
  1516. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
  1517. } else {
  1518. if ((pf->hw_features & I40E_HW_RSS_AQ_CAPABLE) &&
  1519. (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_AQ))
  1520. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_AQ;
  1521. else
  1522. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_REG;
  1523. }
  1524. if (pf->hw_features & I40E_HW_MULTIPLE_TCP_UDP_RSS_PCTYPE) {
  1525. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  1526. vfres->vf_cap_flags |=
  1527. VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
  1528. }
  1529. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
  1530. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
  1531. if ((pf->hw_features & I40E_HW_OUTER_UDP_CSUM_CAPABLE) &&
  1532. (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM))
  1533. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
  1534. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING) {
  1535. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  1536. dev_err(&pf->pdev->dev,
  1537. "VF %d requested polling mode: this feature is supported only when the device is running in single function per port (SFP) mode\n",
  1538. vf->vf_id);
  1539. aq_ret = I40E_ERR_PARAM;
  1540. goto err;
  1541. }
  1542. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
  1543. }
  1544. if (pf->hw_features & I40E_HW_WB_ON_ITR_CAPABLE) {
  1545. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
  1546. vfres->vf_cap_flags |=
  1547. VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
  1548. }
  1549. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
  1550. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
  1551. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADQ)
  1552. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADQ;
  1553. vfres->num_vsis = num_vsis;
  1554. vfres->num_queue_pairs = vf->num_queue_pairs;
  1555. vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
  1556. vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
  1557. vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
  1558. if (vf->lan_vsi_idx) {
  1559. vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
  1560. vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
  1561. vfres->vsi_res[0].num_queue_pairs = vsi->alloc_queue_pairs;
  1562. /* VFs only use TC 0 */
  1563. vfres->vsi_res[0].qset_handle
  1564. = le16_to_cpu(vsi->info.qs_handle[0]);
  1565. ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
  1566. vf->default_lan_addr.addr);
  1567. }
  1568. set_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states);
  1569. err:
  1570. /* send the response back to the VF */
  1571. ret = i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES,
  1572. aq_ret, (u8 *)vfres, len);
  1573. kfree(vfres);
  1574. return ret;
  1575. }
  1576. /**
  1577. * i40e_vc_reset_vf_msg
  1578. * @vf: pointer to the VF info
  1579. *
  1580. * called from the VF to reset itself,
  1581. * unlike other virtchnl messages, PF driver
  1582. * doesn't send the response back to the VF
  1583. **/
  1584. static void i40e_vc_reset_vf_msg(struct i40e_vf *vf)
  1585. {
  1586. if (test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
  1587. i40e_reset_vf(vf, false);
  1588. }
  1589. /**
  1590. * i40e_getnum_vf_vsi_vlan_filters
  1591. * @vsi: pointer to the vsi
  1592. *
  1593. * called to get the number of VLANs offloaded on this VF
  1594. **/
  1595. static inline int i40e_getnum_vf_vsi_vlan_filters(struct i40e_vsi *vsi)
  1596. {
  1597. struct i40e_mac_filter *f;
  1598. int num_vlans = 0, bkt;
  1599. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1600. if (f->vlan >= 0 && f->vlan <= I40E_MAX_VLANID)
  1601. num_vlans++;
  1602. }
  1603. return num_vlans;
  1604. }
  1605. /**
  1606. * i40e_vc_config_promiscuous_mode_msg
  1607. * @vf: pointer to the VF info
  1608. * @msg: pointer to the msg buffer
  1609. * @msglen: msg length
  1610. *
  1611. * called from the VF to configure the promiscuous mode of
  1612. * VF vsis
  1613. **/
  1614. static int i40e_vc_config_promiscuous_mode_msg(struct i40e_vf *vf,
  1615. u8 *msg, u16 msglen)
  1616. {
  1617. struct virtchnl_promisc_info *info =
  1618. (struct virtchnl_promisc_info *)msg;
  1619. struct i40e_pf *pf = vf->pf;
  1620. struct i40e_hw *hw = &pf->hw;
  1621. struct i40e_mac_filter *f;
  1622. i40e_status aq_ret = 0;
  1623. bool allmulti = false;
  1624. struct i40e_vsi *vsi;
  1625. bool alluni = false;
  1626. int aq_err = 0;
  1627. int bkt;
  1628. vsi = i40e_find_vsi_from_id(pf, info->vsi_id);
  1629. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  1630. !i40e_vc_isvalid_vsi_id(vf, info->vsi_id) ||
  1631. !vsi) {
  1632. aq_ret = I40E_ERR_PARAM;
  1633. goto error_param;
  1634. }
  1635. if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
  1636. dev_err(&pf->pdev->dev,
  1637. "Unprivileged VF %d is attempting to configure promiscuous mode\n",
  1638. vf->vf_id);
  1639. /* Lie to the VF on purpose. */
  1640. aq_ret = 0;
  1641. goto error_param;
  1642. }
  1643. /* Multicast promiscuous handling*/
  1644. if (info->flags & FLAG_VF_MULTICAST_PROMISC)
  1645. allmulti = true;
  1646. if (vf->port_vlan_id) {
  1647. aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw, vsi->seid,
  1648. allmulti,
  1649. vf->port_vlan_id,
  1650. NULL);
  1651. } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
  1652. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1653. if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
  1654. continue;
  1655. aq_ret = i40e_aq_set_vsi_mc_promisc_on_vlan(hw,
  1656. vsi->seid,
  1657. allmulti,
  1658. f->vlan,
  1659. NULL);
  1660. aq_err = pf->hw.aq.asq_last_status;
  1661. if (aq_ret) {
  1662. dev_err(&pf->pdev->dev,
  1663. "Could not add VLAN %d to multicast promiscuous domain err %s aq_err %s\n",
  1664. f->vlan,
  1665. i40e_stat_str(&pf->hw, aq_ret),
  1666. i40e_aq_str(&pf->hw, aq_err));
  1667. break;
  1668. }
  1669. }
  1670. } else {
  1671. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(hw, vsi->seid,
  1672. allmulti, NULL);
  1673. aq_err = pf->hw.aq.asq_last_status;
  1674. if (aq_ret) {
  1675. dev_err(&pf->pdev->dev,
  1676. "VF %d failed to set multicast promiscuous mode err %s aq_err %s\n",
  1677. vf->vf_id,
  1678. i40e_stat_str(&pf->hw, aq_ret),
  1679. i40e_aq_str(&pf->hw, aq_err));
  1680. goto error_param;
  1681. }
  1682. }
  1683. if (!aq_ret) {
  1684. dev_info(&pf->pdev->dev,
  1685. "VF %d successfully set multicast promiscuous mode\n",
  1686. vf->vf_id);
  1687. if (allmulti)
  1688. set_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
  1689. else
  1690. clear_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states);
  1691. }
  1692. if (info->flags & FLAG_VF_UNICAST_PROMISC)
  1693. alluni = true;
  1694. if (vf->port_vlan_id) {
  1695. aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw, vsi->seid,
  1696. alluni,
  1697. vf->port_vlan_id,
  1698. NULL);
  1699. } else if (i40e_getnum_vf_vsi_vlan_filters(vsi)) {
  1700. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1701. if (f->vlan < 0 || f->vlan > I40E_MAX_VLANID)
  1702. continue;
  1703. aq_ret = i40e_aq_set_vsi_uc_promisc_on_vlan(hw,
  1704. vsi->seid,
  1705. alluni,
  1706. f->vlan,
  1707. NULL);
  1708. aq_err = pf->hw.aq.asq_last_status;
  1709. if (aq_ret)
  1710. dev_err(&pf->pdev->dev,
  1711. "Could not add VLAN %d to Unicast promiscuous domain err %s aq_err %s\n",
  1712. f->vlan,
  1713. i40e_stat_str(&pf->hw, aq_ret),
  1714. i40e_aq_str(&pf->hw, aq_err));
  1715. }
  1716. } else {
  1717. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(hw, vsi->seid,
  1718. alluni, NULL,
  1719. true);
  1720. aq_err = pf->hw.aq.asq_last_status;
  1721. if (aq_ret) {
  1722. dev_err(&pf->pdev->dev,
  1723. "VF %d failed to set unicast promiscuous mode %8.8x err %s aq_err %s\n",
  1724. vf->vf_id, info->flags,
  1725. i40e_stat_str(&pf->hw, aq_ret),
  1726. i40e_aq_str(&pf->hw, aq_err));
  1727. goto error_param;
  1728. }
  1729. }
  1730. if (!aq_ret) {
  1731. dev_info(&pf->pdev->dev,
  1732. "VF %d successfully set unicast promiscuous mode\n",
  1733. vf->vf_id);
  1734. if (alluni)
  1735. set_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
  1736. else
  1737. clear_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states);
  1738. }
  1739. error_param:
  1740. /* send the response to the VF */
  1741. return i40e_vc_send_resp_to_vf(vf,
  1742. VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  1743. aq_ret);
  1744. }
  1745. /**
  1746. * i40e_vc_config_queues_msg
  1747. * @vf: pointer to the VF info
  1748. * @msg: pointer to the msg buffer
  1749. * @msglen: msg length
  1750. *
  1751. * called from the VF to configure the rx/tx
  1752. * queues
  1753. **/
  1754. static int i40e_vc_config_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1755. {
  1756. struct virtchnl_vsi_queue_config_info *qci =
  1757. (struct virtchnl_vsi_queue_config_info *)msg;
  1758. struct virtchnl_queue_pair_info *qpi;
  1759. struct i40e_pf *pf = vf->pf;
  1760. u16 vsi_id, vsi_queue_id = 0;
  1761. i40e_status aq_ret = 0;
  1762. int i, j = 0, idx = 0;
  1763. vsi_id = qci->vsi_id;
  1764. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  1765. aq_ret = I40E_ERR_PARAM;
  1766. goto error_param;
  1767. }
  1768. if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1769. aq_ret = I40E_ERR_PARAM;
  1770. goto error_param;
  1771. }
  1772. for (i = 0; i < qci->num_queue_pairs; i++) {
  1773. qpi = &qci->qpair[i];
  1774. if (!vf->adq_enabled) {
  1775. vsi_queue_id = qpi->txq.queue_id;
  1776. if (qpi->txq.vsi_id != qci->vsi_id ||
  1777. qpi->rxq.vsi_id != qci->vsi_id ||
  1778. qpi->rxq.queue_id != vsi_queue_id) {
  1779. aq_ret = I40E_ERR_PARAM;
  1780. goto error_param;
  1781. }
  1782. }
  1783. if (!i40e_vc_isvalid_queue_id(vf, vsi_id, vsi_queue_id)) {
  1784. aq_ret = I40E_ERR_PARAM;
  1785. goto error_param;
  1786. }
  1787. if (i40e_config_vsi_rx_queue(vf, vsi_id, vsi_queue_id,
  1788. &qpi->rxq) ||
  1789. i40e_config_vsi_tx_queue(vf, vsi_id, vsi_queue_id,
  1790. &qpi->txq)) {
  1791. aq_ret = I40E_ERR_PARAM;
  1792. goto error_param;
  1793. }
  1794. /* For ADq there can be up to 4 VSIs with max 4 queues each.
  1795. * VF does not know about these additional VSIs and all
  1796. * it cares is about its own queues. PF configures these queues
  1797. * to its appropriate VSIs based on TC mapping
  1798. **/
  1799. if (vf->adq_enabled) {
  1800. if (j == (vf->ch[idx].num_qps - 1)) {
  1801. idx++;
  1802. j = 0; /* resetting the queue count */
  1803. vsi_queue_id = 0;
  1804. } else {
  1805. j++;
  1806. vsi_queue_id++;
  1807. }
  1808. vsi_id = vf->ch[idx].vsi_id;
  1809. }
  1810. }
  1811. /* set vsi num_queue_pairs in use to num configured by VF */
  1812. if (!vf->adq_enabled) {
  1813. pf->vsi[vf->lan_vsi_idx]->num_queue_pairs =
  1814. qci->num_queue_pairs;
  1815. } else {
  1816. for (i = 0; i < vf->num_tc; i++)
  1817. pf->vsi[vf->ch[i].vsi_idx]->num_queue_pairs =
  1818. vf->ch[i].num_qps;
  1819. }
  1820. error_param:
  1821. /* send the response to the VF */
  1822. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  1823. aq_ret);
  1824. }
  1825. /**
  1826. * i40e_validate_queue_map
  1827. * @vsi_id: vsi id
  1828. * @queuemap: Tx or Rx queue map
  1829. *
  1830. * check if Tx or Rx queue map is valid
  1831. **/
  1832. static int i40e_validate_queue_map(struct i40e_vf *vf, u16 vsi_id,
  1833. unsigned long queuemap)
  1834. {
  1835. u16 vsi_queue_id, queue_id;
  1836. for_each_set_bit(vsi_queue_id, &queuemap, I40E_MAX_VSI_QP) {
  1837. if (vf->adq_enabled) {
  1838. vsi_id = vf->ch[vsi_queue_id / I40E_MAX_VF_VSI].vsi_id;
  1839. queue_id = (vsi_queue_id % I40E_DEFAULT_QUEUES_PER_VF);
  1840. } else {
  1841. queue_id = vsi_queue_id;
  1842. }
  1843. if (!i40e_vc_isvalid_queue_id(vf, vsi_id, queue_id))
  1844. return -EINVAL;
  1845. }
  1846. return 0;
  1847. }
  1848. /**
  1849. * i40e_vc_config_irq_map_msg
  1850. * @vf: pointer to the VF info
  1851. * @msg: pointer to the msg buffer
  1852. * @msglen: msg length
  1853. *
  1854. * called from the VF to configure the irq to
  1855. * queue map
  1856. **/
  1857. static int i40e_vc_config_irq_map_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1858. {
  1859. struct virtchnl_irq_map_info *irqmap_info =
  1860. (struct virtchnl_irq_map_info *)msg;
  1861. struct virtchnl_vector_map *map;
  1862. u16 vsi_id, vector_id;
  1863. i40e_status aq_ret = 0;
  1864. int i;
  1865. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  1866. aq_ret = I40E_ERR_PARAM;
  1867. goto error_param;
  1868. }
  1869. for (i = 0; i < irqmap_info->num_vectors; i++) {
  1870. map = &irqmap_info->vecmap[i];
  1871. vector_id = map->vector_id;
  1872. vsi_id = map->vsi_id;
  1873. /* validate msg params */
  1874. if (!i40e_vc_isvalid_vector_id(vf, vector_id) ||
  1875. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1876. aq_ret = I40E_ERR_PARAM;
  1877. goto error_param;
  1878. }
  1879. if (i40e_validate_queue_map(vf, vsi_id, map->rxq_map)) {
  1880. aq_ret = I40E_ERR_PARAM;
  1881. goto error_param;
  1882. }
  1883. if (i40e_validate_queue_map(vf, vsi_id, map->txq_map)) {
  1884. aq_ret = I40E_ERR_PARAM;
  1885. goto error_param;
  1886. }
  1887. i40e_config_irq_link_list(vf, vsi_id, map);
  1888. }
  1889. error_param:
  1890. /* send the response to the VF */
  1891. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP,
  1892. aq_ret);
  1893. }
  1894. /**
  1895. * i40e_vc_enable_queues_msg
  1896. * @vf: pointer to the VF info
  1897. * @msg: pointer to the msg buffer
  1898. * @msglen: msg length
  1899. *
  1900. * called from the VF to enable all or specific queue(s)
  1901. **/
  1902. static int i40e_vc_enable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1903. {
  1904. struct virtchnl_queue_select *vqs =
  1905. (struct virtchnl_queue_select *)msg;
  1906. struct i40e_pf *pf = vf->pf;
  1907. u16 vsi_id = vqs->vsi_id;
  1908. i40e_status aq_ret = 0;
  1909. int i;
  1910. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  1911. aq_ret = I40E_ERR_PARAM;
  1912. goto error_param;
  1913. }
  1914. if (!i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  1915. aq_ret = I40E_ERR_PARAM;
  1916. goto error_param;
  1917. }
  1918. if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
  1919. aq_ret = I40E_ERR_PARAM;
  1920. goto error_param;
  1921. }
  1922. if (i40e_vsi_start_rings(pf->vsi[vf->lan_vsi_idx]))
  1923. aq_ret = I40E_ERR_TIMEOUT;
  1924. /* need to start the rings for additional ADq VSI's as well */
  1925. if (vf->adq_enabled) {
  1926. /* zero belongs to LAN VSI */
  1927. for (i = 1; i < vf->num_tc; i++) {
  1928. if (i40e_vsi_start_rings(pf->vsi[vf->ch[i].vsi_idx]))
  1929. aq_ret = I40E_ERR_TIMEOUT;
  1930. }
  1931. }
  1932. error_param:
  1933. /* send the response to the VF */
  1934. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES,
  1935. aq_ret);
  1936. }
  1937. /**
  1938. * i40e_vc_disable_queues_msg
  1939. * @vf: pointer to the VF info
  1940. * @msg: pointer to the msg buffer
  1941. * @msglen: msg length
  1942. *
  1943. * called from the VF to disable all or specific
  1944. * queue(s)
  1945. **/
  1946. static int i40e_vc_disable_queues_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  1947. {
  1948. struct virtchnl_queue_select *vqs =
  1949. (struct virtchnl_queue_select *)msg;
  1950. struct i40e_pf *pf = vf->pf;
  1951. i40e_status aq_ret = 0;
  1952. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  1953. aq_ret = I40E_ERR_PARAM;
  1954. goto error_param;
  1955. }
  1956. if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1957. aq_ret = I40E_ERR_PARAM;
  1958. goto error_param;
  1959. }
  1960. if ((0 == vqs->rx_queues) && (0 == vqs->tx_queues)) {
  1961. aq_ret = I40E_ERR_PARAM;
  1962. goto error_param;
  1963. }
  1964. i40e_vsi_stop_rings(pf->vsi[vf->lan_vsi_idx]);
  1965. error_param:
  1966. /* send the response to the VF */
  1967. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES,
  1968. aq_ret);
  1969. }
  1970. /**
  1971. * i40e_vc_request_queues_msg
  1972. * @vf: pointer to the VF info
  1973. * @msg: pointer to the msg buffer
  1974. * @msglen: msg length
  1975. *
  1976. * VFs get a default number of queues but can use this message to request a
  1977. * different number. If the request is successful, PF will reset the VF and
  1978. * return 0. If unsuccessful, PF will send message informing VF of number of
  1979. * available queues and return result of sending VF a message.
  1980. **/
  1981. static int i40e_vc_request_queues_msg(struct i40e_vf *vf, u8 *msg, int msglen)
  1982. {
  1983. struct virtchnl_vf_res_request *vfres =
  1984. (struct virtchnl_vf_res_request *)msg;
  1985. int req_pairs = vfres->num_queue_pairs;
  1986. int cur_pairs = vf->num_queue_pairs;
  1987. struct i40e_pf *pf = vf->pf;
  1988. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states))
  1989. return -EINVAL;
  1990. if (req_pairs <= 0) {
  1991. dev_err(&pf->pdev->dev,
  1992. "VF %d tried to request %d queues. Ignoring.\n",
  1993. vf->vf_id, req_pairs);
  1994. } else if (req_pairs > I40E_MAX_VF_QUEUES) {
  1995. dev_err(&pf->pdev->dev,
  1996. "VF %d tried to request more than %d queues.\n",
  1997. vf->vf_id,
  1998. I40E_MAX_VF_QUEUES);
  1999. vfres->num_queue_pairs = I40E_MAX_VF_QUEUES;
  2000. } else if (req_pairs - cur_pairs > pf->queues_left) {
  2001. dev_warn(&pf->pdev->dev,
  2002. "VF %d requested %d more queues, but only %d left.\n",
  2003. vf->vf_id,
  2004. req_pairs - cur_pairs,
  2005. pf->queues_left);
  2006. vfres->num_queue_pairs = pf->queues_left + cur_pairs;
  2007. } else {
  2008. /* successful request */
  2009. vf->num_req_queues = req_pairs;
  2010. i40e_vc_notify_vf_reset(vf);
  2011. i40e_reset_vf(vf, false);
  2012. return 0;
  2013. }
  2014. return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES, 0,
  2015. (u8 *)vfres, sizeof(*vfres));
  2016. }
  2017. /**
  2018. * i40e_vc_get_stats_msg
  2019. * @vf: pointer to the VF info
  2020. * @msg: pointer to the msg buffer
  2021. * @msglen: msg length
  2022. *
  2023. * called from the VF to get vsi stats
  2024. **/
  2025. static int i40e_vc_get_stats_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2026. {
  2027. struct virtchnl_queue_select *vqs =
  2028. (struct virtchnl_queue_select *)msg;
  2029. struct i40e_pf *pf = vf->pf;
  2030. struct i40e_eth_stats stats;
  2031. i40e_status aq_ret = 0;
  2032. struct i40e_vsi *vsi;
  2033. memset(&stats, 0, sizeof(struct i40e_eth_stats));
  2034. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2035. aq_ret = I40E_ERR_PARAM;
  2036. goto error_param;
  2037. }
  2038. if (!i40e_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  2039. aq_ret = I40E_ERR_PARAM;
  2040. goto error_param;
  2041. }
  2042. vsi = pf->vsi[vf->lan_vsi_idx];
  2043. if (!vsi) {
  2044. aq_ret = I40E_ERR_PARAM;
  2045. goto error_param;
  2046. }
  2047. i40e_update_eth_stats(vsi);
  2048. stats = vsi->eth_stats;
  2049. error_param:
  2050. /* send the response back to the VF */
  2051. return i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, aq_ret,
  2052. (u8 *)&stats, sizeof(stats));
  2053. }
  2054. /* If the VF is not trusted restrict the number of MAC/VLAN it can program */
  2055. #define I40E_VC_MAX_MAC_ADDR_PER_VF 12
  2056. #define I40E_VC_MAX_VLAN_PER_VF 8
  2057. /**
  2058. * i40e_check_vf_permission
  2059. * @vf: pointer to the VF info
  2060. * @al: MAC address list from virtchnl
  2061. *
  2062. * Check that the given list of MAC addresses is allowed. Will return -EPERM
  2063. * if any address in the list is not valid. Checks the following conditions:
  2064. *
  2065. * 1) broadcast and zero addresses are never valid
  2066. * 2) unicast addresses are not allowed if the VMM has administratively set
  2067. * the VF MAC address, unless the VF is marked as privileged.
  2068. * 3) There is enough space to add all the addresses.
  2069. *
  2070. * Note that to guarantee consistency, it is expected this function be called
  2071. * while holding the mac_filter_hash_lock, as otherwise the current number of
  2072. * addresses might not be accurate.
  2073. **/
  2074. static inline int i40e_check_vf_permission(struct i40e_vf *vf,
  2075. struct virtchnl_ether_addr_list *al)
  2076. {
  2077. struct i40e_pf *pf = vf->pf;
  2078. int i;
  2079. /* If this VF is not privileged, then we can't add more than a limited
  2080. * number of addresses. Check to make sure that the additions do not
  2081. * push us over the limit.
  2082. */
  2083. if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
  2084. (vf->num_mac + al->num_elements) > I40E_VC_MAX_MAC_ADDR_PER_VF) {
  2085. dev_err(&pf->pdev->dev,
  2086. "Cannot add more MAC addresses, VF is not trusted, switch the VF to trusted to add more functionality\n");
  2087. return -EPERM;
  2088. }
  2089. for (i = 0; i < al->num_elements; i++) {
  2090. u8 *addr = al->list[i].addr;
  2091. if (is_broadcast_ether_addr(addr) ||
  2092. is_zero_ether_addr(addr)) {
  2093. dev_err(&pf->pdev->dev, "invalid VF MAC addr %pM\n",
  2094. addr);
  2095. return I40E_ERR_INVALID_MAC_ADDR;
  2096. }
  2097. /* If the host VMM administrator has set the VF MAC address
  2098. * administratively via the ndo_set_vf_mac command then deny
  2099. * permission to the VF to add or delete unicast MAC addresses.
  2100. * Unless the VF is privileged and then it can do whatever.
  2101. * The VF may request to set the MAC address filter already
  2102. * assigned to it so do not return an error in that case.
  2103. */
  2104. if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps) &&
  2105. !is_multicast_ether_addr(addr) && vf->pf_set_mac &&
  2106. !ether_addr_equal(addr, vf->default_lan_addr.addr)) {
  2107. dev_err(&pf->pdev->dev,
  2108. "VF attempting to override administratively set MAC address, reload the VF driver to resume normal operation\n");
  2109. return -EPERM;
  2110. }
  2111. }
  2112. return 0;
  2113. }
  2114. /**
  2115. * i40e_vc_add_mac_addr_msg
  2116. * @vf: pointer to the VF info
  2117. * @msg: pointer to the msg buffer
  2118. * @msglen: msg length
  2119. *
  2120. * add guest mac address filter
  2121. **/
  2122. static int i40e_vc_add_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2123. {
  2124. struct virtchnl_ether_addr_list *al =
  2125. (struct virtchnl_ether_addr_list *)msg;
  2126. struct i40e_pf *pf = vf->pf;
  2127. struct i40e_vsi *vsi = NULL;
  2128. u16 vsi_id = al->vsi_id;
  2129. i40e_status ret = 0;
  2130. int i;
  2131. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2132. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  2133. ret = I40E_ERR_PARAM;
  2134. goto error_param;
  2135. }
  2136. vsi = pf->vsi[vf->lan_vsi_idx];
  2137. /* Lock once, because all function inside for loop accesses VSI's
  2138. * MAC filter list which needs to be protected using same lock.
  2139. */
  2140. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2141. ret = i40e_check_vf_permission(vf, al);
  2142. if (ret) {
  2143. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2144. goto error_param;
  2145. }
  2146. /* add new addresses to the list */
  2147. for (i = 0; i < al->num_elements; i++) {
  2148. struct i40e_mac_filter *f;
  2149. f = i40e_find_mac(vsi, al->list[i].addr);
  2150. if (!f) {
  2151. f = i40e_add_mac_filter(vsi, al->list[i].addr);
  2152. if (!f) {
  2153. dev_err(&pf->pdev->dev,
  2154. "Unable to add MAC filter %pM for VF %d\n",
  2155. al->list[i].addr, vf->vf_id);
  2156. ret = I40E_ERR_PARAM;
  2157. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2158. goto error_param;
  2159. } else {
  2160. vf->num_mac++;
  2161. }
  2162. }
  2163. }
  2164. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2165. /* program the updated filter list */
  2166. ret = i40e_sync_vsi_filters(vsi);
  2167. if (ret)
  2168. dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
  2169. vf->vf_id, ret);
  2170. error_param:
  2171. /* send the response to the VF */
  2172. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
  2173. ret);
  2174. }
  2175. /**
  2176. * i40e_vc_del_mac_addr_msg
  2177. * @vf: pointer to the VF info
  2178. * @msg: pointer to the msg buffer
  2179. * @msglen: msg length
  2180. *
  2181. * remove guest mac address filter
  2182. **/
  2183. static int i40e_vc_del_mac_addr_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2184. {
  2185. struct virtchnl_ether_addr_list *al =
  2186. (struct virtchnl_ether_addr_list *)msg;
  2187. struct i40e_pf *pf = vf->pf;
  2188. struct i40e_vsi *vsi = NULL;
  2189. u16 vsi_id = al->vsi_id;
  2190. i40e_status ret = 0;
  2191. int i;
  2192. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2193. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  2194. ret = I40E_ERR_PARAM;
  2195. goto error_param;
  2196. }
  2197. for (i = 0; i < al->num_elements; i++) {
  2198. if (is_broadcast_ether_addr(al->list[i].addr) ||
  2199. is_zero_ether_addr(al->list[i].addr)) {
  2200. dev_err(&pf->pdev->dev, "Invalid MAC addr %pM for VF %d\n",
  2201. al->list[i].addr, vf->vf_id);
  2202. ret = I40E_ERR_INVALID_MAC_ADDR;
  2203. goto error_param;
  2204. }
  2205. }
  2206. vsi = pf->vsi[vf->lan_vsi_idx];
  2207. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2208. /* delete addresses from the list */
  2209. for (i = 0; i < al->num_elements; i++)
  2210. if (i40e_del_mac_filter(vsi, al->list[i].addr)) {
  2211. ret = I40E_ERR_INVALID_MAC_ADDR;
  2212. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2213. goto error_param;
  2214. } else {
  2215. vf->num_mac--;
  2216. }
  2217. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2218. /* program the updated filter list */
  2219. ret = i40e_sync_vsi_filters(vsi);
  2220. if (ret)
  2221. dev_err(&pf->pdev->dev, "Unable to program VF %d MAC filters, error %d\n",
  2222. vf->vf_id, ret);
  2223. error_param:
  2224. /* send the response to the VF */
  2225. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
  2226. ret);
  2227. }
  2228. /**
  2229. * i40e_vc_add_vlan_msg
  2230. * @vf: pointer to the VF info
  2231. * @msg: pointer to the msg buffer
  2232. * @msglen: msg length
  2233. *
  2234. * program guest vlan id
  2235. **/
  2236. static int i40e_vc_add_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2237. {
  2238. struct virtchnl_vlan_filter_list *vfl =
  2239. (struct virtchnl_vlan_filter_list *)msg;
  2240. struct i40e_pf *pf = vf->pf;
  2241. struct i40e_vsi *vsi = NULL;
  2242. u16 vsi_id = vfl->vsi_id;
  2243. i40e_status aq_ret = 0;
  2244. int i;
  2245. if ((vf->num_vlan >= I40E_VC_MAX_VLAN_PER_VF) &&
  2246. !test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
  2247. dev_err(&pf->pdev->dev,
  2248. "VF is not trusted, switch the VF to trusted to add more VLAN addresses\n");
  2249. goto error_param;
  2250. }
  2251. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2252. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  2253. aq_ret = I40E_ERR_PARAM;
  2254. goto error_param;
  2255. }
  2256. for (i = 0; i < vfl->num_elements; i++) {
  2257. if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
  2258. aq_ret = I40E_ERR_PARAM;
  2259. dev_err(&pf->pdev->dev,
  2260. "invalid VF VLAN id %d\n", vfl->vlan_id[i]);
  2261. goto error_param;
  2262. }
  2263. }
  2264. vsi = pf->vsi[vf->lan_vsi_idx];
  2265. if (vsi->info.pvid) {
  2266. aq_ret = I40E_ERR_PARAM;
  2267. goto error_param;
  2268. }
  2269. i40e_vlan_stripping_enable(vsi);
  2270. for (i = 0; i < vfl->num_elements; i++) {
  2271. /* add new VLAN filter */
  2272. int ret = i40e_vsi_add_vlan(vsi, vfl->vlan_id[i]);
  2273. if (!ret)
  2274. vf->num_vlan++;
  2275. if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
  2276. i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
  2277. true,
  2278. vfl->vlan_id[i],
  2279. NULL);
  2280. if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
  2281. i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
  2282. true,
  2283. vfl->vlan_id[i],
  2284. NULL);
  2285. if (ret)
  2286. dev_err(&pf->pdev->dev,
  2287. "Unable to add VLAN filter %d for VF %d, error %d\n",
  2288. vfl->vlan_id[i], vf->vf_id, ret);
  2289. }
  2290. error_param:
  2291. /* send the response to the VF */
  2292. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, aq_ret);
  2293. }
  2294. /**
  2295. * i40e_vc_remove_vlan_msg
  2296. * @vf: pointer to the VF info
  2297. * @msg: pointer to the msg buffer
  2298. * @msglen: msg length
  2299. *
  2300. * remove programmed guest vlan id
  2301. **/
  2302. static int i40e_vc_remove_vlan_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2303. {
  2304. struct virtchnl_vlan_filter_list *vfl =
  2305. (struct virtchnl_vlan_filter_list *)msg;
  2306. struct i40e_pf *pf = vf->pf;
  2307. struct i40e_vsi *vsi = NULL;
  2308. u16 vsi_id = vfl->vsi_id;
  2309. i40e_status aq_ret = 0;
  2310. int i;
  2311. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2312. !i40e_vc_isvalid_vsi_id(vf, vsi_id)) {
  2313. aq_ret = I40E_ERR_PARAM;
  2314. goto error_param;
  2315. }
  2316. for (i = 0; i < vfl->num_elements; i++) {
  2317. if (vfl->vlan_id[i] > I40E_MAX_VLANID) {
  2318. aq_ret = I40E_ERR_PARAM;
  2319. goto error_param;
  2320. }
  2321. }
  2322. vsi = pf->vsi[vf->lan_vsi_idx];
  2323. if (vsi->info.pvid) {
  2324. aq_ret = I40E_ERR_PARAM;
  2325. goto error_param;
  2326. }
  2327. for (i = 0; i < vfl->num_elements; i++) {
  2328. i40e_vsi_kill_vlan(vsi, vfl->vlan_id[i]);
  2329. vf->num_vlan--;
  2330. if (test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states))
  2331. i40e_aq_set_vsi_uc_promisc_on_vlan(&pf->hw, vsi->seid,
  2332. false,
  2333. vfl->vlan_id[i],
  2334. NULL);
  2335. if (test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))
  2336. i40e_aq_set_vsi_mc_promisc_on_vlan(&pf->hw, vsi->seid,
  2337. false,
  2338. vfl->vlan_id[i],
  2339. NULL);
  2340. }
  2341. error_param:
  2342. /* send the response to the VF */
  2343. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, aq_ret);
  2344. }
  2345. /**
  2346. * i40e_vc_iwarp_msg
  2347. * @vf: pointer to the VF info
  2348. * @msg: pointer to the msg buffer
  2349. * @msglen: msg length
  2350. *
  2351. * called from the VF for the iwarp msgs
  2352. **/
  2353. static int i40e_vc_iwarp_msg(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2354. {
  2355. struct i40e_pf *pf = vf->pf;
  2356. int abs_vf_id = vf->vf_id + pf->hw.func_caps.vf_base_id;
  2357. i40e_status aq_ret = 0;
  2358. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2359. !test_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states)) {
  2360. aq_ret = I40E_ERR_PARAM;
  2361. goto error_param;
  2362. }
  2363. i40e_notify_client_of_vf_msg(pf->vsi[pf->lan_vsi], abs_vf_id,
  2364. msg, msglen);
  2365. error_param:
  2366. /* send the response to the VF */
  2367. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_IWARP,
  2368. aq_ret);
  2369. }
  2370. /**
  2371. * i40e_vc_iwarp_qvmap_msg
  2372. * @vf: pointer to the VF info
  2373. * @msg: pointer to the msg buffer
  2374. * @msglen: msg length
  2375. * @config: config qvmap or release it
  2376. *
  2377. * called from the VF for the iwarp msgs
  2378. **/
  2379. static int i40e_vc_iwarp_qvmap_msg(struct i40e_vf *vf, u8 *msg, u16 msglen,
  2380. bool config)
  2381. {
  2382. struct virtchnl_iwarp_qvlist_info *qvlist_info =
  2383. (struct virtchnl_iwarp_qvlist_info *)msg;
  2384. i40e_status aq_ret = 0;
  2385. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2386. !test_bit(I40E_VF_STATE_IWARPENA, &vf->vf_states)) {
  2387. aq_ret = I40E_ERR_PARAM;
  2388. goto error_param;
  2389. }
  2390. if (config) {
  2391. if (i40e_config_iwarp_qvlist(vf, qvlist_info))
  2392. aq_ret = I40E_ERR_PARAM;
  2393. } else {
  2394. i40e_release_iwarp_qvlist(vf);
  2395. }
  2396. error_param:
  2397. /* send the response to the VF */
  2398. return i40e_vc_send_resp_to_vf(vf,
  2399. config ? VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP :
  2400. VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP,
  2401. aq_ret);
  2402. }
  2403. /**
  2404. * i40e_vc_config_rss_key
  2405. * @vf: pointer to the VF info
  2406. * @msg: pointer to the msg buffer
  2407. * @msglen: msg length
  2408. *
  2409. * Configure the VF's RSS key
  2410. **/
  2411. static int i40e_vc_config_rss_key(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2412. {
  2413. struct virtchnl_rss_key *vrk =
  2414. (struct virtchnl_rss_key *)msg;
  2415. struct i40e_pf *pf = vf->pf;
  2416. struct i40e_vsi *vsi = NULL;
  2417. u16 vsi_id = vrk->vsi_id;
  2418. i40e_status aq_ret = 0;
  2419. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2420. !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
  2421. (vrk->key_len != I40E_HKEY_ARRAY_SIZE)) {
  2422. aq_ret = I40E_ERR_PARAM;
  2423. goto err;
  2424. }
  2425. vsi = pf->vsi[vf->lan_vsi_idx];
  2426. aq_ret = i40e_config_rss(vsi, vrk->key, NULL, 0);
  2427. err:
  2428. /* send the response to the VF */
  2429. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY,
  2430. aq_ret);
  2431. }
  2432. /**
  2433. * i40e_vc_config_rss_lut
  2434. * @vf: pointer to the VF info
  2435. * @msg: pointer to the msg buffer
  2436. * @msglen: msg length
  2437. *
  2438. * Configure the VF's RSS LUT
  2439. **/
  2440. static int i40e_vc_config_rss_lut(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2441. {
  2442. struct virtchnl_rss_lut *vrl =
  2443. (struct virtchnl_rss_lut *)msg;
  2444. struct i40e_pf *pf = vf->pf;
  2445. struct i40e_vsi *vsi = NULL;
  2446. u16 vsi_id = vrl->vsi_id;
  2447. i40e_status aq_ret = 0;
  2448. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states) ||
  2449. !i40e_vc_isvalid_vsi_id(vf, vsi_id) ||
  2450. (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)) {
  2451. aq_ret = I40E_ERR_PARAM;
  2452. goto err;
  2453. }
  2454. vsi = pf->vsi[vf->lan_vsi_idx];
  2455. aq_ret = i40e_config_rss(vsi, NULL, vrl->lut, I40E_VF_HLUT_ARRAY_SIZE);
  2456. /* send the response to the VF */
  2457. err:
  2458. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT,
  2459. aq_ret);
  2460. }
  2461. /**
  2462. * i40e_vc_get_rss_hena
  2463. * @vf: pointer to the VF info
  2464. * @msg: pointer to the msg buffer
  2465. * @msglen: msg length
  2466. *
  2467. * Return the RSS HENA bits allowed by the hardware
  2468. **/
  2469. static int i40e_vc_get_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2470. {
  2471. struct virtchnl_rss_hena *vrh = NULL;
  2472. struct i40e_pf *pf = vf->pf;
  2473. i40e_status aq_ret = 0;
  2474. int len = 0;
  2475. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2476. aq_ret = I40E_ERR_PARAM;
  2477. goto err;
  2478. }
  2479. len = sizeof(struct virtchnl_rss_hena);
  2480. vrh = kzalloc(len, GFP_KERNEL);
  2481. if (!vrh) {
  2482. aq_ret = I40E_ERR_NO_MEMORY;
  2483. len = 0;
  2484. goto err;
  2485. }
  2486. vrh->hena = i40e_pf_get_default_rss_hena(pf);
  2487. err:
  2488. /* send the response back to the VF */
  2489. aq_ret = i40e_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS,
  2490. aq_ret, (u8 *)vrh, len);
  2491. kfree(vrh);
  2492. return aq_ret;
  2493. }
  2494. /**
  2495. * i40e_vc_set_rss_hena
  2496. * @vf: pointer to the VF info
  2497. * @msg: pointer to the msg buffer
  2498. * @msglen: msg length
  2499. *
  2500. * Set the RSS HENA bits for the VF
  2501. **/
  2502. static int i40e_vc_set_rss_hena(struct i40e_vf *vf, u8 *msg, u16 msglen)
  2503. {
  2504. struct virtchnl_rss_hena *vrh =
  2505. (struct virtchnl_rss_hena *)msg;
  2506. struct i40e_pf *pf = vf->pf;
  2507. struct i40e_hw *hw = &pf->hw;
  2508. i40e_status aq_ret = 0;
  2509. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2510. aq_ret = I40E_ERR_PARAM;
  2511. goto err;
  2512. }
  2513. i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(0, vf->vf_id), (u32)vrh->hena);
  2514. i40e_write_rx_ctl(hw, I40E_VFQF_HENA1(1, vf->vf_id),
  2515. (u32)(vrh->hena >> 32));
  2516. /* send the response to the VF */
  2517. err:
  2518. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA, aq_ret);
  2519. }
  2520. /**
  2521. * i40e_vc_enable_vlan_stripping
  2522. * @vf: pointer to the VF info
  2523. * @msg: pointer to the msg buffer
  2524. * @msglen: msg length
  2525. *
  2526. * Enable vlan header stripping for the VF
  2527. **/
  2528. static int i40e_vc_enable_vlan_stripping(struct i40e_vf *vf, u8 *msg,
  2529. u16 msglen)
  2530. {
  2531. struct i40e_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
  2532. i40e_status aq_ret = 0;
  2533. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2534. aq_ret = I40E_ERR_PARAM;
  2535. goto err;
  2536. }
  2537. i40e_vlan_stripping_enable(vsi);
  2538. /* send the response to the VF */
  2539. err:
  2540. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
  2541. aq_ret);
  2542. }
  2543. /**
  2544. * i40e_vc_disable_vlan_stripping
  2545. * @vf: pointer to the VF info
  2546. * @msg: pointer to the msg buffer
  2547. * @msglen: msg length
  2548. *
  2549. * Disable vlan header stripping for the VF
  2550. **/
  2551. static int i40e_vc_disable_vlan_stripping(struct i40e_vf *vf, u8 *msg,
  2552. u16 msglen)
  2553. {
  2554. struct i40e_vsi *vsi = vf->pf->vsi[vf->lan_vsi_idx];
  2555. i40e_status aq_ret = 0;
  2556. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2557. aq_ret = I40E_ERR_PARAM;
  2558. goto err;
  2559. }
  2560. i40e_vlan_stripping_disable(vsi);
  2561. /* send the response to the VF */
  2562. err:
  2563. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
  2564. aq_ret);
  2565. }
  2566. /**
  2567. * i40e_validate_cloud_filter
  2568. * @mask: mask for TC filter
  2569. * @data: data for TC filter
  2570. *
  2571. * This function validates cloud filter programmed as TC filter for ADq
  2572. **/
  2573. static int i40e_validate_cloud_filter(struct i40e_vf *vf,
  2574. struct virtchnl_filter *tc_filter)
  2575. {
  2576. struct virtchnl_l4_spec mask = tc_filter->mask.tcp_spec;
  2577. struct virtchnl_l4_spec data = tc_filter->data.tcp_spec;
  2578. struct i40e_pf *pf = vf->pf;
  2579. struct i40e_vsi *vsi = NULL;
  2580. struct i40e_mac_filter *f;
  2581. struct hlist_node *h;
  2582. bool found = false;
  2583. int bkt;
  2584. if (!tc_filter->action) {
  2585. dev_info(&pf->pdev->dev,
  2586. "VF %d: Currently ADq doesn't support Drop Action\n",
  2587. vf->vf_id);
  2588. goto err;
  2589. }
  2590. /* action_meta is TC number here to which the filter is applied */
  2591. if (!tc_filter->action_meta ||
  2592. tc_filter->action_meta > I40E_MAX_VF_VSI) {
  2593. dev_info(&pf->pdev->dev, "VF %d: Invalid TC number %u\n",
  2594. vf->vf_id, tc_filter->action_meta);
  2595. goto err;
  2596. }
  2597. /* Check filter if it's programmed for advanced mode or basic mode.
  2598. * There are two ADq modes (for VF only),
  2599. * 1. Basic mode: intended to allow as many filter options as possible
  2600. * to be added to a VF in Non-trusted mode. Main goal is
  2601. * to add filters to its own MAC and VLAN id.
  2602. * 2. Advanced mode: is for allowing filters to be applied other than
  2603. * its own MAC or VLAN. This mode requires the VF to be
  2604. * Trusted.
  2605. */
  2606. if (mask.dst_mac[0] && !mask.dst_ip[0]) {
  2607. vsi = pf->vsi[vf->lan_vsi_idx];
  2608. f = i40e_find_mac(vsi, data.dst_mac);
  2609. if (!f) {
  2610. dev_info(&pf->pdev->dev,
  2611. "Destination MAC %pM doesn't belong to VF %d\n",
  2612. data.dst_mac, vf->vf_id);
  2613. goto err;
  2614. }
  2615. if (mask.vlan_id) {
  2616. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f,
  2617. hlist) {
  2618. if (f->vlan == ntohs(data.vlan_id)) {
  2619. found = true;
  2620. break;
  2621. }
  2622. }
  2623. if (!found) {
  2624. dev_info(&pf->pdev->dev,
  2625. "VF %d doesn't have any VLAN id %u\n",
  2626. vf->vf_id, ntohs(data.vlan_id));
  2627. goto err;
  2628. }
  2629. }
  2630. } else {
  2631. /* Check if VF is trusted */
  2632. if (!test_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps)) {
  2633. dev_err(&pf->pdev->dev,
  2634. "VF %d not trusted, make VF trusted to add advanced mode ADq cloud filters\n",
  2635. vf->vf_id);
  2636. return I40E_ERR_CONFIG;
  2637. }
  2638. }
  2639. if (mask.dst_mac[0] & data.dst_mac[0]) {
  2640. if (is_broadcast_ether_addr(data.dst_mac) ||
  2641. is_zero_ether_addr(data.dst_mac)) {
  2642. dev_info(&pf->pdev->dev, "VF %d: Invalid Dest MAC addr %pM\n",
  2643. vf->vf_id, data.dst_mac);
  2644. goto err;
  2645. }
  2646. }
  2647. if (mask.src_mac[0] & data.src_mac[0]) {
  2648. if (is_broadcast_ether_addr(data.src_mac) ||
  2649. is_zero_ether_addr(data.src_mac)) {
  2650. dev_info(&pf->pdev->dev, "VF %d: Invalid Source MAC addr %pM\n",
  2651. vf->vf_id, data.src_mac);
  2652. goto err;
  2653. }
  2654. }
  2655. if (mask.dst_port & data.dst_port) {
  2656. if (!data.dst_port || be16_to_cpu(data.dst_port) > 0xFFFF) {
  2657. dev_info(&pf->pdev->dev, "VF %d: Invalid Dest port\n",
  2658. vf->vf_id);
  2659. goto err;
  2660. }
  2661. }
  2662. if (mask.src_port & data.src_port) {
  2663. if (!data.src_port || be16_to_cpu(data.src_port) > 0xFFFF) {
  2664. dev_info(&pf->pdev->dev, "VF %d: Invalid Source port\n",
  2665. vf->vf_id);
  2666. goto err;
  2667. }
  2668. }
  2669. if (tc_filter->flow_type != VIRTCHNL_TCP_V6_FLOW &&
  2670. tc_filter->flow_type != VIRTCHNL_TCP_V4_FLOW) {
  2671. dev_info(&pf->pdev->dev, "VF %d: Invalid Flow type\n",
  2672. vf->vf_id);
  2673. goto err;
  2674. }
  2675. if (mask.vlan_id & data.vlan_id) {
  2676. if (ntohs(data.vlan_id) > I40E_MAX_VLANID) {
  2677. dev_info(&pf->pdev->dev, "VF %d: invalid VLAN ID\n",
  2678. vf->vf_id);
  2679. goto err;
  2680. }
  2681. }
  2682. return I40E_SUCCESS;
  2683. err:
  2684. return I40E_ERR_CONFIG;
  2685. }
  2686. /**
  2687. * i40e_find_vsi_from_seid - searches for the vsi with the given seid
  2688. * @vf: pointer to the VF info
  2689. * @seid - seid of the vsi it is searching for
  2690. **/
  2691. static struct i40e_vsi *i40e_find_vsi_from_seid(struct i40e_vf *vf, u16 seid)
  2692. {
  2693. struct i40e_pf *pf = vf->pf;
  2694. struct i40e_vsi *vsi = NULL;
  2695. int i;
  2696. for (i = 0; i < vf->num_tc ; i++) {
  2697. vsi = i40e_find_vsi_from_id(pf, vf->ch[i].vsi_id);
  2698. if (vsi && vsi->seid == seid)
  2699. return vsi;
  2700. }
  2701. return NULL;
  2702. }
  2703. /**
  2704. * i40e_del_all_cloud_filters
  2705. * @vf: pointer to the VF info
  2706. *
  2707. * This function deletes all cloud filters
  2708. **/
  2709. static void i40e_del_all_cloud_filters(struct i40e_vf *vf)
  2710. {
  2711. struct i40e_cloud_filter *cfilter = NULL;
  2712. struct i40e_pf *pf = vf->pf;
  2713. struct i40e_vsi *vsi = NULL;
  2714. struct hlist_node *node;
  2715. int ret;
  2716. hlist_for_each_entry_safe(cfilter, node,
  2717. &vf->cloud_filter_list, cloud_node) {
  2718. vsi = i40e_find_vsi_from_seid(vf, cfilter->seid);
  2719. if (!vsi) {
  2720. dev_err(&pf->pdev->dev, "VF %d: no VSI found for matching %u seid, can't delete cloud filter\n",
  2721. vf->vf_id, cfilter->seid);
  2722. continue;
  2723. }
  2724. if (cfilter->dst_port)
  2725. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter,
  2726. false);
  2727. else
  2728. ret = i40e_add_del_cloud_filter(vsi, cfilter, false);
  2729. if (ret)
  2730. dev_err(&pf->pdev->dev,
  2731. "VF %d: Failed to delete cloud filter, err %s aq_err %s\n",
  2732. vf->vf_id, i40e_stat_str(&pf->hw, ret),
  2733. i40e_aq_str(&pf->hw,
  2734. pf->hw.aq.asq_last_status));
  2735. hlist_del(&cfilter->cloud_node);
  2736. kfree(cfilter);
  2737. vf->num_cloud_filters--;
  2738. }
  2739. }
  2740. /**
  2741. * i40e_vc_del_cloud_filter
  2742. * @vf: pointer to the VF info
  2743. * @msg: pointer to the msg buffer
  2744. *
  2745. * This function deletes a cloud filter programmed as TC filter for ADq
  2746. **/
  2747. static int i40e_vc_del_cloud_filter(struct i40e_vf *vf, u8 *msg)
  2748. {
  2749. struct virtchnl_filter *vcf = (struct virtchnl_filter *)msg;
  2750. struct virtchnl_l4_spec mask = vcf->mask.tcp_spec;
  2751. struct virtchnl_l4_spec tcf = vcf->data.tcp_spec;
  2752. struct i40e_cloud_filter cfilter, *cf = NULL;
  2753. struct i40e_pf *pf = vf->pf;
  2754. struct i40e_vsi *vsi = NULL;
  2755. struct hlist_node *node;
  2756. i40e_status aq_ret = 0;
  2757. int i, ret;
  2758. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2759. aq_ret = I40E_ERR_PARAM;
  2760. goto err;
  2761. }
  2762. if (!vf->adq_enabled) {
  2763. dev_info(&pf->pdev->dev,
  2764. "VF %d: ADq not enabled, can't apply cloud filter\n",
  2765. vf->vf_id);
  2766. aq_ret = I40E_ERR_PARAM;
  2767. goto err;
  2768. }
  2769. if (i40e_validate_cloud_filter(vf, vcf)) {
  2770. dev_info(&pf->pdev->dev,
  2771. "VF %d: Invalid input, can't apply cloud filter\n",
  2772. vf->vf_id);
  2773. aq_ret = I40E_ERR_PARAM;
  2774. goto err;
  2775. }
  2776. memset(&cfilter, 0, sizeof(cfilter));
  2777. /* parse destination mac address */
  2778. for (i = 0; i < ETH_ALEN; i++)
  2779. cfilter.dst_mac[i] = mask.dst_mac[i] & tcf.dst_mac[i];
  2780. /* parse source mac address */
  2781. for (i = 0; i < ETH_ALEN; i++)
  2782. cfilter.src_mac[i] = mask.src_mac[i] & tcf.src_mac[i];
  2783. cfilter.vlan_id = mask.vlan_id & tcf.vlan_id;
  2784. cfilter.dst_port = mask.dst_port & tcf.dst_port;
  2785. cfilter.src_port = mask.src_port & tcf.src_port;
  2786. switch (vcf->flow_type) {
  2787. case VIRTCHNL_TCP_V4_FLOW:
  2788. cfilter.n_proto = ETH_P_IP;
  2789. if (mask.dst_ip[0] & tcf.dst_ip[0])
  2790. memcpy(&cfilter.ip.v4.dst_ip, tcf.dst_ip,
  2791. ARRAY_SIZE(tcf.dst_ip));
  2792. else if (mask.src_ip[0] & tcf.dst_ip[0])
  2793. memcpy(&cfilter.ip.v4.src_ip, tcf.src_ip,
  2794. ARRAY_SIZE(tcf.dst_ip));
  2795. break;
  2796. case VIRTCHNL_TCP_V6_FLOW:
  2797. cfilter.n_proto = ETH_P_IPV6;
  2798. if (mask.dst_ip[3] & tcf.dst_ip[3])
  2799. memcpy(&cfilter.ip.v6.dst_ip6, tcf.dst_ip,
  2800. sizeof(cfilter.ip.v6.dst_ip6));
  2801. if (mask.src_ip[3] & tcf.src_ip[3])
  2802. memcpy(&cfilter.ip.v6.src_ip6, tcf.src_ip,
  2803. sizeof(cfilter.ip.v6.src_ip6));
  2804. break;
  2805. default:
  2806. /* TC filter can be configured based on different combinations
  2807. * and in this case IP is not a part of filter config
  2808. */
  2809. dev_info(&pf->pdev->dev, "VF %d: Flow type not configured\n",
  2810. vf->vf_id);
  2811. }
  2812. /* get the vsi to which the tc belongs to */
  2813. vsi = pf->vsi[vf->ch[vcf->action_meta].vsi_idx];
  2814. cfilter.seid = vsi->seid;
  2815. cfilter.flags = vcf->field_flags;
  2816. /* Deleting TC filter */
  2817. if (tcf.dst_port)
  2818. ret = i40e_add_del_cloud_filter_big_buf(vsi, &cfilter, false);
  2819. else
  2820. ret = i40e_add_del_cloud_filter(vsi, &cfilter, false);
  2821. if (ret) {
  2822. dev_err(&pf->pdev->dev,
  2823. "VF %d: Failed to delete cloud filter, err %s aq_err %s\n",
  2824. vf->vf_id, i40e_stat_str(&pf->hw, ret),
  2825. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  2826. goto err;
  2827. }
  2828. hlist_for_each_entry_safe(cf, node,
  2829. &vf->cloud_filter_list, cloud_node) {
  2830. if (cf->seid != cfilter.seid)
  2831. continue;
  2832. if (mask.dst_port)
  2833. if (cfilter.dst_port != cf->dst_port)
  2834. continue;
  2835. if (mask.dst_mac[0])
  2836. if (!ether_addr_equal(cf->src_mac, cfilter.src_mac))
  2837. continue;
  2838. /* for ipv4 data to be valid, only first byte of mask is set */
  2839. if (cfilter.n_proto == ETH_P_IP && mask.dst_ip[0])
  2840. if (memcmp(&cfilter.ip.v4.dst_ip, &cf->ip.v4.dst_ip,
  2841. ARRAY_SIZE(tcf.dst_ip)))
  2842. continue;
  2843. /* for ipv6, mask is set for all sixteen bytes (4 words) */
  2844. if (cfilter.n_proto == ETH_P_IPV6 && mask.dst_ip[3])
  2845. if (memcmp(&cfilter.ip.v6.dst_ip6, &cf->ip.v6.dst_ip6,
  2846. sizeof(cfilter.ip.v6.src_ip6)))
  2847. continue;
  2848. if (mask.vlan_id)
  2849. if (cfilter.vlan_id != cf->vlan_id)
  2850. continue;
  2851. hlist_del(&cf->cloud_node);
  2852. kfree(cf);
  2853. vf->num_cloud_filters--;
  2854. }
  2855. err:
  2856. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DEL_CLOUD_FILTER,
  2857. aq_ret);
  2858. }
  2859. /**
  2860. * i40e_vc_add_cloud_filter
  2861. * @vf: pointer to the VF info
  2862. * @msg: pointer to the msg buffer
  2863. *
  2864. * This function adds a cloud filter programmed as TC filter for ADq
  2865. **/
  2866. static int i40e_vc_add_cloud_filter(struct i40e_vf *vf, u8 *msg)
  2867. {
  2868. struct virtchnl_filter *vcf = (struct virtchnl_filter *)msg;
  2869. struct virtchnl_l4_spec mask = vcf->mask.tcp_spec;
  2870. struct virtchnl_l4_spec tcf = vcf->data.tcp_spec;
  2871. struct i40e_cloud_filter *cfilter = NULL;
  2872. struct i40e_pf *pf = vf->pf;
  2873. struct i40e_vsi *vsi = NULL;
  2874. i40e_status aq_ret = 0;
  2875. int i, ret;
  2876. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2877. aq_ret = I40E_ERR_PARAM;
  2878. goto err;
  2879. }
  2880. if (!vf->adq_enabled) {
  2881. dev_info(&pf->pdev->dev,
  2882. "VF %d: ADq is not enabled, can't apply cloud filter\n",
  2883. vf->vf_id);
  2884. aq_ret = I40E_ERR_PARAM;
  2885. goto err;
  2886. }
  2887. if (i40e_validate_cloud_filter(vf, vcf)) {
  2888. dev_info(&pf->pdev->dev,
  2889. "VF %d: Invalid input/s, can't apply cloud filter\n",
  2890. vf->vf_id);
  2891. aq_ret = I40E_ERR_PARAM;
  2892. goto err;
  2893. }
  2894. cfilter = kzalloc(sizeof(*cfilter), GFP_KERNEL);
  2895. if (!cfilter)
  2896. return -ENOMEM;
  2897. /* parse destination mac address */
  2898. for (i = 0; i < ETH_ALEN; i++)
  2899. cfilter->dst_mac[i] = mask.dst_mac[i] & tcf.dst_mac[i];
  2900. /* parse source mac address */
  2901. for (i = 0; i < ETH_ALEN; i++)
  2902. cfilter->src_mac[i] = mask.src_mac[i] & tcf.src_mac[i];
  2903. cfilter->vlan_id = mask.vlan_id & tcf.vlan_id;
  2904. cfilter->dst_port = mask.dst_port & tcf.dst_port;
  2905. cfilter->src_port = mask.src_port & tcf.src_port;
  2906. switch (vcf->flow_type) {
  2907. case VIRTCHNL_TCP_V4_FLOW:
  2908. cfilter->n_proto = ETH_P_IP;
  2909. if (mask.dst_ip[0] & tcf.dst_ip[0])
  2910. memcpy(&cfilter->ip.v4.dst_ip, tcf.dst_ip,
  2911. ARRAY_SIZE(tcf.dst_ip));
  2912. else if (mask.src_ip[0] & tcf.dst_ip[0])
  2913. memcpy(&cfilter->ip.v4.src_ip, tcf.src_ip,
  2914. ARRAY_SIZE(tcf.dst_ip));
  2915. break;
  2916. case VIRTCHNL_TCP_V6_FLOW:
  2917. cfilter->n_proto = ETH_P_IPV6;
  2918. if (mask.dst_ip[3] & tcf.dst_ip[3])
  2919. memcpy(&cfilter->ip.v6.dst_ip6, tcf.dst_ip,
  2920. sizeof(cfilter->ip.v6.dst_ip6));
  2921. if (mask.src_ip[3] & tcf.src_ip[3])
  2922. memcpy(&cfilter->ip.v6.src_ip6, tcf.src_ip,
  2923. sizeof(cfilter->ip.v6.src_ip6));
  2924. break;
  2925. default:
  2926. /* TC filter can be configured based on different combinations
  2927. * and in this case IP is not a part of filter config
  2928. */
  2929. dev_info(&pf->pdev->dev, "VF %d: Flow type not configured\n",
  2930. vf->vf_id);
  2931. }
  2932. /* get the VSI to which the TC belongs to */
  2933. vsi = pf->vsi[vf->ch[vcf->action_meta].vsi_idx];
  2934. cfilter->seid = vsi->seid;
  2935. cfilter->flags = vcf->field_flags;
  2936. /* Adding cloud filter programmed as TC filter */
  2937. if (tcf.dst_port)
  2938. ret = i40e_add_del_cloud_filter_big_buf(vsi, cfilter, true);
  2939. else
  2940. ret = i40e_add_del_cloud_filter(vsi, cfilter, true);
  2941. if (ret) {
  2942. dev_err(&pf->pdev->dev,
  2943. "VF %d: Failed to add cloud filter, err %s aq_err %s\n",
  2944. vf->vf_id, i40e_stat_str(&pf->hw, ret),
  2945. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  2946. goto err;
  2947. }
  2948. INIT_HLIST_NODE(&cfilter->cloud_node);
  2949. hlist_add_head(&cfilter->cloud_node, &vf->cloud_filter_list);
  2950. vf->num_cloud_filters++;
  2951. err:
  2952. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ADD_CLOUD_FILTER,
  2953. aq_ret);
  2954. }
  2955. /**
  2956. * i40e_vc_add_qch_msg: Add queue channel and enable ADq
  2957. * @vf: pointer to the VF info
  2958. * @msg: pointer to the msg buffer
  2959. **/
  2960. static int i40e_vc_add_qch_msg(struct i40e_vf *vf, u8 *msg)
  2961. {
  2962. struct virtchnl_tc_info *tci =
  2963. (struct virtchnl_tc_info *)msg;
  2964. struct i40e_pf *pf = vf->pf;
  2965. struct i40e_link_status *ls = &pf->hw.phy.link_info;
  2966. int i, adq_request_qps = 0, speed = 0;
  2967. i40e_status aq_ret = 0;
  2968. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  2969. aq_ret = I40E_ERR_PARAM;
  2970. goto err;
  2971. }
  2972. /* ADq cannot be applied if spoof check is ON */
  2973. if (vf->spoofchk) {
  2974. dev_err(&pf->pdev->dev,
  2975. "Spoof check is ON, turn it OFF to enable ADq\n");
  2976. aq_ret = I40E_ERR_PARAM;
  2977. goto err;
  2978. }
  2979. if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADQ)) {
  2980. dev_err(&pf->pdev->dev,
  2981. "VF %d attempting to enable ADq, but hasn't properly negotiated that capability\n",
  2982. vf->vf_id);
  2983. aq_ret = I40E_ERR_PARAM;
  2984. goto err;
  2985. }
  2986. /* max number of traffic classes for VF currently capped at 4 */
  2987. if (!tci->num_tc || tci->num_tc > I40E_MAX_VF_VSI) {
  2988. dev_err(&pf->pdev->dev,
  2989. "VF %d trying to set %u TCs, valid range 1-4 TCs per VF\n",
  2990. vf->vf_id, tci->num_tc);
  2991. aq_ret = I40E_ERR_PARAM;
  2992. goto err;
  2993. }
  2994. /* validate queues for each TC */
  2995. for (i = 0; i < tci->num_tc; i++)
  2996. if (!tci->list[i].count ||
  2997. tci->list[i].count > I40E_DEFAULT_QUEUES_PER_VF) {
  2998. dev_err(&pf->pdev->dev,
  2999. "VF %d: TC %d trying to set %u queues, valid range 1-4 queues per TC\n",
  3000. vf->vf_id, i, tci->list[i].count);
  3001. aq_ret = I40E_ERR_PARAM;
  3002. goto err;
  3003. }
  3004. /* need Max VF queues but already have default number of queues */
  3005. adq_request_qps = I40E_MAX_VF_QUEUES - I40E_DEFAULT_QUEUES_PER_VF;
  3006. if (pf->queues_left < adq_request_qps) {
  3007. dev_err(&pf->pdev->dev,
  3008. "No queues left to allocate to VF %d\n",
  3009. vf->vf_id);
  3010. aq_ret = I40E_ERR_PARAM;
  3011. goto err;
  3012. } else {
  3013. /* we need to allocate max VF queues to enable ADq so as to
  3014. * make sure ADq enabled VF always gets back queues when it
  3015. * goes through a reset.
  3016. */
  3017. vf->num_queue_pairs = I40E_MAX_VF_QUEUES;
  3018. }
  3019. /* get link speed in MB to validate rate limit */
  3020. switch (ls->link_speed) {
  3021. case VIRTCHNL_LINK_SPEED_100MB:
  3022. speed = SPEED_100;
  3023. break;
  3024. case VIRTCHNL_LINK_SPEED_1GB:
  3025. speed = SPEED_1000;
  3026. break;
  3027. case VIRTCHNL_LINK_SPEED_10GB:
  3028. speed = SPEED_10000;
  3029. break;
  3030. case VIRTCHNL_LINK_SPEED_20GB:
  3031. speed = SPEED_20000;
  3032. break;
  3033. case VIRTCHNL_LINK_SPEED_25GB:
  3034. speed = SPEED_25000;
  3035. break;
  3036. case VIRTCHNL_LINK_SPEED_40GB:
  3037. speed = SPEED_40000;
  3038. break;
  3039. default:
  3040. dev_err(&pf->pdev->dev,
  3041. "Cannot detect link speed\n");
  3042. aq_ret = I40E_ERR_PARAM;
  3043. goto err;
  3044. }
  3045. /* parse data from the queue channel info */
  3046. vf->num_tc = tci->num_tc;
  3047. for (i = 0; i < vf->num_tc; i++) {
  3048. if (tci->list[i].max_tx_rate) {
  3049. if (tci->list[i].max_tx_rate > speed) {
  3050. dev_err(&pf->pdev->dev,
  3051. "Invalid max tx rate %llu specified for VF %d.",
  3052. tci->list[i].max_tx_rate,
  3053. vf->vf_id);
  3054. aq_ret = I40E_ERR_PARAM;
  3055. goto err;
  3056. } else {
  3057. vf->ch[i].max_tx_rate =
  3058. tci->list[i].max_tx_rate;
  3059. }
  3060. }
  3061. vf->ch[i].num_qps = tci->list[i].count;
  3062. }
  3063. /* set this flag only after making sure all inputs are sane */
  3064. vf->adq_enabled = true;
  3065. /* num_req_queues is set when user changes number of queues via ethtool
  3066. * and this causes issue for default VSI(which depends on this variable)
  3067. * when ADq is enabled, hence reset it.
  3068. */
  3069. vf->num_req_queues = 0;
  3070. /* reset the VF in order to allocate resources */
  3071. i40e_vc_notify_vf_reset(vf);
  3072. i40e_reset_vf(vf, false);
  3073. return I40E_SUCCESS;
  3074. /* send the response to the VF */
  3075. err:
  3076. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_ENABLE_CHANNELS,
  3077. aq_ret);
  3078. }
  3079. /**
  3080. * i40e_vc_del_qch_msg
  3081. * @vf: pointer to the VF info
  3082. * @msg: pointer to the msg buffer
  3083. **/
  3084. static int i40e_vc_del_qch_msg(struct i40e_vf *vf, u8 *msg)
  3085. {
  3086. struct i40e_pf *pf = vf->pf;
  3087. i40e_status aq_ret = 0;
  3088. if (!test_bit(I40E_VF_STATE_ACTIVE, &vf->vf_states)) {
  3089. aq_ret = I40E_ERR_PARAM;
  3090. goto err;
  3091. }
  3092. if (vf->adq_enabled) {
  3093. i40e_del_all_cloud_filters(vf);
  3094. i40e_del_qch(vf);
  3095. vf->adq_enabled = false;
  3096. vf->num_tc = 0;
  3097. dev_info(&pf->pdev->dev,
  3098. "Deleting Queue Channels and cloud filters for ADq on VF %d\n",
  3099. vf->vf_id);
  3100. } else {
  3101. dev_info(&pf->pdev->dev, "VF %d trying to delete queue channels but ADq isn't enabled\n",
  3102. vf->vf_id);
  3103. aq_ret = I40E_ERR_PARAM;
  3104. }
  3105. /* reset the VF in order to allocate resources */
  3106. i40e_vc_notify_vf_reset(vf);
  3107. i40e_reset_vf(vf, false);
  3108. return I40E_SUCCESS;
  3109. err:
  3110. return i40e_vc_send_resp_to_vf(vf, VIRTCHNL_OP_DISABLE_CHANNELS,
  3111. aq_ret);
  3112. }
  3113. /**
  3114. * i40e_vc_process_vf_msg
  3115. * @pf: pointer to the PF structure
  3116. * @vf_id: source VF id
  3117. * @v_opcode: operation code
  3118. * @v_retval: unused return value code
  3119. * @msg: pointer to the msg buffer
  3120. * @msglen: msg length
  3121. *
  3122. * called from the common aeq/arq handler to
  3123. * process request from VF
  3124. **/
  3125. int i40e_vc_process_vf_msg(struct i40e_pf *pf, s16 vf_id, u32 v_opcode,
  3126. u32 __always_unused v_retval, u8 *msg, u16 msglen)
  3127. {
  3128. struct i40e_hw *hw = &pf->hw;
  3129. int local_vf_id = vf_id - (s16)hw->func_caps.vf_base_id;
  3130. struct i40e_vf *vf;
  3131. int ret;
  3132. pf->vf_aq_requests++;
  3133. if (local_vf_id >= pf->num_alloc_vfs)
  3134. return -EINVAL;
  3135. vf = &(pf->vf[local_vf_id]);
  3136. /* Check if VF is disabled. */
  3137. if (test_bit(I40E_VF_STATE_DISABLED, &vf->vf_states))
  3138. return I40E_ERR_PARAM;
  3139. /* perform basic checks on the msg */
  3140. ret = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
  3141. /* perform additional checks specific to this driver */
  3142. if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_KEY) {
  3143. struct virtchnl_rss_key *vrk = (struct virtchnl_rss_key *)msg;
  3144. if (vrk->key_len != I40E_HKEY_ARRAY_SIZE)
  3145. ret = -EINVAL;
  3146. } else if (v_opcode == VIRTCHNL_OP_CONFIG_RSS_LUT) {
  3147. struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
  3148. if (vrl->lut_entries != I40E_VF_HLUT_ARRAY_SIZE)
  3149. ret = -EINVAL;
  3150. }
  3151. if (ret) {
  3152. i40e_vc_send_resp_to_vf(vf, v_opcode, I40E_ERR_PARAM);
  3153. dev_err(&pf->pdev->dev, "Invalid message from VF %d, opcode %d, len %d\n",
  3154. local_vf_id, v_opcode, msglen);
  3155. switch (ret) {
  3156. case VIRTCHNL_ERR_PARAM:
  3157. return -EPERM;
  3158. default:
  3159. return -EINVAL;
  3160. }
  3161. }
  3162. switch (v_opcode) {
  3163. case VIRTCHNL_OP_VERSION:
  3164. ret = i40e_vc_get_version_msg(vf, msg);
  3165. break;
  3166. case VIRTCHNL_OP_GET_VF_RESOURCES:
  3167. ret = i40e_vc_get_vf_resources_msg(vf, msg);
  3168. i40e_vc_notify_vf_link_state(vf);
  3169. break;
  3170. case VIRTCHNL_OP_RESET_VF:
  3171. i40e_vc_reset_vf_msg(vf);
  3172. ret = 0;
  3173. break;
  3174. case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
  3175. ret = i40e_vc_config_promiscuous_mode_msg(vf, msg, msglen);
  3176. break;
  3177. case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  3178. ret = i40e_vc_config_queues_msg(vf, msg, msglen);
  3179. break;
  3180. case VIRTCHNL_OP_CONFIG_IRQ_MAP:
  3181. ret = i40e_vc_config_irq_map_msg(vf, msg, msglen);
  3182. break;
  3183. case VIRTCHNL_OP_ENABLE_QUEUES:
  3184. ret = i40e_vc_enable_queues_msg(vf, msg, msglen);
  3185. i40e_vc_notify_vf_link_state(vf);
  3186. break;
  3187. case VIRTCHNL_OP_DISABLE_QUEUES:
  3188. ret = i40e_vc_disable_queues_msg(vf, msg, msglen);
  3189. break;
  3190. case VIRTCHNL_OP_ADD_ETH_ADDR:
  3191. ret = i40e_vc_add_mac_addr_msg(vf, msg, msglen);
  3192. break;
  3193. case VIRTCHNL_OP_DEL_ETH_ADDR:
  3194. ret = i40e_vc_del_mac_addr_msg(vf, msg, msglen);
  3195. break;
  3196. case VIRTCHNL_OP_ADD_VLAN:
  3197. ret = i40e_vc_add_vlan_msg(vf, msg, msglen);
  3198. break;
  3199. case VIRTCHNL_OP_DEL_VLAN:
  3200. ret = i40e_vc_remove_vlan_msg(vf, msg, msglen);
  3201. break;
  3202. case VIRTCHNL_OP_GET_STATS:
  3203. ret = i40e_vc_get_stats_msg(vf, msg, msglen);
  3204. break;
  3205. case VIRTCHNL_OP_IWARP:
  3206. ret = i40e_vc_iwarp_msg(vf, msg, msglen);
  3207. break;
  3208. case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
  3209. ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, true);
  3210. break;
  3211. case VIRTCHNL_OP_RELEASE_IWARP_IRQ_MAP:
  3212. ret = i40e_vc_iwarp_qvmap_msg(vf, msg, msglen, false);
  3213. break;
  3214. case VIRTCHNL_OP_CONFIG_RSS_KEY:
  3215. ret = i40e_vc_config_rss_key(vf, msg, msglen);
  3216. break;
  3217. case VIRTCHNL_OP_CONFIG_RSS_LUT:
  3218. ret = i40e_vc_config_rss_lut(vf, msg, msglen);
  3219. break;
  3220. case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
  3221. ret = i40e_vc_get_rss_hena(vf, msg, msglen);
  3222. break;
  3223. case VIRTCHNL_OP_SET_RSS_HENA:
  3224. ret = i40e_vc_set_rss_hena(vf, msg, msglen);
  3225. break;
  3226. case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
  3227. ret = i40e_vc_enable_vlan_stripping(vf, msg, msglen);
  3228. break;
  3229. case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
  3230. ret = i40e_vc_disable_vlan_stripping(vf, msg, msglen);
  3231. break;
  3232. case VIRTCHNL_OP_REQUEST_QUEUES:
  3233. ret = i40e_vc_request_queues_msg(vf, msg, msglen);
  3234. break;
  3235. case VIRTCHNL_OP_ENABLE_CHANNELS:
  3236. ret = i40e_vc_add_qch_msg(vf, msg);
  3237. break;
  3238. case VIRTCHNL_OP_DISABLE_CHANNELS:
  3239. ret = i40e_vc_del_qch_msg(vf, msg);
  3240. break;
  3241. case VIRTCHNL_OP_ADD_CLOUD_FILTER:
  3242. ret = i40e_vc_add_cloud_filter(vf, msg);
  3243. break;
  3244. case VIRTCHNL_OP_DEL_CLOUD_FILTER:
  3245. ret = i40e_vc_del_cloud_filter(vf, msg);
  3246. break;
  3247. case VIRTCHNL_OP_UNKNOWN:
  3248. default:
  3249. dev_err(&pf->pdev->dev, "Unsupported opcode %d from VF %d\n",
  3250. v_opcode, local_vf_id);
  3251. ret = i40e_vc_send_resp_to_vf(vf, v_opcode,
  3252. I40E_ERR_NOT_IMPLEMENTED);
  3253. break;
  3254. }
  3255. return ret;
  3256. }
  3257. /**
  3258. * i40e_vc_process_vflr_event
  3259. * @pf: pointer to the PF structure
  3260. *
  3261. * called from the vlfr irq handler to
  3262. * free up VF resources and state variables
  3263. **/
  3264. int i40e_vc_process_vflr_event(struct i40e_pf *pf)
  3265. {
  3266. struct i40e_hw *hw = &pf->hw;
  3267. u32 reg, reg_idx, bit_idx;
  3268. struct i40e_vf *vf;
  3269. int vf_id;
  3270. if (!test_bit(__I40E_VFLR_EVENT_PENDING, pf->state))
  3271. return 0;
  3272. /* Re-enable the VFLR interrupt cause here, before looking for which
  3273. * VF got reset. Otherwise, if another VF gets a reset while the
  3274. * first one is being processed, that interrupt will be lost, and
  3275. * that VF will be stuck in reset forever.
  3276. */
  3277. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  3278. reg |= I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3279. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  3280. i40e_flush(hw);
  3281. clear_bit(__I40E_VFLR_EVENT_PENDING, pf->state);
  3282. for (vf_id = 0; vf_id < pf->num_alloc_vfs; vf_id++) {
  3283. reg_idx = (hw->func_caps.vf_base_id + vf_id) / 32;
  3284. bit_idx = (hw->func_caps.vf_base_id + vf_id) % 32;
  3285. /* read GLGEN_VFLRSTAT register to find out the flr VFs */
  3286. vf = &pf->vf[vf_id];
  3287. reg = rd32(hw, I40E_GLGEN_VFLRSTAT(reg_idx));
  3288. if (reg & BIT(bit_idx))
  3289. /* i40e_reset_vf will clear the bit in GLGEN_VFLRSTAT */
  3290. i40e_reset_vf(vf, true);
  3291. }
  3292. return 0;
  3293. }
  3294. /**
  3295. * i40e_ndo_set_vf_mac
  3296. * @netdev: network interface device structure
  3297. * @vf_id: VF identifier
  3298. * @mac: mac address
  3299. *
  3300. * program VF mac address
  3301. **/
  3302. int i40e_ndo_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
  3303. {
  3304. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3305. struct i40e_vsi *vsi = np->vsi;
  3306. struct i40e_pf *pf = vsi->back;
  3307. struct i40e_mac_filter *f;
  3308. struct i40e_vf *vf;
  3309. int ret = 0;
  3310. struct hlist_node *h;
  3311. int bkt;
  3312. u8 i;
  3313. /* validate the request */
  3314. if (vf_id >= pf->num_alloc_vfs) {
  3315. dev_err(&pf->pdev->dev,
  3316. "Invalid VF Identifier %d\n", vf_id);
  3317. ret = -EINVAL;
  3318. goto error_param;
  3319. }
  3320. vf = &(pf->vf[vf_id]);
  3321. vsi = pf->vsi[vf->lan_vsi_idx];
  3322. /* When the VF is resetting wait until it is done.
  3323. * It can take up to 200 milliseconds,
  3324. * but wait for up to 300 milliseconds to be safe.
  3325. */
  3326. for (i = 0; i < 15; i++) {
  3327. if (test_bit(I40E_VF_STATE_INIT, &vf->vf_states))
  3328. break;
  3329. msleep(20);
  3330. }
  3331. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
  3332. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  3333. vf_id);
  3334. ret = -EAGAIN;
  3335. goto error_param;
  3336. }
  3337. if (is_multicast_ether_addr(mac)) {
  3338. dev_err(&pf->pdev->dev,
  3339. "Invalid Ethernet address %pM for VF %d\n", mac, vf_id);
  3340. ret = -EINVAL;
  3341. goto error_param;
  3342. }
  3343. /* Lock once because below invoked function add/del_filter requires
  3344. * mac_filter_hash_lock to be held
  3345. */
  3346. spin_lock_bh(&vsi->mac_filter_hash_lock);
  3347. /* delete the temporary mac address */
  3348. if (!is_zero_ether_addr(vf->default_lan_addr.addr))
  3349. i40e_del_mac_filter(vsi, vf->default_lan_addr.addr);
  3350. /* Delete all the filters for this VSI - we're going to kill it
  3351. * anyway.
  3352. */
  3353. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  3354. __i40e_del_filter(vsi, f);
  3355. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  3356. /* program mac filter */
  3357. if (i40e_sync_vsi_filters(vsi)) {
  3358. dev_err(&pf->pdev->dev, "Unable to program ucast filters\n");
  3359. ret = -EIO;
  3360. goto error_param;
  3361. }
  3362. ether_addr_copy(vf->default_lan_addr.addr, mac);
  3363. if (is_zero_ether_addr(mac)) {
  3364. vf->pf_set_mac = false;
  3365. dev_info(&pf->pdev->dev, "Removing MAC on VF %d\n", vf_id);
  3366. } else {
  3367. vf->pf_set_mac = true;
  3368. dev_info(&pf->pdev->dev, "Setting MAC %pM on VF %d\n",
  3369. mac, vf_id);
  3370. }
  3371. /* Force the VF driver stop so it has to reload with new MAC address */
  3372. i40e_vc_disable_vf(vf);
  3373. dev_info(&pf->pdev->dev, "Reload the VF driver to make this change effective.\n");
  3374. error_param:
  3375. return ret;
  3376. }
  3377. /**
  3378. * i40e_vsi_has_vlans - True if VSI has configured VLANs
  3379. * @vsi: pointer to the vsi
  3380. *
  3381. * Check if a VSI has configured any VLANs. False if we have a port VLAN or if
  3382. * we have no configured VLANs. Do not call while holding the
  3383. * mac_filter_hash_lock.
  3384. */
  3385. static bool i40e_vsi_has_vlans(struct i40e_vsi *vsi)
  3386. {
  3387. bool have_vlans;
  3388. /* If we have a port VLAN, then the VSI cannot have any VLANs
  3389. * configured, as all MAC/VLAN filters will be assigned to the PVID.
  3390. */
  3391. if (vsi->info.pvid)
  3392. return false;
  3393. /* Since we don't have a PVID, we know that if the device is in VLAN
  3394. * mode it must be because of a VLAN filter configured on this VSI.
  3395. */
  3396. spin_lock_bh(&vsi->mac_filter_hash_lock);
  3397. have_vlans = i40e_is_vsi_in_vlan(vsi);
  3398. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  3399. return have_vlans;
  3400. }
  3401. /**
  3402. * i40e_ndo_set_vf_port_vlan
  3403. * @netdev: network interface device structure
  3404. * @vf_id: VF identifier
  3405. * @vlan_id: mac address
  3406. * @qos: priority setting
  3407. * @vlan_proto: vlan protocol
  3408. *
  3409. * program VF vlan id and/or qos
  3410. **/
  3411. int i40e_ndo_set_vf_port_vlan(struct net_device *netdev, int vf_id,
  3412. u16 vlan_id, u8 qos, __be16 vlan_proto)
  3413. {
  3414. u16 vlanprio = vlan_id | (qos << I40E_VLAN_PRIORITY_SHIFT);
  3415. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3416. struct i40e_pf *pf = np->vsi->back;
  3417. struct i40e_vsi *vsi;
  3418. struct i40e_vf *vf;
  3419. int ret = 0;
  3420. /* validate the request */
  3421. if (vf_id >= pf->num_alloc_vfs) {
  3422. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  3423. ret = -EINVAL;
  3424. goto error_pvid;
  3425. }
  3426. if ((vlan_id > I40E_MAX_VLANID) || (qos > 7)) {
  3427. dev_err(&pf->pdev->dev, "Invalid VF Parameters\n");
  3428. ret = -EINVAL;
  3429. goto error_pvid;
  3430. }
  3431. if (vlan_proto != htons(ETH_P_8021Q)) {
  3432. dev_err(&pf->pdev->dev, "VF VLAN protocol is not supported\n");
  3433. ret = -EPROTONOSUPPORT;
  3434. goto error_pvid;
  3435. }
  3436. vf = &(pf->vf[vf_id]);
  3437. vsi = pf->vsi[vf->lan_vsi_idx];
  3438. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
  3439. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  3440. vf_id);
  3441. ret = -EAGAIN;
  3442. goto error_pvid;
  3443. }
  3444. if (le16_to_cpu(vsi->info.pvid) == vlanprio)
  3445. /* duplicate request, so just return success */
  3446. goto error_pvid;
  3447. if (i40e_vsi_has_vlans(vsi)) {
  3448. dev_err(&pf->pdev->dev,
  3449. "VF %d has already configured VLAN filters and the administrator is requesting a port VLAN override.\nPlease unload and reload the VF driver for this change to take effect.\n",
  3450. vf_id);
  3451. /* Administrator Error - knock the VF offline until he does
  3452. * the right thing by reconfiguring his network correctly
  3453. * and then reloading the VF driver.
  3454. */
  3455. i40e_vc_disable_vf(vf);
  3456. /* During reset the VF got a new VSI, so refresh the pointer. */
  3457. vsi = pf->vsi[vf->lan_vsi_idx];
  3458. }
  3459. /* Locked once because multiple functions below iterate list */
  3460. spin_lock_bh(&vsi->mac_filter_hash_lock);
  3461. /* Check for condition where there was already a port VLAN ID
  3462. * filter set and now it is being deleted by setting it to zero.
  3463. * Additionally check for the condition where there was a port
  3464. * VLAN but now there is a new and different port VLAN being set.
  3465. * Before deleting all the old VLAN filters we must add new ones
  3466. * with -1 (I40E_VLAN_ANY) or otherwise we're left with all our
  3467. * MAC addresses deleted.
  3468. */
  3469. if ((!(vlan_id || qos) ||
  3470. vlanprio != le16_to_cpu(vsi->info.pvid)) &&
  3471. vsi->info.pvid) {
  3472. ret = i40e_add_vlan_all_mac(vsi, I40E_VLAN_ANY);
  3473. if (ret) {
  3474. dev_info(&vsi->back->pdev->dev,
  3475. "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
  3476. vsi->back->hw.aq.asq_last_status);
  3477. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  3478. goto error_pvid;
  3479. }
  3480. }
  3481. if (vsi->info.pvid) {
  3482. /* remove all filters on the old VLAN */
  3483. i40e_rm_vlan_all_mac(vsi, (le16_to_cpu(vsi->info.pvid) &
  3484. VLAN_VID_MASK));
  3485. }
  3486. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  3487. if (vlan_id || qos)
  3488. ret = i40e_vsi_add_pvid(vsi, vlanprio);
  3489. else
  3490. i40e_vsi_remove_pvid(vsi);
  3491. spin_lock_bh(&vsi->mac_filter_hash_lock);
  3492. if (vlan_id) {
  3493. dev_info(&pf->pdev->dev, "Setting VLAN %d, QOS 0x%x on VF %d\n",
  3494. vlan_id, qos, vf_id);
  3495. /* add new VLAN filter for each MAC */
  3496. ret = i40e_add_vlan_all_mac(vsi, vlan_id);
  3497. if (ret) {
  3498. dev_info(&vsi->back->pdev->dev,
  3499. "add VF VLAN failed, ret=%d aq_err=%d\n", ret,
  3500. vsi->back->hw.aq.asq_last_status);
  3501. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  3502. goto error_pvid;
  3503. }
  3504. /* remove the previously added non-VLAN MAC filters */
  3505. i40e_rm_vlan_all_mac(vsi, I40E_VLAN_ANY);
  3506. }
  3507. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  3508. /* Schedule the worker thread to take care of applying changes */
  3509. i40e_service_event_schedule(vsi->back);
  3510. if (ret) {
  3511. dev_err(&pf->pdev->dev, "Unable to update VF vsi context\n");
  3512. goto error_pvid;
  3513. }
  3514. /* The Port VLAN needs to be saved across resets the same as the
  3515. * default LAN MAC address.
  3516. */
  3517. vf->port_vlan_id = le16_to_cpu(vsi->info.pvid);
  3518. ret = 0;
  3519. error_pvid:
  3520. return ret;
  3521. }
  3522. /**
  3523. * i40e_ndo_set_vf_bw
  3524. * @netdev: network interface device structure
  3525. * @vf_id: VF identifier
  3526. * @min_tx_rate: Minimum Tx rate
  3527. * @max_tx_rate: Maximum Tx rate
  3528. *
  3529. * configure VF Tx rate
  3530. **/
  3531. int i40e_ndo_set_vf_bw(struct net_device *netdev, int vf_id, int min_tx_rate,
  3532. int max_tx_rate)
  3533. {
  3534. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3535. struct i40e_pf *pf = np->vsi->back;
  3536. struct i40e_vsi *vsi;
  3537. struct i40e_vf *vf;
  3538. int ret = 0;
  3539. /* validate the request */
  3540. if (vf_id >= pf->num_alloc_vfs) {
  3541. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d.\n", vf_id);
  3542. ret = -EINVAL;
  3543. goto error;
  3544. }
  3545. if (min_tx_rate) {
  3546. dev_err(&pf->pdev->dev, "Invalid min tx rate (%d) (greater than 0) specified for VF %d.\n",
  3547. min_tx_rate, vf_id);
  3548. return -EINVAL;
  3549. }
  3550. vf = &(pf->vf[vf_id]);
  3551. vsi = pf->vsi[vf->lan_vsi_idx];
  3552. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
  3553. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  3554. vf_id);
  3555. ret = -EAGAIN;
  3556. goto error;
  3557. }
  3558. ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
  3559. if (ret)
  3560. goto error;
  3561. vf->tx_rate = max_tx_rate;
  3562. error:
  3563. return ret;
  3564. }
  3565. /**
  3566. * i40e_ndo_get_vf_config
  3567. * @netdev: network interface device structure
  3568. * @vf_id: VF identifier
  3569. * @ivi: VF configuration structure
  3570. *
  3571. * return VF configuration
  3572. **/
  3573. int i40e_ndo_get_vf_config(struct net_device *netdev,
  3574. int vf_id, struct ifla_vf_info *ivi)
  3575. {
  3576. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3577. struct i40e_vsi *vsi = np->vsi;
  3578. struct i40e_pf *pf = vsi->back;
  3579. struct i40e_vf *vf;
  3580. int ret = 0;
  3581. /* validate the request */
  3582. if (vf_id >= pf->num_alloc_vfs) {
  3583. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  3584. ret = -EINVAL;
  3585. goto error_param;
  3586. }
  3587. vf = &(pf->vf[vf_id]);
  3588. /* first vsi is always the LAN vsi */
  3589. vsi = pf->vsi[vf->lan_vsi_idx];
  3590. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
  3591. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  3592. vf_id);
  3593. ret = -EAGAIN;
  3594. goto error_param;
  3595. }
  3596. ivi->vf = vf_id;
  3597. ether_addr_copy(ivi->mac, vf->default_lan_addr.addr);
  3598. ivi->max_tx_rate = vf->tx_rate;
  3599. ivi->min_tx_rate = 0;
  3600. ivi->vlan = le16_to_cpu(vsi->info.pvid) & I40E_VLAN_MASK;
  3601. ivi->qos = (le16_to_cpu(vsi->info.pvid) & I40E_PRIORITY_MASK) >>
  3602. I40E_VLAN_PRIORITY_SHIFT;
  3603. if (vf->link_forced == false)
  3604. ivi->linkstate = IFLA_VF_LINK_STATE_AUTO;
  3605. else if (vf->link_up == true)
  3606. ivi->linkstate = IFLA_VF_LINK_STATE_ENABLE;
  3607. else
  3608. ivi->linkstate = IFLA_VF_LINK_STATE_DISABLE;
  3609. ivi->spoofchk = vf->spoofchk;
  3610. ivi->trusted = vf->trusted;
  3611. ret = 0;
  3612. error_param:
  3613. return ret;
  3614. }
  3615. /**
  3616. * i40e_ndo_set_vf_link_state
  3617. * @netdev: network interface device structure
  3618. * @vf_id: VF identifier
  3619. * @link: required link state
  3620. *
  3621. * Set the link state of a specified VF, regardless of physical link state
  3622. **/
  3623. int i40e_ndo_set_vf_link_state(struct net_device *netdev, int vf_id, int link)
  3624. {
  3625. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3626. struct i40e_pf *pf = np->vsi->back;
  3627. struct virtchnl_pf_event pfe;
  3628. struct i40e_hw *hw = &pf->hw;
  3629. struct i40e_vf *vf;
  3630. int abs_vf_id;
  3631. int ret = 0;
  3632. /* validate the request */
  3633. if (vf_id >= pf->num_alloc_vfs) {
  3634. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  3635. ret = -EINVAL;
  3636. goto error_out;
  3637. }
  3638. vf = &pf->vf[vf_id];
  3639. abs_vf_id = vf->vf_id + hw->func_caps.vf_base_id;
  3640. pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
  3641. pfe.severity = PF_EVENT_SEVERITY_INFO;
  3642. switch (link) {
  3643. case IFLA_VF_LINK_STATE_AUTO:
  3644. vf->link_forced = false;
  3645. pfe.event_data.link_event.link_status =
  3646. pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP;
  3647. pfe.event_data.link_event.link_speed =
  3648. (enum virtchnl_link_speed)
  3649. pf->hw.phy.link_info.link_speed;
  3650. break;
  3651. case IFLA_VF_LINK_STATE_ENABLE:
  3652. vf->link_forced = true;
  3653. vf->link_up = true;
  3654. pfe.event_data.link_event.link_status = true;
  3655. pfe.event_data.link_event.link_speed = I40E_LINK_SPEED_40GB;
  3656. break;
  3657. case IFLA_VF_LINK_STATE_DISABLE:
  3658. vf->link_forced = true;
  3659. vf->link_up = false;
  3660. pfe.event_data.link_event.link_status = false;
  3661. pfe.event_data.link_event.link_speed = 0;
  3662. break;
  3663. default:
  3664. ret = -EINVAL;
  3665. goto error_out;
  3666. }
  3667. /* Notify the VF of its new link state */
  3668. i40e_aq_send_msg_to_vf(hw, abs_vf_id, VIRTCHNL_OP_EVENT,
  3669. 0, (u8 *)&pfe, sizeof(pfe), NULL);
  3670. error_out:
  3671. return ret;
  3672. }
  3673. /**
  3674. * i40e_ndo_set_vf_spoofchk
  3675. * @netdev: network interface device structure
  3676. * @vf_id: VF identifier
  3677. * @enable: flag to enable or disable feature
  3678. *
  3679. * Enable or disable VF spoof checking
  3680. **/
  3681. int i40e_ndo_set_vf_spoofchk(struct net_device *netdev, int vf_id, bool enable)
  3682. {
  3683. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3684. struct i40e_vsi *vsi = np->vsi;
  3685. struct i40e_pf *pf = vsi->back;
  3686. struct i40e_vsi_context ctxt;
  3687. struct i40e_hw *hw = &pf->hw;
  3688. struct i40e_vf *vf;
  3689. int ret = 0;
  3690. /* validate the request */
  3691. if (vf_id >= pf->num_alloc_vfs) {
  3692. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  3693. ret = -EINVAL;
  3694. goto out;
  3695. }
  3696. vf = &(pf->vf[vf_id]);
  3697. if (!test_bit(I40E_VF_STATE_INIT, &vf->vf_states)) {
  3698. dev_err(&pf->pdev->dev, "VF %d still in reset. Try again.\n",
  3699. vf_id);
  3700. ret = -EAGAIN;
  3701. goto out;
  3702. }
  3703. if (enable == vf->spoofchk)
  3704. goto out;
  3705. vf->spoofchk = enable;
  3706. memset(&ctxt, 0, sizeof(ctxt));
  3707. ctxt.seid = pf->vsi[vf->lan_vsi_idx]->seid;
  3708. ctxt.pf_num = pf->hw.pf_id;
  3709. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  3710. if (enable)
  3711. ctxt.info.sec_flags |= (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  3712. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  3713. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  3714. if (ret) {
  3715. dev_err(&pf->pdev->dev, "Error %d updating VSI parameters\n",
  3716. ret);
  3717. ret = -EIO;
  3718. }
  3719. out:
  3720. return ret;
  3721. }
  3722. /**
  3723. * i40e_ndo_set_vf_trust
  3724. * @netdev: network interface device structure of the pf
  3725. * @vf_id: VF identifier
  3726. * @setting: trust setting
  3727. *
  3728. * Enable or disable VF trust setting
  3729. **/
  3730. int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
  3731. {
  3732. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3733. struct i40e_pf *pf = np->vsi->back;
  3734. struct i40e_vf *vf;
  3735. int ret = 0;
  3736. /* validate the request */
  3737. if (vf_id >= pf->num_alloc_vfs) {
  3738. dev_err(&pf->pdev->dev, "Invalid VF Identifier %d\n", vf_id);
  3739. return -EINVAL;
  3740. }
  3741. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3742. dev_err(&pf->pdev->dev, "Trusted VF not supported in MFP mode.\n");
  3743. return -EINVAL;
  3744. }
  3745. vf = &pf->vf[vf_id];
  3746. if (setting == vf->trusted)
  3747. goto out;
  3748. vf->trusted = setting;
  3749. i40e_vc_disable_vf(vf);
  3750. dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
  3751. vf_id, setting ? "" : "un");
  3752. if (vf->adq_enabled) {
  3753. if (!vf->trusted) {
  3754. dev_info(&pf->pdev->dev,
  3755. "VF %u no longer Trusted, deleting all cloud filters\n",
  3756. vf_id);
  3757. i40e_del_all_cloud_filters(vf);
  3758. }
  3759. }
  3760. out:
  3761. return ret;
  3762. }