qed_sriov.c 104 KB

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