qed_sriov.c 114 KB

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