ice_virtchnl.c 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2022, Intel Corporation. */
  3. #include "ice_virtchnl.h"
  4. #include "ice_vf_lib_private.h"
  5. #include "ice.h"
  6. #include "ice_base.h"
  7. #include "ice_lib.h"
  8. #include "ice_fltr.h"
  9. #include "ice_virtchnl_allowlist.h"
  10. #include "ice_vf_vsi_vlan_ops.h"
  11. #include "ice_vlan.h"
  12. #include "ice_flex_pipe.h"
  13. #include "ice_dcb_lib.h"
  14. #define FIELD_SELECTOR(proto_hdr_field) \
  15. BIT((proto_hdr_field) & PROTO_HDR_FIELD_MASK)
  16. struct ice_vc_hdr_match_type {
  17. u32 vc_hdr; /* virtchnl headers (VIRTCHNL_PROTO_HDR_XXX) */
  18. u32 ice_hdr; /* ice headers (ICE_FLOW_SEG_HDR_XXX) */
  19. };
  20. static const struct ice_vc_hdr_match_type ice_vc_hdr_list[] = {
  21. {VIRTCHNL_PROTO_HDR_NONE, ICE_FLOW_SEG_HDR_NONE},
  22. {VIRTCHNL_PROTO_HDR_ETH, ICE_FLOW_SEG_HDR_ETH},
  23. {VIRTCHNL_PROTO_HDR_S_VLAN, ICE_FLOW_SEG_HDR_VLAN},
  24. {VIRTCHNL_PROTO_HDR_C_VLAN, ICE_FLOW_SEG_HDR_VLAN},
  25. {VIRTCHNL_PROTO_HDR_IPV4, ICE_FLOW_SEG_HDR_IPV4 |
  26. ICE_FLOW_SEG_HDR_IPV_OTHER},
  27. {VIRTCHNL_PROTO_HDR_IPV6, ICE_FLOW_SEG_HDR_IPV6 |
  28. ICE_FLOW_SEG_HDR_IPV_OTHER},
  29. {VIRTCHNL_PROTO_HDR_TCP, ICE_FLOW_SEG_HDR_TCP},
  30. {VIRTCHNL_PROTO_HDR_UDP, ICE_FLOW_SEG_HDR_UDP},
  31. {VIRTCHNL_PROTO_HDR_SCTP, ICE_FLOW_SEG_HDR_SCTP},
  32. {VIRTCHNL_PROTO_HDR_PPPOE, ICE_FLOW_SEG_HDR_PPPOE},
  33. {VIRTCHNL_PROTO_HDR_GTPU_IP, ICE_FLOW_SEG_HDR_GTPU_IP},
  34. {VIRTCHNL_PROTO_HDR_GTPU_EH, ICE_FLOW_SEG_HDR_GTPU_EH},
  35. {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_DWN,
  36. ICE_FLOW_SEG_HDR_GTPU_DWN},
  37. {VIRTCHNL_PROTO_HDR_GTPU_EH_PDU_UP,
  38. ICE_FLOW_SEG_HDR_GTPU_UP},
  39. {VIRTCHNL_PROTO_HDR_L2TPV3, ICE_FLOW_SEG_HDR_L2TPV3},
  40. {VIRTCHNL_PROTO_HDR_ESP, ICE_FLOW_SEG_HDR_ESP},
  41. {VIRTCHNL_PROTO_HDR_AH, ICE_FLOW_SEG_HDR_AH},
  42. {VIRTCHNL_PROTO_HDR_PFCP, ICE_FLOW_SEG_HDR_PFCP_SESSION},
  43. };
  44. struct ice_vc_hash_field_match_type {
  45. u32 vc_hdr; /* virtchnl headers
  46. * (VIRTCHNL_PROTO_HDR_XXX)
  47. */
  48. u32 vc_hash_field; /* virtchnl hash fields selector
  49. * FIELD_SELECTOR((VIRTCHNL_PROTO_HDR_ETH_XXX))
  50. */
  51. u64 ice_hash_field; /* ice hash fields
  52. * (BIT_ULL(ICE_FLOW_FIELD_IDX_XXX))
  53. */
  54. };
  55. static const struct
  56. ice_vc_hash_field_match_type ice_vc_hash_field_list[] = {
  57. {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC),
  58. BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
  59. {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
  60. BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_DA)},
  61. {VIRTCHNL_PROTO_HDR_ETH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_SRC) |
  62. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_DST),
  63. ICE_FLOW_HASH_ETH},
  64. {VIRTCHNL_PROTO_HDR_ETH,
  65. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ETH_ETHERTYPE),
  66. BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_TYPE)},
  67. {VIRTCHNL_PROTO_HDR_S_VLAN,
  68. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_S_VLAN_ID),
  69. BIT_ULL(ICE_FLOW_FIELD_IDX_S_VLAN)},
  70. {VIRTCHNL_PROTO_HDR_C_VLAN,
  71. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_C_VLAN_ID),
  72. BIT_ULL(ICE_FLOW_FIELD_IDX_C_VLAN)},
  73. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC),
  74. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
  75. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
  76. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
  77. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
  78. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST),
  79. ICE_FLOW_HASH_IPV4},
  80. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
  81. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
  82. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
  83. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
  84. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
  85. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
  86. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
  87. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
  88. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_SRC) |
  89. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_DST) |
  90. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
  91. ICE_FLOW_HASH_IPV4 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
  92. {VIRTCHNL_PROTO_HDR_IPV4, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV4_PROT),
  93. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
  94. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC),
  95. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
  96. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
  97. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
  98. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
  99. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST),
  100. ICE_FLOW_HASH_IPV6},
  101. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
  102. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
  103. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
  104. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
  105. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
  106. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
  107. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
  108. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
  109. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_SRC) |
  110. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_DST) |
  111. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
  112. ICE_FLOW_HASH_IPV6 | BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
  113. {VIRTCHNL_PROTO_HDR_IPV6, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_IPV6_PROT),
  114. BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
  115. {VIRTCHNL_PROTO_HDR_TCP,
  116. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT),
  117. BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
  118. {VIRTCHNL_PROTO_HDR_TCP,
  119. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
  120. BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
  121. {VIRTCHNL_PROTO_HDR_TCP,
  122. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_SRC_PORT) |
  123. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_TCP_DST_PORT),
  124. ICE_FLOW_HASH_TCP_PORT},
  125. {VIRTCHNL_PROTO_HDR_UDP,
  126. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT),
  127. BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
  128. {VIRTCHNL_PROTO_HDR_UDP,
  129. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
  130. BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
  131. {VIRTCHNL_PROTO_HDR_UDP,
  132. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_SRC_PORT) |
  133. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_UDP_DST_PORT),
  134. ICE_FLOW_HASH_UDP_PORT},
  135. {VIRTCHNL_PROTO_HDR_SCTP,
  136. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT),
  137. BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
  138. {VIRTCHNL_PROTO_HDR_SCTP,
  139. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
  140. BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
  141. {VIRTCHNL_PROTO_HDR_SCTP,
  142. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_SRC_PORT) |
  143. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_SCTP_DST_PORT),
  144. ICE_FLOW_HASH_SCTP_PORT},
  145. {VIRTCHNL_PROTO_HDR_PPPOE,
  146. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PPPOE_SESS_ID),
  147. BIT_ULL(ICE_FLOW_FIELD_IDX_PPPOE_SESS_ID)},
  148. {VIRTCHNL_PROTO_HDR_GTPU_IP,
  149. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_GTPU_IP_TEID),
  150. BIT_ULL(ICE_FLOW_FIELD_IDX_GTPU_IP_TEID)},
  151. {VIRTCHNL_PROTO_HDR_L2TPV3,
  152. FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_L2TPV3_SESS_ID),
  153. BIT_ULL(ICE_FLOW_FIELD_IDX_L2TPV3_SESS_ID)},
  154. {VIRTCHNL_PROTO_HDR_ESP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_ESP_SPI),
  155. BIT_ULL(ICE_FLOW_FIELD_IDX_ESP_SPI)},
  156. {VIRTCHNL_PROTO_HDR_AH, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_AH_SPI),
  157. BIT_ULL(ICE_FLOW_FIELD_IDX_AH_SPI)},
  158. {VIRTCHNL_PROTO_HDR_PFCP, FIELD_SELECTOR(VIRTCHNL_PROTO_HDR_PFCP_SEID),
  159. BIT_ULL(ICE_FLOW_FIELD_IDX_PFCP_SEID)},
  160. };
  161. /**
  162. * ice_vc_vf_broadcast - Broadcast a message to all VFs on PF
  163. * @pf: pointer to the PF structure
  164. * @v_opcode: operation code
  165. * @v_retval: return value
  166. * @msg: pointer to the msg buffer
  167. * @msglen: msg length
  168. */
  169. static void
  170. ice_vc_vf_broadcast(struct ice_pf *pf, enum virtchnl_ops v_opcode,
  171. enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
  172. {
  173. struct ice_hw *hw = &pf->hw;
  174. struct ice_vf *vf;
  175. unsigned int bkt;
  176. mutex_lock(&pf->vfs.table_lock);
  177. ice_for_each_vf(pf, bkt, vf) {
  178. /* Not all vfs are enabled so skip the ones that are not */
  179. if (!test_bit(ICE_VF_STATE_INIT, vf->vf_states) &&
  180. !test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
  181. continue;
  182. /* Ignore return value on purpose - a given VF may fail, but
  183. * we need to keep going and send to all of them
  184. */
  185. ice_aq_send_msg_to_vf(hw, vf->vf_id, v_opcode, v_retval, msg,
  186. msglen, NULL);
  187. }
  188. mutex_unlock(&pf->vfs.table_lock);
  189. }
  190. /**
  191. * ice_set_pfe_link - Set the link speed/status of the virtchnl_pf_event
  192. * @vf: pointer to the VF structure
  193. * @pfe: pointer to the virtchnl_pf_event to set link speed/status for
  194. * @ice_link_speed: link speed specified by ICE_AQ_LINK_SPEED_*
  195. * @link_up: whether or not to set the link up/down
  196. */
  197. static void
  198. ice_set_pfe_link(struct ice_vf *vf, struct virtchnl_pf_event *pfe,
  199. int ice_link_speed, bool link_up)
  200. {
  201. if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED) {
  202. pfe->event_data.link_event_adv.link_status = link_up;
  203. /* Speed in Mbps */
  204. pfe->event_data.link_event_adv.link_speed =
  205. ice_conv_link_speed_to_virtchnl(true, ice_link_speed);
  206. } else {
  207. pfe->event_data.link_event.link_status = link_up;
  208. /* Legacy method for virtchnl link speeds */
  209. pfe->event_data.link_event.link_speed =
  210. (enum virtchnl_link_speed)
  211. ice_conv_link_speed_to_virtchnl(false, ice_link_speed);
  212. }
  213. }
  214. /**
  215. * ice_vc_notify_vf_link_state - Inform a VF of link status
  216. * @vf: pointer to the VF structure
  217. *
  218. * send a link status message to a single VF
  219. */
  220. void ice_vc_notify_vf_link_state(struct ice_vf *vf)
  221. {
  222. struct virtchnl_pf_event pfe = { 0 };
  223. struct ice_hw *hw = &vf->pf->hw;
  224. pfe.event = VIRTCHNL_EVENT_LINK_CHANGE;
  225. pfe.severity = PF_EVENT_SEVERITY_INFO;
  226. if (ice_is_vf_link_up(vf))
  227. ice_set_pfe_link(vf, &pfe,
  228. hw->port_info->phy.link_info.link_speed, true);
  229. else
  230. ice_set_pfe_link(vf, &pfe, ICE_AQ_LINK_SPEED_UNKNOWN, false);
  231. ice_aq_send_msg_to_vf(hw, vf->vf_id, VIRTCHNL_OP_EVENT,
  232. VIRTCHNL_STATUS_SUCCESS, (u8 *)&pfe,
  233. sizeof(pfe), NULL);
  234. }
  235. /**
  236. * ice_vc_notify_link_state - Inform all VFs on a PF of link status
  237. * @pf: pointer to the PF structure
  238. */
  239. void ice_vc_notify_link_state(struct ice_pf *pf)
  240. {
  241. struct ice_vf *vf;
  242. unsigned int bkt;
  243. mutex_lock(&pf->vfs.table_lock);
  244. ice_for_each_vf(pf, bkt, vf)
  245. ice_vc_notify_vf_link_state(vf);
  246. mutex_unlock(&pf->vfs.table_lock);
  247. }
  248. /**
  249. * ice_vc_notify_reset - Send pending reset message to all VFs
  250. * @pf: pointer to the PF structure
  251. *
  252. * indicate a pending reset to all VFs on a given PF
  253. */
  254. void ice_vc_notify_reset(struct ice_pf *pf)
  255. {
  256. struct virtchnl_pf_event pfe;
  257. if (!ice_has_vfs(pf))
  258. return;
  259. pfe.event = VIRTCHNL_EVENT_RESET_IMPENDING;
  260. pfe.severity = PF_EVENT_SEVERITY_CERTAIN_DOOM;
  261. ice_vc_vf_broadcast(pf, VIRTCHNL_OP_EVENT, VIRTCHNL_STATUS_SUCCESS,
  262. (u8 *)&pfe, sizeof(struct virtchnl_pf_event));
  263. }
  264. /**
  265. * ice_vc_send_msg_to_vf - Send message to VF
  266. * @vf: pointer to the VF info
  267. * @v_opcode: virtual channel opcode
  268. * @v_retval: virtual channel return value
  269. * @msg: pointer to the msg buffer
  270. * @msglen: msg length
  271. *
  272. * send msg to VF
  273. */
  274. int
  275. ice_vc_send_msg_to_vf(struct ice_vf *vf, u32 v_opcode,
  276. enum virtchnl_status_code v_retval, u8 *msg, u16 msglen)
  277. {
  278. struct device *dev;
  279. struct ice_pf *pf;
  280. int aq_ret;
  281. pf = vf->pf;
  282. dev = ice_pf_to_dev(pf);
  283. aq_ret = ice_aq_send_msg_to_vf(&pf->hw, vf->vf_id, v_opcode, v_retval,
  284. msg, msglen, NULL);
  285. if (aq_ret && pf->hw.mailboxq.sq_last_status != ICE_AQ_RC_ENOSYS) {
  286. dev_info(dev, "Unable to send the message to VF %d ret %d aq_err %s\n",
  287. vf->vf_id, aq_ret,
  288. ice_aq_str(pf->hw.mailboxq.sq_last_status));
  289. return -EIO;
  290. }
  291. return 0;
  292. }
  293. /**
  294. * ice_vc_get_ver_msg
  295. * @vf: pointer to the VF info
  296. * @msg: pointer to the msg buffer
  297. *
  298. * called from the VF to request the API version used by the PF
  299. */
  300. static int ice_vc_get_ver_msg(struct ice_vf *vf, u8 *msg)
  301. {
  302. struct virtchnl_version_info info = {
  303. VIRTCHNL_VERSION_MAJOR, VIRTCHNL_VERSION_MINOR
  304. };
  305. vf->vf_ver = *(struct virtchnl_version_info *)msg;
  306. /* VFs running the 1.0 API expect to get 1.0 back or they will cry. */
  307. if (VF_IS_V10(&vf->vf_ver))
  308. info.minor = VIRTCHNL_VERSION_MINOR_NO_VF_CAPS;
  309. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_VERSION,
  310. VIRTCHNL_STATUS_SUCCESS, (u8 *)&info,
  311. sizeof(struct virtchnl_version_info));
  312. }
  313. /**
  314. * ice_vc_get_max_frame_size - get max frame size allowed for VF
  315. * @vf: VF used to determine max frame size
  316. *
  317. * Max frame size is determined based on the current port's max frame size and
  318. * whether a port VLAN is configured on this VF. The VF is not aware whether
  319. * it's in a port VLAN so the PF needs to account for this in max frame size
  320. * checks and sending the max frame size to the VF.
  321. */
  322. static u16 ice_vc_get_max_frame_size(struct ice_vf *vf)
  323. {
  324. struct ice_port_info *pi = ice_vf_get_port_info(vf);
  325. u16 max_frame_size;
  326. max_frame_size = pi->phy.link_info.max_frame_size;
  327. if (ice_vf_is_port_vlan_ena(vf))
  328. max_frame_size -= VLAN_HLEN;
  329. return max_frame_size;
  330. }
  331. /**
  332. * ice_vc_get_vlan_caps
  333. * @hw: pointer to the hw
  334. * @vf: pointer to the VF info
  335. * @vsi: pointer to the VSI
  336. * @driver_caps: current driver caps
  337. *
  338. * Return 0 if there is no VLAN caps supported, or VLAN caps value
  339. */
  340. static u32
  341. ice_vc_get_vlan_caps(struct ice_hw *hw, struct ice_vf *vf, struct ice_vsi *vsi,
  342. u32 driver_caps)
  343. {
  344. if (ice_is_eswitch_mode_switchdev(vf->pf))
  345. /* In switchdev setting VLAN from VF isn't supported */
  346. return 0;
  347. if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN_V2) {
  348. /* VLAN offloads based on current device configuration */
  349. return VIRTCHNL_VF_OFFLOAD_VLAN_V2;
  350. } else if (driver_caps & VIRTCHNL_VF_OFFLOAD_VLAN) {
  351. /* allow VF to negotiate VIRTCHNL_VF_OFFLOAD explicitly for
  352. * these two conditions, which amounts to guest VLAN filtering
  353. * and offloads being based on the inner VLAN or the
  354. * inner/single VLAN respectively and don't allow VF to
  355. * negotiate VIRTCHNL_VF_OFFLOAD in any other cases
  356. */
  357. if (ice_is_dvm_ena(hw) && ice_vf_is_port_vlan_ena(vf)) {
  358. return VIRTCHNL_VF_OFFLOAD_VLAN;
  359. } else if (!ice_is_dvm_ena(hw) &&
  360. !ice_vf_is_port_vlan_ena(vf)) {
  361. /* configure backward compatible support for VFs that
  362. * only support VIRTCHNL_VF_OFFLOAD_VLAN, the PF is
  363. * configured in SVM, and no port VLAN is configured
  364. */
  365. ice_vf_vsi_cfg_svm_legacy_vlan_mode(vsi);
  366. return VIRTCHNL_VF_OFFLOAD_VLAN;
  367. } else if (ice_is_dvm_ena(hw)) {
  368. /* configure software offloaded VLAN support when DVM
  369. * is enabled, but no port VLAN is enabled
  370. */
  371. ice_vf_vsi_cfg_dvm_legacy_vlan_mode(vsi);
  372. }
  373. }
  374. return 0;
  375. }
  376. /**
  377. * ice_vc_get_vf_res_msg
  378. * @vf: pointer to the VF info
  379. * @msg: pointer to the msg buffer
  380. *
  381. * called from the VF to request its resources
  382. */
  383. static int ice_vc_get_vf_res_msg(struct ice_vf *vf, u8 *msg)
  384. {
  385. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  386. struct virtchnl_vf_resource *vfres = NULL;
  387. struct ice_hw *hw = &vf->pf->hw;
  388. struct ice_vsi *vsi;
  389. int len = 0;
  390. int ret;
  391. if (ice_check_vf_init(vf)) {
  392. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  393. goto err;
  394. }
  395. len = virtchnl_struct_size(vfres, vsi_res, 0);
  396. vfres = kzalloc(len, GFP_KERNEL);
  397. if (!vfres) {
  398. v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
  399. len = 0;
  400. goto err;
  401. }
  402. if (VF_IS_V11(&vf->vf_ver))
  403. vf->driver_caps = *(u32 *)msg;
  404. else
  405. vf->driver_caps = VIRTCHNL_VF_OFFLOAD_L2 |
  406. VIRTCHNL_VF_OFFLOAD_VLAN;
  407. vfres->vf_cap_flags = VIRTCHNL_VF_OFFLOAD_L2;
  408. vsi = ice_get_vf_vsi(vf);
  409. if (!vsi) {
  410. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  411. goto err;
  412. }
  413. vfres->vf_cap_flags |= ice_vc_get_vlan_caps(hw, vf, vsi,
  414. vf->driver_caps);
  415. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PF)
  416. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PF;
  417. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)
  418. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC;
  419. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
  420. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_FDIR_PF;
  421. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_TC_U32 &&
  422. vfres->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_FDIR_PF)
  423. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_TC_U32;
  424. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2)
  425. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
  426. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP)
  427. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP;
  428. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM)
  429. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM;
  430. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_POLLING)
  431. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_RX_POLLING;
  432. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
  433. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_WB_ON_ITR;
  434. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_REQ_QUEUES)
  435. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_REQ_QUEUES;
  436. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC)
  437. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_CRC;
  438. if (vf->driver_caps & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
  439. vfres->vf_cap_flags |= VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
  440. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF)
  441. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF;
  442. if (vf->driver_caps & VIRTCHNL_VF_OFFLOAD_USO)
  443. vfres->vf_cap_flags |= VIRTCHNL_VF_OFFLOAD_USO;
  444. vfres->num_vsis = 1;
  445. /* Tx and Rx queue are equal for VF */
  446. vfres->num_queue_pairs = vsi->num_txq;
  447. vfres->max_vectors = vf->num_msix;
  448. vfres->rss_key_size = ICE_VSIQF_HKEY_ARRAY_SIZE;
  449. vfres->rss_lut_size = ICE_LUT_VSI_SIZE;
  450. vfres->max_mtu = ice_vc_get_max_frame_size(vf);
  451. vfres->vsi_res[0].vsi_id = ICE_VF_VSI_ID;
  452. vfres->vsi_res[0].vsi_type = VIRTCHNL_VSI_SRIOV;
  453. vfres->vsi_res[0].num_queue_pairs = vsi->num_txq;
  454. ether_addr_copy(vfres->vsi_res[0].default_mac_addr,
  455. vf->hw_lan_addr);
  456. /* match guest capabilities */
  457. vf->driver_caps = vfres->vf_cap_flags;
  458. ice_vc_set_caps_allowlist(vf);
  459. ice_vc_set_working_allowlist(vf);
  460. set_bit(ICE_VF_STATE_ACTIVE, vf->vf_states);
  461. err:
  462. /* send the response back to the VF */
  463. ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_VF_RESOURCES, v_ret,
  464. (u8 *)vfres, len);
  465. kfree(vfres);
  466. return ret;
  467. }
  468. /**
  469. * ice_vc_reset_vf_msg
  470. * @vf: pointer to the VF info
  471. *
  472. * called from the VF to reset itself,
  473. * unlike other virtchnl messages, PF driver
  474. * doesn't send the response back to the VF
  475. */
  476. static void ice_vc_reset_vf_msg(struct ice_vf *vf)
  477. {
  478. if (test_bit(ICE_VF_STATE_INIT, vf->vf_states))
  479. ice_reset_vf(vf, 0);
  480. }
  481. /**
  482. * ice_vc_isvalid_vsi_id
  483. * @vf: pointer to the VF info
  484. * @vsi_id: VF relative VSI ID
  485. *
  486. * check for the valid VSI ID
  487. */
  488. bool ice_vc_isvalid_vsi_id(struct ice_vf *vf, u16 vsi_id)
  489. {
  490. return vsi_id == ICE_VF_VSI_ID;
  491. }
  492. /**
  493. * ice_vc_isvalid_q_id
  494. * @vsi: VSI to check queue ID against
  495. * @qid: VSI relative queue ID
  496. *
  497. * check for the valid queue ID
  498. */
  499. static bool ice_vc_isvalid_q_id(struct ice_vsi *vsi, u8 qid)
  500. {
  501. /* allocated Tx and Rx queues should be always equal for VF VSI */
  502. return qid < vsi->alloc_txq;
  503. }
  504. /**
  505. * ice_vc_isvalid_ring_len
  506. * @ring_len: length of ring
  507. *
  508. * check for the valid ring count, should be multiple of ICE_REQ_DESC_MULTIPLE
  509. * or zero
  510. */
  511. static bool ice_vc_isvalid_ring_len(u16 ring_len)
  512. {
  513. return ring_len == 0 ||
  514. (ring_len >= ICE_MIN_NUM_DESC &&
  515. ring_len <= ICE_MAX_NUM_DESC &&
  516. !(ring_len % ICE_REQ_DESC_MULTIPLE));
  517. }
  518. /**
  519. * ice_vc_validate_pattern
  520. * @vf: pointer to the VF info
  521. * @proto: virtchnl protocol headers
  522. *
  523. * validate the pattern is supported or not.
  524. *
  525. * Return: true on success, false on error.
  526. */
  527. bool
  528. ice_vc_validate_pattern(struct ice_vf *vf, struct virtchnl_proto_hdrs *proto)
  529. {
  530. bool is_ipv4 = false;
  531. bool is_ipv6 = false;
  532. bool is_udp = false;
  533. u16 ptype = -1;
  534. int i = 0;
  535. while (i < proto->count &&
  536. proto->proto_hdr[i].type != VIRTCHNL_PROTO_HDR_NONE) {
  537. switch (proto->proto_hdr[i].type) {
  538. case VIRTCHNL_PROTO_HDR_ETH:
  539. ptype = ICE_PTYPE_MAC_PAY;
  540. break;
  541. case VIRTCHNL_PROTO_HDR_IPV4:
  542. ptype = ICE_PTYPE_IPV4_PAY;
  543. is_ipv4 = true;
  544. break;
  545. case VIRTCHNL_PROTO_HDR_IPV6:
  546. ptype = ICE_PTYPE_IPV6_PAY;
  547. is_ipv6 = true;
  548. break;
  549. case VIRTCHNL_PROTO_HDR_UDP:
  550. if (is_ipv4)
  551. ptype = ICE_PTYPE_IPV4_UDP_PAY;
  552. else if (is_ipv6)
  553. ptype = ICE_PTYPE_IPV6_UDP_PAY;
  554. is_udp = true;
  555. break;
  556. case VIRTCHNL_PROTO_HDR_TCP:
  557. if (is_ipv4)
  558. ptype = ICE_PTYPE_IPV4_TCP_PAY;
  559. else if (is_ipv6)
  560. ptype = ICE_PTYPE_IPV6_TCP_PAY;
  561. break;
  562. case VIRTCHNL_PROTO_HDR_SCTP:
  563. if (is_ipv4)
  564. ptype = ICE_PTYPE_IPV4_SCTP_PAY;
  565. else if (is_ipv6)
  566. ptype = ICE_PTYPE_IPV6_SCTP_PAY;
  567. break;
  568. case VIRTCHNL_PROTO_HDR_GTPU_IP:
  569. case VIRTCHNL_PROTO_HDR_GTPU_EH:
  570. if (is_ipv4)
  571. ptype = ICE_MAC_IPV4_GTPU;
  572. else if (is_ipv6)
  573. ptype = ICE_MAC_IPV6_GTPU;
  574. goto out;
  575. case VIRTCHNL_PROTO_HDR_L2TPV3:
  576. if (is_ipv4)
  577. ptype = ICE_MAC_IPV4_L2TPV3;
  578. else if (is_ipv6)
  579. ptype = ICE_MAC_IPV6_L2TPV3;
  580. goto out;
  581. case VIRTCHNL_PROTO_HDR_ESP:
  582. if (is_ipv4)
  583. ptype = is_udp ? ICE_MAC_IPV4_NAT_T_ESP :
  584. ICE_MAC_IPV4_ESP;
  585. else if (is_ipv6)
  586. ptype = is_udp ? ICE_MAC_IPV6_NAT_T_ESP :
  587. ICE_MAC_IPV6_ESP;
  588. goto out;
  589. case VIRTCHNL_PROTO_HDR_AH:
  590. if (is_ipv4)
  591. ptype = ICE_MAC_IPV4_AH;
  592. else if (is_ipv6)
  593. ptype = ICE_MAC_IPV6_AH;
  594. goto out;
  595. case VIRTCHNL_PROTO_HDR_PFCP:
  596. if (is_ipv4)
  597. ptype = ICE_MAC_IPV4_PFCP_SESSION;
  598. else if (is_ipv6)
  599. ptype = ICE_MAC_IPV6_PFCP_SESSION;
  600. goto out;
  601. default:
  602. break;
  603. }
  604. i++;
  605. }
  606. out:
  607. return ice_hw_ptype_ena(&vf->pf->hw, ptype);
  608. }
  609. /**
  610. * ice_vc_parse_rss_cfg - parses hash fields and headers from
  611. * a specific virtchnl RSS cfg
  612. * @hw: pointer to the hardware
  613. * @rss_cfg: pointer to the virtchnl RSS cfg
  614. * @hash_cfg: pointer to the HW hash configuration
  615. *
  616. * Return true if all the protocol header and hash fields in the RSS cfg could
  617. * be parsed, else return false
  618. *
  619. * This function parses the virtchnl RSS cfg to be the intended
  620. * hash fields and the intended header for RSS configuration
  621. */
  622. static bool ice_vc_parse_rss_cfg(struct ice_hw *hw,
  623. struct virtchnl_rss_cfg *rss_cfg,
  624. struct ice_rss_hash_cfg *hash_cfg)
  625. {
  626. const struct ice_vc_hash_field_match_type *hf_list;
  627. const struct ice_vc_hdr_match_type *hdr_list;
  628. int i, hf_list_len, hdr_list_len;
  629. u32 *addl_hdrs = &hash_cfg->addl_hdrs;
  630. u64 *hash_flds = &hash_cfg->hash_flds;
  631. /* set outer layer RSS as default */
  632. hash_cfg->hdr_type = ICE_RSS_OUTER_HEADERS;
  633. if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
  634. hash_cfg->symm = true;
  635. else
  636. hash_cfg->symm = false;
  637. hf_list = ice_vc_hash_field_list;
  638. hf_list_len = ARRAY_SIZE(ice_vc_hash_field_list);
  639. hdr_list = ice_vc_hdr_list;
  640. hdr_list_len = ARRAY_SIZE(ice_vc_hdr_list);
  641. for (i = 0; i < rss_cfg->proto_hdrs.count; i++) {
  642. struct virtchnl_proto_hdr *proto_hdr =
  643. &rss_cfg->proto_hdrs.proto_hdr[i];
  644. bool hdr_found = false;
  645. int j;
  646. /* Find matched ice headers according to virtchnl headers. */
  647. for (j = 0; j < hdr_list_len; j++) {
  648. struct ice_vc_hdr_match_type hdr_map = hdr_list[j];
  649. if (proto_hdr->type == hdr_map.vc_hdr) {
  650. *addl_hdrs |= hdr_map.ice_hdr;
  651. hdr_found = true;
  652. }
  653. }
  654. if (!hdr_found)
  655. return false;
  656. /* Find matched ice hash fields according to
  657. * virtchnl hash fields.
  658. */
  659. for (j = 0; j < hf_list_len; j++) {
  660. struct ice_vc_hash_field_match_type hf_map = hf_list[j];
  661. if (proto_hdr->type == hf_map.vc_hdr &&
  662. proto_hdr->field_selector == hf_map.vc_hash_field) {
  663. *hash_flds |= hf_map.ice_hash_field;
  664. break;
  665. }
  666. }
  667. }
  668. return true;
  669. }
  670. /**
  671. * ice_vf_adv_rss_offload_ena - determine if capabilities support advanced
  672. * RSS offloads
  673. * @caps: VF driver negotiated capabilities
  674. *
  675. * Return true if VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF capability is set,
  676. * else return false
  677. */
  678. static bool ice_vf_adv_rss_offload_ena(u32 caps)
  679. {
  680. return !!(caps & VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF);
  681. }
  682. /**
  683. * ice_vc_handle_rss_cfg
  684. * @vf: pointer to the VF info
  685. * @msg: pointer to the message buffer
  686. * @add: add a RSS config if true, otherwise delete a RSS config
  687. *
  688. * This function adds/deletes a RSS config
  689. */
  690. static int ice_vc_handle_rss_cfg(struct ice_vf *vf, u8 *msg, bool add)
  691. {
  692. u32 v_opcode = add ? VIRTCHNL_OP_ADD_RSS_CFG : VIRTCHNL_OP_DEL_RSS_CFG;
  693. struct virtchnl_rss_cfg *rss_cfg = (struct virtchnl_rss_cfg *)msg;
  694. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  695. struct device *dev = ice_pf_to_dev(vf->pf);
  696. struct ice_hw *hw = &vf->pf->hw;
  697. struct ice_vsi *vsi;
  698. if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
  699. dev_dbg(dev, "VF %d attempting to configure RSS, but RSS is not supported by the PF\n",
  700. vf->vf_id);
  701. v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
  702. goto error_param;
  703. }
  704. if (!ice_vf_adv_rss_offload_ena(vf->driver_caps)) {
  705. dev_dbg(dev, "VF %d attempting to configure RSS, but Advanced RSS offload is not supported\n",
  706. vf->vf_id);
  707. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  708. goto error_param;
  709. }
  710. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  711. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  712. goto error_param;
  713. }
  714. if (rss_cfg->proto_hdrs.count > VIRTCHNL_MAX_NUM_PROTO_HDRS ||
  715. rss_cfg->rss_algorithm < VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC ||
  716. rss_cfg->rss_algorithm > VIRTCHNL_RSS_ALG_XOR_SYMMETRIC) {
  717. dev_dbg(dev, "VF %d attempting to configure RSS, but RSS configuration is not valid\n",
  718. vf->vf_id);
  719. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  720. goto error_param;
  721. }
  722. vsi = ice_get_vf_vsi(vf);
  723. if (!vsi) {
  724. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  725. goto error_param;
  726. }
  727. if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
  728. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  729. goto error_param;
  730. }
  731. if (rss_cfg->rss_algorithm == VIRTCHNL_RSS_ALG_R_ASYMMETRIC) {
  732. struct ice_vsi_ctx *ctx;
  733. u8 lut_type, hash_type;
  734. int status;
  735. lut_type = ICE_AQ_VSI_Q_OPT_RSS_LUT_VSI;
  736. hash_type = add ? ICE_AQ_VSI_Q_OPT_RSS_HASH_XOR :
  737. ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
  738. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  739. if (!ctx) {
  740. v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
  741. goto error_param;
  742. }
  743. ctx->info.q_opt_rss =
  744. FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_LUT_M, lut_type) |
  745. FIELD_PREP(ICE_AQ_VSI_Q_OPT_RSS_HASH_M, hash_type);
  746. /* Preserve existing queueing option setting */
  747. ctx->info.q_opt_rss |= (vsi->info.q_opt_rss &
  748. ICE_AQ_VSI_Q_OPT_RSS_GBL_LUT_M);
  749. ctx->info.q_opt_tc = vsi->info.q_opt_tc;
  750. ctx->info.q_opt_flags = vsi->info.q_opt_rss;
  751. ctx->info.valid_sections =
  752. cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
  753. status = ice_update_vsi(hw, vsi->idx, ctx, NULL);
  754. if (status) {
  755. dev_err(dev, "update VSI for RSS failed, err %d aq_err %s\n",
  756. status, ice_aq_str(hw->adminq.sq_last_status));
  757. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  758. } else {
  759. vsi->info.q_opt_rss = ctx->info.q_opt_rss;
  760. }
  761. kfree(ctx);
  762. } else {
  763. struct ice_rss_hash_cfg cfg;
  764. /* Only check for none raw pattern case */
  765. if (!ice_vc_validate_pattern(vf, &rss_cfg->proto_hdrs)) {
  766. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  767. goto error_param;
  768. }
  769. cfg.addl_hdrs = ICE_FLOW_SEG_HDR_NONE;
  770. cfg.hash_flds = ICE_HASH_INVALID;
  771. cfg.hdr_type = ICE_RSS_ANY_HEADERS;
  772. if (!ice_vc_parse_rss_cfg(hw, rss_cfg, &cfg)) {
  773. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  774. goto error_param;
  775. }
  776. if (add) {
  777. if (ice_add_rss_cfg(hw, vsi, &cfg)) {
  778. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  779. dev_err(dev, "ice_add_rss_cfg failed for vsi = %d, v_ret = %d\n",
  780. vsi->vsi_num, v_ret);
  781. }
  782. } else {
  783. int status;
  784. status = ice_rem_rss_cfg(hw, vsi->idx, &cfg);
  785. /* We just ignore -ENOENT, because if two configurations
  786. * share the same profile remove one of them actually
  787. * removes both, since the profile is deleted.
  788. */
  789. if (status && status != -ENOENT) {
  790. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  791. dev_err(dev, "ice_rem_rss_cfg failed for VF ID:%d, error:%d\n",
  792. vf->vf_id, status);
  793. }
  794. }
  795. }
  796. error_param:
  797. return ice_vc_send_msg_to_vf(vf, v_opcode, v_ret, NULL, 0);
  798. }
  799. /**
  800. * ice_vc_config_rss_key
  801. * @vf: pointer to the VF info
  802. * @msg: pointer to the msg buffer
  803. *
  804. * Configure the VF's RSS key
  805. */
  806. static int ice_vc_config_rss_key(struct ice_vf *vf, u8 *msg)
  807. {
  808. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  809. struct virtchnl_rss_key *vrk =
  810. (struct virtchnl_rss_key *)msg;
  811. struct ice_vsi *vsi;
  812. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  813. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  814. goto error_param;
  815. }
  816. if (!ice_vc_isvalid_vsi_id(vf, vrk->vsi_id)) {
  817. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  818. goto error_param;
  819. }
  820. if (vrk->key_len != ICE_VSIQF_HKEY_ARRAY_SIZE) {
  821. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  822. goto error_param;
  823. }
  824. if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
  825. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  826. goto error_param;
  827. }
  828. vsi = ice_get_vf_vsi(vf);
  829. if (!vsi) {
  830. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  831. goto error_param;
  832. }
  833. if (ice_set_rss_key(vsi, vrk->key))
  834. v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
  835. error_param:
  836. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_KEY, v_ret,
  837. NULL, 0);
  838. }
  839. /**
  840. * ice_vc_config_rss_lut
  841. * @vf: pointer to the VF info
  842. * @msg: pointer to the msg buffer
  843. *
  844. * Configure the VF's RSS LUT
  845. */
  846. static int ice_vc_config_rss_lut(struct ice_vf *vf, u8 *msg)
  847. {
  848. struct virtchnl_rss_lut *vrl = (struct virtchnl_rss_lut *)msg;
  849. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  850. struct ice_vsi *vsi;
  851. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  852. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  853. goto error_param;
  854. }
  855. if (!ice_vc_isvalid_vsi_id(vf, vrl->vsi_id)) {
  856. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  857. goto error_param;
  858. }
  859. if (vrl->lut_entries != ICE_LUT_VSI_SIZE) {
  860. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  861. goto error_param;
  862. }
  863. if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
  864. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  865. goto error_param;
  866. }
  867. vsi = ice_get_vf_vsi(vf);
  868. if (!vsi) {
  869. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  870. goto error_param;
  871. }
  872. if (ice_set_rss_lut(vsi, vrl->lut, ICE_LUT_VSI_SIZE))
  873. v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
  874. error_param:
  875. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_LUT, v_ret,
  876. NULL, 0);
  877. }
  878. /**
  879. * ice_vc_config_rss_hfunc
  880. * @vf: pointer to the VF info
  881. * @msg: pointer to the msg buffer
  882. *
  883. * Configure the VF's RSS Hash function
  884. */
  885. static int ice_vc_config_rss_hfunc(struct ice_vf *vf, u8 *msg)
  886. {
  887. struct virtchnl_rss_hfunc *vrh = (struct virtchnl_rss_hfunc *)msg;
  888. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  889. u8 hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_TPLZ;
  890. struct ice_vsi *vsi;
  891. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  892. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  893. goto error_param;
  894. }
  895. if (!ice_vc_isvalid_vsi_id(vf, vrh->vsi_id)) {
  896. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  897. goto error_param;
  898. }
  899. if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
  900. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  901. goto error_param;
  902. }
  903. vsi = ice_get_vf_vsi(vf);
  904. if (!vsi) {
  905. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  906. goto error_param;
  907. }
  908. if (vrh->rss_algorithm == VIRTCHNL_RSS_ALG_TOEPLITZ_SYMMETRIC)
  909. hfunc = ICE_AQ_VSI_Q_OPT_RSS_HASH_SYM_TPLZ;
  910. if (ice_set_rss_hfunc(vsi, hfunc))
  911. v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
  912. error_param:
  913. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_RSS_HFUNC, v_ret,
  914. NULL, 0);
  915. }
  916. /**
  917. * ice_vc_cfg_promiscuous_mode_msg
  918. * @vf: pointer to the VF info
  919. * @msg: pointer to the msg buffer
  920. *
  921. * called from the VF to configure VF VSIs promiscuous mode
  922. */
  923. static int ice_vc_cfg_promiscuous_mode_msg(struct ice_vf *vf, u8 *msg)
  924. {
  925. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  926. bool rm_promisc, alluni = false, allmulti = false;
  927. struct virtchnl_promisc_info *info =
  928. (struct virtchnl_promisc_info *)msg;
  929. struct ice_vsi_vlan_ops *vlan_ops;
  930. int mcast_err = 0, ucast_err = 0;
  931. struct ice_pf *pf = vf->pf;
  932. struct ice_vsi *vsi;
  933. u8 mcast_m, ucast_m;
  934. struct device *dev;
  935. int ret = 0;
  936. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  937. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  938. goto error_param;
  939. }
  940. if (!ice_vc_isvalid_vsi_id(vf, info->vsi_id)) {
  941. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  942. goto error_param;
  943. }
  944. vsi = ice_get_vf_vsi(vf);
  945. if (!vsi) {
  946. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  947. goto error_param;
  948. }
  949. dev = ice_pf_to_dev(pf);
  950. if (!ice_is_vf_trusted(vf)) {
  951. dev_err(dev, "Unprivileged VF %d is attempting to configure promiscuous mode\n",
  952. vf->vf_id);
  953. /* Leave v_ret alone, lie to the VF on purpose. */
  954. goto error_param;
  955. }
  956. if (info->flags & FLAG_VF_UNICAST_PROMISC)
  957. alluni = true;
  958. if (info->flags & FLAG_VF_MULTICAST_PROMISC)
  959. allmulti = true;
  960. rm_promisc = !allmulti && !alluni;
  961. vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
  962. if (rm_promisc)
  963. ret = vlan_ops->ena_rx_filtering(vsi);
  964. else
  965. ret = vlan_ops->dis_rx_filtering(vsi);
  966. if (ret) {
  967. dev_err(dev, "Failed to configure VLAN pruning in promiscuous mode\n");
  968. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  969. goto error_param;
  970. }
  971. ice_vf_get_promisc_masks(vf, vsi, &ucast_m, &mcast_m);
  972. if (!test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, pf->flags)) {
  973. if (alluni) {
  974. /* in this case we're turning on promiscuous mode */
  975. ret = ice_set_dflt_vsi(vsi);
  976. } else {
  977. /* in this case we're turning off promiscuous mode */
  978. if (ice_is_dflt_vsi_in_use(vsi->port_info))
  979. ret = ice_clear_dflt_vsi(vsi);
  980. }
  981. /* in this case we're turning on/off only
  982. * allmulticast
  983. */
  984. if (allmulti)
  985. mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
  986. else
  987. mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
  988. if (ret) {
  989. dev_err(dev, "Turning on/off promiscuous mode for VF %d failed, error: %d\n",
  990. vf->vf_id, ret);
  991. v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
  992. goto error_param;
  993. }
  994. } else {
  995. if (alluni)
  996. ucast_err = ice_vf_set_vsi_promisc(vf, vsi, ucast_m);
  997. else
  998. ucast_err = ice_vf_clear_vsi_promisc(vf, vsi, ucast_m);
  999. if (allmulti)
  1000. mcast_err = ice_vf_set_vsi_promisc(vf, vsi, mcast_m);
  1001. else
  1002. mcast_err = ice_vf_clear_vsi_promisc(vf, vsi, mcast_m);
  1003. if (ucast_err || mcast_err)
  1004. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1005. }
  1006. if (!mcast_err) {
  1007. if (allmulti &&
  1008. !test_and_set_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))
  1009. dev_info(dev, "VF %u successfully set multicast promiscuous mode\n",
  1010. vf->vf_id);
  1011. else if (!allmulti &&
  1012. test_and_clear_bit(ICE_VF_STATE_MC_PROMISC,
  1013. vf->vf_states))
  1014. dev_info(dev, "VF %u successfully unset multicast promiscuous mode\n",
  1015. vf->vf_id);
  1016. } else {
  1017. dev_err(dev, "Error while modifying multicast promiscuous mode for VF %u, error: %d\n",
  1018. vf->vf_id, mcast_err);
  1019. }
  1020. if (!ucast_err) {
  1021. if (alluni &&
  1022. !test_and_set_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states))
  1023. dev_info(dev, "VF %u successfully set unicast promiscuous mode\n",
  1024. vf->vf_id);
  1025. else if (!alluni &&
  1026. test_and_clear_bit(ICE_VF_STATE_UC_PROMISC,
  1027. vf->vf_states))
  1028. dev_info(dev, "VF %u successfully unset unicast promiscuous mode\n",
  1029. vf->vf_id);
  1030. } else {
  1031. dev_err(dev, "Error while modifying unicast promiscuous mode for VF %u, error: %d\n",
  1032. vf->vf_id, ucast_err);
  1033. }
  1034. error_param:
  1035. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  1036. v_ret, NULL, 0);
  1037. }
  1038. /**
  1039. * ice_vc_get_stats_msg
  1040. * @vf: pointer to the VF info
  1041. * @msg: pointer to the msg buffer
  1042. *
  1043. * called from the VF to get VSI stats
  1044. */
  1045. static int ice_vc_get_stats_msg(struct ice_vf *vf, u8 *msg)
  1046. {
  1047. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  1048. struct virtchnl_queue_select *vqs =
  1049. (struct virtchnl_queue_select *)msg;
  1050. struct ice_eth_stats stats = { 0 };
  1051. struct ice_vsi *vsi;
  1052. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  1053. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1054. goto error_param;
  1055. }
  1056. if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1057. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1058. goto error_param;
  1059. }
  1060. vsi = ice_get_vf_vsi(vf);
  1061. if (!vsi) {
  1062. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1063. goto error_param;
  1064. }
  1065. ice_update_eth_stats(vsi);
  1066. stats = vsi->eth_stats;
  1067. error_param:
  1068. /* send the response to the VF */
  1069. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_STATS, v_ret,
  1070. (u8 *)&stats, sizeof(stats));
  1071. }
  1072. /**
  1073. * ice_vc_validate_vqs_bitmaps - validate Rx/Tx queue bitmaps from VIRTCHNL
  1074. * @vqs: virtchnl_queue_select structure containing bitmaps to validate
  1075. *
  1076. * Return true on successful validation, else false
  1077. */
  1078. static bool ice_vc_validate_vqs_bitmaps(struct virtchnl_queue_select *vqs)
  1079. {
  1080. if ((!vqs->rx_queues && !vqs->tx_queues) ||
  1081. vqs->rx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF) ||
  1082. vqs->tx_queues >= BIT(ICE_MAX_RSS_QS_PER_VF))
  1083. return false;
  1084. return true;
  1085. }
  1086. /**
  1087. * ice_vf_ena_txq_interrupt - enable Tx queue interrupt via QINT_TQCTL
  1088. * @vsi: VSI of the VF to configure
  1089. * @q_idx: VF queue index used to determine the queue in the PF's space
  1090. */
  1091. static void ice_vf_ena_txq_interrupt(struct ice_vsi *vsi, u32 q_idx)
  1092. {
  1093. struct ice_hw *hw = &vsi->back->hw;
  1094. u32 pfq = vsi->txq_map[q_idx];
  1095. u32 reg;
  1096. reg = rd32(hw, QINT_TQCTL(pfq));
  1097. /* MSI-X index 0 in the VF's space is always for the OICR, which means
  1098. * this is most likely a poll mode VF driver, so don't enable an
  1099. * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
  1100. */
  1101. if (!(reg & QINT_TQCTL_MSIX_INDX_M))
  1102. return;
  1103. wr32(hw, QINT_TQCTL(pfq), reg | QINT_TQCTL_CAUSE_ENA_M);
  1104. }
  1105. /**
  1106. * ice_vf_ena_rxq_interrupt - enable Tx queue interrupt via QINT_RQCTL
  1107. * @vsi: VSI of the VF to configure
  1108. * @q_idx: VF queue index used to determine the queue in the PF's space
  1109. */
  1110. static void ice_vf_ena_rxq_interrupt(struct ice_vsi *vsi, u32 q_idx)
  1111. {
  1112. struct ice_hw *hw = &vsi->back->hw;
  1113. u32 pfq = vsi->rxq_map[q_idx];
  1114. u32 reg;
  1115. reg = rd32(hw, QINT_RQCTL(pfq));
  1116. /* MSI-X index 0 in the VF's space is always for the OICR, which means
  1117. * this is most likely a poll mode VF driver, so don't enable an
  1118. * interrupt that was never configured via VIRTCHNL_OP_CONFIG_IRQ_MAP
  1119. */
  1120. if (!(reg & QINT_RQCTL_MSIX_INDX_M))
  1121. return;
  1122. wr32(hw, QINT_RQCTL(pfq), reg | QINT_RQCTL_CAUSE_ENA_M);
  1123. }
  1124. /**
  1125. * ice_vc_ena_qs_msg
  1126. * @vf: pointer to the VF info
  1127. * @msg: pointer to the msg buffer
  1128. *
  1129. * called from the VF to enable all or specific queue(s)
  1130. */
  1131. static int ice_vc_ena_qs_msg(struct ice_vf *vf, u8 *msg)
  1132. {
  1133. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  1134. struct virtchnl_queue_select *vqs =
  1135. (struct virtchnl_queue_select *)msg;
  1136. struct ice_vsi *vsi;
  1137. unsigned long q_map;
  1138. u16 vf_q_id;
  1139. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  1140. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1141. goto error_param;
  1142. }
  1143. if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1144. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1145. goto error_param;
  1146. }
  1147. if (!ice_vc_validate_vqs_bitmaps(vqs)) {
  1148. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1149. goto error_param;
  1150. }
  1151. vsi = ice_get_vf_vsi(vf);
  1152. if (!vsi) {
  1153. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1154. goto error_param;
  1155. }
  1156. /* Enable only Rx rings, Tx rings were enabled by the FW when the
  1157. * Tx queue group list was configured and the context bits were
  1158. * programmed using ice_vsi_cfg_txqs
  1159. */
  1160. q_map = vqs->rx_queues;
  1161. for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
  1162. if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
  1163. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1164. goto error_param;
  1165. }
  1166. /* Skip queue if enabled */
  1167. if (test_bit(vf_q_id, vf->rxq_ena))
  1168. continue;
  1169. if (ice_vsi_ctrl_one_rx_ring(vsi, true, vf_q_id, true)) {
  1170. dev_err(ice_pf_to_dev(vsi->back), "Failed to enable Rx ring %d on VSI %d\n",
  1171. vf_q_id, vsi->vsi_num);
  1172. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1173. goto error_param;
  1174. }
  1175. ice_vf_ena_rxq_interrupt(vsi, vf_q_id);
  1176. set_bit(vf_q_id, vf->rxq_ena);
  1177. }
  1178. q_map = vqs->tx_queues;
  1179. for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
  1180. if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
  1181. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1182. goto error_param;
  1183. }
  1184. /* Skip queue if enabled */
  1185. if (test_bit(vf_q_id, vf->txq_ena))
  1186. continue;
  1187. ice_vf_ena_txq_interrupt(vsi, vf_q_id);
  1188. set_bit(vf_q_id, vf->txq_ena);
  1189. }
  1190. /* Set flag to indicate that queues are enabled */
  1191. if (v_ret == VIRTCHNL_STATUS_SUCCESS)
  1192. set_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
  1193. error_param:
  1194. /* send the response to the VF */
  1195. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_QUEUES, v_ret,
  1196. NULL, 0);
  1197. }
  1198. /**
  1199. * ice_vf_vsi_dis_single_txq - disable a single Tx queue
  1200. * @vf: VF to disable queue for
  1201. * @vsi: VSI for the VF
  1202. * @q_id: VF relative (0-based) queue ID
  1203. *
  1204. * Attempt to disable the Tx queue passed in. If the Tx queue was successfully
  1205. * disabled then clear q_id bit in the enabled queues bitmap and return
  1206. * success. Otherwise return error.
  1207. */
  1208. static int
  1209. ice_vf_vsi_dis_single_txq(struct ice_vf *vf, struct ice_vsi *vsi, u16 q_id)
  1210. {
  1211. struct ice_txq_meta txq_meta = { 0 };
  1212. struct ice_tx_ring *ring;
  1213. int err;
  1214. if (!test_bit(q_id, vf->txq_ena))
  1215. dev_dbg(ice_pf_to_dev(vsi->back), "Queue %u on VSI %u is not enabled, but stopping it anyway\n",
  1216. q_id, vsi->vsi_num);
  1217. ring = vsi->tx_rings[q_id];
  1218. if (!ring)
  1219. return -EINVAL;
  1220. ice_fill_txq_meta(vsi, ring, &txq_meta);
  1221. err = ice_vsi_stop_tx_ring(vsi, ICE_NO_RESET, vf->vf_id, ring, &txq_meta);
  1222. if (err) {
  1223. dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Tx ring %d on VSI %d\n",
  1224. q_id, vsi->vsi_num);
  1225. return err;
  1226. }
  1227. /* Clear enabled queues flag */
  1228. clear_bit(q_id, vf->txq_ena);
  1229. return 0;
  1230. }
  1231. /**
  1232. * ice_vc_dis_qs_msg
  1233. * @vf: pointer to the VF info
  1234. * @msg: pointer to the msg buffer
  1235. *
  1236. * called from the VF to disable all or specific queue(s)
  1237. */
  1238. static int ice_vc_dis_qs_msg(struct ice_vf *vf, u8 *msg)
  1239. {
  1240. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  1241. struct virtchnl_queue_select *vqs =
  1242. (struct virtchnl_queue_select *)msg;
  1243. struct ice_vsi *vsi;
  1244. unsigned long q_map;
  1245. u16 vf_q_id;
  1246. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) &&
  1247. !test_bit(ICE_VF_STATE_QS_ENA, vf->vf_states)) {
  1248. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1249. goto error_param;
  1250. }
  1251. if (!ice_vc_isvalid_vsi_id(vf, vqs->vsi_id)) {
  1252. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1253. goto error_param;
  1254. }
  1255. if (!ice_vc_validate_vqs_bitmaps(vqs)) {
  1256. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1257. goto error_param;
  1258. }
  1259. vsi = ice_get_vf_vsi(vf);
  1260. if (!vsi) {
  1261. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1262. goto error_param;
  1263. }
  1264. if (vqs->tx_queues) {
  1265. q_map = vqs->tx_queues;
  1266. for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
  1267. if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
  1268. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1269. goto error_param;
  1270. }
  1271. if (ice_vf_vsi_dis_single_txq(vf, vsi, vf_q_id)) {
  1272. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1273. goto error_param;
  1274. }
  1275. }
  1276. }
  1277. q_map = vqs->rx_queues;
  1278. /* speed up Rx queue disable by batching them if possible */
  1279. if (q_map &&
  1280. bitmap_equal(&q_map, vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF)) {
  1281. if (ice_vsi_stop_all_rx_rings(vsi)) {
  1282. dev_err(ice_pf_to_dev(vsi->back), "Failed to stop all Rx rings on VSI %d\n",
  1283. vsi->vsi_num);
  1284. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1285. goto error_param;
  1286. }
  1287. bitmap_zero(vf->rxq_ena, ICE_MAX_RSS_QS_PER_VF);
  1288. } else if (q_map) {
  1289. for_each_set_bit(vf_q_id, &q_map, ICE_MAX_RSS_QS_PER_VF) {
  1290. if (!ice_vc_isvalid_q_id(vsi, vf_q_id)) {
  1291. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1292. goto error_param;
  1293. }
  1294. /* Skip queue if not enabled */
  1295. if (!test_bit(vf_q_id, vf->rxq_ena))
  1296. continue;
  1297. if (ice_vsi_ctrl_one_rx_ring(vsi, false, vf_q_id,
  1298. true)) {
  1299. dev_err(ice_pf_to_dev(vsi->back), "Failed to stop Rx ring %d on VSI %d\n",
  1300. vf_q_id, vsi->vsi_num);
  1301. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1302. goto error_param;
  1303. }
  1304. /* Clear enabled queues flag */
  1305. clear_bit(vf_q_id, vf->rxq_ena);
  1306. }
  1307. }
  1308. /* Clear enabled queues flag */
  1309. if (v_ret == VIRTCHNL_STATUS_SUCCESS && ice_vf_has_no_qs_ena(vf))
  1310. clear_bit(ICE_VF_STATE_QS_ENA, vf->vf_states);
  1311. error_param:
  1312. /* send the response to the VF */
  1313. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_QUEUES, v_ret,
  1314. NULL, 0);
  1315. }
  1316. /**
  1317. * ice_cfg_interrupt
  1318. * @vf: pointer to the VF info
  1319. * @vsi: the VSI being configured
  1320. * @map: vector map for mapping vectors to queues
  1321. * @q_vector: structure for interrupt vector
  1322. * configure the IRQ to queue map
  1323. */
  1324. static enum virtchnl_status_code
  1325. ice_cfg_interrupt(struct ice_vf *vf, struct ice_vsi *vsi,
  1326. struct virtchnl_vector_map *map,
  1327. struct ice_q_vector *q_vector)
  1328. {
  1329. u16 vsi_q_id, vsi_q_id_idx;
  1330. unsigned long qmap;
  1331. q_vector->num_ring_rx = 0;
  1332. q_vector->num_ring_tx = 0;
  1333. qmap = map->rxq_map;
  1334. for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
  1335. vsi_q_id = vsi_q_id_idx;
  1336. if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
  1337. return VIRTCHNL_STATUS_ERR_PARAM;
  1338. q_vector->num_ring_rx++;
  1339. q_vector->rx.itr_idx = map->rxitr_idx;
  1340. vsi->rx_rings[vsi_q_id]->q_vector = q_vector;
  1341. ice_cfg_rxq_interrupt(vsi, vsi_q_id,
  1342. q_vector->vf_reg_idx,
  1343. q_vector->rx.itr_idx);
  1344. }
  1345. qmap = map->txq_map;
  1346. for_each_set_bit(vsi_q_id_idx, &qmap, ICE_MAX_RSS_QS_PER_VF) {
  1347. vsi_q_id = vsi_q_id_idx;
  1348. if (!ice_vc_isvalid_q_id(vsi, vsi_q_id))
  1349. return VIRTCHNL_STATUS_ERR_PARAM;
  1350. q_vector->num_ring_tx++;
  1351. q_vector->tx.itr_idx = map->txitr_idx;
  1352. vsi->tx_rings[vsi_q_id]->q_vector = q_vector;
  1353. ice_cfg_txq_interrupt(vsi, vsi_q_id,
  1354. q_vector->vf_reg_idx,
  1355. q_vector->tx.itr_idx);
  1356. }
  1357. return VIRTCHNL_STATUS_SUCCESS;
  1358. }
  1359. /**
  1360. * ice_vc_cfg_irq_map_msg
  1361. * @vf: pointer to the VF info
  1362. * @msg: pointer to the msg buffer
  1363. *
  1364. * called from the VF to configure the IRQ to queue map
  1365. */
  1366. static int ice_vc_cfg_irq_map_msg(struct ice_vf *vf, u8 *msg)
  1367. {
  1368. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  1369. u16 num_q_vectors_mapped, vsi_id, vector_id;
  1370. struct virtchnl_irq_map_info *irqmap_info;
  1371. struct virtchnl_vector_map *map;
  1372. struct ice_vsi *vsi;
  1373. int i;
  1374. irqmap_info = (struct virtchnl_irq_map_info *)msg;
  1375. num_q_vectors_mapped = irqmap_info->num_vectors;
  1376. /* Check to make sure number of VF vectors mapped is not greater than
  1377. * number of VF vectors originally allocated, and check that
  1378. * there is actually at least a single VF queue vector mapped
  1379. */
  1380. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
  1381. vf->num_msix < num_q_vectors_mapped ||
  1382. !num_q_vectors_mapped) {
  1383. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1384. goto error_param;
  1385. }
  1386. vsi = ice_get_vf_vsi(vf);
  1387. if (!vsi) {
  1388. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1389. goto error_param;
  1390. }
  1391. for (i = 0; i < num_q_vectors_mapped; i++) {
  1392. struct ice_q_vector *q_vector;
  1393. map = &irqmap_info->vecmap[i];
  1394. vector_id = map->vector_id;
  1395. vsi_id = map->vsi_id;
  1396. /* vector_id is always 0-based for each VF, and can never be
  1397. * larger than or equal to the max allowed interrupts per VF
  1398. */
  1399. if (!(vector_id < vf->num_msix) ||
  1400. !ice_vc_isvalid_vsi_id(vf, vsi_id) ||
  1401. (!vector_id && (map->rxq_map || map->txq_map))) {
  1402. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1403. goto error_param;
  1404. }
  1405. /* No need to map VF miscellaneous or rogue vector */
  1406. if (!vector_id)
  1407. continue;
  1408. /* Subtract non queue vector from vector_id passed by VF
  1409. * to get actual number of VSI queue vector array index
  1410. */
  1411. q_vector = vsi->q_vectors[vector_id - ICE_NONQ_VECS_VF];
  1412. if (!q_vector) {
  1413. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1414. goto error_param;
  1415. }
  1416. /* lookout for the invalid queue index */
  1417. v_ret = ice_cfg_interrupt(vf, vsi, map, q_vector);
  1418. if (v_ret)
  1419. goto error_param;
  1420. }
  1421. error_param:
  1422. /* send the response to the VF */
  1423. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_IRQ_MAP, v_ret,
  1424. NULL, 0);
  1425. }
  1426. /**
  1427. * ice_vc_cfg_qs_msg
  1428. * @vf: pointer to the VF info
  1429. * @msg: pointer to the msg buffer
  1430. *
  1431. * called from the VF to configure the Rx/Tx queues
  1432. */
  1433. static int ice_vc_cfg_qs_msg(struct ice_vf *vf, u8 *msg)
  1434. {
  1435. struct virtchnl_vsi_queue_config_info *qci =
  1436. (struct virtchnl_vsi_queue_config_info *)msg;
  1437. struct virtchnl_queue_pair_info *qpi;
  1438. struct ice_pf *pf = vf->pf;
  1439. struct ice_lag *lag;
  1440. struct ice_vsi *vsi;
  1441. u8 act_prt, pri_prt;
  1442. int i = -1, q_idx;
  1443. lag = pf->lag;
  1444. mutex_lock(&pf->lag_mutex);
  1445. act_prt = ICE_LAG_INVALID_PORT;
  1446. pri_prt = pf->hw.port_info->lport;
  1447. if (lag && lag->bonded && lag->primary) {
  1448. act_prt = lag->active_port;
  1449. if (act_prt != pri_prt && act_prt != ICE_LAG_INVALID_PORT &&
  1450. lag->upper_netdev)
  1451. ice_lag_move_vf_nodes_cfg(lag, act_prt, pri_prt);
  1452. else
  1453. act_prt = ICE_LAG_INVALID_PORT;
  1454. }
  1455. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states))
  1456. goto error_param;
  1457. if (!ice_vc_isvalid_vsi_id(vf, qci->vsi_id))
  1458. goto error_param;
  1459. vsi = ice_get_vf_vsi(vf);
  1460. if (!vsi)
  1461. goto error_param;
  1462. if (qci->num_queue_pairs > ICE_MAX_RSS_QS_PER_VF ||
  1463. qci->num_queue_pairs > min_t(u16, vsi->alloc_txq, vsi->alloc_rxq)) {
  1464. dev_err(ice_pf_to_dev(pf), "VF-%d requesting more than supported number of queues: %d\n",
  1465. vf->vf_id, min_t(u16, vsi->alloc_txq, vsi->alloc_rxq));
  1466. goto error_param;
  1467. }
  1468. for (i = 0; i < qci->num_queue_pairs; i++) {
  1469. if (!qci->qpair[i].rxq.crc_disable)
  1470. continue;
  1471. if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_CRC) ||
  1472. vf->vlan_strip_ena)
  1473. goto error_param;
  1474. }
  1475. for (i = 0; i < qci->num_queue_pairs; i++) {
  1476. qpi = &qci->qpair[i];
  1477. if (qpi->txq.vsi_id != qci->vsi_id ||
  1478. qpi->rxq.vsi_id != qci->vsi_id ||
  1479. qpi->rxq.queue_id != qpi->txq.queue_id ||
  1480. qpi->txq.headwb_enabled ||
  1481. !ice_vc_isvalid_ring_len(qpi->txq.ring_len) ||
  1482. !ice_vc_isvalid_ring_len(qpi->rxq.ring_len) ||
  1483. !ice_vc_isvalid_q_id(vsi, qpi->txq.queue_id)) {
  1484. goto error_param;
  1485. }
  1486. q_idx = qpi->rxq.queue_id;
  1487. /* make sure selected "q_idx" is in valid range of queues
  1488. * for selected "vsi"
  1489. */
  1490. if (q_idx >= vsi->alloc_txq || q_idx >= vsi->alloc_rxq) {
  1491. goto error_param;
  1492. }
  1493. /* copy Tx queue info from VF into VSI */
  1494. if (qpi->txq.ring_len > 0) {
  1495. vsi->tx_rings[q_idx]->dma = qpi->txq.dma_ring_addr;
  1496. vsi->tx_rings[q_idx]->count = qpi->txq.ring_len;
  1497. /* Disable any existing queue first */
  1498. if (ice_vf_vsi_dis_single_txq(vf, vsi, q_idx))
  1499. goto error_param;
  1500. /* Configure a queue with the requested settings */
  1501. if (ice_vsi_cfg_single_txq(vsi, vsi->tx_rings, q_idx)) {
  1502. dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure TX queue %d\n",
  1503. vf->vf_id, q_idx);
  1504. goto error_param;
  1505. }
  1506. }
  1507. /* copy Rx queue info from VF into VSI */
  1508. if (qpi->rxq.ring_len > 0) {
  1509. u16 max_frame_size = ice_vc_get_max_frame_size(vf);
  1510. struct ice_rx_ring *ring = vsi->rx_rings[q_idx];
  1511. u32 rxdid;
  1512. ring->dma = qpi->rxq.dma_ring_addr;
  1513. ring->count = qpi->rxq.ring_len;
  1514. if (qpi->rxq.crc_disable)
  1515. ring->flags |= ICE_RX_FLAGS_CRC_STRIP_DIS;
  1516. else
  1517. ring->flags &= ~ICE_RX_FLAGS_CRC_STRIP_DIS;
  1518. if (qpi->rxq.databuffer_size != 0 &&
  1519. (qpi->rxq.databuffer_size > ((16 * 1024) - 128) ||
  1520. qpi->rxq.databuffer_size < 1024))
  1521. goto error_param;
  1522. ring->rx_buf_len = qpi->rxq.databuffer_size;
  1523. if (qpi->rxq.max_pkt_size > max_frame_size ||
  1524. qpi->rxq.max_pkt_size < 64)
  1525. goto error_param;
  1526. ring->max_frame = qpi->rxq.max_pkt_size;
  1527. /* add space for the port VLAN since the VF driver is
  1528. * not expected to account for it in the MTU
  1529. * calculation
  1530. */
  1531. if (ice_vf_is_port_vlan_ena(vf))
  1532. ring->max_frame += VLAN_HLEN;
  1533. if (ice_vsi_cfg_single_rxq(vsi, q_idx)) {
  1534. dev_warn(ice_pf_to_dev(pf), "VF-%d failed to configure RX queue %d\n",
  1535. vf->vf_id, q_idx);
  1536. goto error_param;
  1537. }
  1538. /* If Rx flex desc is supported, select RXDID for Rx
  1539. * queues. Otherwise, use legacy 32byte descriptor
  1540. * format. Legacy 16byte descriptor is not supported.
  1541. * If this RXDID is selected, return error.
  1542. */
  1543. if (vf->driver_caps &
  1544. VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC) {
  1545. rxdid = qpi->rxq.rxdid;
  1546. if (!(BIT(rxdid) & pf->supported_rxdids))
  1547. goto error_param;
  1548. } else {
  1549. rxdid = ICE_RXDID_LEGACY_1;
  1550. }
  1551. ice_write_qrxflxp_cntxt(&vsi->back->hw,
  1552. vsi->rxq_map[q_idx],
  1553. rxdid, 0x03, false);
  1554. }
  1555. }
  1556. if (lag && lag->bonded && lag->primary &&
  1557. act_prt != ICE_LAG_INVALID_PORT)
  1558. ice_lag_move_vf_nodes_cfg(lag, pri_prt, act_prt);
  1559. mutex_unlock(&pf->lag_mutex);
  1560. /* send the response to the VF */
  1561. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  1562. VIRTCHNL_STATUS_SUCCESS, NULL, 0);
  1563. error_param:
  1564. /* disable whatever we can */
  1565. for (; i >= 0; i--) {
  1566. if (ice_vsi_ctrl_one_rx_ring(vsi, false, i, true))
  1567. dev_err(ice_pf_to_dev(pf), "VF-%d could not disable RX queue %d\n",
  1568. vf->vf_id, i);
  1569. if (ice_vf_vsi_dis_single_txq(vf, vsi, i))
  1570. dev_err(ice_pf_to_dev(pf), "VF-%d could not disable TX queue %d\n",
  1571. vf->vf_id, i);
  1572. }
  1573. if (lag && lag->bonded && lag->primary &&
  1574. act_prt != ICE_LAG_INVALID_PORT)
  1575. ice_lag_move_vf_nodes_cfg(lag, pri_prt, act_prt);
  1576. mutex_unlock(&pf->lag_mutex);
  1577. ice_lag_move_new_vf_nodes(vf);
  1578. /* send the response to the VF */
  1579. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
  1580. VIRTCHNL_STATUS_ERR_PARAM, NULL, 0);
  1581. }
  1582. /**
  1583. * ice_can_vf_change_mac
  1584. * @vf: pointer to the VF info
  1585. *
  1586. * Return true if the VF is allowed to change its MAC filters, false otherwise
  1587. */
  1588. static bool ice_can_vf_change_mac(struct ice_vf *vf)
  1589. {
  1590. /* If the VF MAC address has been set administratively (via the
  1591. * ndo_set_vf_mac command), then deny permission to the VF to
  1592. * add/delete unicast MAC addresses, unless the VF is trusted
  1593. */
  1594. if (vf->pf_set_mac && !ice_is_vf_trusted(vf))
  1595. return false;
  1596. return true;
  1597. }
  1598. /**
  1599. * ice_vc_ether_addr_type - get type of virtchnl_ether_addr
  1600. * @vc_ether_addr: used to extract the type
  1601. */
  1602. static u8
  1603. ice_vc_ether_addr_type(struct virtchnl_ether_addr *vc_ether_addr)
  1604. {
  1605. return (vc_ether_addr->type & VIRTCHNL_ETHER_ADDR_TYPE_MASK);
  1606. }
  1607. /**
  1608. * ice_is_vc_addr_legacy - check if the MAC address is from an older VF
  1609. * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
  1610. */
  1611. static bool
  1612. ice_is_vc_addr_legacy(struct virtchnl_ether_addr *vc_ether_addr)
  1613. {
  1614. u8 type = ice_vc_ether_addr_type(vc_ether_addr);
  1615. return (type == VIRTCHNL_ETHER_ADDR_LEGACY);
  1616. }
  1617. /**
  1618. * ice_is_vc_addr_primary - check if the MAC address is the VF's primary MAC
  1619. * @vc_ether_addr: VIRTCHNL structure that contains MAC and type
  1620. *
  1621. * This function should only be called when the MAC address in
  1622. * virtchnl_ether_addr is a valid unicast MAC
  1623. */
  1624. static bool
  1625. ice_is_vc_addr_primary(struct virtchnl_ether_addr __maybe_unused *vc_ether_addr)
  1626. {
  1627. u8 type = ice_vc_ether_addr_type(vc_ether_addr);
  1628. return (type == VIRTCHNL_ETHER_ADDR_PRIMARY);
  1629. }
  1630. /**
  1631. * ice_vfhw_mac_add - update the VF's cached hardware MAC if allowed
  1632. * @vf: VF to update
  1633. * @vc_ether_addr: structure from VIRTCHNL with MAC to add
  1634. */
  1635. static void
  1636. ice_vfhw_mac_add(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
  1637. {
  1638. u8 *mac_addr = vc_ether_addr->addr;
  1639. if (!is_valid_ether_addr(mac_addr))
  1640. return;
  1641. /* only allow legacy VF drivers to set the device and hardware MAC if it
  1642. * is zero and allow new VF drivers to set the hardware MAC if the type
  1643. * was correctly specified over VIRTCHNL
  1644. */
  1645. if ((ice_is_vc_addr_legacy(vc_ether_addr) &&
  1646. is_zero_ether_addr(vf->hw_lan_addr)) ||
  1647. ice_is_vc_addr_primary(vc_ether_addr)) {
  1648. ether_addr_copy(vf->dev_lan_addr, mac_addr);
  1649. ether_addr_copy(vf->hw_lan_addr, mac_addr);
  1650. }
  1651. /* hardware and device MACs are already set, but its possible that the
  1652. * VF driver sent the VIRTCHNL_OP_ADD_ETH_ADDR message before the
  1653. * VIRTCHNL_OP_DEL_ETH_ADDR when trying to update its MAC, so save it
  1654. * away for the legacy VF driver case as it will be updated in the
  1655. * delete flow for this case
  1656. */
  1657. if (ice_is_vc_addr_legacy(vc_ether_addr)) {
  1658. ether_addr_copy(vf->legacy_last_added_umac.addr,
  1659. mac_addr);
  1660. vf->legacy_last_added_umac.time_modified = jiffies;
  1661. }
  1662. }
  1663. /**
  1664. * ice_vc_add_mac_addr - attempt to add the MAC address passed in
  1665. * @vf: pointer to the VF info
  1666. * @vsi: pointer to the VF's VSI
  1667. * @vc_ether_addr: VIRTCHNL MAC address structure used to add MAC
  1668. */
  1669. static int
  1670. ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
  1671. struct virtchnl_ether_addr *vc_ether_addr)
  1672. {
  1673. struct device *dev = ice_pf_to_dev(vf->pf);
  1674. u8 *mac_addr = vc_ether_addr->addr;
  1675. int ret;
  1676. /* device MAC already added */
  1677. if (ether_addr_equal(mac_addr, vf->dev_lan_addr))
  1678. return 0;
  1679. if (is_unicast_ether_addr(mac_addr) && !ice_can_vf_change_mac(vf)) {
  1680. dev_err(dev, "VF attempting to override administratively set MAC address, bring down and up the VF interface to resume normal operation\n");
  1681. return -EPERM;
  1682. }
  1683. ret = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
  1684. if (ret == -EEXIST) {
  1685. dev_dbg(dev, "MAC %pM already exists for VF %d\n", mac_addr,
  1686. vf->vf_id);
  1687. /* don't return since we might need to update
  1688. * the primary MAC in ice_vfhw_mac_add() below
  1689. */
  1690. } else if (ret) {
  1691. dev_err(dev, "Failed to add MAC %pM for VF %d\n, error %d\n",
  1692. mac_addr, vf->vf_id, ret);
  1693. return ret;
  1694. } else {
  1695. vf->num_mac++;
  1696. }
  1697. ice_vfhw_mac_add(vf, vc_ether_addr);
  1698. return ret;
  1699. }
  1700. /**
  1701. * ice_is_legacy_umac_expired - check if last added legacy unicast MAC expired
  1702. * @last_added_umac: structure used to check expiration
  1703. */
  1704. static bool ice_is_legacy_umac_expired(struct ice_time_mac *last_added_umac)
  1705. {
  1706. #define ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME msecs_to_jiffies(3000)
  1707. return time_is_before_jiffies(last_added_umac->time_modified +
  1708. ICE_LEGACY_VF_MAC_CHANGE_EXPIRE_TIME);
  1709. }
  1710. /**
  1711. * ice_update_legacy_cached_mac - update cached hardware MAC for legacy VF
  1712. * @vf: VF to update
  1713. * @vc_ether_addr: structure from VIRTCHNL with MAC to check
  1714. *
  1715. * only update cached hardware MAC for legacy VF drivers on delete
  1716. * because we cannot guarantee order/type of MAC from the VF driver
  1717. */
  1718. static void
  1719. ice_update_legacy_cached_mac(struct ice_vf *vf,
  1720. struct virtchnl_ether_addr *vc_ether_addr)
  1721. {
  1722. if (!ice_is_vc_addr_legacy(vc_ether_addr) ||
  1723. ice_is_legacy_umac_expired(&vf->legacy_last_added_umac))
  1724. return;
  1725. ether_addr_copy(vf->dev_lan_addr, vf->legacy_last_added_umac.addr);
  1726. ether_addr_copy(vf->hw_lan_addr, vf->legacy_last_added_umac.addr);
  1727. }
  1728. /**
  1729. * ice_vfhw_mac_del - update the VF's cached hardware MAC if allowed
  1730. * @vf: VF to update
  1731. * @vc_ether_addr: structure from VIRTCHNL with MAC to delete
  1732. */
  1733. static void
  1734. ice_vfhw_mac_del(struct ice_vf *vf, struct virtchnl_ether_addr *vc_ether_addr)
  1735. {
  1736. u8 *mac_addr = vc_ether_addr->addr;
  1737. if (!is_valid_ether_addr(mac_addr) ||
  1738. !ether_addr_equal(vf->dev_lan_addr, mac_addr))
  1739. return;
  1740. /* allow the device MAC to be repopulated in the add flow and don't
  1741. * clear the hardware MAC (i.e. hw_lan_addr) here as that is meant
  1742. * to be persistent on VM reboot and across driver unload/load, which
  1743. * won't work if we clear the hardware MAC here
  1744. */
  1745. eth_zero_addr(vf->dev_lan_addr);
  1746. ice_update_legacy_cached_mac(vf, vc_ether_addr);
  1747. }
  1748. /**
  1749. * ice_vc_del_mac_addr - attempt to delete the MAC address passed in
  1750. * @vf: pointer to the VF info
  1751. * @vsi: pointer to the VF's VSI
  1752. * @vc_ether_addr: VIRTCHNL MAC address structure used to delete MAC
  1753. */
  1754. static int
  1755. ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi,
  1756. struct virtchnl_ether_addr *vc_ether_addr)
  1757. {
  1758. struct device *dev = ice_pf_to_dev(vf->pf);
  1759. u8 *mac_addr = vc_ether_addr->addr;
  1760. int status;
  1761. if (!ice_can_vf_change_mac(vf) &&
  1762. ether_addr_equal(vf->dev_lan_addr, mac_addr))
  1763. return 0;
  1764. status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
  1765. if (status == -ENOENT) {
  1766. dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
  1767. vf->vf_id);
  1768. return -ENOENT;
  1769. } else if (status) {
  1770. dev_err(dev, "Failed to delete MAC %pM for VF %d, error %d\n",
  1771. mac_addr, vf->vf_id, status);
  1772. return -EIO;
  1773. }
  1774. ice_vfhw_mac_del(vf, vc_ether_addr);
  1775. vf->num_mac--;
  1776. return 0;
  1777. }
  1778. /**
  1779. * ice_vc_handle_mac_addr_msg
  1780. * @vf: pointer to the VF info
  1781. * @msg: pointer to the msg buffer
  1782. * @set: true if MAC filters are being set, false otherwise
  1783. *
  1784. * add guest MAC address filter
  1785. */
  1786. static int
  1787. ice_vc_handle_mac_addr_msg(struct ice_vf *vf, u8 *msg, bool set)
  1788. {
  1789. int (*ice_vc_cfg_mac)
  1790. (struct ice_vf *vf, struct ice_vsi *vsi,
  1791. struct virtchnl_ether_addr *virtchnl_ether_addr);
  1792. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  1793. struct virtchnl_ether_addr_list *al =
  1794. (struct virtchnl_ether_addr_list *)msg;
  1795. struct ice_pf *pf = vf->pf;
  1796. enum virtchnl_ops vc_op;
  1797. struct ice_vsi *vsi;
  1798. int i;
  1799. if (set) {
  1800. vc_op = VIRTCHNL_OP_ADD_ETH_ADDR;
  1801. ice_vc_cfg_mac = ice_vc_add_mac_addr;
  1802. } else {
  1803. vc_op = VIRTCHNL_OP_DEL_ETH_ADDR;
  1804. ice_vc_cfg_mac = ice_vc_del_mac_addr;
  1805. }
  1806. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
  1807. !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
  1808. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1809. goto handle_mac_exit;
  1810. }
  1811. /* If this VF is not privileged, then we can't add more than a
  1812. * limited number of addresses. Check to make sure that the
  1813. * additions do not push us over the limit.
  1814. */
  1815. if (set && !ice_is_vf_trusted(vf) &&
  1816. (vf->num_mac + al->num_elements) > ICE_MAX_MACADDR_PER_VF) {
  1817. dev_err(ice_pf_to_dev(pf), "Can't add more MAC addresses, because VF-%d is not trusted, switch the VF to trusted mode in order to add more functionalities\n",
  1818. vf->vf_id);
  1819. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1820. goto handle_mac_exit;
  1821. }
  1822. vsi = ice_get_vf_vsi(vf);
  1823. if (!vsi) {
  1824. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1825. goto handle_mac_exit;
  1826. }
  1827. for (i = 0; i < al->num_elements; i++) {
  1828. u8 *mac_addr = al->list[i].addr;
  1829. int result;
  1830. if (is_broadcast_ether_addr(mac_addr) ||
  1831. is_zero_ether_addr(mac_addr))
  1832. continue;
  1833. result = ice_vc_cfg_mac(vf, vsi, &al->list[i]);
  1834. if (result == -EEXIST || result == -ENOENT) {
  1835. continue;
  1836. } else if (result) {
  1837. v_ret = VIRTCHNL_STATUS_ERR_ADMIN_QUEUE_ERROR;
  1838. goto handle_mac_exit;
  1839. }
  1840. }
  1841. handle_mac_exit:
  1842. /* send the response to the VF */
  1843. return ice_vc_send_msg_to_vf(vf, vc_op, v_ret, NULL, 0);
  1844. }
  1845. /**
  1846. * ice_vc_add_mac_addr_msg
  1847. * @vf: pointer to the VF info
  1848. * @msg: pointer to the msg buffer
  1849. *
  1850. * add guest MAC address filter
  1851. */
  1852. static int ice_vc_add_mac_addr_msg(struct ice_vf *vf, u8 *msg)
  1853. {
  1854. return ice_vc_handle_mac_addr_msg(vf, msg, true);
  1855. }
  1856. /**
  1857. * ice_vc_del_mac_addr_msg
  1858. * @vf: pointer to the VF info
  1859. * @msg: pointer to the msg buffer
  1860. *
  1861. * remove guest MAC address filter
  1862. */
  1863. static int ice_vc_del_mac_addr_msg(struct ice_vf *vf, u8 *msg)
  1864. {
  1865. return ice_vc_handle_mac_addr_msg(vf, msg, false);
  1866. }
  1867. /**
  1868. * ice_vc_request_qs_msg
  1869. * @vf: pointer to the VF info
  1870. * @msg: pointer to the msg buffer
  1871. *
  1872. * VFs get a default number of queues but can use this message to request a
  1873. * different number. If the request is successful, PF will reset the VF and
  1874. * return 0. If unsuccessful, PF will send message informing VF of number of
  1875. * available queue pairs via virtchnl message response to VF.
  1876. */
  1877. static int ice_vc_request_qs_msg(struct ice_vf *vf, u8 *msg)
  1878. {
  1879. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  1880. struct virtchnl_vf_res_request *vfres =
  1881. (struct virtchnl_vf_res_request *)msg;
  1882. u16 req_queues = vfres->num_queue_pairs;
  1883. struct ice_pf *pf = vf->pf;
  1884. u16 max_allowed_vf_queues;
  1885. u16 tx_rx_queue_left;
  1886. struct device *dev;
  1887. u16 cur_queues;
  1888. dev = ice_pf_to_dev(pf);
  1889. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  1890. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  1891. goto error_param;
  1892. }
  1893. cur_queues = vf->num_vf_qs;
  1894. tx_rx_queue_left = min_t(u16, ice_get_avail_txq_count(pf),
  1895. ice_get_avail_rxq_count(pf));
  1896. max_allowed_vf_queues = tx_rx_queue_left + cur_queues;
  1897. if (!req_queues) {
  1898. dev_err(dev, "VF %d tried to request 0 queues. Ignoring.\n",
  1899. vf->vf_id);
  1900. } else if (req_queues > ICE_MAX_RSS_QS_PER_VF) {
  1901. dev_err(dev, "VF %d tried to request more than %d queues.\n",
  1902. vf->vf_id, ICE_MAX_RSS_QS_PER_VF);
  1903. vfres->num_queue_pairs = ICE_MAX_RSS_QS_PER_VF;
  1904. } else if (req_queues > cur_queues &&
  1905. req_queues - cur_queues > tx_rx_queue_left) {
  1906. dev_warn(dev, "VF %d requested %u more queues, but only %u left.\n",
  1907. vf->vf_id, req_queues - cur_queues, tx_rx_queue_left);
  1908. vfres->num_queue_pairs = min_t(u16, max_allowed_vf_queues,
  1909. ICE_MAX_RSS_QS_PER_VF);
  1910. } else {
  1911. /* request is successful, then reset VF */
  1912. vf->num_req_qs = req_queues;
  1913. ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
  1914. dev_info(dev, "VF %d granted request of %u queues.\n",
  1915. vf->vf_id, req_queues);
  1916. return 0;
  1917. }
  1918. error_param:
  1919. /* send the response to the VF */
  1920. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_REQUEST_QUEUES,
  1921. v_ret, (u8 *)vfres, sizeof(*vfres));
  1922. }
  1923. /**
  1924. * ice_vf_vlan_offload_ena - determine if capabilities support VLAN offloads
  1925. * @caps: VF driver negotiated capabilities
  1926. *
  1927. * Return true if VIRTCHNL_VF_OFFLOAD_VLAN capability is set, else return false
  1928. */
  1929. static bool ice_vf_vlan_offload_ena(u32 caps)
  1930. {
  1931. return !!(caps & VIRTCHNL_VF_OFFLOAD_VLAN);
  1932. }
  1933. /**
  1934. * ice_is_vlan_promisc_allowed - check if VLAN promiscuous config is allowed
  1935. * @vf: VF used to determine if VLAN promiscuous config is allowed
  1936. */
  1937. static bool ice_is_vlan_promisc_allowed(struct ice_vf *vf)
  1938. {
  1939. if ((test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
  1940. test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states)) &&
  1941. test_bit(ICE_FLAG_VF_TRUE_PROMISC_ENA, vf->pf->flags))
  1942. return true;
  1943. return false;
  1944. }
  1945. /**
  1946. * ice_vf_ena_vlan_promisc - Enable Tx/Rx VLAN promiscuous for the VLAN
  1947. * @vsi: VF's VSI used to enable VLAN promiscuous mode
  1948. * @vlan: VLAN used to enable VLAN promiscuous
  1949. *
  1950. * This function should only be called if VLAN promiscuous mode is allowed,
  1951. * which can be determined via ice_is_vlan_promisc_allowed().
  1952. */
  1953. static int ice_vf_ena_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
  1954. {
  1955. u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
  1956. int status;
  1957. status = ice_fltr_set_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
  1958. vlan->vid);
  1959. if (status && status != -EEXIST)
  1960. return status;
  1961. return 0;
  1962. }
  1963. /**
  1964. * ice_vf_dis_vlan_promisc - Disable Tx/Rx VLAN promiscuous for the VLAN
  1965. * @vsi: VF's VSI used to disable VLAN promiscuous mode for
  1966. * @vlan: VLAN used to disable VLAN promiscuous
  1967. *
  1968. * This function should only be called if VLAN promiscuous mode is allowed,
  1969. * which can be determined via ice_is_vlan_promisc_allowed().
  1970. */
  1971. static int ice_vf_dis_vlan_promisc(struct ice_vsi *vsi, struct ice_vlan *vlan)
  1972. {
  1973. u8 promisc_m = ICE_PROMISC_VLAN_TX | ICE_PROMISC_VLAN_RX;
  1974. int status;
  1975. status = ice_fltr_clear_vsi_promisc(&vsi->back->hw, vsi->idx, promisc_m,
  1976. vlan->vid);
  1977. if (status && status != -ENOENT)
  1978. return status;
  1979. return 0;
  1980. }
  1981. /**
  1982. * ice_vf_has_max_vlans - check if VF already has the max allowed VLAN filters
  1983. * @vf: VF to check against
  1984. * @vsi: VF's VSI
  1985. *
  1986. * If the VF is trusted then the VF is allowed to add as many VLANs as it
  1987. * wants to, so return false.
  1988. *
  1989. * When the VF is untrusted compare the number of non-zero VLANs + 1 to the max
  1990. * allowed VLANs for an untrusted VF. Return the result of this comparison.
  1991. */
  1992. static bool ice_vf_has_max_vlans(struct ice_vf *vf, struct ice_vsi *vsi)
  1993. {
  1994. if (ice_is_vf_trusted(vf))
  1995. return false;
  1996. #define ICE_VF_ADDED_VLAN_ZERO_FLTRS 1
  1997. return ((ice_vsi_num_non_zero_vlans(vsi) +
  1998. ICE_VF_ADDED_VLAN_ZERO_FLTRS) >= ICE_MAX_VLAN_PER_VF);
  1999. }
  2000. /**
  2001. * ice_vc_process_vlan_msg
  2002. * @vf: pointer to the VF info
  2003. * @msg: pointer to the msg buffer
  2004. * @add_v: Add VLAN if true, otherwise delete VLAN
  2005. *
  2006. * Process virtchnl op to add or remove programmed guest VLAN ID
  2007. */
  2008. static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
  2009. {
  2010. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2011. struct virtchnl_vlan_filter_list *vfl =
  2012. (struct virtchnl_vlan_filter_list *)msg;
  2013. struct ice_pf *pf = vf->pf;
  2014. bool vlan_promisc = false;
  2015. struct ice_vsi *vsi;
  2016. struct device *dev;
  2017. int status = 0;
  2018. int i;
  2019. dev = ice_pf_to_dev(pf);
  2020. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2021. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2022. goto error_param;
  2023. }
  2024. if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
  2025. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2026. goto error_param;
  2027. }
  2028. if (!ice_vc_isvalid_vsi_id(vf, vfl->vsi_id)) {
  2029. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2030. goto error_param;
  2031. }
  2032. for (i = 0; i < vfl->num_elements; i++) {
  2033. if (vfl->vlan_id[i] >= VLAN_N_VID) {
  2034. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2035. dev_err(dev, "invalid VF VLAN id %d\n",
  2036. vfl->vlan_id[i]);
  2037. goto error_param;
  2038. }
  2039. }
  2040. vsi = ice_get_vf_vsi(vf);
  2041. if (!vsi) {
  2042. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2043. goto error_param;
  2044. }
  2045. if (add_v && ice_vf_has_max_vlans(vf, vsi)) {
  2046. dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
  2047. vf->vf_id);
  2048. /* There is no need to let VF know about being not trusted,
  2049. * so we can just return success message here
  2050. */
  2051. goto error_param;
  2052. }
  2053. /* in DVM a VF can add/delete inner VLAN filters when
  2054. * VIRTCHNL_VF_OFFLOAD_VLAN is negotiated, so only reject in SVM
  2055. */
  2056. if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&pf->hw)) {
  2057. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2058. goto error_param;
  2059. }
  2060. /* in DVM VLAN promiscuous is based on the outer VLAN, which would be
  2061. * the port VLAN if VIRTCHNL_VF_OFFLOAD_VLAN was negotiated, so only
  2062. * allow vlan_promisc = true in SVM and if no port VLAN is configured
  2063. */
  2064. vlan_promisc = ice_is_vlan_promisc_allowed(vf) &&
  2065. !ice_is_dvm_ena(&pf->hw) &&
  2066. !ice_vf_is_port_vlan_ena(vf);
  2067. if (add_v) {
  2068. for (i = 0; i < vfl->num_elements; i++) {
  2069. u16 vid = vfl->vlan_id[i];
  2070. struct ice_vlan vlan;
  2071. if (ice_vf_has_max_vlans(vf, vsi)) {
  2072. dev_info(dev, "VF-%d is not trusted, switch the VF to trusted mode, in order to add more VLAN addresses\n",
  2073. vf->vf_id);
  2074. /* There is no need to let VF know about being
  2075. * not trusted, so we can just return success
  2076. * message here as well.
  2077. */
  2078. goto error_param;
  2079. }
  2080. /* we add VLAN 0 by default for each VF so we can enable
  2081. * Tx VLAN anti-spoof without triggering MDD events so
  2082. * we don't need to add it again here
  2083. */
  2084. if (!vid)
  2085. continue;
  2086. vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
  2087. status = vsi->inner_vlan_ops.add_vlan(vsi, &vlan);
  2088. if (status) {
  2089. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2090. goto error_param;
  2091. }
  2092. /* Enable VLAN filtering on first non-zero VLAN */
  2093. if (!vlan_promisc && vid && !ice_is_dvm_ena(&pf->hw)) {
  2094. if (vf->spoofchk) {
  2095. status = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
  2096. if (status) {
  2097. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2098. dev_err(dev, "Enable VLAN anti-spoofing on VLAN ID: %d failed error-%d\n",
  2099. vid, status);
  2100. goto error_param;
  2101. }
  2102. }
  2103. if (vsi->inner_vlan_ops.ena_rx_filtering(vsi)) {
  2104. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2105. dev_err(dev, "Enable VLAN pruning on VLAN ID: %d failed error-%d\n",
  2106. vid, status);
  2107. goto error_param;
  2108. }
  2109. } else if (vlan_promisc) {
  2110. status = ice_vf_ena_vlan_promisc(vsi, &vlan);
  2111. if (status) {
  2112. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2113. dev_err(dev, "Enable Unicast/multicast promiscuous mode on VLAN ID:%d failed error-%d\n",
  2114. vid, status);
  2115. }
  2116. }
  2117. }
  2118. } else {
  2119. /* In case of non_trusted VF, number of VLAN elements passed
  2120. * to PF for removal might be greater than number of VLANs
  2121. * filter programmed for that VF - So, use actual number of
  2122. * VLANS added earlier with add VLAN opcode. In order to avoid
  2123. * removing VLAN that doesn't exist, which result to sending
  2124. * erroneous failed message back to the VF
  2125. */
  2126. int num_vf_vlan;
  2127. num_vf_vlan = vsi->num_vlan;
  2128. for (i = 0; i < vfl->num_elements && i < num_vf_vlan; i++) {
  2129. u16 vid = vfl->vlan_id[i];
  2130. struct ice_vlan vlan;
  2131. /* we add VLAN 0 by default for each VF so we can enable
  2132. * Tx VLAN anti-spoof without triggering MDD events so
  2133. * we don't want a VIRTCHNL request to remove it
  2134. */
  2135. if (!vid)
  2136. continue;
  2137. vlan = ICE_VLAN(ETH_P_8021Q, vid, 0);
  2138. status = vsi->inner_vlan_ops.del_vlan(vsi, &vlan);
  2139. if (status) {
  2140. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2141. goto error_param;
  2142. }
  2143. /* Disable VLAN filtering when only VLAN 0 is left */
  2144. if (!ice_vsi_has_non_zero_vlans(vsi)) {
  2145. vsi->inner_vlan_ops.dis_tx_filtering(vsi);
  2146. vsi->inner_vlan_ops.dis_rx_filtering(vsi);
  2147. }
  2148. if (vlan_promisc)
  2149. ice_vf_dis_vlan_promisc(vsi, &vlan);
  2150. }
  2151. }
  2152. error_param:
  2153. /* send the response to the VF */
  2154. if (add_v)
  2155. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN, v_ret,
  2156. NULL, 0);
  2157. else
  2158. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN, v_ret,
  2159. NULL, 0);
  2160. }
  2161. /**
  2162. * ice_vc_add_vlan_msg
  2163. * @vf: pointer to the VF info
  2164. * @msg: pointer to the msg buffer
  2165. *
  2166. * Add and program guest VLAN ID
  2167. */
  2168. static int ice_vc_add_vlan_msg(struct ice_vf *vf, u8 *msg)
  2169. {
  2170. return ice_vc_process_vlan_msg(vf, msg, true);
  2171. }
  2172. /**
  2173. * ice_vc_remove_vlan_msg
  2174. * @vf: pointer to the VF info
  2175. * @msg: pointer to the msg buffer
  2176. *
  2177. * remove programmed guest VLAN ID
  2178. */
  2179. static int ice_vc_remove_vlan_msg(struct ice_vf *vf, u8 *msg)
  2180. {
  2181. return ice_vc_process_vlan_msg(vf, msg, false);
  2182. }
  2183. /**
  2184. * ice_vsi_is_rxq_crc_strip_dis - check if Rx queue CRC strip is disabled or not
  2185. * @vsi: pointer to the VF VSI info
  2186. */
  2187. static bool ice_vsi_is_rxq_crc_strip_dis(struct ice_vsi *vsi)
  2188. {
  2189. unsigned int i;
  2190. ice_for_each_alloc_rxq(vsi, i)
  2191. if (vsi->rx_rings[i]->flags & ICE_RX_FLAGS_CRC_STRIP_DIS)
  2192. return true;
  2193. return false;
  2194. }
  2195. /**
  2196. * ice_vc_ena_vlan_stripping
  2197. * @vf: pointer to the VF info
  2198. *
  2199. * Enable VLAN header stripping for a given VF
  2200. */
  2201. static int ice_vc_ena_vlan_stripping(struct ice_vf *vf)
  2202. {
  2203. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2204. struct ice_vsi *vsi;
  2205. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2206. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2207. goto error_param;
  2208. }
  2209. if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
  2210. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2211. goto error_param;
  2212. }
  2213. vsi = ice_get_vf_vsi(vf);
  2214. if (!vsi) {
  2215. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2216. goto error_param;
  2217. }
  2218. if (vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q))
  2219. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2220. else
  2221. vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
  2222. error_param:
  2223. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING,
  2224. v_ret, NULL, 0);
  2225. }
  2226. /**
  2227. * ice_vc_dis_vlan_stripping
  2228. * @vf: pointer to the VF info
  2229. *
  2230. * Disable VLAN header stripping for a given VF
  2231. */
  2232. static int ice_vc_dis_vlan_stripping(struct ice_vf *vf)
  2233. {
  2234. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2235. struct ice_vsi *vsi;
  2236. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2237. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2238. goto error_param;
  2239. }
  2240. if (!ice_vf_vlan_offload_ena(vf->driver_caps)) {
  2241. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2242. goto error_param;
  2243. }
  2244. vsi = ice_get_vf_vsi(vf);
  2245. if (!vsi) {
  2246. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2247. goto error_param;
  2248. }
  2249. if (vsi->inner_vlan_ops.dis_stripping(vsi))
  2250. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2251. else
  2252. vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
  2253. error_param:
  2254. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
  2255. v_ret, NULL, 0);
  2256. }
  2257. /**
  2258. * ice_vc_get_rss_hena - return the RSS HENA bits allowed by the hardware
  2259. * @vf: pointer to the VF info
  2260. */
  2261. static int ice_vc_get_rss_hena(struct ice_vf *vf)
  2262. {
  2263. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2264. struct virtchnl_rss_hena *vrh = NULL;
  2265. int len = 0, ret;
  2266. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2267. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2268. goto err;
  2269. }
  2270. if (!test_bit(ICE_FLAG_RSS_ENA, vf->pf->flags)) {
  2271. dev_err(ice_pf_to_dev(vf->pf), "RSS not supported by PF\n");
  2272. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2273. goto err;
  2274. }
  2275. len = sizeof(struct virtchnl_rss_hena);
  2276. vrh = kzalloc(len, GFP_KERNEL);
  2277. if (!vrh) {
  2278. v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
  2279. len = 0;
  2280. goto err;
  2281. }
  2282. vrh->hena = ICE_DEFAULT_RSS_HENA;
  2283. err:
  2284. /* send the response back to the VF */
  2285. ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_RSS_HENA_CAPS, v_ret,
  2286. (u8 *)vrh, len);
  2287. kfree(vrh);
  2288. return ret;
  2289. }
  2290. /**
  2291. * ice_vc_set_rss_hena - set RSS HENA bits for the VF
  2292. * @vf: pointer to the VF info
  2293. * @msg: pointer to the msg buffer
  2294. */
  2295. static int ice_vc_set_rss_hena(struct ice_vf *vf, u8 *msg)
  2296. {
  2297. struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
  2298. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2299. struct ice_pf *pf = vf->pf;
  2300. struct ice_vsi *vsi;
  2301. struct device *dev;
  2302. int status;
  2303. dev = ice_pf_to_dev(pf);
  2304. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2305. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2306. goto err;
  2307. }
  2308. if (!test_bit(ICE_FLAG_RSS_ENA, pf->flags)) {
  2309. dev_err(dev, "RSS not supported by PF\n");
  2310. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2311. goto err;
  2312. }
  2313. vsi = ice_get_vf_vsi(vf);
  2314. if (!vsi) {
  2315. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2316. goto err;
  2317. }
  2318. /* clear all previously programmed RSS configuration to allow VF drivers
  2319. * the ability to customize the RSS configuration and/or completely
  2320. * disable RSS
  2321. */
  2322. status = ice_rem_vsi_rss_cfg(&pf->hw, vsi->idx);
  2323. if (status && !vrh->hena) {
  2324. /* only report failure to clear the current RSS configuration if
  2325. * that was clearly the VF's intention (i.e. vrh->hena = 0)
  2326. */
  2327. v_ret = ice_err_to_virt_err(status);
  2328. goto err;
  2329. } else if (status) {
  2330. /* allow the VF to update the RSS configuration even on failure
  2331. * to clear the current RSS confguration in an attempt to keep
  2332. * RSS in a working state
  2333. */
  2334. dev_warn(dev, "Failed to clear the RSS configuration for VF %u\n",
  2335. vf->vf_id);
  2336. }
  2337. if (vrh->hena) {
  2338. status = ice_add_avf_rss_cfg(&pf->hw, vsi, vrh->hena);
  2339. v_ret = ice_err_to_virt_err(status);
  2340. }
  2341. /* send the response to the VF */
  2342. err:
  2343. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_SET_RSS_HENA, v_ret,
  2344. NULL, 0);
  2345. }
  2346. /**
  2347. * ice_vc_query_rxdid - query RXDID supported by DDP package
  2348. * @vf: pointer to VF info
  2349. *
  2350. * Called from VF to query a bitmap of supported flexible
  2351. * descriptor RXDIDs of a DDP package.
  2352. */
  2353. static int ice_vc_query_rxdid(struct ice_vf *vf)
  2354. {
  2355. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2356. struct virtchnl_supported_rxdids *rxdid = NULL;
  2357. struct ice_hw *hw = &vf->pf->hw;
  2358. struct ice_pf *pf = vf->pf;
  2359. int len = 0;
  2360. int ret, i;
  2361. u32 regval;
  2362. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2363. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2364. goto err;
  2365. }
  2366. if (!(vf->driver_caps & VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC)) {
  2367. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2368. goto err;
  2369. }
  2370. len = sizeof(struct virtchnl_supported_rxdids);
  2371. rxdid = kzalloc(len, GFP_KERNEL);
  2372. if (!rxdid) {
  2373. v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
  2374. len = 0;
  2375. goto err;
  2376. }
  2377. /* RXDIDs supported by DDP package can be read from the register
  2378. * to get the supported RXDID bitmap. But the legacy 32byte RXDID
  2379. * is not listed in DDP package, add it in the bitmap manually.
  2380. * Legacy 16byte descriptor is not supported.
  2381. */
  2382. rxdid->supported_rxdids |= BIT(ICE_RXDID_LEGACY_1);
  2383. for (i = ICE_RXDID_FLEX_NIC; i < ICE_FLEX_DESC_RXDID_MAX_NUM; i++) {
  2384. regval = rd32(hw, GLFLXP_RXDID_FLAGS(i, 0));
  2385. if ((regval >> GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_S)
  2386. & GLFLXP_RXDID_FLAGS_FLEXIFLAG_4N_M)
  2387. rxdid->supported_rxdids |= BIT(i);
  2388. }
  2389. pf->supported_rxdids = rxdid->supported_rxdids;
  2390. err:
  2391. ret = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
  2392. v_ret, (u8 *)rxdid, len);
  2393. kfree(rxdid);
  2394. return ret;
  2395. }
  2396. /**
  2397. * ice_vf_init_vlan_stripping - enable/disable VLAN stripping on initialization
  2398. * @vf: VF to enable/disable VLAN stripping for on initialization
  2399. *
  2400. * Set the default for VLAN stripping based on whether a port VLAN is configured
  2401. * and the current VLAN mode of the device.
  2402. */
  2403. static int ice_vf_init_vlan_stripping(struct ice_vf *vf)
  2404. {
  2405. struct ice_vsi *vsi = ice_get_vf_vsi(vf);
  2406. vf->vlan_strip_ena = 0;
  2407. if (!vsi)
  2408. return -EINVAL;
  2409. /* don't modify stripping if port VLAN is configured in SVM since the
  2410. * port VLAN is based on the inner/single VLAN in SVM
  2411. */
  2412. if (ice_vf_is_port_vlan_ena(vf) && !ice_is_dvm_ena(&vsi->back->hw))
  2413. return 0;
  2414. if (ice_vf_vlan_offload_ena(vf->driver_caps)) {
  2415. int err;
  2416. err = vsi->inner_vlan_ops.ena_stripping(vsi, ETH_P_8021Q);
  2417. if (!err)
  2418. vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
  2419. return err;
  2420. }
  2421. return vsi->inner_vlan_ops.dis_stripping(vsi);
  2422. }
  2423. static u16 ice_vc_get_max_vlan_fltrs(struct ice_vf *vf)
  2424. {
  2425. if (vf->trusted)
  2426. return VLAN_N_VID;
  2427. else
  2428. return ICE_MAX_VLAN_PER_VF;
  2429. }
  2430. /**
  2431. * ice_vf_outer_vlan_not_allowed - check if outer VLAN can be used
  2432. * @vf: VF that being checked for
  2433. *
  2434. * When the device is in double VLAN mode, check whether or not the outer VLAN
  2435. * is allowed.
  2436. */
  2437. static bool ice_vf_outer_vlan_not_allowed(struct ice_vf *vf)
  2438. {
  2439. if (ice_vf_is_port_vlan_ena(vf))
  2440. return true;
  2441. return false;
  2442. }
  2443. /**
  2444. * ice_vc_set_dvm_caps - set VLAN capabilities when the device is in DVM
  2445. * @vf: VF that capabilities are being set for
  2446. * @caps: VLAN capabilities to populate
  2447. *
  2448. * Determine VLAN capabilities support based on whether a port VLAN is
  2449. * configured. If a port VLAN is configured then the VF should use the inner
  2450. * filtering/offload capabilities since the port VLAN is using the outer VLAN
  2451. * capabilies.
  2452. */
  2453. static void
  2454. ice_vc_set_dvm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
  2455. {
  2456. struct virtchnl_vlan_supported_caps *supported_caps;
  2457. if (ice_vf_outer_vlan_not_allowed(vf)) {
  2458. /* until support for inner VLAN filtering is added when a port
  2459. * VLAN is configured, only support software offloaded inner
  2460. * VLANs when a port VLAN is confgured in DVM
  2461. */
  2462. supported_caps = &caps->filtering.filtering_support;
  2463. supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
  2464. supported_caps = &caps->offloads.stripping_support;
  2465. supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2466. VIRTCHNL_VLAN_TOGGLE |
  2467. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
  2468. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2469. supported_caps = &caps->offloads.insertion_support;
  2470. supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2471. VIRTCHNL_VLAN_TOGGLE |
  2472. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
  2473. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2474. caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
  2475. caps->offloads.ethertype_match =
  2476. VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
  2477. } else {
  2478. supported_caps = &caps->filtering.filtering_support;
  2479. supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
  2480. supported_caps->outer = VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2481. VIRTCHNL_VLAN_ETHERTYPE_88A8 |
  2482. VIRTCHNL_VLAN_ETHERTYPE_9100 |
  2483. VIRTCHNL_VLAN_ETHERTYPE_AND;
  2484. caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2485. VIRTCHNL_VLAN_ETHERTYPE_88A8 |
  2486. VIRTCHNL_VLAN_ETHERTYPE_9100;
  2487. supported_caps = &caps->offloads.stripping_support;
  2488. supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
  2489. VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2490. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
  2491. supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
  2492. VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2493. VIRTCHNL_VLAN_ETHERTYPE_88A8 |
  2494. VIRTCHNL_VLAN_ETHERTYPE_9100 |
  2495. VIRTCHNL_VLAN_ETHERTYPE_XOR |
  2496. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2;
  2497. supported_caps = &caps->offloads.insertion_support;
  2498. supported_caps->inner = VIRTCHNL_VLAN_TOGGLE |
  2499. VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2500. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
  2501. supported_caps->outer = VIRTCHNL_VLAN_TOGGLE |
  2502. VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2503. VIRTCHNL_VLAN_ETHERTYPE_88A8 |
  2504. VIRTCHNL_VLAN_ETHERTYPE_9100 |
  2505. VIRTCHNL_VLAN_ETHERTYPE_XOR |
  2506. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2;
  2507. caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
  2508. caps->offloads.ethertype_match =
  2509. VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
  2510. }
  2511. caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
  2512. }
  2513. /**
  2514. * ice_vc_set_svm_caps - set VLAN capabilities when the device is in SVM
  2515. * @vf: VF that capabilities are being set for
  2516. * @caps: VLAN capabilities to populate
  2517. *
  2518. * Determine VLAN capabilities support based on whether a port VLAN is
  2519. * configured. If a port VLAN is configured then the VF does not have any VLAN
  2520. * filtering or offload capabilities since the port VLAN is using the inner VLAN
  2521. * capabilities in single VLAN mode (SVM). Otherwise allow the VF to use inner
  2522. * VLAN fitlering and offload capabilities.
  2523. */
  2524. static void
  2525. ice_vc_set_svm_caps(struct ice_vf *vf, struct virtchnl_vlan_caps *caps)
  2526. {
  2527. struct virtchnl_vlan_supported_caps *supported_caps;
  2528. if (ice_vf_is_port_vlan_ena(vf)) {
  2529. supported_caps = &caps->filtering.filtering_support;
  2530. supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
  2531. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2532. supported_caps = &caps->offloads.stripping_support;
  2533. supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
  2534. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2535. supported_caps = &caps->offloads.insertion_support;
  2536. supported_caps->inner = VIRTCHNL_VLAN_UNSUPPORTED;
  2537. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2538. caps->offloads.ethertype_init = VIRTCHNL_VLAN_UNSUPPORTED;
  2539. caps->offloads.ethertype_match = VIRTCHNL_VLAN_UNSUPPORTED;
  2540. caps->filtering.max_filters = 0;
  2541. } else {
  2542. supported_caps = &caps->filtering.filtering_support;
  2543. supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100;
  2544. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2545. caps->filtering.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
  2546. supported_caps = &caps->offloads.stripping_support;
  2547. supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2548. VIRTCHNL_VLAN_TOGGLE |
  2549. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
  2550. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2551. supported_caps = &caps->offloads.insertion_support;
  2552. supported_caps->inner = VIRTCHNL_VLAN_ETHERTYPE_8100 |
  2553. VIRTCHNL_VLAN_TOGGLE |
  2554. VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1;
  2555. supported_caps->outer = VIRTCHNL_VLAN_UNSUPPORTED;
  2556. caps->offloads.ethertype_init = VIRTCHNL_VLAN_ETHERTYPE_8100;
  2557. caps->offloads.ethertype_match =
  2558. VIRTCHNL_ETHERTYPE_STRIPPING_MATCHES_INSERTION;
  2559. caps->filtering.max_filters = ice_vc_get_max_vlan_fltrs(vf);
  2560. }
  2561. }
  2562. /**
  2563. * ice_vc_get_offload_vlan_v2_caps - determine VF's VLAN capabilities
  2564. * @vf: VF to determine VLAN capabilities for
  2565. *
  2566. * This will only be called if the VF and PF successfully negotiated
  2567. * VIRTCHNL_VF_OFFLOAD_VLAN_V2.
  2568. *
  2569. * Set VLAN capabilities based on the current VLAN mode and whether a port VLAN
  2570. * is configured or not.
  2571. */
  2572. static int ice_vc_get_offload_vlan_v2_caps(struct ice_vf *vf)
  2573. {
  2574. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2575. struct virtchnl_vlan_caps *caps = NULL;
  2576. int err, len = 0;
  2577. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2578. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2579. goto out;
  2580. }
  2581. caps = kzalloc(sizeof(*caps), GFP_KERNEL);
  2582. if (!caps) {
  2583. v_ret = VIRTCHNL_STATUS_ERR_NO_MEMORY;
  2584. goto out;
  2585. }
  2586. len = sizeof(*caps);
  2587. if (ice_is_dvm_ena(&vf->pf->hw))
  2588. ice_vc_set_dvm_caps(vf, caps);
  2589. else
  2590. ice_vc_set_svm_caps(vf, caps);
  2591. /* store negotiated caps to prevent invalid VF messages */
  2592. memcpy(&vf->vlan_v2_caps, caps, sizeof(*caps));
  2593. out:
  2594. err = ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
  2595. v_ret, (u8 *)caps, len);
  2596. kfree(caps);
  2597. return err;
  2598. }
  2599. /**
  2600. * ice_vc_validate_vlan_tpid - validate VLAN TPID
  2601. * @filtering_caps: negotiated/supported VLAN filtering capabilities
  2602. * @tpid: VLAN TPID used for validation
  2603. *
  2604. * Convert the VLAN TPID to a VIRTCHNL_VLAN_ETHERTYPE_* and then compare against
  2605. * the negotiated/supported filtering caps to see if the VLAN TPID is valid.
  2606. */
  2607. static bool ice_vc_validate_vlan_tpid(u16 filtering_caps, u16 tpid)
  2608. {
  2609. enum virtchnl_vlan_support vlan_ethertype = VIRTCHNL_VLAN_UNSUPPORTED;
  2610. switch (tpid) {
  2611. case ETH_P_8021Q:
  2612. vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_8100;
  2613. break;
  2614. case ETH_P_8021AD:
  2615. vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_88A8;
  2616. break;
  2617. case ETH_P_QINQ1:
  2618. vlan_ethertype = VIRTCHNL_VLAN_ETHERTYPE_9100;
  2619. break;
  2620. }
  2621. if (!(filtering_caps & vlan_ethertype))
  2622. return false;
  2623. return true;
  2624. }
  2625. /**
  2626. * ice_vc_is_valid_vlan - validate the virtchnl_vlan
  2627. * @vc_vlan: virtchnl_vlan to validate
  2628. *
  2629. * If the VLAN TCI and VLAN TPID are 0, then this filter is invalid, so return
  2630. * false. Otherwise return true.
  2631. */
  2632. static bool ice_vc_is_valid_vlan(struct virtchnl_vlan *vc_vlan)
  2633. {
  2634. if (!vc_vlan->tci || !vc_vlan->tpid)
  2635. return false;
  2636. return true;
  2637. }
  2638. /**
  2639. * ice_vc_validate_vlan_filter_list - validate the filter list from the VF
  2640. * @vfc: negotiated/supported VLAN filtering capabilities
  2641. * @vfl: VLAN filter list from VF to validate
  2642. *
  2643. * Validate all of the filters in the VLAN filter list from the VF. If any of
  2644. * the checks fail then return false. Otherwise return true.
  2645. */
  2646. static bool
  2647. ice_vc_validate_vlan_filter_list(struct virtchnl_vlan_filtering_caps *vfc,
  2648. struct virtchnl_vlan_filter_list_v2 *vfl)
  2649. {
  2650. u16 i;
  2651. if (!vfl->num_elements)
  2652. return false;
  2653. for (i = 0; i < vfl->num_elements; i++) {
  2654. struct virtchnl_vlan_supported_caps *filtering_support =
  2655. &vfc->filtering_support;
  2656. struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
  2657. struct virtchnl_vlan *outer = &vlan_fltr->outer;
  2658. struct virtchnl_vlan *inner = &vlan_fltr->inner;
  2659. if ((ice_vc_is_valid_vlan(outer) &&
  2660. filtering_support->outer == VIRTCHNL_VLAN_UNSUPPORTED) ||
  2661. (ice_vc_is_valid_vlan(inner) &&
  2662. filtering_support->inner == VIRTCHNL_VLAN_UNSUPPORTED))
  2663. return false;
  2664. if ((outer->tci_mask &&
  2665. !(filtering_support->outer & VIRTCHNL_VLAN_FILTER_MASK)) ||
  2666. (inner->tci_mask &&
  2667. !(filtering_support->inner & VIRTCHNL_VLAN_FILTER_MASK)))
  2668. return false;
  2669. if (((outer->tci & VLAN_PRIO_MASK) &&
  2670. !(filtering_support->outer & VIRTCHNL_VLAN_PRIO)) ||
  2671. ((inner->tci & VLAN_PRIO_MASK) &&
  2672. !(filtering_support->inner & VIRTCHNL_VLAN_PRIO)))
  2673. return false;
  2674. if ((ice_vc_is_valid_vlan(outer) &&
  2675. !ice_vc_validate_vlan_tpid(filtering_support->outer,
  2676. outer->tpid)) ||
  2677. (ice_vc_is_valid_vlan(inner) &&
  2678. !ice_vc_validate_vlan_tpid(filtering_support->inner,
  2679. inner->tpid)))
  2680. return false;
  2681. }
  2682. return true;
  2683. }
  2684. /**
  2685. * ice_vc_to_vlan - transform from struct virtchnl_vlan to struct ice_vlan
  2686. * @vc_vlan: struct virtchnl_vlan to transform
  2687. */
  2688. static struct ice_vlan ice_vc_to_vlan(struct virtchnl_vlan *vc_vlan)
  2689. {
  2690. struct ice_vlan vlan = { 0 };
  2691. vlan.prio = FIELD_GET(VLAN_PRIO_MASK, vc_vlan->tci);
  2692. vlan.vid = vc_vlan->tci & VLAN_VID_MASK;
  2693. vlan.tpid = vc_vlan->tpid;
  2694. return vlan;
  2695. }
  2696. /**
  2697. * ice_vc_vlan_action - action to perform on the virthcnl_vlan
  2698. * @vsi: VF's VSI used to perform the action
  2699. * @vlan_action: function to perform the action with (i.e. add/del)
  2700. * @vlan: VLAN filter to perform the action with
  2701. */
  2702. static int
  2703. ice_vc_vlan_action(struct ice_vsi *vsi,
  2704. int (*vlan_action)(struct ice_vsi *, struct ice_vlan *),
  2705. struct ice_vlan *vlan)
  2706. {
  2707. int err;
  2708. err = vlan_action(vsi, vlan);
  2709. if (err)
  2710. return err;
  2711. return 0;
  2712. }
  2713. /**
  2714. * ice_vc_del_vlans - delete VLAN(s) from the virtchnl filter list
  2715. * @vf: VF used to delete the VLAN(s)
  2716. * @vsi: VF's VSI used to delete the VLAN(s)
  2717. * @vfl: virthchnl filter list used to delete the filters
  2718. */
  2719. static int
  2720. ice_vc_del_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
  2721. struct virtchnl_vlan_filter_list_v2 *vfl)
  2722. {
  2723. bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
  2724. int err;
  2725. u16 i;
  2726. for (i = 0; i < vfl->num_elements; i++) {
  2727. struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
  2728. struct virtchnl_vlan *vc_vlan;
  2729. vc_vlan = &vlan_fltr->outer;
  2730. if (ice_vc_is_valid_vlan(vc_vlan)) {
  2731. struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
  2732. err = ice_vc_vlan_action(vsi,
  2733. vsi->outer_vlan_ops.del_vlan,
  2734. &vlan);
  2735. if (err)
  2736. return err;
  2737. if (vlan_promisc)
  2738. ice_vf_dis_vlan_promisc(vsi, &vlan);
  2739. /* Disable VLAN filtering when only VLAN 0 is left */
  2740. if (!ice_vsi_has_non_zero_vlans(vsi) && ice_is_dvm_ena(&vsi->back->hw)) {
  2741. err = vsi->outer_vlan_ops.dis_tx_filtering(vsi);
  2742. if (err)
  2743. return err;
  2744. }
  2745. }
  2746. vc_vlan = &vlan_fltr->inner;
  2747. if (ice_vc_is_valid_vlan(vc_vlan)) {
  2748. struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
  2749. err = ice_vc_vlan_action(vsi,
  2750. vsi->inner_vlan_ops.del_vlan,
  2751. &vlan);
  2752. if (err)
  2753. return err;
  2754. /* no support for VLAN promiscuous on inner VLAN unless
  2755. * we are in Single VLAN Mode (SVM)
  2756. */
  2757. if (!ice_is_dvm_ena(&vsi->back->hw)) {
  2758. if (vlan_promisc)
  2759. ice_vf_dis_vlan_promisc(vsi, &vlan);
  2760. /* Disable VLAN filtering when only VLAN 0 is left */
  2761. if (!ice_vsi_has_non_zero_vlans(vsi)) {
  2762. err = vsi->inner_vlan_ops.dis_tx_filtering(vsi);
  2763. if (err)
  2764. return err;
  2765. }
  2766. }
  2767. }
  2768. }
  2769. return 0;
  2770. }
  2771. /**
  2772. * ice_vc_remove_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_DEL_VLAN_V2
  2773. * @vf: VF the message was received from
  2774. * @msg: message received from the VF
  2775. */
  2776. static int ice_vc_remove_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
  2777. {
  2778. struct virtchnl_vlan_filter_list_v2 *vfl =
  2779. (struct virtchnl_vlan_filter_list_v2 *)msg;
  2780. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2781. struct ice_vsi *vsi;
  2782. if (!ice_vc_validate_vlan_filter_list(&vf->vlan_v2_caps.filtering,
  2783. vfl)) {
  2784. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2785. goto out;
  2786. }
  2787. if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
  2788. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2789. goto out;
  2790. }
  2791. vsi = ice_get_vf_vsi(vf);
  2792. if (!vsi) {
  2793. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2794. goto out;
  2795. }
  2796. if (ice_vc_del_vlans(vf, vsi, vfl))
  2797. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2798. out:
  2799. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_VLAN_V2, v_ret, NULL,
  2800. 0);
  2801. }
  2802. /**
  2803. * ice_vc_add_vlans - add VLAN(s) from the virtchnl filter list
  2804. * @vf: VF used to add the VLAN(s)
  2805. * @vsi: VF's VSI used to add the VLAN(s)
  2806. * @vfl: virthchnl filter list used to add the filters
  2807. */
  2808. static int
  2809. ice_vc_add_vlans(struct ice_vf *vf, struct ice_vsi *vsi,
  2810. struct virtchnl_vlan_filter_list_v2 *vfl)
  2811. {
  2812. bool vlan_promisc = ice_is_vlan_promisc_allowed(vf);
  2813. int err;
  2814. u16 i;
  2815. for (i = 0; i < vfl->num_elements; i++) {
  2816. struct virtchnl_vlan_filter *vlan_fltr = &vfl->filters[i];
  2817. struct virtchnl_vlan *vc_vlan;
  2818. vc_vlan = &vlan_fltr->outer;
  2819. if (ice_vc_is_valid_vlan(vc_vlan)) {
  2820. struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
  2821. err = ice_vc_vlan_action(vsi,
  2822. vsi->outer_vlan_ops.add_vlan,
  2823. &vlan);
  2824. if (err)
  2825. return err;
  2826. if (vlan_promisc) {
  2827. err = ice_vf_ena_vlan_promisc(vsi, &vlan);
  2828. if (err)
  2829. return err;
  2830. }
  2831. /* Enable VLAN filtering on first non-zero VLAN */
  2832. if (vf->spoofchk && vlan.vid && ice_is_dvm_ena(&vsi->back->hw)) {
  2833. err = vsi->outer_vlan_ops.ena_tx_filtering(vsi);
  2834. if (err)
  2835. return err;
  2836. }
  2837. }
  2838. vc_vlan = &vlan_fltr->inner;
  2839. if (ice_vc_is_valid_vlan(vc_vlan)) {
  2840. struct ice_vlan vlan = ice_vc_to_vlan(vc_vlan);
  2841. err = ice_vc_vlan_action(vsi,
  2842. vsi->inner_vlan_ops.add_vlan,
  2843. &vlan);
  2844. if (err)
  2845. return err;
  2846. /* no support for VLAN promiscuous on inner VLAN unless
  2847. * we are in Single VLAN Mode (SVM)
  2848. */
  2849. if (!ice_is_dvm_ena(&vsi->back->hw)) {
  2850. if (vlan_promisc) {
  2851. err = ice_vf_ena_vlan_promisc(vsi, &vlan);
  2852. if (err)
  2853. return err;
  2854. }
  2855. /* Enable VLAN filtering on first non-zero VLAN */
  2856. if (vf->spoofchk && vlan.vid) {
  2857. err = vsi->inner_vlan_ops.ena_tx_filtering(vsi);
  2858. if (err)
  2859. return err;
  2860. }
  2861. }
  2862. }
  2863. }
  2864. return 0;
  2865. }
  2866. /**
  2867. * ice_vc_validate_add_vlan_filter_list - validate add filter list from the VF
  2868. * @vsi: VF VSI used to get number of existing VLAN filters
  2869. * @vfc: negotiated/supported VLAN filtering capabilities
  2870. * @vfl: VLAN filter list from VF to validate
  2871. *
  2872. * Validate all of the filters in the VLAN filter list from the VF during the
  2873. * VIRTCHNL_OP_ADD_VLAN_V2 opcode. If any of the checks fail then return false.
  2874. * Otherwise return true.
  2875. */
  2876. static bool
  2877. ice_vc_validate_add_vlan_filter_list(struct ice_vsi *vsi,
  2878. struct virtchnl_vlan_filtering_caps *vfc,
  2879. struct virtchnl_vlan_filter_list_v2 *vfl)
  2880. {
  2881. u16 num_requested_filters = ice_vsi_num_non_zero_vlans(vsi) +
  2882. vfl->num_elements;
  2883. if (num_requested_filters > vfc->max_filters)
  2884. return false;
  2885. return ice_vc_validate_vlan_filter_list(vfc, vfl);
  2886. }
  2887. /**
  2888. * ice_vc_add_vlan_v2_msg - virtchnl handler for VIRTCHNL_OP_ADD_VLAN_V2
  2889. * @vf: VF the message was received from
  2890. * @msg: message received from the VF
  2891. */
  2892. static int ice_vc_add_vlan_v2_msg(struct ice_vf *vf, u8 *msg)
  2893. {
  2894. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  2895. struct virtchnl_vlan_filter_list_v2 *vfl =
  2896. (struct virtchnl_vlan_filter_list_v2 *)msg;
  2897. struct ice_vsi *vsi;
  2898. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  2899. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2900. goto out;
  2901. }
  2902. if (!ice_vc_isvalid_vsi_id(vf, vfl->vport_id)) {
  2903. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2904. goto out;
  2905. }
  2906. vsi = ice_get_vf_vsi(vf);
  2907. if (!vsi) {
  2908. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2909. goto out;
  2910. }
  2911. if (!ice_vc_validate_add_vlan_filter_list(vsi,
  2912. &vf->vlan_v2_caps.filtering,
  2913. vfl)) {
  2914. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2915. goto out;
  2916. }
  2917. if (ice_vc_add_vlans(vf, vsi, vfl))
  2918. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  2919. out:
  2920. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_VLAN_V2, v_ret, NULL,
  2921. 0);
  2922. }
  2923. /**
  2924. * ice_vc_valid_vlan_setting - validate VLAN setting
  2925. * @negotiated_settings: negotiated VLAN settings during VF init
  2926. * @ethertype_setting: ethertype(s) requested for the VLAN setting
  2927. */
  2928. static bool
  2929. ice_vc_valid_vlan_setting(u32 negotiated_settings, u32 ethertype_setting)
  2930. {
  2931. if (ethertype_setting && !(negotiated_settings & ethertype_setting))
  2932. return false;
  2933. /* only allow a single VIRTCHNL_VLAN_ETHERTYPE if
  2934. * VIRTHCNL_VLAN_ETHERTYPE_AND is not negotiated/supported
  2935. */
  2936. if (!(negotiated_settings & VIRTCHNL_VLAN_ETHERTYPE_AND) &&
  2937. hweight32(ethertype_setting) > 1)
  2938. return false;
  2939. /* ability to modify the VLAN setting was not negotiated */
  2940. if (!(negotiated_settings & VIRTCHNL_VLAN_TOGGLE))
  2941. return false;
  2942. return true;
  2943. }
  2944. /**
  2945. * ice_vc_valid_vlan_setting_msg - validate the VLAN setting message
  2946. * @caps: negotiated VLAN settings during VF init
  2947. * @msg: message to validate
  2948. *
  2949. * Used to validate any VLAN virtchnl message sent as a
  2950. * virtchnl_vlan_setting structure. Validates the message against the
  2951. * negotiated/supported caps during VF driver init.
  2952. */
  2953. static bool
  2954. ice_vc_valid_vlan_setting_msg(struct virtchnl_vlan_supported_caps *caps,
  2955. struct virtchnl_vlan_setting *msg)
  2956. {
  2957. if ((!msg->outer_ethertype_setting &&
  2958. !msg->inner_ethertype_setting) ||
  2959. (!caps->outer && !caps->inner))
  2960. return false;
  2961. if (msg->outer_ethertype_setting &&
  2962. !ice_vc_valid_vlan_setting(caps->outer,
  2963. msg->outer_ethertype_setting))
  2964. return false;
  2965. if (msg->inner_ethertype_setting &&
  2966. !ice_vc_valid_vlan_setting(caps->inner,
  2967. msg->inner_ethertype_setting))
  2968. return false;
  2969. return true;
  2970. }
  2971. /**
  2972. * ice_vc_get_tpid - transform from VIRTCHNL_VLAN_ETHERTYPE_* to VLAN TPID
  2973. * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* used to get VLAN TPID
  2974. * @tpid: VLAN TPID to populate
  2975. */
  2976. static int ice_vc_get_tpid(u32 ethertype_setting, u16 *tpid)
  2977. {
  2978. switch (ethertype_setting) {
  2979. case VIRTCHNL_VLAN_ETHERTYPE_8100:
  2980. *tpid = ETH_P_8021Q;
  2981. break;
  2982. case VIRTCHNL_VLAN_ETHERTYPE_88A8:
  2983. *tpid = ETH_P_8021AD;
  2984. break;
  2985. case VIRTCHNL_VLAN_ETHERTYPE_9100:
  2986. *tpid = ETH_P_QINQ1;
  2987. break;
  2988. default:
  2989. *tpid = 0;
  2990. return -EINVAL;
  2991. }
  2992. return 0;
  2993. }
  2994. /**
  2995. * ice_vc_ena_vlan_offload - enable VLAN offload based on the ethertype_setting
  2996. * @vsi: VF's VSI used to enable the VLAN offload
  2997. * @ena_offload: function used to enable the VLAN offload
  2998. * @ethertype_setting: VIRTCHNL_VLAN_ETHERTYPE_* to enable offloads for
  2999. */
  3000. static int
  3001. ice_vc_ena_vlan_offload(struct ice_vsi *vsi,
  3002. int (*ena_offload)(struct ice_vsi *vsi, u16 tpid),
  3003. u32 ethertype_setting)
  3004. {
  3005. u16 tpid;
  3006. int err;
  3007. err = ice_vc_get_tpid(ethertype_setting, &tpid);
  3008. if (err)
  3009. return err;
  3010. err = ena_offload(vsi, tpid);
  3011. if (err)
  3012. return err;
  3013. return 0;
  3014. }
  3015. #define ICE_L2TSEL_QRX_CONTEXT_REG_IDX 3
  3016. #define ICE_L2TSEL_BIT_OFFSET 23
  3017. enum ice_l2tsel {
  3018. ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND,
  3019. ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1,
  3020. };
  3021. /**
  3022. * ice_vsi_update_l2tsel - update l2tsel field for all Rx rings on this VSI
  3023. * @vsi: VSI used to update l2tsel on
  3024. * @l2tsel: l2tsel setting requested
  3025. *
  3026. * Use the l2tsel setting to update all of the Rx queue context bits for l2tsel.
  3027. * This will modify which descriptor field the first offloaded VLAN will be
  3028. * stripped into.
  3029. */
  3030. static void ice_vsi_update_l2tsel(struct ice_vsi *vsi, enum ice_l2tsel l2tsel)
  3031. {
  3032. struct ice_hw *hw = &vsi->back->hw;
  3033. u32 l2tsel_bit;
  3034. int i;
  3035. if (l2tsel == ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND)
  3036. l2tsel_bit = 0;
  3037. else
  3038. l2tsel_bit = BIT(ICE_L2TSEL_BIT_OFFSET);
  3039. for (i = 0; i < vsi->alloc_rxq; i++) {
  3040. u16 pfq = vsi->rxq_map[i];
  3041. u32 qrx_context_offset;
  3042. u32 regval;
  3043. qrx_context_offset =
  3044. QRX_CONTEXT(ICE_L2TSEL_QRX_CONTEXT_REG_IDX, pfq);
  3045. regval = rd32(hw, qrx_context_offset);
  3046. regval &= ~BIT(ICE_L2TSEL_BIT_OFFSET);
  3047. regval |= l2tsel_bit;
  3048. wr32(hw, qrx_context_offset, regval);
  3049. }
  3050. }
  3051. /**
  3052. * ice_vc_ena_vlan_stripping_v2_msg
  3053. * @vf: VF the message was received from
  3054. * @msg: message received from the VF
  3055. *
  3056. * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2
  3057. */
  3058. static int ice_vc_ena_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
  3059. {
  3060. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  3061. struct virtchnl_vlan_supported_caps *stripping_support;
  3062. struct virtchnl_vlan_setting *strip_msg =
  3063. (struct virtchnl_vlan_setting *)msg;
  3064. u32 ethertype_setting;
  3065. struct ice_vsi *vsi;
  3066. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  3067. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3068. goto out;
  3069. }
  3070. if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
  3071. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3072. goto out;
  3073. }
  3074. vsi = ice_get_vf_vsi(vf);
  3075. if (!vsi) {
  3076. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3077. goto out;
  3078. }
  3079. stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
  3080. if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
  3081. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3082. goto out;
  3083. }
  3084. if (ice_vsi_is_rxq_crc_strip_dis(vsi)) {
  3085. v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
  3086. goto out;
  3087. }
  3088. ethertype_setting = strip_msg->outer_ethertype_setting;
  3089. if (ethertype_setting) {
  3090. if (ice_vc_ena_vlan_offload(vsi,
  3091. vsi->outer_vlan_ops.ena_stripping,
  3092. ethertype_setting)) {
  3093. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3094. goto out;
  3095. } else {
  3096. enum ice_l2tsel l2tsel =
  3097. ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG2_2ND;
  3098. /* PF tells the VF that the outer VLAN tag is always
  3099. * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
  3100. * inner is always extracted to
  3101. * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
  3102. * support outer stripping so the first tag always ends
  3103. * up in L2TAG2_2ND and the second/inner tag, if
  3104. * enabled, is extracted in L2TAG1.
  3105. */
  3106. ice_vsi_update_l2tsel(vsi, l2tsel);
  3107. vf->vlan_strip_ena |= ICE_OUTER_VLAN_STRIP_ENA;
  3108. }
  3109. }
  3110. ethertype_setting = strip_msg->inner_ethertype_setting;
  3111. if (ethertype_setting &&
  3112. ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_stripping,
  3113. ethertype_setting)) {
  3114. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3115. goto out;
  3116. }
  3117. if (ethertype_setting)
  3118. vf->vlan_strip_ena |= ICE_INNER_VLAN_STRIP_ENA;
  3119. out:
  3120. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
  3121. v_ret, NULL, 0);
  3122. }
  3123. /**
  3124. * ice_vc_dis_vlan_stripping_v2_msg
  3125. * @vf: VF the message was received from
  3126. * @msg: message received from the VF
  3127. *
  3128. * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2
  3129. */
  3130. static int ice_vc_dis_vlan_stripping_v2_msg(struct ice_vf *vf, u8 *msg)
  3131. {
  3132. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  3133. struct virtchnl_vlan_supported_caps *stripping_support;
  3134. struct virtchnl_vlan_setting *strip_msg =
  3135. (struct virtchnl_vlan_setting *)msg;
  3136. u32 ethertype_setting;
  3137. struct ice_vsi *vsi;
  3138. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  3139. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3140. goto out;
  3141. }
  3142. if (!ice_vc_isvalid_vsi_id(vf, strip_msg->vport_id)) {
  3143. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3144. goto out;
  3145. }
  3146. vsi = ice_get_vf_vsi(vf);
  3147. if (!vsi) {
  3148. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3149. goto out;
  3150. }
  3151. stripping_support = &vf->vlan_v2_caps.offloads.stripping_support;
  3152. if (!ice_vc_valid_vlan_setting_msg(stripping_support, strip_msg)) {
  3153. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3154. goto out;
  3155. }
  3156. ethertype_setting = strip_msg->outer_ethertype_setting;
  3157. if (ethertype_setting) {
  3158. if (vsi->outer_vlan_ops.dis_stripping(vsi)) {
  3159. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3160. goto out;
  3161. } else {
  3162. enum ice_l2tsel l2tsel =
  3163. ICE_L2TSEL_EXTRACT_FIRST_TAG_L2TAG1;
  3164. /* PF tells the VF that the outer VLAN tag is always
  3165. * extracted to VIRTCHNL_VLAN_TAG_LOCATION_L2TAG2_2 and
  3166. * inner is always extracted to
  3167. * VIRTCHNL_VLAN_TAG_LOCATION_L2TAG1. This is needed to
  3168. * support inner stripping while outer stripping is
  3169. * disabled so that the first and only tag is extracted
  3170. * in L2TAG1.
  3171. */
  3172. ice_vsi_update_l2tsel(vsi, l2tsel);
  3173. vf->vlan_strip_ena &= ~ICE_OUTER_VLAN_STRIP_ENA;
  3174. }
  3175. }
  3176. ethertype_setting = strip_msg->inner_ethertype_setting;
  3177. if (ethertype_setting && vsi->inner_vlan_ops.dis_stripping(vsi)) {
  3178. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3179. goto out;
  3180. }
  3181. if (ethertype_setting)
  3182. vf->vlan_strip_ena &= ~ICE_INNER_VLAN_STRIP_ENA;
  3183. out:
  3184. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
  3185. v_ret, NULL, 0);
  3186. }
  3187. /**
  3188. * ice_vc_ena_vlan_insertion_v2_msg
  3189. * @vf: VF the message was received from
  3190. * @msg: message received from the VF
  3191. *
  3192. * virthcnl handler for VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2
  3193. */
  3194. static int ice_vc_ena_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
  3195. {
  3196. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  3197. struct virtchnl_vlan_supported_caps *insertion_support;
  3198. struct virtchnl_vlan_setting *insertion_msg =
  3199. (struct virtchnl_vlan_setting *)msg;
  3200. u32 ethertype_setting;
  3201. struct ice_vsi *vsi;
  3202. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  3203. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3204. goto out;
  3205. }
  3206. if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
  3207. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3208. goto out;
  3209. }
  3210. vsi = ice_get_vf_vsi(vf);
  3211. if (!vsi) {
  3212. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3213. goto out;
  3214. }
  3215. insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
  3216. if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
  3217. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3218. goto out;
  3219. }
  3220. ethertype_setting = insertion_msg->outer_ethertype_setting;
  3221. if (ethertype_setting &&
  3222. ice_vc_ena_vlan_offload(vsi, vsi->outer_vlan_ops.ena_insertion,
  3223. ethertype_setting)) {
  3224. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3225. goto out;
  3226. }
  3227. ethertype_setting = insertion_msg->inner_ethertype_setting;
  3228. if (ethertype_setting &&
  3229. ice_vc_ena_vlan_offload(vsi, vsi->inner_vlan_ops.ena_insertion,
  3230. ethertype_setting)) {
  3231. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3232. goto out;
  3233. }
  3234. out:
  3235. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
  3236. v_ret, NULL, 0);
  3237. }
  3238. /**
  3239. * ice_vc_dis_vlan_insertion_v2_msg
  3240. * @vf: VF the message was received from
  3241. * @msg: message received from the VF
  3242. *
  3243. * virthcnl handler for VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2
  3244. */
  3245. static int ice_vc_dis_vlan_insertion_v2_msg(struct ice_vf *vf, u8 *msg)
  3246. {
  3247. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  3248. struct virtchnl_vlan_supported_caps *insertion_support;
  3249. struct virtchnl_vlan_setting *insertion_msg =
  3250. (struct virtchnl_vlan_setting *)msg;
  3251. u32 ethertype_setting;
  3252. struct ice_vsi *vsi;
  3253. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states)) {
  3254. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3255. goto out;
  3256. }
  3257. if (!ice_vc_isvalid_vsi_id(vf, insertion_msg->vport_id)) {
  3258. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3259. goto out;
  3260. }
  3261. vsi = ice_get_vf_vsi(vf);
  3262. if (!vsi) {
  3263. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3264. goto out;
  3265. }
  3266. insertion_support = &vf->vlan_v2_caps.offloads.insertion_support;
  3267. if (!ice_vc_valid_vlan_setting_msg(insertion_support, insertion_msg)) {
  3268. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3269. goto out;
  3270. }
  3271. ethertype_setting = insertion_msg->outer_ethertype_setting;
  3272. if (ethertype_setting && vsi->outer_vlan_ops.dis_insertion(vsi)) {
  3273. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3274. goto out;
  3275. }
  3276. ethertype_setting = insertion_msg->inner_ethertype_setting;
  3277. if (ethertype_setting && vsi->inner_vlan_ops.dis_insertion(vsi)) {
  3278. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3279. goto out;
  3280. }
  3281. out:
  3282. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
  3283. v_ret, NULL, 0);
  3284. }
  3285. static const struct ice_virtchnl_ops ice_virtchnl_dflt_ops = {
  3286. .get_ver_msg = ice_vc_get_ver_msg,
  3287. .get_vf_res_msg = ice_vc_get_vf_res_msg,
  3288. .reset_vf = ice_vc_reset_vf_msg,
  3289. .add_mac_addr_msg = ice_vc_add_mac_addr_msg,
  3290. .del_mac_addr_msg = ice_vc_del_mac_addr_msg,
  3291. .cfg_qs_msg = ice_vc_cfg_qs_msg,
  3292. .ena_qs_msg = ice_vc_ena_qs_msg,
  3293. .dis_qs_msg = ice_vc_dis_qs_msg,
  3294. .request_qs_msg = ice_vc_request_qs_msg,
  3295. .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
  3296. .config_rss_key = ice_vc_config_rss_key,
  3297. .config_rss_lut = ice_vc_config_rss_lut,
  3298. .config_rss_hfunc = ice_vc_config_rss_hfunc,
  3299. .get_stats_msg = ice_vc_get_stats_msg,
  3300. .cfg_promiscuous_mode_msg = ice_vc_cfg_promiscuous_mode_msg,
  3301. .add_vlan_msg = ice_vc_add_vlan_msg,
  3302. .remove_vlan_msg = ice_vc_remove_vlan_msg,
  3303. .query_rxdid = ice_vc_query_rxdid,
  3304. .get_rss_hena = ice_vc_get_rss_hena,
  3305. .set_rss_hena_msg = ice_vc_set_rss_hena,
  3306. .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
  3307. .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
  3308. .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
  3309. .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
  3310. .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
  3311. .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
  3312. .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
  3313. .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
  3314. .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
  3315. .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
  3316. .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
  3317. .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
  3318. };
  3319. /**
  3320. * ice_virtchnl_set_dflt_ops - Switch to default virtchnl ops
  3321. * @vf: the VF to switch ops
  3322. */
  3323. void ice_virtchnl_set_dflt_ops(struct ice_vf *vf)
  3324. {
  3325. vf->virtchnl_ops = &ice_virtchnl_dflt_ops;
  3326. }
  3327. /**
  3328. * ice_vc_repr_add_mac
  3329. * @vf: pointer to VF
  3330. * @msg: virtchannel message
  3331. *
  3332. * When port representors are created, we do not add MAC rule
  3333. * to firmware, we store it so that PF could report same
  3334. * MAC as VF.
  3335. */
  3336. static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
  3337. {
  3338. enum virtchnl_status_code v_ret = VIRTCHNL_STATUS_SUCCESS;
  3339. struct virtchnl_ether_addr_list *al =
  3340. (struct virtchnl_ether_addr_list *)msg;
  3341. struct ice_vsi *vsi;
  3342. struct ice_pf *pf;
  3343. int i;
  3344. if (!test_bit(ICE_VF_STATE_ACTIVE, vf->vf_states) ||
  3345. !ice_vc_isvalid_vsi_id(vf, al->vsi_id)) {
  3346. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3347. goto handle_mac_exit;
  3348. }
  3349. pf = vf->pf;
  3350. vsi = ice_get_vf_vsi(vf);
  3351. if (!vsi) {
  3352. v_ret = VIRTCHNL_STATUS_ERR_PARAM;
  3353. goto handle_mac_exit;
  3354. }
  3355. for (i = 0; i < al->num_elements; i++) {
  3356. u8 *mac_addr = al->list[i].addr;
  3357. if (!is_unicast_ether_addr(mac_addr) ||
  3358. ether_addr_equal(mac_addr, vf->hw_lan_addr))
  3359. continue;
  3360. if (vf->pf_set_mac) {
  3361. dev_err(ice_pf_to_dev(pf), "VF attempting to override administratively set MAC address\n");
  3362. v_ret = VIRTCHNL_STATUS_ERR_NOT_SUPPORTED;
  3363. goto handle_mac_exit;
  3364. }
  3365. ice_vfhw_mac_add(vf, &al->list[i]);
  3366. break;
  3367. }
  3368. handle_mac_exit:
  3369. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_ADD_ETH_ADDR,
  3370. v_ret, NULL, 0);
  3371. }
  3372. /**
  3373. * ice_vc_repr_del_mac - response with success for deleting MAC
  3374. * @vf: pointer to VF
  3375. * @msg: virtchannel message
  3376. *
  3377. * Respond with success to not break normal VF flow.
  3378. * For legacy VF driver try to update cached MAC address.
  3379. */
  3380. static int
  3381. ice_vc_repr_del_mac(struct ice_vf __always_unused *vf, u8 __always_unused *msg)
  3382. {
  3383. struct virtchnl_ether_addr_list *al =
  3384. (struct virtchnl_ether_addr_list *)msg;
  3385. ice_update_legacy_cached_mac(vf, &al->list[0]);
  3386. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_DEL_ETH_ADDR,
  3387. VIRTCHNL_STATUS_SUCCESS, NULL, 0);
  3388. }
  3389. static int
  3390. ice_vc_repr_cfg_promiscuous_mode(struct ice_vf *vf, u8 __always_unused *msg)
  3391. {
  3392. dev_dbg(ice_pf_to_dev(vf->pf),
  3393. "Can't config promiscuous mode in switchdev mode for VF %d\n",
  3394. vf->vf_id);
  3395. return ice_vc_send_msg_to_vf(vf, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
  3396. VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
  3397. NULL, 0);
  3398. }
  3399. static const struct ice_virtchnl_ops ice_virtchnl_repr_ops = {
  3400. .get_ver_msg = ice_vc_get_ver_msg,
  3401. .get_vf_res_msg = ice_vc_get_vf_res_msg,
  3402. .reset_vf = ice_vc_reset_vf_msg,
  3403. .add_mac_addr_msg = ice_vc_repr_add_mac,
  3404. .del_mac_addr_msg = ice_vc_repr_del_mac,
  3405. .cfg_qs_msg = ice_vc_cfg_qs_msg,
  3406. .ena_qs_msg = ice_vc_ena_qs_msg,
  3407. .dis_qs_msg = ice_vc_dis_qs_msg,
  3408. .request_qs_msg = ice_vc_request_qs_msg,
  3409. .cfg_irq_map_msg = ice_vc_cfg_irq_map_msg,
  3410. .config_rss_key = ice_vc_config_rss_key,
  3411. .config_rss_lut = ice_vc_config_rss_lut,
  3412. .config_rss_hfunc = ice_vc_config_rss_hfunc,
  3413. .get_stats_msg = ice_vc_get_stats_msg,
  3414. .cfg_promiscuous_mode_msg = ice_vc_repr_cfg_promiscuous_mode,
  3415. .add_vlan_msg = ice_vc_add_vlan_msg,
  3416. .remove_vlan_msg = ice_vc_remove_vlan_msg,
  3417. .query_rxdid = ice_vc_query_rxdid,
  3418. .get_rss_hena = ice_vc_get_rss_hena,
  3419. .set_rss_hena_msg = ice_vc_set_rss_hena,
  3420. .ena_vlan_stripping = ice_vc_ena_vlan_stripping,
  3421. .dis_vlan_stripping = ice_vc_dis_vlan_stripping,
  3422. .handle_rss_cfg_msg = ice_vc_handle_rss_cfg,
  3423. .add_fdir_fltr_msg = ice_vc_add_fdir_fltr,
  3424. .del_fdir_fltr_msg = ice_vc_del_fdir_fltr,
  3425. .get_offload_vlan_v2_caps = ice_vc_get_offload_vlan_v2_caps,
  3426. .add_vlan_v2_msg = ice_vc_add_vlan_v2_msg,
  3427. .remove_vlan_v2_msg = ice_vc_remove_vlan_v2_msg,
  3428. .ena_vlan_stripping_v2_msg = ice_vc_ena_vlan_stripping_v2_msg,
  3429. .dis_vlan_stripping_v2_msg = ice_vc_dis_vlan_stripping_v2_msg,
  3430. .ena_vlan_insertion_v2_msg = ice_vc_ena_vlan_insertion_v2_msg,
  3431. .dis_vlan_insertion_v2_msg = ice_vc_dis_vlan_insertion_v2_msg,
  3432. };
  3433. /**
  3434. * ice_virtchnl_set_repr_ops - Switch to representor virtchnl ops
  3435. * @vf: the VF to switch ops
  3436. */
  3437. void ice_virtchnl_set_repr_ops(struct ice_vf *vf)
  3438. {
  3439. vf->virtchnl_ops = &ice_virtchnl_repr_ops;
  3440. }
  3441. /**
  3442. * ice_is_malicious_vf - check if this vf might be overflowing mailbox
  3443. * @vf: the VF to check
  3444. * @mbxdata: data about the state of the mailbox
  3445. *
  3446. * Detect if a given VF might be malicious and attempting to overflow the PF
  3447. * mailbox. If so, log a warning message and ignore this event.
  3448. */
  3449. static bool
  3450. ice_is_malicious_vf(struct ice_vf *vf, struct ice_mbx_data *mbxdata)
  3451. {
  3452. bool report_malvf = false;
  3453. struct device *dev;
  3454. struct ice_pf *pf;
  3455. int status;
  3456. pf = vf->pf;
  3457. dev = ice_pf_to_dev(pf);
  3458. if (test_bit(ICE_VF_STATE_DIS, vf->vf_states))
  3459. return vf->mbx_info.malicious;
  3460. /* check to see if we have a newly malicious VF */
  3461. status = ice_mbx_vf_state_handler(&pf->hw, mbxdata, &vf->mbx_info,
  3462. &report_malvf);
  3463. if (status)
  3464. dev_warn_ratelimited(dev, "Unable to check status of mailbox overflow for VF %u MAC %pM, status %d\n",
  3465. vf->vf_id, vf->dev_lan_addr, status);
  3466. if (report_malvf) {
  3467. struct ice_vsi *pf_vsi = ice_get_main_vsi(pf);
  3468. u8 zero_addr[ETH_ALEN] = {};
  3469. dev_warn(dev, "VF MAC %pM on PF MAC %pM is generating asynchronous messages and may be overflowing the PF message queue. Please see the Adapter User Guide for more information\n",
  3470. vf->dev_lan_addr,
  3471. pf_vsi ? pf_vsi->netdev->dev_addr : zero_addr);
  3472. }
  3473. return vf->mbx_info.malicious;
  3474. }
  3475. /**
  3476. * ice_vc_process_vf_msg - Process request from VF
  3477. * @pf: pointer to the PF structure
  3478. * @event: pointer to the AQ event
  3479. * @mbxdata: information used to detect VF attempting mailbox overflow
  3480. *
  3481. * Called from the common asq/arq handler to process request from VF. When this
  3482. * flow is used for devices with hardware VF to PF message queue overflow
  3483. * support (ICE_F_MBX_LIMIT) mbxdata is set to NULL and ice_is_malicious_vf
  3484. * check is skipped.
  3485. */
  3486. void ice_vc_process_vf_msg(struct ice_pf *pf, struct ice_rq_event_info *event,
  3487. struct ice_mbx_data *mbxdata)
  3488. {
  3489. u32 v_opcode = le32_to_cpu(event->desc.cookie_high);
  3490. s16 vf_id = le16_to_cpu(event->desc.retval);
  3491. const struct ice_virtchnl_ops *ops;
  3492. u16 msglen = event->msg_len;
  3493. u8 *msg = event->msg_buf;
  3494. struct ice_vf *vf = NULL;
  3495. struct device *dev;
  3496. int err = 0;
  3497. dev = ice_pf_to_dev(pf);
  3498. vf = ice_get_vf_by_id(pf, vf_id);
  3499. if (!vf) {
  3500. dev_err(dev, "Unable to locate VF for message from VF ID %d, opcode %d, len %d\n",
  3501. vf_id, v_opcode, msglen);
  3502. return;
  3503. }
  3504. mutex_lock(&vf->cfg_lock);
  3505. /* Check if the VF is trying to overflow the mailbox */
  3506. if (mbxdata && ice_is_malicious_vf(vf, mbxdata))
  3507. goto finish;
  3508. /* Check if VF is disabled. */
  3509. if (test_bit(ICE_VF_STATE_DIS, vf->vf_states)) {
  3510. err = -EPERM;
  3511. goto error_handler;
  3512. }
  3513. ops = vf->virtchnl_ops;
  3514. /* Perform basic checks on the msg */
  3515. err = virtchnl_vc_validate_vf_msg(&vf->vf_ver, v_opcode, msg, msglen);
  3516. if (err) {
  3517. if (err == VIRTCHNL_STATUS_ERR_PARAM)
  3518. err = -EPERM;
  3519. else
  3520. err = -EINVAL;
  3521. }
  3522. error_handler:
  3523. if (err) {
  3524. ice_vc_send_msg_to_vf(vf, v_opcode, VIRTCHNL_STATUS_ERR_PARAM,
  3525. NULL, 0);
  3526. dev_err(dev, "Invalid message from VF %d, opcode %d, len %d, error %d\n",
  3527. vf_id, v_opcode, msglen, err);
  3528. goto finish;
  3529. }
  3530. if (!ice_vc_is_opcode_allowed(vf, v_opcode)) {
  3531. ice_vc_send_msg_to_vf(vf, v_opcode,
  3532. VIRTCHNL_STATUS_ERR_NOT_SUPPORTED, NULL,
  3533. 0);
  3534. goto finish;
  3535. }
  3536. switch (v_opcode) {
  3537. case VIRTCHNL_OP_VERSION:
  3538. err = ops->get_ver_msg(vf, msg);
  3539. break;
  3540. case VIRTCHNL_OP_GET_VF_RESOURCES:
  3541. err = ops->get_vf_res_msg(vf, msg);
  3542. if (ice_vf_init_vlan_stripping(vf))
  3543. dev_dbg(dev, "Failed to initialize VLAN stripping for VF %d\n",
  3544. vf->vf_id);
  3545. ice_vc_notify_vf_link_state(vf);
  3546. break;
  3547. case VIRTCHNL_OP_RESET_VF:
  3548. ops->reset_vf(vf);
  3549. break;
  3550. case VIRTCHNL_OP_ADD_ETH_ADDR:
  3551. err = ops->add_mac_addr_msg(vf, msg);
  3552. break;
  3553. case VIRTCHNL_OP_DEL_ETH_ADDR:
  3554. err = ops->del_mac_addr_msg(vf, msg);
  3555. break;
  3556. case VIRTCHNL_OP_CONFIG_VSI_QUEUES:
  3557. err = ops->cfg_qs_msg(vf, msg);
  3558. break;
  3559. case VIRTCHNL_OP_ENABLE_QUEUES:
  3560. err = ops->ena_qs_msg(vf, msg);
  3561. ice_vc_notify_vf_link_state(vf);
  3562. break;
  3563. case VIRTCHNL_OP_DISABLE_QUEUES:
  3564. err = ops->dis_qs_msg(vf, msg);
  3565. break;
  3566. case VIRTCHNL_OP_REQUEST_QUEUES:
  3567. err = ops->request_qs_msg(vf, msg);
  3568. break;
  3569. case VIRTCHNL_OP_CONFIG_IRQ_MAP:
  3570. err = ops->cfg_irq_map_msg(vf, msg);
  3571. break;
  3572. case VIRTCHNL_OP_CONFIG_RSS_KEY:
  3573. err = ops->config_rss_key(vf, msg);
  3574. break;
  3575. case VIRTCHNL_OP_CONFIG_RSS_LUT:
  3576. err = ops->config_rss_lut(vf, msg);
  3577. break;
  3578. case VIRTCHNL_OP_CONFIG_RSS_HFUNC:
  3579. err = ops->config_rss_hfunc(vf, msg);
  3580. break;
  3581. case VIRTCHNL_OP_GET_STATS:
  3582. err = ops->get_stats_msg(vf, msg);
  3583. break;
  3584. case VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE:
  3585. err = ops->cfg_promiscuous_mode_msg(vf, msg);
  3586. break;
  3587. case VIRTCHNL_OP_ADD_VLAN:
  3588. err = ops->add_vlan_msg(vf, msg);
  3589. break;
  3590. case VIRTCHNL_OP_DEL_VLAN:
  3591. err = ops->remove_vlan_msg(vf, msg);
  3592. break;
  3593. case VIRTCHNL_OP_GET_SUPPORTED_RXDIDS:
  3594. err = ops->query_rxdid(vf);
  3595. break;
  3596. case VIRTCHNL_OP_GET_RSS_HENA_CAPS:
  3597. err = ops->get_rss_hena(vf);
  3598. break;
  3599. case VIRTCHNL_OP_SET_RSS_HENA:
  3600. err = ops->set_rss_hena_msg(vf, msg);
  3601. break;
  3602. case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
  3603. err = ops->ena_vlan_stripping(vf);
  3604. break;
  3605. case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
  3606. err = ops->dis_vlan_stripping(vf);
  3607. break;
  3608. case VIRTCHNL_OP_ADD_FDIR_FILTER:
  3609. err = ops->add_fdir_fltr_msg(vf, msg);
  3610. break;
  3611. case VIRTCHNL_OP_DEL_FDIR_FILTER:
  3612. err = ops->del_fdir_fltr_msg(vf, msg);
  3613. break;
  3614. case VIRTCHNL_OP_ADD_RSS_CFG:
  3615. err = ops->handle_rss_cfg_msg(vf, msg, true);
  3616. break;
  3617. case VIRTCHNL_OP_DEL_RSS_CFG:
  3618. err = ops->handle_rss_cfg_msg(vf, msg, false);
  3619. break;
  3620. case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS:
  3621. err = ops->get_offload_vlan_v2_caps(vf);
  3622. break;
  3623. case VIRTCHNL_OP_ADD_VLAN_V2:
  3624. err = ops->add_vlan_v2_msg(vf, msg);
  3625. break;
  3626. case VIRTCHNL_OP_DEL_VLAN_V2:
  3627. err = ops->remove_vlan_v2_msg(vf, msg);
  3628. break;
  3629. case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
  3630. err = ops->ena_vlan_stripping_v2_msg(vf, msg);
  3631. break;
  3632. case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
  3633. err = ops->dis_vlan_stripping_v2_msg(vf, msg);
  3634. break;
  3635. case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
  3636. err = ops->ena_vlan_insertion_v2_msg(vf, msg);
  3637. break;
  3638. case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
  3639. err = ops->dis_vlan_insertion_v2_msg(vf, msg);
  3640. break;
  3641. case VIRTCHNL_OP_UNKNOWN:
  3642. default:
  3643. dev_err(dev, "Unsupported opcode %d from VF %d\n", v_opcode,
  3644. vf_id);
  3645. err = ice_vc_send_msg_to_vf(vf, v_opcode,
  3646. VIRTCHNL_STATUS_ERR_NOT_SUPPORTED,
  3647. NULL, 0);
  3648. break;
  3649. }
  3650. if (err) {
  3651. /* Helper function cares less about error return values here
  3652. * as it is busy with pending work.
  3653. */
  3654. dev_info(dev, "PF failed to honor VF %d, opcode %d, error %d\n",
  3655. vf_id, v_opcode, err);
  3656. }
  3657. finish:
  3658. mutex_unlock(&vf->cfg_lock);
  3659. ice_put_vf(vf);
  3660. }