bnx2x_sriov.c 99 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681
  1. /* bnx2x_sriov.c: Broadcom Everest network driver.
  2. *
  3. * Copyright 2009-2013 Broadcom Corporation
  4. *
  5. * Unless you and Broadcom execute a separate written software license
  6. * agreement governing use of this software, this software is licensed to you
  7. * under the terms of the GNU General Public License version 2, available
  8. * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
  9. *
  10. * Notwithstanding the above, under no circumstances may you combine this
  11. * software in any way with any other Broadcom software provided under a
  12. * license other than the GPL, without Broadcom's express prior written
  13. * consent.
  14. *
  15. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  16. * Written by: Shmulik Ravid <shmulikr@broadcom.com>
  17. * Ariel Elior <ariele@broadcom.com>
  18. *
  19. */
  20. #include "bnx2x.h"
  21. #include "bnx2x_init.h"
  22. #include "bnx2x_cmn.h"
  23. #include "bnx2x_sp.h"
  24. #include <linux/crc32.h>
  25. #include <linux/if_vlan.h>
  26. /* General service functions */
  27. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  28. u16 pf_id)
  29. {
  30. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  31. pf_id);
  32. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  33. pf_id);
  34. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  35. pf_id);
  36. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  37. pf_id);
  38. }
  39. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  40. u8 enable)
  41. {
  42. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  43. enable);
  44. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  45. enable);
  46. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  47. enable);
  48. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  49. enable);
  50. }
  51. int bnx2x_vf_idx_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
  52. {
  53. int idx;
  54. for_each_vf(bp, idx)
  55. if (bnx2x_vf(bp, idx, abs_vfid) == abs_vfid)
  56. break;
  57. return idx;
  58. }
  59. static
  60. struct bnx2x_virtf *bnx2x_vf_by_abs_fid(struct bnx2x *bp, u16 abs_vfid)
  61. {
  62. u16 idx = (u16)bnx2x_vf_idx_by_abs_fid(bp, abs_vfid);
  63. return (idx < BNX2X_NR_VIRTFN(bp)) ? BP_VF(bp, idx) : NULL;
  64. }
  65. static void bnx2x_vf_igu_ack_sb(struct bnx2x *bp, struct bnx2x_virtf *vf,
  66. u8 igu_sb_id, u8 segment, u16 index, u8 op,
  67. u8 update)
  68. {
  69. /* acking a VF sb through the PF - use the GRC */
  70. u32 ctl;
  71. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  72. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  73. u32 func_encode = vf->abs_vfid;
  74. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + igu_sb_id;
  75. struct igu_regular cmd_data = {0};
  76. cmd_data.sb_id_and_flags =
  77. ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
  78. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  79. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  80. (op << IGU_REGULAR_ENABLE_INT_SHIFT));
  81. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  82. func_encode << IGU_CTRL_REG_FID_SHIFT |
  83. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  84. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  85. cmd_data.sb_id_and_flags, igu_addr_data);
  86. REG_WR(bp, igu_addr_data, cmd_data.sb_id_and_flags);
  87. mmiowb();
  88. barrier();
  89. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  90. ctl, igu_addr_ctl);
  91. REG_WR(bp, igu_addr_ctl, ctl);
  92. mmiowb();
  93. barrier();
  94. }
  95. /* VFOP - VF slow-path operation support */
  96. #define BNX2X_VFOP_FILTER_ADD_CNT_MAX 0x10000
  97. /* VFOP operations states */
  98. enum bnx2x_vfop_qctor_state {
  99. BNX2X_VFOP_QCTOR_INIT,
  100. BNX2X_VFOP_QCTOR_SETUP,
  101. BNX2X_VFOP_QCTOR_INT_EN
  102. };
  103. enum bnx2x_vfop_qdtor_state {
  104. BNX2X_VFOP_QDTOR_HALT,
  105. BNX2X_VFOP_QDTOR_TERMINATE,
  106. BNX2X_VFOP_QDTOR_CFCDEL,
  107. BNX2X_VFOP_QDTOR_DONE
  108. };
  109. enum bnx2x_vfop_vlan_mac_state {
  110. BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
  111. BNX2X_VFOP_VLAN_MAC_CLEAR,
  112. BNX2X_VFOP_VLAN_MAC_CHK_DONE,
  113. BNX2X_VFOP_MAC_CONFIG_LIST,
  114. BNX2X_VFOP_VLAN_CONFIG_LIST,
  115. BNX2X_VFOP_VLAN_CONFIG_LIST_0
  116. };
  117. enum bnx2x_vfop_qsetup_state {
  118. BNX2X_VFOP_QSETUP_CTOR,
  119. BNX2X_VFOP_QSETUP_VLAN0,
  120. BNX2X_VFOP_QSETUP_DONE
  121. };
  122. enum bnx2x_vfop_mcast_state {
  123. BNX2X_VFOP_MCAST_DEL,
  124. BNX2X_VFOP_MCAST_ADD,
  125. BNX2X_VFOP_MCAST_CHK_DONE
  126. };
  127. enum bnx2x_vfop_qflr_state {
  128. BNX2X_VFOP_QFLR_CLR_VLAN,
  129. BNX2X_VFOP_QFLR_CLR_MAC,
  130. BNX2X_VFOP_QFLR_TERMINATE,
  131. BNX2X_VFOP_QFLR_DONE
  132. };
  133. enum bnx2x_vfop_flr_state {
  134. BNX2X_VFOP_FLR_QUEUES,
  135. BNX2X_VFOP_FLR_HW
  136. };
  137. enum bnx2x_vfop_close_state {
  138. BNX2X_VFOP_CLOSE_QUEUES,
  139. BNX2X_VFOP_CLOSE_HW
  140. };
  141. enum bnx2x_vfop_rxmode_state {
  142. BNX2X_VFOP_RXMODE_CONFIG,
  143. BNX2X_VFOP_RXMODE_DONE
  144. };
  145. enum bnx2x_vfop_qteardown_state {
  146. BNX2X_VFOP_QTEARDOWN_RXMODE,
  147. BNX2X_VFOP_QTEARDOWN_CLR_VLAN,
  148. BNX2X_VFOP_QTEARDOWN_CLR_MAC,
  149. BNX2X_VFOP_QTEARDOWN_QDTOR,
  150. BNX2X_VFOP_QTEARDOWN_DONE
  151. };
  152. enum bnx2x_vfop_rss_state {
  153. BNX2X_VFOP_RSS_CONFIG,
  154. BNX2X_VFOP_RSS_DONE
  155. };
  156. #define bnx2x_vfop_reset_wq(vf) atomic_set(&vf->op_in_progress, 0)
  157. void bnx2x_vfop_qctor_dump_tx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  158. struct bnx2x_queue_init_params *init_params,
  159. struct bnx2x_queue_setup_params *setup_params,
  160. u16 q_idx, u16 sb_idx)
  161. {
  162. DP(BNX2X_MSG_IOV,
  163. "VF[%d] Q_SETUP: txq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, flags=0x%lx, traffic-type=%d",
  164. vf->abs_vfid,
  165. q_idx,
  166. sb_idx,
  167. init_params->tx.sb_cq_index,
  168. init_params->tx.hc_rate,
  169. setup_params->flags,
  170. setup_params->txq_params.traffic_type);
  171. }
  172. void bnx2x_vfop_qctor_dump_rx(struct bnx2x *bp, struct bnx2x_virtf *vf,
  173. struct bnx2x_queue_init_params *init_params,
  174. struct bnx2x_queue_setup_params *setup_params,
  175. u16 q_idx, u16 sb_idx)
  176. {
  177. struct bnx2x_rxq_setup_params *rxq_params = &setup_params->rxq_params;
  178. DP(BNX2X_MSG_IOV, "VF[%d] Q_SETUP: rxq[%d]-- vfsb=%d, sb-index=%d, hc-rate=%d, mtu=%d, buf-size=%d\n"
  179. "sge-size=%d, max_sge_pkt=%d, tpa-agg-size=%d, flags=0x%lx, drop-flags=0x%x, cache-log=%d\n",
  180. vf->abs_vfid,
  181. q_idx,
  182. sb_idx,
  183. init_params->rx.sb_cq_index,
  184. init_params->rx.hc_rate,
  185. setup_params->gen_params.mtu,
  186. rxq_params->buf_sz,
  187. rxq_params->sge_buf_sz,
  188. rxq_params->max_sges_pkt,
  189. rxq_params->tpa_agg_sz,
  190. setup_params->flags,
  191. rxq_params->drop_flags,
  192. rxq_params->cache_line_log);
  193. }
  194. void bnx2x_vfop_qctor_prep(struct bnx2x *bp,
  195. struct bnx2x_virtf *vf,
  196. struct bnx2x_vf_queue *q,
  197. struct bnx2x_vfop_qctor_params *p,
  198. unsigned long q_type)
  199. {
  200. struct bnx2x_queue_init_params *init_p = &p->qstate.params.init;
  201. struct bnx2x_queue_setup_params *setup_p = &p->prep_qsetup;
  202. /* INIT */
  203. /* Enable host coalescing in the transition to INIT state */
  204. if (test_bit(BNX2X_Q_FLG_HC, &init_p->rx.flags))
  205. __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->rx.flags);
  206. if (test_bit(BNX2X_Q_FLG_HC, &init_p->tx.flags))
  207. __set_bit(BNX2X_Q_FLG_HC_EN, &init_p->tx.flags);
  208. /* FW SB ID */
  209. init_p->rx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  210. init_p->tx.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  211. /* context */
  212. init_p->cxts[0] = q->cxt;
  213. /* SETUP */
  214. /* Setup-op general parameters */
  215. setup_p->gen_params.spcl_id = vf->sp_cl_id;
  216. setup_p->gen_params.stat_id = vfq_stat_id(vf, q);
  217. /* Setup-op pause params:
  218. * Nothing to do, the pause thresholds are set by default to 0 which
  219. * effectively turns off the feature for this queue. We don't want
  220. * one queue (VF) to interfering with another queue (another VF)
  221. */
  222. if (vf->cfg_flags & VF_CFG_FW_FC)
  223. BNX2X_ERR("No support for pause to VFs (abs_vfid: %d)\n",
  224. vf->abs_vfid);
  225. /* Setup-op flags:
  226. * collect statistics, zero statistics, local-switching, security,
  227. * OV for Flex10, RSS and MCAST for leading
  228. */
  229. if (test_bit(BNX2X_Q_FLG_STATS, &setup_p->flags))
  230. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &setup_p->flags);
  231. /* for VFs, enable tx switching, bd coherency, and mac address
  232. * anti-spoofing
  233. */
  234. __set_bit(BNX2X_Q_FLG_TX_SWITCH, &setup_p->flags);
  235. __set_bit(BNX2X_Q_FLG_TX_SEC, &setup_p->flags);
  236. __set_bit(BNX2X_Q_FLG_ANTI_SPOOF, &setup_p->flags);
  237. /* Setup-op rx parameters */
  238. if (test_bit(BNX2X_Q_TYPE_HAS_RX, &q_type)) {
  239. struct bnx2x_rxq_setup_params *rxq_p = &setup_p->rxq_params;
  240. rxq_p->cl_qzone_id = vfq_qzone_id(vf, q);
  241. rxq_p->fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  242. rxq_p->rss_engine_id = FW_VF_HANDLE(vf->abs_vfid);
  243. if (test_bit(BNX2X_Q_FLG_TPA, &setup_p->flags))
  244. rxq_p->max_tpa_queues = BNX2X_VF_MAX_TPA_AGG_QUEUES;
  245. }
  246. /* Setup-op tx parameters */
  247. if (test_bit(BNX2X_Q_TYPE_HAS_TX, &q_type)) {
  248. setup_p->txq_params.tss_leading_cl_id = vf->leading_rss;
  249. setup_p->txq_params.fw_sb_id = vf_igu_sb(vf, q->sb_idx);
  250. }
  251. }
  252. /* VFOP queue construction */
  253. static void bnx2x_vfop_qctor(struct bnx2x *bp, struct bnx2x_virtf *vf)
  254. {
  255. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  256. struct bnx2x_vfop_args_qctor *args = &vfop->args.qctor;
  257. struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
  258. enum bnx2x_vfop_qctor_state state = vfop->state;
  259. bnx2x_vfop_reset_wq(vf);
  260. if (vfop->rc < 0)
  261. goto op_err;
  262. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  263. switch (state) {
  264. case BNX2X_VFOP_QCTOR_INIT:
  265. /* has this queue already been opened? */
  266. if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
  267. BNX2X_Q_LOGICAL_STATE_ACTIVE) {
  268. DP(BNX2X_MSG_IOV,
  269. "Entered qctor but queue was already up. Aborting gracefully\n");
  270. goto op_done;
  271. }
  272. /* next state */
  273. vfop->state = BNX2X_VFOP_QCTOR_SETUP;
  274. q_params->cmd = BNX2X_Q_CMD_INIT;
  275. vfop->rc = bnx2x_queue_state_change(bp, q_params);
  276. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  277. case BNX2X_VFOP_QCTOR_SETUP:
  278. /* next state */
  279. vfop->state = BNX2X_VFOP_QCTOR_INT_EN;
  280. /* copy pre-prepared setup params to the queue-state params */
  281. vfop->op_p->qctor.qstate.params.setup =
  282. vfop->op_p->qctor.prep_qsetup;
  283. q_params->cmd = BNX2X_Q_CMD_SETUP;
  284. vfop->rc = bnx2x_queue_state_change(bp, q_params);
  285. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  286. case BNX2X_VFOP_QCTOR_INT_EN:
  287. /* enable interrupts */
  288. bnx2x_vf_igu_ack_sb(bp, vf, vf_igu_sb(vf, args->sb_idx),
  289. USTORM_ID, 0, IGU_INT_ENABLE, 0);
  290. goto op_done;
  291. default:
  292. bnx2x_vfop_default(state);
  293. }
  294. op_err:
  295. BNX2X_ERR("QCTOR[%d:%d] error: cmd %d, rc %d\n",
  296. vf->abs_vfid, args->qid, q_params->cmd, vfop->rc);
  297. op_done:
  298. bnx2x_vfop_end(bp, vf, vfop);
  299. op_pending:
  300. return;
  301. }
  302. static int bnx2x_vfop_qctor_cmd(struct bnx2x *bp,
  303. struct bnx2x_virtf *vf,
  304. struct bnx2x_vfop_cmd *cmd,
  305. int qid)
  306. {
  307. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  308. if (vfop) {
  309. vf->op_params.qctor.qstate.q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  310. vfop->args.qctor.qid = qid;
  311. vfop->args.qctor.sb_idx = bnx2x_vfq(vf, qid, sb_idx);
  312. bnx2x_vfop_opset(BNX2X_VFOP_QCTOR_INIT,
  313. bnx2x_vfop_qctor, cmd->done);
  314. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qctor,
  315. cmd->block);
  316. }
  317. return -ENOMEM;
  318. }
  319. /* VFOP queue destruction */
  320. static void bnx2x_vfop_qdtor(struct bnx2x *bp, struct bnx2x_virtf *vf)
  321. {
  322. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  323. struct bnx2x_vfop_args_qdtor *qdtor = &vfop->args.qdtor;
  324. struct bnx2x_queue_state_params *q_params = &vfop->op_p->qctor.qstate;
  325. enum bnx2x_vfop_qdtor_state state = vfop->state;
  326. bnx2x_vfop_reset_wq(vf);
  327. if (vfop->rc < 0)
  328. goto op_err;
  329. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  330. switch (state) {
  331. case BNX2X_VFOP_QDTOR_HALT:
  332. /* has this queue already been stopped? */
  333. if (bnx2x_get_q_logical_state(bp, q_params->q_obj) ==
  334. BNX2X_Q_LOGICAL_STATE_STOPPED) {
  335. DP(BNX2X_MSG_IOV,
  336. "Entered qdtor but queue was already stopped. Aborting gracefully\n");
  337. /* next state */
  338. vfop->state = BNX2X_VFOP_QDTOR_DONE;
  339. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  340. }
  341. /* next state */
  342. vfop->state = BNX2X_VFOP_QDTOR_TERMINATE;
  343. q_params->cmd = BNX2X_Q_CMD_HALT;
  344. vfop->rc = bnx2x_queue_state_change(bp, q_params);
  345. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  346. case BNX2X_VFOP_QDTOR_TERMINATE:
  347. /* next state */
  348. vfop->state = BNX2X_VFOP_QDTOR_CFCDEL;
  349. q_params->cmd = BNX2X_Q_CMD_TERMINATE;
  350. vfop->rc = bnx2x_queue_state_change(bp, q_params);
  351. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  352. case BNX2X_VFOP_QDTOR_CFCDEL:
  353. /* next state */
  354. vfop->state = BNX2X_VFOP_QDTOR_DONE;
  355. q_params->cmd = BNX2X_Q_CMD_CFC_DEL;
  356. vfop->rc = bnx2x_queue_state_change(bp, q_params);
  357. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  358. op_err:
  359. BNX2X_ERR("QDTOR[%d:%d] error: cmd %d, rc %d\n",
  360. vf->abs_vfid, qdtor->qid, q_params->cmd, vfop->rc);
  361. op_done:
  362. case BNX2X_VFOP_QDTOR_DONE:
  363. /* invalidate the context */
  364. if (qdtor->cxt) {
  365. qdtor->cxt->ustorm_ag_context.cdu_usage = 0;
  366. qdtor->cxt->xstorm_ag_context.cdu_reserved = 0;
  367. }
  368. bnx2x_vfop_end(bp, vf, vfop);
  369. return;
  370. default:
  371. bnx2x_vfop_default(state);
  372. }
  373. op_pending:
  374. return;
  375. }
  376. static int bnx2x_vfop_qdtor_cmd(struct bnx2x *bp,
  377. struct bnx2x_virtf *vf,
  378. struct bnx2x_vfop_cmd *cmd,
  379. int qid)
  380. {
  381. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  382. if (vfop) {
  383. struct bnx2x_queue_state_params *qstate =
  384. &vf->op_params.qctor.qstate;
  385. memset(qstate, 0, sizeof(*qstate));
  386. qstate->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  387. vfop->args.qdtor.qid = qid;
  388. vfop->args.qdtor.cxt = bnx2x_vfq(vf, qid, cxt);
  389. bnx2x_vfop_opset(BNX2X_VFOP_QDTOR_HALT,
  390. bnx2x_vfop_qdtor, cmd->done);
  391. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdtor,
  392. cmd->block);
  393. }
  394. DP(BNX2X_MSG_IOV, "VF[%d] failed to add a vfop. rc %d\n",
  395. vf->abs_vfid, vfop->rc);
  396. return -ENOMEM;
  397. }
  398. static void
  399. bnx2x_vf_set_igu_info(struct bnx2x *bp, u8 igu_sb_id, u8 abs_vfid)
  400. {
  401. struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
  402. if (vf) {
  403. /* the first igu entry belonging to VFs of this PF */
  404. if (!BP_VFDB(bp)->first_vf_igu_entry)
  405. BP_VFDB(bp)->first_vf_igu_entry = igu_sb_id;
  406. /* the first igu entry belonging to this VF */
  407. if (!vf_sb_count(vf))
  408. vf->igu_base_id = igu_sb_id;
  409. ++vf_sb_count(vf);
  410. ++vf->sb_count;
  411. }
  412. BP_VFDB(bp)->vf_sbs_pool++;
  413. }
  414. /* VFOP MAC/VLAN helpers */
  415. static inline void bnx2x_vfop_credit(struct bnx2x *bp,
  416. struct bnx2x_vfop *vfop,
  417. struct bnx2x_vlan_mac_obj *obj)
  418. {
  419. struct bnx2x_vfop_args_filters *args = &vfop->args.filters;
  420. /* update credit only if there is no error
  421. * and a valid credit counter
  422. */
  423. if (!vfop->rc && args->credit) {
  424. struct list_head *pos;
  425. int read_lock;
  426. int cnt = 0;
  427. read_lock = bnx2x_vlan_mac_h_read_lock(bp, obj);
  428. if (read_lock)
  429. DP(BNX2X_MSG_SP, "Failed to take vlan mac read head; continuing anyway\n");
  430. list_for_each(pos, &obj->head)
  431. cnt++;
  432. if (!read_lock)
  433. bnx2x_vlan_mac_h_read_unlock(bp, obj);
  434. atomic_set(args->credit, cnt);
  435. }
  436. }
  437. static int bnx2x_vfop_set_user_req(struct bnx2x *bp,
  438. struct bnx2x_vfop_filter *pos,
  439. struct bnx2x_vlan_mac_data *user_req)
  440. {
  441. user_req->cmd = pos->add ? BNX2X_VLAN_MAC_ADD :
  442. BNX2X_VLAN_MAC_DEL;
  443. switch (pos->type) {
  444. case BNX2X_VFOP_FILTER_MAC:
  445. memcpy(user_req->u.mac.mac, pos->mac, ETH_ALEN);
  446. break;
  447. case BNX2X_VFOP_FILTER_VLAN:
  448. user_req->u.vlan.vlan = pos->vid;
  449. break;
  450. default:
  451. BNX2X_ERR("Invalid filter type, skipping\n");
  452. return 1;
  453. }
  454. return 0;
  455. }
  456. static int bnx2x_vfop_config_list(struct bnx2x *bp,
  457. struct bnx2x_vfop_filters *filters,
  458. struct bnx2x_vlan_mac_ramrod_params *vlan_mac)
  459. {
  460. struct bnx2x_vfop_filter *pos, *tmp;
  461. struct list_head rollback_list, *filters_list = &filters->head;
  462. struct bnx2x_vlan_mac_data *user_req = &vlan_mac->user_req;
  463. int rc = 0, cnt = 0;
  464. INIT_LIST_HEAD(&rollback_list);
  465. list_for_each_entry_safe(pos, tmp, filters_list, link) {
  466. if (bnx2x_vfop_set_user_req(bp, pos, user_req))
  467. continue;
  468. rc = bnx2x_config_vlan_mac(bp, vlan_mac);
  469. if (rc >= 0) {
  470. cnt += pos->add ? 1 : -1;
  471. list_move(&pos->link, &rollback_list);
  472. rc = 0;
  473. } else if (rc == -EEXIST) {
  474. rc = 0;
  475. } else {
  476. BNX2X_ERR("Failed to add a new vlan_mac command\n");
  477. break;
  478. }
  479. }
  480. /* rollback if error or too many rules added */
  481. if (rc || cnt > filters->add_cnt) {
  482. BNX2X_ERR("error or too many rules added. Performing rollback\n");
  483. list_for_each_entry_safe(pos, tmp, &rollback_list, link) {
  484. pos->add = !pos->add; /* reverse op */
  485. bnx2x_vfop_set_user_req(bp, pos, user_req);
  486. bnx2x_config_vlan_mac(bp, vlan_mac);
  487. list_del(&pos->link);
  488. }
  489. cnt = 0;
  490. if (!rc)
  491. rc = -EINVAL;
  492. }
  493. filters->add_cnt = cnt;
  494. return rc;
  495. }
  496. /* VFOP set VLAN/MAC */
  497. static void bnx2x_vfop_vlan_mac(struct bnx2x *bp, struct bnx2x_virtf *vf)
  498. {
  499. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  500. struct bnx2x_vlan_mac_ramrod_params *vlan_mac = &vfop->op_p->vlan_mac;
  501. struct bnx2x_vlan_mac_obj *obj = vlan_mac->vlan_mac_obj;
  502. struct bnx2x_vfop_filters *filters = vfop->args.filters.multi_filter;
  503. enum bnx2x_vfop_vlan_mac_state state = vfop->state;
  504. if (vfop->rc < 0)
  505. goto op_err;
  506. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  507. bnx2x_vfop_reset_wq(vf);
  508. switch (state) {
  509. case BNX2X_VFOP_VLAN_MAC_CLEAR:
  510. /* next state */
  511. vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
  512. /* do delete */
  513. vfop->rc = obj->delete_all(bp, obj,
  514. &vlan_mac->user_req.vlan_mac_flags,
  515. &vlan_mac->ramrod_flags);
  516. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  517. case BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE:
  518. /* next state */
  519. vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
  520. /* do config */
  521. vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
  522. if (vfop->rc == -EEXIST)
  523. vfop->rc = 0;
  524. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  525. case BNX2X_VFOP_VLAN_MAC_CHK_DONE:
  526. vfop->rc = !!obj->raw.check_pending(&obj->raw);
  527. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  528. case BNX2X_VFOP_MAC_CONFIG_LIST:
  529. /* next state */
  530. vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
  531. /* do list config */
  532. vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
  533. if (vfop->rc)
  534. goto op_err;
  535. set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
  536. vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
  537. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  538. case BNX2X_VFOP_VLAN_CONFIG_LIST:
  539. /* next state */
  540. vfop->state = BNX2X_VFOP_VLAN_MAC_CHK_DONE;
  541. /* do list config */
  542. vfop->rc = bnx2x_vfop_config_list(bp, filters, vlan_mac);
  543. if (!vfop->rc) {
  544. set_bit(RAMROD_CONT, &vlan_mac->ramrod_flags);
  545. vfop->rc = bnx2x_config_vlan_mac(bp, vlan_mac);
  546. }
  547. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  548. default:
  549. bnx2x_vfop_default(state);
  550. }
  551. op_err:
  552. BNX2X_ERR("VLAN-MAC error: rc %d\n", vfop->rc);
  553. op_done:
  554. kfree(filters);
  555. bnx2x_vfop_credit(bp, vfop, obj);
  556. bnx2x_vfop_end(bp, vf, vfop);
  557. op_pending:
  558. return;
  559. }
  560. struct bnx2x_vfop_vlan_mac_flags {
  561. bool drv_only;
  562. bool dont_consume;
  563. bool single_cmd;
  564. bool add;
  565. };
  566. static void
  567. bnx2x_vfop_vlan_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
  568. struct bnx2x_vfop_vlan_mac_flags *flags)
  569. {
  570. struct bnx2x_vlan_mac_data *ureq = &ramrod->user_req;
  571. memset(ramrod, 0, sizeof(*ramrod));
  572. /* ramrod flags */
  573. if (flags->drv_only)
  574. set_bit(RAMROD_DRV_CLR_ONLY, &ramrod->ramrod_flags);
  575. if (flags->single_cmd)
  576. set_bit(RAMROD_EXEC, &ramrod->ramrod_flags);
  577. /* mac_vlan flags */
  578. if (flags->dont_consume)
  579. set_bit(BNX2X_DONT_CONSUME_CAM_CREDIT, &ureq->vlan_mac_flags);
  580. /* cmd */
  581. ureq->cmd = flags->add ? BNX2X_VLAN_MAC_ADD : BNX2X_VLAN_MAC_DEL;
  582. }
  583. static inline void
  584. bnx2x_vfop_mac_prep_ramrod(struct bnx2x_vlan_mac_ramrod_params *ramrod,
  585. struct bnx2x_vfop_vlan_mac_flags *flags)
  586. {
  587. bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, flags);
  588. set_bit(BNX2X_ETH_MAC, &ramrod->user_req.vlan_mac_flags);
  589. }
  590. static int bnx2x_vfop_mac_delall_cmd(struct bnx2x *bp,
  591. struct bnx2x_virtf *vf,
  592. struct bnx2x_vfop_cmd *cmd,
  593. int qid, bool drv_only)
  594. {
  595. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  596. int rc;
  597. if (vfop) {
  598. struct bnx2x_vfop_args_filters filters = {
  599. .multi_filter = NULL, /* single */
  600. .credit = NULL, /* consume credit */
  601. };
  602. struct bnx2x_vfop_vlan_mac_flags flags = {
  603. .drv_only = drv_only,
  604. .dont_consume = (filters.credit != NULL),
  605. .single_cmd = true,
  606. .add = false /* don't care */,
  607. };
  608. struct bnx2x_vlan_mac_ramrod_params *ramrod =
  609. &vf->op_params.vlan_mac;
  610. /* set ramrod params */
  611. bnx2x_vfop_mac_prep_ramrod(ramrod, &flags);
  612. /* set object */
  613. rc = validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, mac_obj));
  614. if (rc)
  615. return rc;
  616. ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
  617. /* set extra args */
  618. vfop->args.filters = filters;
  619. bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CLEAR,
  620. bnx2x_vfop_vlan_mac, cmd->done);
  621. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
  622. cmd->block);
  623. }
  624. return -ENOMEM;
  625. }
  626. int bnx2x_vfop_mac_list_cmd(struct bnx2x *bp,
  627. struct bnx2x_virtf *vf,
  628. struct bnx2x_vfop_cmd *cmd,
  629. struct bnx2x_vfop_filters *macs,
  630. int qid, bool drv_only)
  631. {
  632. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  633. int rc;
  634. if (vfop) {
  635. struct bnx2x_vfop_args_filters filters = {
  636. .multi_filter = macs,
  637. .credit = NULL, /* consume credit */
  638. };
  639. struct bnx2x_vfop_vlan_mac_flags flags = {
  640. .drv_only = drv_only,
  641. .dont_consume = (filters.credit != NULL),
  642. .single_cmd = false,
  643. .add = false, /* don't care since only the items in the
  644. * filters list affect the sp operation,
  645. * not the list itself
  646. */
  647. };
  648. struct bnx2x_vlan_mac_ramrod_params *ramrod =
  649. &vf->op_params.vlan_mac;
  650. /* set ramrod params */
  651. bnx2x_vfop_mac_prep_ramrod(ramrod, &flags);
  652. /* set object */
  653. rc = validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, mac_obj));
  654. if (rc)
  655. return rc;
  656. ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, mac_obj);
  657. /* set extra args */
  658. filters.multi_filter->add_cnt = BNX2X_VFOP_FILTER_ADD_CNT_MAX;
  659. vfop->args.filters = filters;
  660. bnx2x_vfop_opset(BNX2X_VFOP_MAC_CONFIG_LIST,
  661. bnx2x_vfop_vlan_mac, cmd->done);
  662. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
  663. cmd->block);
  664. }
  665. return -ENOMEM;
  666. }
  667. int bnx2x_vfop_vlan_set_cmd(struct bnx2x *bp,
  668. struct bnx2x_virtf *vf,
  669. struct bnx2x_vfop_cmd *cmd,
  670. int qid, u16 vid, bool add)
  671. {
  672. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  673. int rc;
  674. if (vfop) {
  675. struct bnx2x_vfop_args_filters filters = {
  676. .multi_filter = NULL, /* single command */
  677. .credit = &bnx2x_vfq(vf, qid, vlan_count),
  678. };
  679. struct bnx2x_vfop_vlan_mac_flags flags = {
  680. .drv_only = false,
  681. .dont_consume = (filters.credit != NULL),
  682. .single_cmd = true,
  683. .add = add,
  684. };
  685. struct bnx2x_vlan_mac_ramrod_params *ramrod =
  686. &vf->op_params.vlan_mac;
  687. /* set ramrod params */
  688. bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
  689. ramrod->user_req.u.vlan.vlan = vid;
  690. /* set object */
  691. rc = validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, vlan_obj));
  692. if (rc)
  693. return rc;
  694. ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
  695. /* set extra args */
  696. vfop->args.filters = filters;
  697. bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CONFIG_SINGLE,
  698. bnx2x_vfop_vlan_mac, cmd->done);
  699. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
  700. cmd->block);
  701. }
  702. return -ENOMEM;
  703. }
  704. static int bnx2x_vfop_vlan_delall_cmd(struct bnx2x *bp,
  705. struct bnx2x_virtf *vf,
  706. struct bnx2x_vfop_cmd *cmd,
  707. int qid, bool drv_only)
  708. {
  709. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  710. int rc;
  711. if (vfop) {
  712. struct bnx2x_vfop_args_filters filters = {
  713. .multi_filter = NULL, /* single command */
  714. .credit = &bnx2x_vfq(vf, qid, vlan_count),
  715. };
  716. struct bnx2x_vfop_vlan_mac_flags flags = {
  717. .drv_only = drv_only,
  718. .dont_consume = (filters.credit != NULL),
  719. .single_cmd = true,
  720. .add = false, /* don't care */
  721. };
  722. struct bnx2x_vlan_mac_ramrod_params *ramrod =
  723. &vf->op_params.vlan_mac;
  724. /* set ramrod params */
  725. bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
  726. /* set object */
  727. rc = validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, vlan_obj));
  728. if (rc)
  729. return rc;
  730. ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
  731. /* set extra args */
  732. vfop->args.filters = filters;
  733. bnx2x_vfop_opset(BNX2X_VFOP_VLAN_MAC_CLEAR,
  734. bnx2x_vfop_vlan_mac, cmd->done);
  735. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
  736. cmd->block);
  737. }
  738. return -ENOMEM;
  739. }
  740. int bnx2x_vfop_vlan_list_cmd(struct bnx2x *bp,
  741. struct bnx2x_virtf *vf,
  742. struct bnx2x_vfop_cmd *cmd,
  743. struct bnx2x_vfop_filters *vlans,
  744. int qid, bool drv_only)
  745. {
  746. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  747. int rc;
  748. if (vfop) {
  749. struct bnx2x_vfop_args_filters filters = {
  750. .multi_filter = vlans,
  751. .credit = &bnx2x_vfq(vf, qid, vlan_count),
  752. };
  753. struct bnx2x_vfop_vlan_mac_flags flags = {
  754. .drv_only = drv_only,
  755. .dont_consume = (filters.credit != NULL),
  756. .single_cmd = false,
  757. .add = false, /* don't care */
  758. };
  759. struct bnx2x_vlan_mac_ramrod_params *ramrod =
  760. &vf->op_params.vlan_mac;
  761. /* set ramrod params */
  762. bnx2x_vfop_vlan_mac_prep_ramrod(ramrod, &flags);
  763. /* set object */
  764. rc = validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, vlan_obj));
  765. if (rc)
  766. return rc;
  767. ramrod->vlan_mac_obj = &bnx2x_vfq(vf, qid, vlan_obj);
  768. /* set extra args */
  769. filters.multi_filter->add_cnt = vf_vlan_rules_cnt(vf) -
  770. atomic_read(filters.credit);
  771. vfop->args.filters = filters;
  772. bnx2x_vfop_opset(BNX2X_VFOP_VLAN_CONFIG_LIST,
  773. bnx2x_vfop_vlan_mac, cmd->done);
  774. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_vlan_mac,
  775. cmd->block);
  776. }
  777. return -ENOMEM;
  778. }
  779. /* VFOP queue setup (queue constructor + set vlan 0) */
  780. static void bnx2x_vfop_qsetup(struct bnx2x *bp, struct bnx2x_virtf *vf)
  781. {
  782. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  783. int qid = vfop->args.qctor.qid;
  784. enum bnx2x_vfop_qsetup_state state = vfop->state;
  785. struct bnx2x_vfop_cmd cmd = {
  786. .done = bnx2x_vfop_qsetup,
  787. .block = false,
  788. };
  789. if (vfop->rc < 0)
  790. goto op_err;
  791. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  792. switch (state) {
  793. case BNX2X_VFOP_QSETUP_CTOR:
  794. /* init the queue ctor command */
  795. vfop->state = BNX2X_VFOP_QSETUP_VLAN0;
  796. vfop->rc = bnx2x_vfop_qctor_cmd(bp, vf, &cmd, qid);
  797. if (vfop->rc)
  798. goto op_err;
  799. return;
  800. case BNX2X_VFOP_QSETUP_VLAN0:
  801. /* skip if non-leading or FPGA/EMU*/
  802. if (qid)
  803. goto op_done;
  804. /* init the queue set-vlan command (for vlan 0) */
  805. vfop->state = BNX2X_VFOP_QSETUP_DONE;
  806. vfop->rc = bnx2x_vfop_vlan_set_cmd(bp, vf, &cmd, qid, 0, true);
  807. if (vfop->rc)
  808. goto op_err;
  809. return;
  810. op_err:
  811. BNX2X_ERR("QSETUP[%d:%d] error: rc %d\n", vf->abs_vfid, qid, vfop->rc);
  812. op_done:
  813. case BNX2X_VFOP_QSETUP_DONE:
  814. vf->cfg_flags |= VF_CFG_VLAN;
  815. smp_mb__before_clear_bit();
  816. set_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  817. &bp->sp_rtnl_state);
  818. smp_mb__after_clear_bit();
  819. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  820. bnx2x_vfop_end(bp, vf, vfop);
  821. return;
  822. default:
  823. bnx2x_vfop_default(state);
  824. }
  825. }
  826. int bnx2x_vfop_qsetup_cmd(struct bnx2x *bp,
  827. struct bnx2x_virtf *vf,
  828. struct bnx2x_vfop_cmd *cmd,
  829. int qid)
  830. {
  831. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  832. if (vfop) {
  833. vfop->args.qctor.qid = qid;
  834. bnx2x_vfop_opset(BNX2X_VFOP_QSETUP_CTOR,
  835. bnx2x_vfop_qsetup, cmd->done);
  836. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qsetup,
  837. cmd->block);
  838. }
  839. return -ENOMEM;
  840. }
  841. /* VFOP queue FLR handling (clear vlans, clear macs, queue destructor) */
  842. static void bnx2x_vfop_qflr(struct bnx2x *bp, struct bnx2x_virtf *vf)
  843. {
  844. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  845. int qid = vfop->args.qx.qid;
  846. enum bnx2x_vfop_qflr_state state = vfop->state;
  847. struct bnx2x_queue_state_params *qstate;
  848. struct bnx2x_vfop_cmd cmd;
  849. bnx2x_vfop_reset_wq(vf);
  850. if (vfop->rc < 0)
  851. goto op_err;
  852. DP(BNX2X_MSG_IOV, "VF[%d] STATE: %d\n", vf->abs_vfid, state);
  853. cmd.done = bnx2x_vfop_qflr;
  854. cmd.block = false;
  855. switch (state) {
  856. case BNX2X_VFOP_QFLR_CLR_VLAN:
  857. /* vlan-clear-all: driver-only, don't consume credit */
  858. vfop->state = BNX2X_VFOP_QFLR_CLR_MAC;
  859. if (!validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, vlan_obj)))
  860. vfop->rc = bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid,
  861. true);
  862. if (vfop->rc)
  863. goto op_err;
  864. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  865. case BNX2X_VFOP_QFLR_CLR_MAC:
  866. /* mac-clear-all: driver only consume credit */
  867. vfop->state = BNX2X_VFOP_QFLR_TERMINATE;
  868. if (!validate_vlan_mac(bp, &bnx2x_vfq(vf, qid, mac_obj)))
  869. vfop->rc = bnx2x_vfop_mac_delall_cmd(bp, vf, &cmd, qid,
  870. true);
  871. DP(BNX2X_MSG_IOV,
  872. "VF[%d] vfop->rc after bnx2x_vfop_mac_delall_cmd was %d",
  873. vf->abs_vfid, vfop->rc);
  874. if (vfop->rc)
  875. goto op_err;
  876. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  877. case BNX2X_VFOP_QFLR_TERMINATE:
  878. qstate = &vfop->op_p->qctor.qstate;
  879. memset(qstate , 0, sizeof(*qstate));
  880. qstate->q_obj = &bnx2x_vfq(vf, qid, sp_obj);
  881. vfop->state = BNX2X_VFOP_QFLR_DONE;
  882. DP(BNX2X_MSG_IOV, "VF[%d] qstate during flr was %d\n",
  883. vf->abs_vfid, qstate->q_obj->state);
  884. if (qstate->q_obj->state != BNX2X_Q_STATE_RESET) {
  885. qstate->q_obj->state = BNX2X_Q_STATE_STOPPED;
  886. qstate->cmd = BNX2X_Q_CMD_TERMINATE;
  887. vfop->rc = bnx2x_queue_state_change(bp, qstate);
  888. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_VERIFY_PEND);
  889. } else {
  890. goto op_done;
  891. }
  892. op_err:
  893. BNX2X_ERR("QFLR[%d:%d] error: rc %d\n",
  894. vf->abs_vfid, qid, vfop->rc);
  895. op_done:
  896. case BNX2X_VFOP_QFLR_DONE:
  897. bnx2x_vfop_end(bp, vf, vfop);
  898. return;
  899. default:
  900. bnx2x_vfop_default(state);
  901. }
  902. op_pending:
  903. return;
  904. }
  905. static int bnx2x_vfop_qflr_cmd(struct bnx2x *bp,
  906. struct bnx2x_virtf *vf,
  907. struct bnx2x_vfop_cmd *cmd,
  908. int qid)
  909. {
  910. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  911. if (vfop) {
  912. vfop->args.qx.qid = qid;
  913. bnx2x_vfop_opset(BNX2X_VFOP_QFLR_CLR_VLAN,
  914. bnx2x_vfop_qflr, cmd->done);
  915. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qflr,
  916. cmd->block);
  917. }
  918. return -ENOMEM;
  919. }
  920. /* VFOP multi-casts */
  921. static void bnx2x_vfop_mcast(struct bnx2x *bp, struct bnx2x_virtf *vf)
  922. {
  923. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  924. struct bnx2x_mcast_ramrod_params *mcast = &vfop->op_p->mcast;
  925. struct bnx2x_raw_obj *raw = &mcast->mcast_obj->raw;
  926. struct bnx2x_vfop_args_mcast *args = &vfop->args.mc_list;
  927. enum bnx2x_vfop_mcast_state state = vfop->state;
  928. int i;
  929. bnx2x_vfop_reset_wq(vf);
  930. if (vfop->rc < 0)
  931. goto op_err;
  932. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  933. switch (state) {
  934. case BNX2X_VFOP_MCAST_DEL:
  935. /* clear existing mcasts */
  936. vfop->state = BNX2X_VFOP_MCAST_ADD;
  937. vfop->rc = bnx2x_config_mcast(bp, mcast, BNX2X_MCAST_CMD_DEL);
  938. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_CONT);
  939. case BNX2X_VFOP_MCAST_ADD:
  940. if (raw->check_pending(raw))
  941. goto op_pending;
  942. if (args->mc_num) {
  943. /* update mcast list on the ramrod params */
  944. INIT_LIST_HEAD(&mcast->mcast_list);
  945. for (i = 0; i < args->mc_num; i++)
  946. list_add_tail(&(args->mc[i].link),
  947. &mcast->mcast_list);
  948. /* add new mcasts */
  949. vfop->state = BNX2X_VFOP_MCAST_CHK_DONE;
  950. vfop->rc = bnx2x_config_mcast(bp, mcast,
  951. BNX2X_MCAST_CMD_ADD);
  952. }
  953. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  954. case BNX2X_VFOP_MCAST_CHK_DONE:
  955. vfop->rc = raw->check_pending(raw) ? 1 : 0;
  956. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  957. default:
  958. bnx2x_vfop_default(state);
  959. }
  960. op_err:
  961. BNX2X_ERR("MCAST CONFIG error: rc %d\n", vfop->rc);
  962. op_done:
  963. kfree(args->mc);
  964. bnx2x_vfop_end(bp, vf, vfop);
  965. op_pending:
  966. return;
  967. }
  968. int bnx2x_vfop_mcast_cmd(struct bnx2x *bp,
  969. struct bnx2x_virtf *vf,
  970. struct bnx2x_vfop_cmd *cmd,
  971. bnx2x_mac_addr_t *mcasts,
  972. int mcast_num, bool drv_only)
  973. {
  974. struct bnx2x_vfop *vfop = NULL;
  975. size_t mc_sz = mcast_num * sizeof(struct bnx2x_mcast_list_elem);
  976. struct bnx2x_mcast_list_elem *mc = mc_sz ? kzalloc(mc_sz, GFP_KERNEL) :
  977. NULL;
  978. if (!mc_sz || mc) {
  979. vfop = bnx2x_vfop_add(bp, vf);
  980. if (vfop) {
  981. int i;
  982. struct bnx2x_mcast_ramrod_params *ramrod =
  983. &vf->op_params.mcast;
  984. /* set ramrod params */
  985. memset(ramrod, 0, sizeof(*ramrod));
  986. ramrod->mcast_obj = &vf->mcast_obj;
  987. if (drv_only)
  988. set_bit(RAMROD_DRV_CLR_ONLY,
  989. &ramrod->ramrod_flags);
  990. /* copy mcasts pointers */
  991. vfop->args.mc_list.mc_num = mcast_num;
  992. vfop->args.mc_list.mc = mc;
  993. for (i = 0; i < mcast_num; i++)
  994. mc[i].mac = mcasts[i];
  995. bnx2x_vfop_opset(BNX2X_VFOP_MCAST_DEL,
  996. bnx2x_vfop_mcast, cmd->done);
  997. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_mcast,
  998. cmd->block);
  999. } else {
  1000. kfree(mc);
  1001. }
  1002. }
  1003. return -ENOMEM;
  1004. }
  1005. /* VFOP rx-mode */
  1006. static void bnx2x_vfop_rxmode(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1007. {
  1008. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  1009. struct bnx2x_rx_mode_ramrod_params *ramrod = &vfop->op_p->rx_mode;
  1010. enum bnx2x_vfop_rxmode_state state = vfop->state;
  1011. bnx2x_vfop_reset_wq(vf);
  1012. if (vfop->rc < 0)
  1013. goto op_err;
  1014. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  1015. switch (state) {
  1016. case BNX2X_VFOP_RXMODE_CONFIG:
  1017. /* next state */
  1018. vfop->state = BNX2X_VFOP_RXMODE_DONE;
  1019. vfop->rc = bnx2x_config_rx_mode(bp, ramrod);
  1020. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  1021. op_err:
  1022. BNX2X_ERR("RXMODE error: rc %d\n", vfop->rc);
  1023. op_done:
  1024. case BNX2X_VFOP_RXMODE_DONE:
  1025. bnx2x_vfop_end(bp, vf, vfop);
  1026. return;
  1027. default:
  1028. bnx2x_vfop_default(state);
  1029. }
  1030. op_pending:
  1031. return;
  1032. }
  1033. int bnx2x_vfop_rxmode_cmd(struct bnx2x *bp,
  1034. struct bnx2x_virtf *vf,
  1035. struct bnx2x_vfop_cmd *cmd,
  1036. int qid, unsigned long accept_flags)
  1037. {
  1038. struct bnx2x_vf_queue *vfq = vfq_get(vf, qid);
  1039. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  1040. if (vfop) {
  1041. struct bnx2x_rx_mode_ramrod_params *ramrod =
  1042. &vf->op_params.rx_mode;
  1043. memset(ramrod, 0, sizeof(*ramrod));
  1044. /* Prepare ramrod parameters */
  1045. ramrod->cid = vfq->cid;
  1046. ramrod->cl_id = vfq_cl_id(vf, vfq);
  1047. ramrod->rx_mode_obj = &bp->rx_mode_obj;
  1048. ramrod->func_id = FW_VF_HANDLE(vf->abs_vfid);
  1049. ramrod->rx_accept_flags = accept_flags;
  1050. ramrod->tx_accept_flags = accept_flags;
  1051. ramrod->pstate = &vf->filter_state;
  1052. ramrod->state = BNX2X_FILTER_RX_MODE_PENDING;
  1053. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
  1054. set_bit(RAMROD_RX, &ramrod->ramrod_flags);
  1055. set_bit(RAMROD_TX, &ramrod->ramrod_flags);
  1056. ramrod->rdata =
  1057. bnx2x_vf_sp(bp, vf, rx_mode_rdata.e2);
  1058. ramrod->rdata_mapping =
  1059. bnx2x_vf_sp_map(bp, vf, rx_mode_rdata.e2);
  1060. bnx2x_vfop_opset(BNX2X_VFOP_RXMODE_CONFIG,
  1061. bnx2x_vfop_rxmode, cmd->done);
  1062. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_rxmode,
  1063. cmd->block);
  1064. }
  1065. return -ENOMEM;
  1066. }
  1067. /* VFOP queue tear-down ('drop all' rx-mode, clear vlans, clear macs,
  1068. * queue destructor)
  1069. */
  1070. static void bnx2x_vfop_qdown(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1071. {
  1072. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  1073. int qid = vfop->args.qx.qid;
  1074. enum bnx2x_vfop_qteardown_state state = vfop->state;
  1075. struct bnx2x_vfop_cmd cmd;
  1076. if (vfop->rc < 0)
  1077. goto op_err;
  1078. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  1079. cmd.done = bnx2x_vfop_qdown;
  1080. cmd.block = false;
  1081. switch (state) {
  1082. case BNX2X_VFOP_QTEARDOWN_RXMODE:
  1083. /* Drop all */
  1084. vfop->state = BNX2X_VFOP_QTEARDOWN_CLR_VLAN;
  1085. vfop->rc = bnx2x_vfop_rxmode_cmd(bp, vf, &cmd, qid, 0);
  1086. if (vfop->rc)
  1087. goto op_err;
  1088. return;
  1089. case BNX2X_VFOP_QTEARDOWN_CLR_VLAN:
  1090. /* vlan-clear-all: don't consume credit */
  1091. vfop->state = BNX2X_VFOP_QTEARDOWN_CLR_MAC;
  1092. vfop->rc = bnx2x_vfop_vlan_delall_cmd(bp, vf, &cmd, qid, false);
  1093. if (vfop->rc)
  1094. goto op_err;
  1095. return;
  1096. case BNX2X_VFOP_QTEARDOWN_CLR_MAC:
  1097. /* mac-clear-all: consume credit */
  1098. vfop->state = BNX2X_VFOP_QTEARDOWN_QDTOR;
  1099. vfop->rc = bnx2x_vfop_mac_delall_cmd(bp, vf, &cmd, qid, false);
  1100. if (vfop->rc)
  1101. goto op_err;
  1102. return;
  1103. case BNX2X_VFOP_QTEARDOWN_QDTOR:
  1104. /* run the queue destruction flow */
  1105. DP(BNX2X_MSG_IOV, "case: BNX2X_VFOP_QTEARDOWN_QDTOR\n");
  1106. vfop->state = BNX2X_VFOP_QTEARDOWN_DONE;
  1107. DP(BNX2X_MSG_IOV, "new state: BNX2X_VFOP_QTEARDOWN_DONE\n");
  1108. vfop->rc = bnx2x_vfop_qdtor_cmd(bp, vf, &cmd, qid);
  1109. DP(BNX2X_MSG_IOV, "returned from cmd\n");
  1110. if (vfop->rc)
  1111. goto op_err;
  1112. return;
  1113. op_err:
  1114. BNX2X_ERR("QTEARDOWN[%d:%d] error: rc %d\n",
  1115. vf->abs_vfid, qid, vfop->rc);
  1116. case BNX2X_VFOP_QTEARDOWN_DONE:
  1117. bnx2x_vfop_end(bp, vf, vfop);
  1118. return;
  1119. default:
  1120. bnx2x_vfop_default(state);
  1121. }
  1122. }
  1123. int bnx2x_vfop_qdown_cmd(struct bnx2x *bp,
  1124. struct bnx2x_virtf *vf,
  1125. struct bnx2x_vfop_cmd *cmd,
  1126. int qid)
  1127. {
  1128. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  1129. /* for non leading queues skip directly to qdown sate */
  1130. if (vfop) {
  1131. vfop->args.qx.qid = qid;
  1132. bnx2x_vfop_opset(qid == LEADING_IDX ?
  1133. BNX2X_VFOP_QTEARDOWN_RXMODE :
  1134. BNX2X_VFOP_QTEARDOWN_QDTOR, bnx2x_vfop_qdown,
  1135. cmd->done);
  1136. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_qdown,
  1137. cmd->block);
  1138. }
  1139. return -ENOMEM;
  1140. }
  1141. /* VF enable primitives
  1142. * when pretend is required the caller is responsible
  1143. * for calling pretend prior to calling these routines
  1144. */
  1145. /* internal vf enable - until vf is enabled internally all transactions
  1146. * are blocked. This routine should always be called last with pretend.
  1147. */
  1148. static void bnx2x_vf_enable_internal(struct bnx2x *bp, u8 enable)
  1149. {
  1150. REG_WR(bp, PGLUE_B_REG_INTERNAL_VFID_ENABLE, enable ? 1 : 0);
  1151. }
  1152. /* clears vf error in all semi blocks */
  1153. static void bnx2x_vf_semi_clear_err(struct bnx2x *bp, u8 abs_vfid)
  1154. {
  1155. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, abs_vfid);
  1156. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, abs_vfid);
  1157. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, abs_vfid);
  1158. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, abs_vfid);
  1159. }
  1160. static void bnx2x_vf_pglue_clear_err(struct bnx2x *bp, u8 abs_vfid)
  1161. {
  1162. u32 was_err_group = (2 * BP_PATH(bp) + abs_vfid) >> 5;
  1163. u32 was_err_reg = 0;
  1164. switch (was_err_group) {
  1165. case 0:
  1166. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_31_0_CLR;
  1167. break;
  1168. case 1:
  1169. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_63_32_CLR;
  1170. break;
  1171. case 2:
  1172. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_95_64_CLR;
  1173. break;
  1174. case 3:
  1175. was_err_reg = PGLUE_B_REG_WAS_ERROR_VF_127_96_CLR;
  1176. break;
  1177. }
  1178. REG_WR(bp, was_err_reg, 1 << (abs_vfid & 0x1f));
  1179. }
  1180. static void bnx2x_vf_igu_reset(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1181. {
  1182. int i;
  1183. u32 val;
  1184. /* Set VF masks and configuration - pretend */
  1185. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  1186. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  1187. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  1188. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  1189. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  1190. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  1191. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  1192. val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
  1193. val |= (IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_MSI_MSIX_EN);
  1194. if (vf->cfg_flags & VF_CFG_INT_SIMD)
  1195. val |= IGU_VF_CONF_SINGLE_ISR_EN;
  1196. val &= ~IGU_VF_CONF_PARENT_MASK;
  1197. val |= BP_FUNC(bp) << IGU_VF_CONF_PARENT_SHIFT; /* parent PF */
  1198. REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
  1199. DP(BNX2X_MSG_IOV,
  1200. "value in IGU_REG_VF_CONFIGURATION of vf %d after write %x\n",
  1201. vf->abs_vfid, REG_RD(bp, IGU_REG_VF_CONFIGURATION));
  1202. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  1203. /* iterate over all queues, clear sb consumer */
  1204. for (i = 0; i < vf_sb_count(vf); i++) {
  1205. u8 igu_sb_id = vf_igu_sb(vf, i);
  1206. /* zero prod memory */
  1207. REG_WR(bp, IGU_REG_PROD_CONS_MEMORY + igu_sb_id * 4, 0);
  1208. /* clear sb state machine */
  1209. bnx2x_igu_clear_sb_gen(bp, vf->abs_vfid, igu_sb_id,
  1210. false /* VF */);
  1211. /* disable + update */
  1212. bnx2x_vf_igu_ack_sb(bp, vf, igu_sb_id, USTORM_ID, 0,
  1213. IGU_INT_DISABLE, 1);
  1214. }
  1215. }
  1216. void bnx2x_vf_enable_access(struct bnx2x *bp, u8 abs_vfid)
  1217. {
  1218. /* set the VF-PF association in the FW */
  1219. storm_memset_vf_to_pf(bp, FW_VF_HANDLE(abs_vfid), BP_FUNC(bp));
  1220. storm_memset_func_en(bp, FW_VF_HANDLE(abs_vfid), 1);
  1221. /* clear vf errors*/
  1222. bnx2x_vf_semi_clear_err(bp, abs_vfid);
  1223. bnx2x_vf_pglue_clear_err(bp, abs_vfid);
  1224. /* internal vf-enable - pretend */
  1225. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, abs_vfid));
  1226. DP(BNX2X_MSG_IOV, "enabling internal access for vf %x\n", abs_vfid);
  1227. bnx2x_vf_enable_internal(bp, true);
  1228. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  1229. }
  1230. static void bnx2x_vf_enable_traffic(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1231. {
  1232. /* Reset vf in IGU interrupts are still disabled */
  1233. bnx2x_vf_igu_reset(bp, vf);
  1234. /* pretend to enable the vf with the PBF */
  1235. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  1236. REG_WR(bp, PBF_REG_DISABLE_VF, 0);
  1237. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  1238. }
  1239. static u8 bnx2x_vf_is_pcie_pending(struct bnx2x *bp, u8 abs_vfid)
  1240. {
  1241. struct pci_dev *dev;
  1242. struct bnx2x_virtf *vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
  1243. if (!vf)
  1244. return false;
  1245. dev = pci_get_bus_and_slot(vf->bus, vf->devfn);
  1246. if (dev)
  1247. return bnx2x_is_pcie_pending(dev);
  1248. return false;
  1249. }
  1250. int bnx2x_vf_flr_clnup_epilog(struct bnx2x *bp, u8 abs_vfid)
  1251. {
  1252. /* Verify no pending pci transactions */
  1253. if (bnx2x_vf_is_pcie_pending(bp, abs_vfid))
  1254. BNX2X_ERR("PCIE Transactions still pending\n");
  1255. return 0;
  1256. }
  1257. /* must be called after the number of PF queues and the number of VFs are
  1258. * both known
  1259. */
  1260. static void
  1261. bnx2x_iov_static_resc(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1262. {
  1263. struct vf_pf_resc_request *resc = &vf->alloc_resc;
  1264. u16 vlan_count = 0;
  1265. /* will be set only during VF-ACQUIRE */
  1266. resc->num_rxqs = 0;
  1267. resc->num_txqs = 0;
  1268. /* no credit calculations for macs (just yet) */
  1269. resc->num_mac_filters = 1;
  1270. /* divvy up vlan rules */
  1271. vlan_count = bp->vlans_pool.check(&bp->vlans_pool);
  1272. vlan_count = 1 << ilog2(vlan_count);
  1273. resc->num_vlan_filters = vlan_count / BNX2X_NR_VIRTFN(bp);
  1274. /* no real limitation */
  1275. resc->num_mc_filters = 0;
  1276. /* num_sbs already set */
  1277. resc->num_sbs = vf->sb_count;
  1278. }
  1279. /* FLR routines: */
  1280. static void bnx2x_vf_free_resc(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1281. {
  1282. /* reset the state variables */
  1283. bnx2x_iov_static_resc(bp, vf);
  1284. vf->state = VF_FREE;
  1285. }
  1286. static void bnx2x_vf_flr_clnup_hw(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1287. {
  1288. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1289. /* DQ usage counter */
  1290. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  1291. bnx2x_flr_clnup_poll_hw_counter(bp, DORQ_REG_VF_USAGE_CNT,
  1292. "DQ VF usage counter timed out",
  1293. poll_cnt);
  1294. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  1295. /* FW cleanup command - poll for the results */
  1296. if (bnx2x_send_final_clnup(bp, (u8)FW_VF_HANDLE(vf->abs_vfid),
  1297. poll_cnt))
  1298. BNX2X_ERR("VF[%d] Final cleanup timed-out\n", vf->abs_vfid);
  1299. /* verify TX hw is flushed */
  1300. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1301. }
  1302. static void bnx2x_vfop_flr(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1303. {
  1304. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  1305. struct bnx2x_vfop_args_qx *qx = &vfop->args.qx;
  1306. enum bnx2x_vfop_flr_state state = vfop->state;
  1307. struct bnx2x_vfop_cmd cmd = {
  1308. .done = bnx2x_vfop_flr,
  1309. .block = false,
  1310. };
  1311. if (vfop->rc < 0)
  1312. goto op_err;
  1313. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  1314. switch (state) {
  1315. case BNX2X_VFOP_FLR_QUEUES:
  1316. /* the cleanup operations are valid if and only if the VF
  1317. * was first acquired.
  1318. */
  1319. if (++(qx->qid) < vf_rxq_count(vf)) {
  1320. vfop->rc = bnx2x_vfop_qflr_cmd(bp, vf, &cmd,
  1321. qx->qid);
  1322. if (vfop->rc)
  1323. goto op_err;
  1324. return;
  1325. }
  1326. /* remove multicasts */
  1327. vfop->state = BNX2X_VFOP_FLR_HW;
  1328. vfop->rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, NULL,
  1329. 0, true);
  1330. if (vfop->rc)
  1331. goto op_err;
  1332. return;
  1333. case BNX2X_VFOP_FLR_HW:
  1334. /* dispatch final cleanup and wait for HW queues to flush */
  1335. bnx2x_vf_flr_clnup_hw(bp, vf);
  1336. /* release VF resources */
  1337. bnx2x_vf_free_resc(bp, vf);
  1338. /* re-open the mailbox */
  1339. bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
  1340. goto op_done;
  1341. default:
  1342. bnx2x_vfop_default(state);
  1343. }
  1344. op_err:
  1345. BNX2X_ERR("VF[%d] FLR error: rc %d\n", vf->abs_vfid, vfop->rc);
  1346. op_done:
  1347. vf->flr_clnup_stage = VF_FLR_ACK;
  1348. bnx2x_vfop_end(bp, vf, vfop);
  1349. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
  1350. }
  1351. static int bnx2x_vfop_flr_cmd(struct bnx2x *bp,
  1352. struct bnx2x_virtf *vf,
  1353. vfop_handler_t done)
  1354. {
  1355. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  1356. if (vfop) {
  1357. vfop->args.qx.qid = -1; /* loop */
  1358. bnx2x_vfop_opset(BNX2X_VFOP_FLR_QUEUES,
  1359. bnx2x_vfop_flr, done);
  1360. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_flr, false);
  1361. }
  1362. return -ENOMEM;
  1363. }
  1364. static void bnx2x_vf_flr_clnup(struct bnx2x *bp, struct bnx2x_virtf *prev_vf)
  1365. {
  1366. int i = prev_vf ? prev_vf->index + 1 : 0;
  1367. struct bnx2x_virtf *vf;
  1368. /* find next VF to cleanup */
  1369. next_vf_to_clean:
  1370. for (;
  1371. i < BNX2X_NR_VIRTFN(bp) &&
  1372. (bnx2x_vf(bp, i, state) != VF_RESET ||
  1373. bnx2x_vf(bp, i, flr_clnup_stage) != VF_FLR_CLN);
  1374. i++)
  1375. ;
  1376. DP(BNX2X_MSG_IOV, "next vf to cleanup: %d. Num of vfs: %d\n", i,
  1377. BNX2X_NR_VIRTFN(bp));
  1378. if (i < BNX2X_NR_VIRTFN(bp)) {
  1379. vf = BP_VF(bp, i);
  1380. /* lock the vf pf channel */
  1381. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_FLR);
  1382. /* invoke the VF FLR SM */
  1383. if (bnx2x_vfop_flr_cmd(bp, vf, bnx2x_vf_flr_clnup)) {
  1384. BNX2X_ERR("VF[%d]: FLR cleanup failed -ENOMEM\n",
  1385. vf->abs_vfid);
  1386. /* mark the VF to be ACKED and continue */
  1387. vf->flr_clnup_stage = VF_FLR_ACK;
  1388. goto next_vf_to_clean;
  1389. }
  1390. return;
  1391. }
  1392. /* we are done, update vf records */
  1393. for_each_vf(bp, i) {
  1394. vf = BP_VF(bp, i);
  1395. if (vf->flr_clnup_stage != VF_FLR_ACK)
  1396. continue;
  1397. vf->flr_clnup_stage = VF_FLR_EPILOG;
  1398. }
  1399. /* Acknowledge the handled VFs.
  1400. * we are acknowledge all the vfs which an flr was requested for, even
  1401. * if amongst them there are such that we never opened, since the mcp
  1402. * will interrupt us immediately again if we only ack some of the bits,
  1403. * resulting in an endless loop. This can happen for example in KVM
  1404. * where an 'all ones' flr request is sometimes given by hyper visor
  1405. */
  1406. DP(BNX2X_MSG_MCP, "DRV_STATUS_VF_DISABLED ACK for vfs 0x%x 0x%x\n",
  1407. bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
  1408. for (i = 0; i < FLRD_VFS_DWORDS; i++)
  1409. SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i],
  1410. bp->vfdb->flrd_vfs[i]);
  1411. bnx2x_fw_command(bp, DRV_MSG_CODE_VF_DISABLED_DONE, 0);
  1412. /* clear the acked bits - better yet if the MCP implemented
  1413. * write to clear semantics
  1414. */
  1415. for (i = 0; i < FLRD_VFS_DWORDS; i++)
  1416. SHMEM2_WR(bp, drv_ack_vf_disabled[BP_FW_MB_IDX(bp)][i], 0);
  1417. }
  1418. void bnx2x_vf_handle_flr_event(struct bnx2x *bp)
  1419. {
  1420. int i;
  1421. /* Read FLR'd VFs */
  1422. for (i = 0; i < FLRD_VFS_DWORDS; i++)
  1423. bp->vfdb->flrd_vfs[i] = SHMEM2_RD(bp, mcp_vf_disabled[i]);
  1424. DP(BNX2X_MSG_MCP,
  1425. "DRV_STATUS_VF_DISABLED received for vfs 0x%x 0x%x\n",
  1426. bp->vfdb->flrd_vfs[0], bp->vfdb->flrd_vfs[1]);
  1427. for_each_vf(bp, i) {
  1428. struct bnx2x_virtf *vf = BP_VF(bp, i);
  1429. u32 reset = 0;
  1430. if (vf->abs_vfid < 32)
  1431. reset = bp->vfdb->flrd_vfs[0] & (1 << vf->abs_vfid);
  1432. else
  1433. reset = bp->vfdb->flrd_vfs[1] &
  1434. (1 << (vf->abs_vfid - 32));
  1435. if (reset) {
  1436. /* set as reset and ready for cleanup */
  1437. vf->state = VF_RESET;
  1438. vf->flr_clnup_stage = VF_FLR_CLN;
  1439. DP(BNX2X_MSG_IOV,
  1440. "Initiating Final cleanup for VF %d\n",
  1441. vf->abs_vfid);
  1442. }
  1443. }
  1444. /* do the FLR cleanup for all marked VFs*/
  1445. bnx2x_vf_flr_clnup(bp, NULL);
  1446. }
  1447. /* IOV global initialization routines */
  1448. void bnx2x_iov_init_dq(struct bnx2x *bp)
  1449. {
  1450. if (!IS_SRIOV(bp))
  1451. return;
  1452. /* Set the DQ such that the CID reflect the abs_vfid */
  1453. REG_WR(bp, DORQ_REG_VF_NORM_VF_BASE, 0);
  1454. REG_WR(bp, DORQ_REG_MAX_RVFID_SIZE, ilog2(BNX2X_MAX_NUM_OF_VFS));
  1455. /* Set VFs starting CID. If its > 0 the preceding CIDs are belong to
  1456. * the PF L2 queues
  1457. */
  1458. REG_WR(bp, DORQ_REG_VF_NORM_CID_BASE, BNX2X_FIRST_VF_CID);
  1459. /* The VF window size is the log2 of the max number of CIDs per VF */
  1460. REG_WR(bp, DORQ_REG_VF_NORM_CID_WND_SIZE, BNX2X_VF_CID_WND);
  1461. /* The VF doorbell size 0 - *B, 4 - 128B. We set it here to match
  1462. * the Pf doorbell size although the 2 are independent.
  1463. */
  1464. REG_WR(bp, DORQ_REG_VF_NORM_CID_OFST, 3);
  1465. /* No security checks for now -
  1466. * configure single rule (out of 16) mask = 0x1, value = 0x0,
  1467. * CID range 0 - 0x1ffff
  1468. */
  1469. REG_WR(bp, DORQ_REG_VF_TYPE_MASK_0, 1);
  1470. REG_WR(bp, DORQ_REG_VF_TYPE_VALUE_0, 0);
  1471. REG_WR(bp, DORQ_REG_VF_TYPE_MIN_MCID_0, 0);
  1472. REG_WR(bp, DORQ_REG_VF_TYPE_MAX_MCID_0, 0x1ffff);
  1473. /* set the number of VF allowed doorbells to the full DQ range */
  1474. REG_WR(bp, DORQ_REG_VF_NORM_MAX_CID_COUNT, 0x20000);
  1475. /* set the VF doorbell threshold */
  1476. REG_WR(bp, DORQ_REG_VF_USAGE_CT_LIMIT, 4);
  1477. }
  1478. void bnx2x_iov_init_dmae(struct bnx2x *bp)
  1479. {
  1480. if (pci_find_ext_capability(bp->pdev, PCI_EXT_CAP_ID_SRIOV))
  1481. REG_WR(bp, DMAE_REG_BACKWARD_COMP_EN, 0);
  1482. }
  1483. static int bnx2x_vf_bus(struct bnx2x *bp, int vfid)
  1484. {
  1485. struct pci_dev *dev = bp->pdev;
  1486. struct bnx2x_sriov *iov = &bp->vfdb->sriov;
  1487. return dev->bus->number + ((dev->devfn + iov->offset +
  1488. iov->stride * vfid) >> 8);
  1489. }
  1490. static int bnx2x_vf_devfn(struct bnx2x *bp, int vfid)
  1491. {
  1492. struct pci_dev *dev = bp->pdev;
  1493. struct bnx2x_sriov *iov = &bp->vfdb->sriov;
  1494. return (dev->devfn + iov->offset + iov->stride * vfid) & 0xff;
  1495. }
  1496. static void bnx2x_vf_set_bars(struct bnx2x *bp, struct bnx2x_virtf *vf)
  1497. {
  1498. int i, n;
  1499. struct pci_dev *dev = bp->pdev;
  1500. struct bnx2x_sriov *iov = &bp->vfdb->sriov;
  1501. for (i = 0, n = 0; i < PCI_SRIOV_NUM_BARS; i += 2, n++) {
  1502. u64 start = pci_resource_start(dev, PCI_IOV_RESOURCES + i);
  1503. u32 size = pci_resource_len(dev, PCI_IOV_RESOURCES + i);
  1504. size /= iov->total;
  1505. vf->bars[n].bar = start + size * vf->abs_vfid;
  1506. vf->bars[n].size = size;
  1507. }
  1508. }
  1509. static int bnx2x_ari_enabled(struct pci_dev *dev)
  1510. {
  1511. return dev->bus->self && dev->bus->self->ari_enabled;
  1512. }
  1513. static void
  1514. bnx2x_get_vf_igu_cam_info(struct bnx2x *bp)
  1515. {
  1516. int sb_id;
  1517. u32 val;
  1518. u8 fid, current_pf = 0;
  1519. /* IGU in normal mode - read CAM */
  1520. for (sb_id = 0; sb_id < IGU_REG_MAPPING_MEMORY_SIZE; sb_id++) {
  1521. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + sb_id * 4);
  1522. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  1523. continue;
  1524. fid = GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID);
  1525. if (fid & IGU_FID_ENCODE_IS_PF)
  1526. current_pf = fid & IGU_FID_PF_NUM_MASK;
  1527. else if (current_pf == BP_ABS_FUNC(bp))
  1528. bnx2x_vf_set_igu_info(bp, sb_id,
  1529. (fid & IGU_FID_VF_NUM_MASK));
  1530. DP(BNX2X_MSG_IOV, "%s[%d], igu_sb_id=%d, msix=%d\n",
  1531. ((fid & IGU_FID_ENCODE_IS_PF) ? "PF" : "VF"),
  1532. ((fid & IGU_FID_ENCODE_IS_PF) ? (fid & IGU_FID_PF_NUM_MASK) :
  1533. (fid & IGU_FID_VF_NUM_MASK)), sb_id,
  1534. GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR));
  1535. }
  1536. DP(BNX2X_MSG_IOV, "vf_sbs_pool is %d\n", BP_VFDB(bp)->vf_sbs_pool);
  1537. }
  1538. static void __bnx2x_iov_free_vfdb(struct bnx2x *bp)
  1539. {
  1540. if (bp->vfdb) {
  1541. kfree(bp->vfdb->vfqs);
  1542. kfree(bp->vfdb->vfs);
  1543. kfree(bp->vfdb);
  1544. }
  1545. bp->vfdb = NULL;
  1546. }
  1547. static int bnx2x_sriov_pci_cfg_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
  1548. {
  1549. int pos;
  1550. struct pci_dev *dev = bp->pdev;
  1551. pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV);
  1552. if (!pos) {
  1553. BNX2X_ERR("failed to find SRIOV capability in device\n");
  1554. return -ENODEV;
  1555. }
  1556. iov->pos = pos;
  1557. DP(BNX2X_MSG_IOV, "sriov ext pos %d\n", pos);
  1558. pci_read_config_word(dev, pos + PCI_SRIOV_CTRL, &iov->ctrl);
  1559. pci_read_config_word(dev, pos + PCI_SRIOV_TOTAL_VF, &iov->total);
  1560. pci_read_config_word(dev, pos + PCI_SRIOV_INITIAL_VF, &iov->initial);
  1561. pci_read_config_word(dev, pos + PCI_SRIOV_VF_OFFSET, &iov->offset);
  1562. pci_read_config_word(dev, pos + PCI_SRIOV_VF_STRIDE, &iov->stride);
  1563. pci_read_config_dword(dev, pos + PCI_SRIOV_SUP_PGSIZE, &iov->pgsz);
  1564. pci_read_config_dword(dev, pos + PCI_SRIOV_CAP, &iov->cap);
  1565. pci_read_config_byte(dev, pos + PCI_SRIOV_FUNC_LINK, &iov->link);
  1566. return 0;
  1567. }
  1568. static int bnx2x_sriov_info(struct bnx2x *bp, struct bnx2x_sriov *iov)
  1569. {
  1570. u32 val;
  1571. /* read the SRIOV capability structure
  1572. * The fields can be read via configuration read or
  1573. * directly from the device (starting at offset PCICFG_OFFSET)
  1574. */
  1575. if (bnx2x_sriov_pci_cfg_info(bp, iov))
  1576. return -ENODEV;
  1577. /* get the number of SRIOV bars */
  1578. iov->nres = 0;
  1579. /* read the first_vfid */
  1580. val = REG_RD(bp, PCICFG_OFFSET + GRC_CONFIG_REG_PF_INIT_VF);
  1581. iov->first_vf_in_pf = ((val & GRC_CR_PF_INIT_VF_PF_FIRST_VF_NUM_MASK)
  1582. * 8) - (BNX2X_MAX_NUM_OF_VFS * BP_PATH(bp));
  1583. DP(BNX2X_MSG_IOV,
  1584. "IOV info[%d]: first vf %d, nres %d, cap 0x%x, ctrl 0x%x, total %d, initial %d, num vfs %d, offset %d, stride %d, page size 0x%x\n",
  1585. BP_FUNC(bp),
  1586. iov->first_vf_in_pf, iov->nres, iov->cap, iov->ctrl, iov->total,
  1587. iov->initial, iov->nr_virtfn, iov->offset, iov->stride, iov->pgsz);
  1588. return 0;
  1589. }
  1590. /* must be called after PF bars are mapped */
  1591. int bnx2x_iov_init_one(struct bnx2x *bp, int int_mode_param,
  1592. int num_vfs_param)
  1593. {
  1594. int err, i;
  1595. struct bnx2x_sriov *iov;
  1596. struct pci_dev *dev = bp->pdev;
  1597. bp->vfdb = NULL;
  1598. /* verify is pf */
  1599. if (IS_VF(bp))
  1600. return 0;
  1601. /* verify sriov capability is present in configuration space */
  1602. if (!pci_find_ext_capability(dev, PCI_EXT_CAP_ID_SRIOV))
  1603. return 0;
  1604. /* verify chip revision */
  1605. if (CHIP_IS_E1x(bp))
  1606. return 0;
  1607. /* check if SRIOV support is turned off */
  1608. if (!num_vfs_param)
  1609. return 0;
  1610. /* SRIOV assumes that num of PF CIDs < BNX2X_FIRST_VF_CID */
  1611. if (BNX2X_L2_MAX_CID(bp) >= BNX2X_FIRST_VF_CID) {
  1612. BNX2X_ERR("PF cids %d are overspilling into vf space (starts at %d). Abort SRIOV\n",
  1613. BNX2X_L2_MAX_CID(bp), BNX2X_FIRST_VF_CID);
  1614. return 0;
  1615. }
  1616. /* SRIOV can be enabled only with MSIX */
  1617. if (int_mode_param == BNX2X_INT_MODE_MSI ||
  1618. int_mode_param == BNX2X_INT_MODE_INTX) {
  1619. BNX2X_ERR("Forced MSI/INTx mode is incompatible with SRIOV\n");
  1620. return 0;
  1621. }
  1622. err = -EIO;
  1623. /* verify ari is enabled */
  1624. if (!bnx2x_ari_enabled(bp->pdev)) {
  1625. BNX2X_ERR("ARI not supported (check pci bridge ARI forwarding), SRIOV can not be enabled\n");
  1626. return 0;
  1627. }
  1628. /* verify igu is in normal mode */
  1629. if (CHIP_INT_MODE_IS_BC(bp)) {
  1630. BNX2X_ERR("IGU not normal mode, SRIOV can not be enabled\n");
  1631. return 0;
  1632. }
  1633. /* allocate the vfs database */
  1634. bp->vfdb = kzalloc(sizeof(*(bp->vfdb)), GFP_KERNEL);
  1635. if (!bp->vfdb) {
  1636. BNX2X_ERR("failed to allocate vf database\n");
  1637. err = -ENOMEM;
  1638. goto failed;
  1639. }
  1640. /* get the sriov info - Linux already collected all the pertinent
  1641. * information, however the sriov structure is for the private use
  1642. * of the pci module. Also we want this information regardless
  1643. * of the hyper-visor.
  1644. */
  1645. iov = &(bp->vfdb->sriov);
  1646. err = bnx2x_sriov_info(bp, iov);
  1647. if (err)
  1648. goto failed;
  1649. /* SR-IOV capability was enabled but there are no VFs*/
  1650. if (iov->total == 0)
  1651. goto failed;
  1652. iov->nr_virtfn = min_t(u16, iov->total, num_vfs_param);
  1653. DP(BNX2X_MSG_IOV, "num_vfs_param was %d, nr_virtfn was %d\n",
  1654. num_vfs_param, iov->nr_virtfn);
  1655. /* allocate the vf array */
  1656. bp->vfdb->vfs = kzalloc(sizeof(struct bnx2x_virtf) *
  1657. BNX2X_NR_VIRTFN(bp), GFP_KERNEL);
  1658. if (!bp->vfdb->vfs) {
  1659. BNX2X_ERR("failed to allocate vf array\n");
  1660. err = -ENOMEM;
  1661. goto failed;
  1662. }
  1663. /* Initial VF init - index and abs_vfid - nr_virtfn must be set */
  1664. for_each_vf(bp, i) {
  1665. bnx2x_vf(bp, i, index) = i;
  1666. bnx2x_vf(bp, i, abs_vfid) = iov->first_vf_in_pf + i;
  1667. bnx2x_vf(bp, i, state) = VF_FREE;
  1668. INIT_LIST_HEAD(&bnx2x_vf(bp, i, op_list_head));
  1669. mutex_init(&bnx2x_vf(bp, i, op_mutex));
  1670. bnx2x_vf(bp, i, op_current) = CHANNEL_TLV_NONE;
  1671. }
  1672. /* re-read the IGU CAM for VFs - index and abs_vfid must be set */
  1673. bnx2x_get_vf_igu_cam_info(bp);
  1674. /* allocate the queue arrays for all VFs */
  1675. bp->vfdb->vfqs = kzalloc(
  1676. BNX2X_MAX_NUM_VF_QUEUES * sizeof(struct bnx2x_vf_queue),
  1677. GFP_KERNEL);
  1678. DP(BNX2X_MSG_IOV, "bp->vfdb->vfqs was %p\n", bp->vfdb->vfqs);
  1679. if (!bp->vfdb->vfqs) {
  1680. BNX2X_ERR("failed to allocate vf queue array\n");
  1681. err = -ENOMEM;
  1682. goto failed;
  1683. }
  1684. return 0;
  1685. failed:
  1686. DP(BNX2X_MSG_IOV, "Failed err=%d\n", err);
  1687. __bnx2x_iov_free_vfdb(bp);
  1688. return err;
  1689. }
  1690. void bnx2x_iov_remove_one(struct bnx2x *bp)
  1691. {
  1692. /* if SRIOV is not enabled there's nothing to do */
  1693. if (!IS_SRIOV(bp))
  1694. return;
  1695. DP(BNX2X_MSG_IOV, "about to call disable sriov\n");
  1696. pci_disable_sriov(bp->pdev);
  1697. DP(BNX2X_MSG_IOV, "sriov disabled\n");
  1698. /* free vf database */
  1699. __bnx2x_iov_free_vfdb(bp);
  1700. }
  1701. void bnx2x_iov_free_mem(struct bnx2x *bp)
  1702. {
  1703. int i;
  1704. if (!IS_SRIOV(bp))
  1705. return;
  1706. /* free vfs hw contexts */
  1707. for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
  1708. struct hw_dma *cxt = &bp->vfdb->context[i];
  1709. BNX2X_PCI_FREE(cxt->addr, cxt->mapping, cxt->size);
  1710. }
  1711. BNX2X_PCI_FREE(BP_VFDB(bp)->sp_dma.addr,
  1712. BP_VFDB(bp)->sp_dma.mapping,
  1713. BP_VFDB(bp)->sp_dma.size);
  1714. BNX2X_PCI_FREE(BP_VF_MBX_DMA(bp)->addr,
  1715. BP_VF_MBX_DMA(bp)->mapping,
  1716. BP_VF_MBX_DMA(bp)->size);
  1717. BNX2X_PCI_FREE(BP_VF_BULLETIN_DMA(bp)->addr,
  1718. BP_VF_BULLETIN_DMA(bp)->mapping,
  1719. BP_VF_BULLETIN_DMA(bp)->size);
  1720. }
  1721. int bnx2x_iov_alloc_mem(struct bnx2x *bp)
  1722. {
  1723. size_t tot_size;
  1724. int i, rc = 0;
  1725. if (!IS_SRIOV(bp))
  1726. return rc;
  1727. /* allocate vfs hw contexts */
  1728. tot_size = (BP_VFDB(bp)->sriov.first_vf_in_pf + BNX2X_NR_VIRTFN(bp)) *
  1729. BNX2X_CIDS_PER_VF * sizeof(union cdu_context);
  1730. for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
  1731. struct hw_dma *cxt = BP_VF_CXT_PAGE(bp, i);
  1732. cxt->size = min_t(size_t, tot_size, CDU_ILT_PAGE_SZ);
  1733. if (cxt->size) {
  1734. BNX2X_PCI_ALLOC(cxt->addr, &cxt->mapping, cxt->size);
  1735. } else {
  1736. cxt->addr = NULL;
  1737. cxt->mapping = 0;
  1738. }
  1739. tot_size -= cxt->size;
  1740. }
  1741. /* allocate vfs ramrods dma memory - client_init and set_mac */
  1742. tot_size = BNX2X_NR_VIRTFN(bp) * sizeof(struct bnx2x_vf_sp);
  1743. BNX2X_PCI_ALLOC(BP_VFDB(bp)->sp_dma.addr, &BP_VFDB(bp)->sp_dma.mapping,
  1744. tot_size);
  1745. BP_VFDB(bp)->sp_dma.size = tot_size;
  1746. /* allocate mailboxes */
  1747. tot_size = BNX2X_NR_VIRTFN(bp) * MBX_MSG_ALIGNED_SIZE;
  1748. BNX2X_PCI_ALLOC(BP_VF_MBX_DMA(bp)->addr, &BP_VF_MBX_DMA(bp)->mapping,
  1749. tot_size);
  1750. BP_VF_MBX_DMA(bp)->size = tot_size;
  1751. /* allocate local bulletin boards */
  1752. tot_size = BNX2X_NR_VIRTFN(bp) * BULLETIN_CONTENT_SIZE;
  1753. BNX2X_PCI_ALLOC(BP_VF_BULLETIN_DMA(bp)->addr,
  1754. &BP_VF_BULLETIN_DMA(bp)->mapping, tot_size);
  1755. BP_VF_BULLETIN_DMA(bp)->size = tot_size;
  1756. return 0;
  1757. alloc_mem_err:
  1758. return -ENOMEM;
  1759. }
  1760. static void bnx2x_vfq_init(struct bnx2x *bp, struct bnx2x_virtf *vf,
  1761. struct bnx2x_vf_queue *q)
  1762. {
  1763. u8 cl_id = vfq_cl_id(vf, q);
  1764. u8 func_id = FW_VF_HANDLE(vf->abs_vfid);
  1765. unsigned long q_type = 0;
  1766. set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  1767. set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  1768. /* Queue State object */
  1769. bnx2x_init_queue_obj(bp, &q->sp_obj,
  1770. cl_id, &q->cid, 1, func_id,
  1771. bnx2x_vf_sp(bp, vf, q_data),
  1772. bnx2x_vf_sp_map(bp, vf, q_data),
  1773. q_type);
  1774. DP(BNX2X_MSG_IOV,
  1775. "initialized vf %d's queue object. func id set to %d. cid set to 0x%x\n",
  1776. vf->abs_vfid, q->sp_obj.func_id, q->cid);
  1777. }
  1778. /* called by bnx2x_nic_load */
  1779. int bnx2x_iov_nic_init(struct bnx2x *bp)
  1780. {
  1781. int vfid;
  1782. if (!IS_SRIOV(bp)) {
  1783. DP(BNX2X_MSG_IOV, "vfdb was not allocated\n");
  1784. return 0;
  1785. }
  1786. DP(BNX2X_MSG_IOV, "num of vfs: %d\n", (bp)->vfdb->sriov.nr_virtfn);
  1787. /* let FLR complete ... */
  1788. msleep(100);
  1789. /* initialize vf database */
  1790. for_each_vf(bp, vfid) {
  1791. struct bnx2x_virtf *vf = BP_VF(bp, vfid);
  1792. int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vfid) *
  1793. BNX2X_CIDS_PER_VF;
  1794. union cdu_context *base_cxt = (union cdu_context *)
  1795. BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
  1796. (base_vf_cid & (ILT_PAGE_CIDS-1));
  1797. DP(BNX2X_MSG_IOV,
  1798. "VF[%d] Max IGU SBs: %d, base vf cid 0x%x, base cid 0x%x, base cxt %p\n",
  1799. vf->abs_vfid, vf_sb_count(vf), base_vf_cid,
  1800. BNX2X_FIRST_VF_CID + base_vf_cid, base_cxt);
  1801. /* init statically provisioned resources */
  1802. bnx2x_iov_static_resc(bp, vf);
  1803. /* queues are initialized during VF-ACQUIRE */
  1804. /* reserve the vf vlan credit */
  1805. bp->vlans_pool.get(&bp->vlans_pool, vf_vlan_rules_cnt(vf));
  1806. vf->filter_state = 0;
  1807. vf->sp_cl_id = bnx2x_fp(bp, 0, cl_id);
  1808. /* init mcast object - This object will be re-initialized
  1809. * during VF-ACQUIRE with the proper cl_id and cid.
  1810. * It needs to be initialized here so that it can be safely
  1811. * handled by a subsequent FLR flow.
  1812. */
  1813. bnx2x_init_mcast_obj(bp, &vf->mcast_obj, 0xFF,
  1814. 0xFF, 0xFF, 0xFF,
  1815. bnx2x_vf_sp(bp, vf, mcast_rdata),
  1816. bnx2x_vf_sp_map(bp, vf, mcast_rdata),
  1817. BNX2X_FILTER_MCAST_PENDING,
  1818. &vf->filter_state,
  1819. BNX2X_OBJ_TYPE_RX_TX);
  1820. /* set the mailbox message addresses */
  1821. BP_VF_MBX(bp, vfid)->msg = (struct bnx2x_vf_mbx_msg *)
  1822. (((u8 *)BP_VF_MBX_DMA(bp)->addr) + vfid *
  1823. MBX_MSG_ALIGNED_SIZE);
  1824. BP_VF_MBX(bp, vfid)->msg_mapping = BP_VF_MBX_DMA(bp)->mapping +
  1825. vfid * MBX_MSG_ALIGNED_SIZE;
  1826. /* Enable vf mailbox */
  1827. bnx2x_vf_enable_mbx(bp, vf->abs_vfid);
  1828. }
  1829. /* Final VF init */
  1830. for_each_vf(bp, vfid) {
  1831. struct bnx2x_virtf *vf = BP_VF(bp, vfid);
  1832. /* fill in the BDF and bars */
  1833. vf->bus = bnx2x_vf_bus(bp, vfid);
  1834. vf->devfn = bnx2x_vf_devfn(bp, vfid);
  1835. bnx2x_vf_set_bars(bp, vf);
  1836. DP(BNX2X_MSG_IOV,
  1837. "VF info[%d]: bus 0x%x, devfn 0x%x, bar0 [0x%x, %d], bar1 [0x%x, %d], bar2 [0x%x, %d]\n",
  1838. vf->abs_vfid, vf->bus, vf->devfn,
  1839. (unsigned)vf->bars[0].bar, vf->bars[0].size,
  1840. (unsigned)vf->bars[1].bar, vf->bars[1].size,
  1841. (unsigned)vf->bars[2].bar, vf->bars[2].size);
  1842. }
  1843. return 0;
  1844. }
  1845. /* called by bnx2x_chip_cleanup */
  1846. int bnx2x_iov_chip_cleanup(struct bnx2x *bp)
  1847. {
  1848. int i;
  1849. if (!IS_SRIOV(bp))
  1850. return 0;
  1851. /* release all the VFs */
  1852. for_each_vf(bp, i)
  1853. bnx2x_vf_release(bp, BP_VF(bp, i), true); /* blocking */
  1854. return 0;
  1855. }
  1856. /* called by bnx2x_init_hw_func, returns the next ilt line */
  1857. int bnx2x_iov_init_ilt(struct bnx2x *bp, u16 line)
  1858. {
  1859. int i;
  1860. struct bnx2x_ilt *ilt = BP_ILT(bp);
  1861. if (!IS_SRIOV(bp))
  1862. return line;
  1863. /* set vfs ilt lines */
  1864. for (i = 0; i < BNX2X_VF_CIDS/ILT_PAGE_CIDS; i++) {
  1865. struct hw_dma *hw_cxt = BP_VF_CXT_PAGE(bp, i);
  1866. ilt->lines[line+i].page = hw_cxt->addr;
  1867. ilt->lines[line+i].page_mapping = hw_cxt->mapping;
  1868. ilt->lines[line+i].size = hw_cxt->size; /* doesn't matter */
  1869. }
  1870. return line + i;
  1871. }
  1872. static u8 bnx2x_iov_is_vf_cid(struct bnx2x *bp, u16 cid)
  1873. {
  1874. return ((cid >= BNX2X_FIRST_VF_CID) &&
  1875. ((cid - BNX2X_FIRST_VF_CID) < BNX2X_VF_CIDS));
  1876. }
  1877. static
  1878. void bnx2x_vf_handle_classification_eqe(struct bnx2x *bp,
  1879. struct bnx2x_vf_queue *vfq,
  1880. union event_ring_elem *elem)
  1881. {
  1882. unsigned long ramrod_flags = 0;
  1883. int rc = 0;
  1884. /* Always push next commands out, don't wait here */
  1885. set_bit(RAMROD_CONT, &ramrod_flags);
  1886. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  1887. case BNX2X_FILTER_MAC_PENDING:
  1888. rc = vfq->mac_obj.complete(bp, &vfq->mac_obj, elem,
  1889. &ramrod_flags);
  1890. break;
  1891. case BNX2X_FILTER_VLAN_PENDING:
  1892. rc = vfq->vlan_obj.complete(bp, &vfq->vlan_obj, elem,
  1893. &ramrod_flags);
  1894. break;
  1895. default:
  1896. BNX2X_ERR("Unsupported classification command: %d\n",
  1897. elem->message.data.eth_event.echo);
  1898. return;
  1899. }
  1900. if (rc < 0)
  1901. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  1902. else if (rc > 0)
  1903. DP(BNX2X_MSG_IOV, "Scheduled next pending commands...\n");
  1904. }
  1905. static
  1906. void bnx2x_vf_handle_mcast_eqe(struct bnx2x *bp,
  1907. struct bnx2x_virtf *vf)
  1908. {
  1909. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  1910. int rc;
  1911. rparam.mcast_obj = &vf->mcast_obj;
  1912. vf->mcast_obj.raw.clear_pending(&vf->mcast_obj.raw);
  1913. /* If there are pending mcast commands - send them */
  1914. if (vf->mcast_obj.check_pending(&vf->mcast_obj)) {
  1915. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  1916. if (rc < 0)
  1917. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  1918. rc);
  1919. }
  1920. }
  1921. static
  1922. void bnx2x_vf_handle_filters_eqe(struct bnx2x *bp,
  1923. struct bnx2x_virtf *vf)
  1924. {
  1925. smp_mb__before_clear_bit();
  1926. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &vf->filter_state);
  1927. smp_mb__after_clear_bit();
  1928. }
  1929. int bnx2x_iov_eq_sp_event(struct bnx2x *bp, union event_ring_elem *elem)
  1930. {
  1931. struct bnx2x_virtf *vf;
  1932. int qidx = 0, abs_vfid;
  1933. u8 opcode;
  1934. u16 cid = 0xffff;
  1935. if (!IS_SRIOV(bp))
  1936. return 1;
  1937. /* first get the cid - the only events we handle here are cfc-delete
  1938. * and set-mac completion
  1939. */
  1940. opcode = elem->message.opcode;
  1941. switch (opcode) {
  1942. case EVENT_RING_OPCODE_CFC_DEL:
  1943. cid = SW_CID((__force __le32)
  1944. elem->message.data.cfc_del_event.cid);
  1945. DP(BNX2X_MSG_IOV, "checking cfc-del comp cid=%d\n", cid);
  1946. break;
  1947. case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
  1948. case EVENT_RING_OPCODE_MULTICAST_RULES:
  1949. case EVENT_RING_OPCODE_FILTERS_RULES:
  1950. cid = (elem->message.data.eth_event.echo &
  1951. BNX2X_SWCID_MASK);
  1952. DP(BNX2X_MSG_IOV, "checking filtering comp cid=%d\n", cid);
  1953. break;
  1954. case EVENT_RING_OPCODE_VF_FLR:
  1955. abs_vfid = elem->message.data.vf_flr_event.vf_id;
  1956. DP(BNX2X_MSG_IOV, "Got VF FLR notification abs_vfid=%d\n",
  1957. abs_vfid);
  1958. goto get_vf;
  1959. case EVENT_RING_OPCODE_MALICIOUS_VF:
  1960. abs_vfid = elem->message.data.malicious_vf_event.vf_id;
  1961. DP(BNX2X_MSG_IOV, "Got VF MALICIOUS notification abs_vfid=%d err_id=0x%x\n",
  1962. abs_vfid, elem->message.data.malicious_vf_event.err_id);
  1963. goto get_vf;
  1964. default:
  1965. return 1;
  1966. }
  1967. /* check if the cid is the VF range */
  1968. if (!bnx2x_iov_is_vf_cid(bp, cid)) {
  1969. DP(BNX2X_MSG_IOV, "cid is outside vf range: %d\n", cid);
  1970. return 1;
  1971. }
  1972. /* extract vf and rxq index from vf_cid - relies on the following:
  1973. * 1. vfid on cid reflects the true abs_vfid
  1974. * 2. The max number of VFs (per path) is 64
  1975. */
  1976. qidx = cid & ((1 << BNX2X_VF_CID_WND)-1);
  1977. abs_vfid = (cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
  1978. get_vf:
  1979. vf = bnx2x_vf_by_abs_fid(bp, abs_vfid);
  1980. if (!vf) {
  1981. BNX2X_ERR("EQ completion for unknown VF, cid %d, abs_vfid %d\n",
  1982. cid, abs_vfid);
  1983. return 0;
  1984. }
  1985. switch (opcode) {
  1986. case EVENT_RING_OPCODE_CFC_DEL:
  1987. DP(BNX2X_MSG_IOV, "got VF [%d:%d] cfc delete ramrod\n",
  1988. vf->abs_vfid, qidx);
  1989. vfq_get(vf, qidx)->sp_obj.complete_cmd(bp,
  1990. &vfq_get(vf,
  1991. qidx)->sp_obj,
  1992. BNX2X_Q_CMD_CFC_DEL);
  1993. break;
  1994. case EVENT_RING_OPCODE_CLASSIFICATION_RULES:
  1995. DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mac/vlan ramrod\n",
  1996. vf->abs_vfid, qidx);
  1997. bnx2x_vf_handle_classification_eqe(bp, vfq_get(vf, qidx), elem);
  1998. break;
  1999. case EVENT_RING_OPCODE_MULTICAST_RULES:
  2000. DP(BNX2X_MSG_IOV, "got VF [%d:%d] set mcast ramrod\n",
  2001. vf->abs_vfid, qidx);
  2002. bnx2x_vf_handle_mcast_eqe(bp, vf);
  2003. break;
  2004. case EVENT_RING_OPCODE_FILTERS_RULES:
  2005. DP(BNX2X_MSG_IOV, "got VF [%d:%d] set rx-mode ramrod\n",
  2006. vf->abs_vfid, qidx);
  2007. bnx2x_vf_handle_filters_eqe(bp, vf);
  2008. break;
  2009. case EVENT_RING_OPCODE_VF_FLR:
  2010. DP(BNX2X_MSG_IOV, "got VF [%d] FLR notification\n",
  2011. vf->abs_vfid);
  2012. /* Do nothing for now */
  2013. break;
  2014. case EVENT_RING_OPCODE_MALICIOUS_VF:
  2015. DP(BNX2X_MSG_IOV, "Got VF MALICIOUS notification abs_vfid=%d error id %x\n",
  2016. abs_vfid, elem->message.data.malicious_vf_event.err_id);
  2017. /* Do nothing for now */
  2018. break;
  2019. }
  2020. /* SRIOV: reschedule any 'in_progress' operations */
  2021. bnx2x_iov_sp_event(bp, cid, false);
  2022. return 0;
  2023. }
  2024. static struct bnx2x_virtf *bnx2x_vf_by_cid(struct bnx2x *bp, int vf_cid)
  2025. {
  2026. /* extract the vf from vf_cid - relies on the following:
  2027. * 1. vfid on cid reflects the true abs_vfid
  2028. * 2. The max number of VFs (per path) is 64
  2029. */
  2030. int abs_vfid = (vf_cid >> BNX2X_VF_CID_WND) & (BNX2X_MAX_NUM_OF_VFS-1);
  2031. return bnx2x_vf_by_abs_fid(bp, abs_vfid);
  2032. }
  2033. void bnx2x_iov_set_queue_sp_obj(struct bnx2x *bp, int vf_cid,
  2034. struct bnx2x_queue_sp_obj **q_obj)
  2035. {
  2036. struct bnx2x_virtf *vf;
  2037. if (!IS_SRIOV(bp))
  2038. return;
  2039. vf = bnx2x_vf_by_cid(bp, vf_cid);
  2040. if (vf) {
  2041. /* extract queue index from vf_cid - relies on the following:
  2042. * 1. vfid on cid reflects the true abs_vfid
  2043. * 2. The max number of VFs (per path) is 64
  2044. */
  2045. int q_index = vf_cid & ((1 << BNX2X_VF_CID_WND)-1);
  2046. *q_obj = &bnx2x_vfq(vf, q_index, sp_obj);
  2047. } else {
  2048. BNX2X_ERR("No vf matching cid %d\n", vf_cid);
  2049. }
  2050. }
  2051. void bnx2x_iov_sp_event(struct bnx2x *bp, int vf_cid, bool queue_work)
  2052. {
  2053. struct bnx2x_virtf *vf;
  2054. /* check if the cid is the VF range */
  2055. if (!IS_SRIOV(bp) || !bnx2x_iov_is_vf_cid(bp, vf_cid))
  2056. return;
  2057. vf = bnx2x_vf_by_cid(bp, vf_cid);
  2058. if (vf) {
  2059. /* set in_progress flag */
  2060. atomic_set(&vf->op_in_progress, 1);
  2061. if (queue_work)
  2062. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  2063. }
  2064. }
  2065. void bnx2x_iov_adjust_stats_req(struct bnx2x *bp)
  2066. {
  2067. int i;
  2068. int first_queue_query_index, num_queues_req;
  2069. dma_addr_t cur_data_offset;
  2070. struct stats_query_entry *cur_query_entry;
  2071. u8 stats_count = 0;
  2072. bool is_fcoe = false;
  2073. if (!IS_SRIOV(bp))
  2074. return;
  2075. if (!NO_FCOE(bp))
  2076. is_fcoe = true;
  2077. /* fcoe adds one global request and one queue request */
  2078. num_queues_req = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe;
  2079. first_queue_query_index = BNX2X_FIRST_QUEUE_QUERY_IDX -
  2080. (is_fcoe ? 0 : 1);
  2081. DP(BNX2X_MSG_IOV,
  2082. "BNX2X_NUM_ETH_QUEUES %d, is_fcoe %d, first_queue_query_index %d => determined the last non virtual statistics query index is %d. Will add queries on top of that\n",
  2083. BNX2X_NUM_ETH_QUEUES(bp), is_fcoe, first_queue_query_index,
  2084. first_queue_query_index + num_queues_req);
  2085. cur_data_offset = bp->fw_stats_data_mapping +
  2086. offsetof(struct bnx2x_fw_stats_data, queue_stats) +
  2087. num_queues_req * sizeof(struct per_queue_stats);
  2088. cur_query_entry = &bp->fw_stats_req->
  2089. query[first_queue_query_index + num_queues_req];
  2090. for_each_vf(bp, i) {
  2091. int j;
  2092. struct bnx2x_virtf *vf = BP_VF(bp, i);
  2093. if (vf->state != VF_ENABLED) {
  2094. DP(BNX2X_MSG_IOV,
  2095. "vf %d not enabled so no stats for it\n",
  2096. vf->abs_vfid);
  2097. continue;
  2098. }
  2099. DP(BNX2X_MSG_IOV, "add addresses for vf %d\n", vf->abs_vfid);
  2100. for_each_vfq(vf, j) {
  2101. struct bnx2x_vf_queue *rxq = vfq_get(vf, j);
  2102. dma_addr_t q_stats_addr =
  2103. vf->fw_stat_map + j * vf->stats_stride;
  2104. /* collect stats fro active queues only */
  2105. if (bnx2x_get_q_logical_state(bp, &rxq->sp_obj) ==
  2106. BNX2X_Q_LOGICAL_STATE_STOPPED)
  2107. continue;
  2108. /* create stats query entry for this queue */
  2109. cur_query_entry->kind = STATS_TYPE_QUEUE;
  2110. cur_query_entry->index = vfq_stat_id(vf, rxq);
  2111. cur_query_entry->funcID =
  2112. cpu_to_le16(FW_VF_HANDLE(vf->abs_vfid));
  2113. cur_query_entry->address.hi =
  2114. cpu_to_le32(U64_HI(q_stats_addr));
  2115. cur_query_entry->address.lo =
  2116. cpu_to_le32(U64_LO(q_stats_addr));
  2117. DP(BNX2X_MSG_IOV,
  2118. "added address %x %x for vf %d queue %d client %d\n",
  2119. cur_query_entry->address.hi,
  2120. cur_query_entry->address.lo, cur_query_entry->funcID,
  2121. j, cur_query_entry->index);
  2122. cur_query_entry++;
  2123. cur_data_offset += sizeof(struct per_queue_stats);
  2124. stats_count++;
  2125. /* all stats are coalesced to the leading queue */
  2126. if (vf->cfg_flags & VF_CFG_STATS_COALESCE)
  2127. break;
  2128. }
  2129. }
  2130. bp->fw_stats_req->hdr.cmd_num = bp->fw_stats_num + stats_count;
  2131. }
  2132. void bnx2x_iov_sp_task(struct bnx2x *bp)
  2133. {
  2134. int i;
  2135. if (!IS_SRIOV(bp))
  2136. return;
  2137. /* Iterate over all VFs and invoke state transition for VFs with
  2138. * 'in-progress' slow-path operations
  2139. */
  2140. DP(BNX2X_MSG_IOV, "searching for pending vf operations\n");
  2141. for_each_vf(bp, i) {
  2142. struct bnx2x_virtf *vf = BP_VF(bp, i);
  2143. if (!vf) {
  2144. BNX2X_ERR("VF was null! skipping...\n");
  2145. continue;
  2146. }
  2147. if (!list_empty(&vf->op_list_head) &&
  2148. atomic_read(&vf->op_in_progress)) {
  2149. DP(BNX2X_MSG_IOV, "running pending op for vf %d\n", i);
  2150. bnx2x_vfop_cur(bp, vf)->transition(bp, vf);
  2151. }
  2152. }
  2153. }
  2154. static inline
  2155. struct bnx2x_virtf *__vf_from_stat_id(struct bnx2x *bp, u8 stat_id)
  2156. {
  2157. int i;
  2158. struct bnx2x_virtf *vf = NULL;
  2159. for_each_vf(bp, i) {
  2160. vf = BP_VF(bp, i);
  2161. if (stat_id >= vf->igu_base_id &&
  2162. stat_id < vf->igu_base_id + vf_sb_count(vf))
  2163. break;
  2164. }
  2165. return vf;
  2166. }
  2167. /* VF API helpers */
  2168. static void bnx2x_vf_qtbl_set_q(struct bnx2x *bp, u8 abs_vfid, u8 qid,
  2169. u8 enable)
  2170. {
  2171. u32 reg = PXP_REG_HST_ZONE_PERMISSION_TABLE + qid * 4;
  2172. u32 val = enable ? (abs_vfid | (1 << 6)) : 0;
  2173. REG_WR(bp, reg, val);
  2174. }
  2175. static void bnx2x_vf_clr_qtbl(struct bnx2x *bp, struct bnx2x_virtf *vf)
  2176. {
  2177. int i;
  2178. for_each_vfq(vf, i)
  2179. bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
  2180. vfq_qzone_id(vf, vfq_get(vf, i)), false);
  2181. }
  2182. static void bnx2x_vf_igu_disable(struct bnx2x *bp, struct bnx2x_virtf *vf)
  2183. {
  2184. u32 val;
  2185. /* clear the VF configuration - pretend */
  2186. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf->abs_vfid));
  2187. val = REG_RD(bp, IGU_REG_VF_CONFIGURATION);
  2188. val &= ~(IGU_VF_CONF_MSI_MSIX_EN | IGU_VF_CONF_SINGLE_ISR_EN |
  2189. IGU_VF_CONF_FUNC_EN | IGU_VF_CONF_PARENT_MASK);
  2190. REG_WR(bp, IGU_REG_VF_CONFIGURATION, val);
  2191. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  2192. }
  2193. u8 bnx2x_vf_max_queue_cnt(struct bnx2x *bp, struct bnx2x_virtf *vf)
  2194. {
  2195. return min_t(u8, min_t(u8, vf_sb_count(vf), BNX2X_CIDS_PER_VF),
  2196. BNX2X_VF_MAX_QUEUES);
  2197. }
  2198. static
  2199. int bnx2x_vf_chk_avail_resc(struct bnx2x *bp, struct bnx2x_virtf *vf,
  2200. struct vf_pf_resc_request *req_resc)
  2201. {
  2202. u8 rxq_cnt = vf_rxq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
  2203. u8 txq_cnt = vf_txq_count(vf) ? : bnx2x_vf_max_queue_cnt(bp, vf);
  2204. return ((req_resc->num_rxqs <= rxq_cnt) &&
  2205. (req_resc->num_txqs <= txq_cnt) &&
  2206. (req_resc->num_sbs <= vf_sb_count(vf)) &&
  2207. (req_resc->num_mac_filters <= vf_mac_rules_cnt(vf)) &&
  2208. (req_resc->num_vlan_filters <= vf_vlan_rules_cnt(vf)));
  2209. }
  2210. /* CORE VF API */
  2211. int bnx2x_vf_acquire(struct bnx2x *bp, struct bnx2x_virtf *vf,
  2212. struct vf_pf_resc_request *resc)
  2213. {
  2214. int base_vf_cid = (BP_VFDB(bp)->sriov.first_vf_in_pf + vf->index) *
  2215. BNX2X_CIDS_PER_VF;
  2216. union cdu_context *base_cxt = (union cdu_context *)
  2217. BP_VF_CXT_PAGE(bp, base_vf_cid/ILT_PAGE_CIDS)->addr +
  2218. (base_vf_cid & (ILT_PAGE_CIDS-1));
  2219. int i;
  2220. /* if state is 'acquired' the VF was not released or FLR'd, in
  2221. * this case the returned resources match the acquired already
  2222. * acquired resources. Verify that the requested numbers do
  2223. * not exceed the already acquired numbers.
  2224. */
  2225. if (vf->state == VF_ACQUIRED) {
  2226. DP(BNX2X_MSG_IOV, "VF[%d] Trying to re-acquire resources (VF was not released or FLR'd)\n",
  2227. vf->abs_vfid);
  2228. if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
  2229. BNX2X_ERR("VF[%d] When re-acquiring resources, requested numbers must be <= then previously acquired numbers\n",
  2230. vf->abs_vfid);
  2231. return -EINVAL;
  2232. }
  2233. return 0;
  2234. }
  2235. /* Otherwise vf state must be 'free' or 'reset' */
  2236. if (vf->state != VF_FREE && vf->state != VF_RESET) {
  2237. BNX2X_ERR("VF[%d] Can not acquire a VF with state %d\n",
  2238. vf->abs_vfid, vf->state);
  2239. return -EINVAL;
  2240. }
  2241. /* static allocation:
  2242. * the global maximum number are fixed per VF. Fail the request if
  2243. * requested number exceed these globals
  2244. */
  2245. if (!bnx2x_vf_chk_avail_resc(bp, vf, resc)) {
  2246. DP(BNX2X_MSG_IOV,
  2247. "cannot fulfill vf resource request. Placing maximal available values in response\n");
  2248. /* set the max resource in the vf */
  2249. return -ENOMEM;
  2250. }
  2251. /* Set resources counters - 0 request means max available */
  2252. vf_sb_count(vf) = resc->num_sbs;
  2253. vf_rxq_count(vf) = resc->num_rxqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
  2254. vf_txq_count(vf) = resc->num_txqs ? : bnx2x_vf_max_queue_cnt(bp, vf);
  2255. if (resc->num_mac_filters)
  2256. vf_mac_rules_cnt(vf) = resc->num_mac_filters;
  2257. if (resc->num_vlan_filters)
  2258. vf_vlan_rules_cnt(vf) = resc->num_vlan_filters;
  2259. DP(BNX2X_MSG_IOV,
  2260. "Fulfilling vf request: sb count %d, tx_count %d, rx_count %d, mac_rules_count %d, vlan_rules_count %d\n",
  2261. vf_sb_count(vf), vf_rxq_count(vf),
  2262. vf_txq_count(vf), vf_mac_rules_cnt(vf),
  2263. vf_vlan_rules_cnt(vf));
  2264. /* Initialize the queues */
  2265. if (!vf->vfqs) {
  2266. DP(BNX2X_MSG_IOV, "vf->vfqs was not allocated\n");
  2267. return -EINVAL;
  2268. }
  2269. for_each_vfq(vf, i) {
  2270. struct bnx2x_vf_queue *q = vfq_get(vf, i);
  2271. if (!q) {
  2272. BNX2X_ERR("q number %d was not allocated\n", i);
  2273. return -EINVAL;
  2274. }
  2275. q->index = i;
  2276. q->cxt = &((base_cxt + i)->eth);
  2277. q->cid = BNX2X_FIRST_VF_CID + base_vf_cid + i;
  2278. DP(BNX2X_MSG_IOV, "VFQ[%d:%d]: index %d, cid 0x%x, cxt %p\n",
  2279. vf->abs_vfid, i, q->index, q->cid, q->cxt);
  2280. /* init SP objects */
  2281. bnx2x_vfq_init(bp, vf, q);
  2282. }
  2283. vf->state = VF_ACQUIRED;
  2284. return 0;
  2285. }
  2286. int bnx2x_vf_init(struct bnx2x *bp, struct bnx2x_virtf *vf, dma_addr_t *sb_map)
  2287. {
  2288. struct bnx2x_func_init_params func_init = {0};
  2289. u16 flags = 0;
  2290. int i;
  2291. /* the sb resources are initialized at this point, do the
  2292. * FW/HW initializations
  2293. */
  2294. for_each_vf_sb(vf, i)
  2295. bnx2x_init_sb(bp, (dma_addr_t)sb_map[i], vf->abs_vfid, true,
  2296. vf_igu_sb(vf, i), vf_igu_sb(vf, i));
  2297. /* Sanity checks */
  2298. if (vf->state != VF_ACQUIRED) {
  2299. DP(BNX2X_MSG_IOV, "VF[%d] is not in VF_ACQUIRED, but %d\n",
  2300. vf->abs_vfid, vf->state);
  2301. return -EINVAL;
  2302. }
  2303. /* let FLR complete ... */
  2304. msleep(100);
  2305. /* FLR cleanup epilogue */
  2306. if (bnx2x_vf_flr_clnup_epilog(bp, vf->abs_vfid))
  2307. return -EBUSY;
  2308. /* reset IGU VF statistics: MSIX */
  2309. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT + vf->abs_vfid * 4 , 0);
  2310. /* vf init */
  2311. if (vf->cfg_flags & VF_CFG_STATS)
  2312. flags |= (FUNC_FLG_STATS | FUNC_FLG_SPQ);
  2313. if (vf->cfg_flags & VF_CFG_TPA)
  2314. flags |= FUNC_FLG_TPA;
  2315. if (is_vf_multi(vf))
  2316. flags |= FUNC_FLG_RSS;
  2317. /* function setup */
  2318. func_init.func_flgs = flags;
  2319. func_init.pf_id = BP_FUNC(bp);
  2320. func_init.func_id = FW_VF_HANDLE(vf->abs_vfid);
  2321. func_init.fw_stat_map = vf->fw_stat_map;
  2322. func_init.spq_map = vf->spq_map;
  2323. func_init.spq_prod = 0;
  2324. bnx2x_func_init(bp, &func_init);
  2325. /* Enable the vf */
  2326. bnx2x_vf_enable_access(bp, vf->abs_vfid);
  2327. bnx2x_vf_enable_traffic(bp, vf);
  2328. /* queue protection table */
  2329. for_each_vfq(vf, i)
  2330. bnx2x_vf_qtbl_set_q(bp, vf->abs_vfid,
  2331. vfq_qzone_id(vf, vfq_get(vf, i)), true);
  2332. vf->state = VF_ENABLED;
  2333. /* update vf bulletin board */
  2334. bnx2x_post_vf_bulletin(bp, vf->index);
  2335. return 0;
  2336. }
  2337. struct set_vf_state_cookie {
  2338. struct bnx2x_virtf *vf;
  2339. u8 state;
  2340. };
  2341. void bnx2x_set_vf_state(void *cookie)
  2342. {
  2343. struct set_vf_state_cookie *p = (struct set_vf_state_cookie *)cookie;
  2344. p->vf->state = p->state;
  2345. }
  2346. /* VFOP close (teardown the queues, delete mcasts and close HW) */
  2347. static void bnx2x_vfop_close(struct bnx2x *bp, struct bnx2x_virtf *vf)
  2348. {
  2349. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  2350. struct bnx2x_vfop_args_qx *qx = &vfop->args.qx;
  2351. enum bnx2x_vfop_close_state state = vfop->state;
  2352. struct bnx2x_vfop_cmd cmd = {
  2353. .done = bnx2x_vfop_close,
  2354. .block = false,
  2355. };
  2356. if (vfop->rc < 0)
  2357. goto op_err;
  2358. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  2359. switch (state) {
  2360. case BNX2X_VFOP_CLOSE_QUEUES:
  2361. if (++(qx->qid) < vf_rxq_count(vf)) {
  2362. vfop->rc = bnx2x_vfop_qdown_cmd(bp, vf, &cmd, qx->qid);
  2363. if (vfop->rc)
  2364. goto op_err;
  2365. return;
  2366. }
  2367. /* remove multicasts */
  2368. vfop->state = BNX2X_VFOP_CLOSE_HW;
  2369. vfop->rc = bnx2x_vfop_mcast_cmd(bp, vf, &cmd, NULL, 0, false);
  2370. if (vfop->rc)
  2371. goto op_err;
  2372. return;
  2373. case BNX2X_VFOP_CLOSE_HW:
  2374. /* disable the interrupts */
  2375. DP(BNX2X_MSG_IOV, "disabling igu\n");
  2376. bnx2x_vf_igu_disable(bp, vf);
  2377. /* disable the VF */
  2378. DP(BNX2X_MSG_IOV, "clearing qtbl\n");
  2379. bnx2x_vf_clr_qtbl(bp, vf);
  2380. goto op_done;
  2381. default:
  2382. bnx2x_vfop_default(state);
  2383. }
  2384. op_err:
  2385. BNX2X_ERR("VF[%d] CLOSE error: rc %d\n", vf->abs_vfid, vfop->rc);
  2386. op_done:
  2387. /* need to make sure there are no outstanding stats ramrods which may
  2388. * cause the device to access the VF's stats buffer which it will free
  2389. * as soon as we return from the close flow.
  2390. */
  2391. {
  2392. struct set_vf_state_cookie cookie;
  2393. cookie.vf = vf;
  2394. cookie.state = VF_ACQUIRED;
  2395. bnx2x_stats_safe_exec(bp, bnx2x_set_vf_state, &cookie);
  2396. }
  2397. DP(BNX2X_MSG_IOV, "set state to acquired\n");
  2398. bnx2x_vfop_end(bp, vf, vfop);
  2399. }
  2400. int bnx2x_vfop_close_cmd(struct bnx2x *bp,
  2401. struct bnx2x_virtf *vf,
  2402. struct bnx2x_vfop_cmd *cmd)
  2403. {
  2404. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  2405. if (vfop) {
  2406. vfop->args.qx.qid = -1; /* loop */
  2407. bnx2x_vfop_opset(BNX2X_VFOP_CLOSE_QUEUES,
  2408. bnx2x_vfop_close, cmd->done);
  2409. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_close,
  2410. cmd->block);
  2411. }
  2412. return -ENOMEM;
  2413. }
  2414. /* VF release can be called either: 1. The VF was acquired but
  2415. * not enabled 2. the vf was enabled or in the process of being
  2416. * enabled
  2417. */
  2418. static void bnx2x_vfop_release(struct bnx2x *bp, struct bnx2x_virtf *vf)
  2419. {
  2420. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  2421. struct bnx2x_vfop_cmd cmd = {
  2422. .done = bnx2x_vfop_release,
  2423. .block = false,
  2424. };
  2425. DP(BNX2X_MSG_IOV, "vfop->rc %d\n", vfop->rc);
  2426. if (vfop->rc < 0)
  2427. goto op_err;
  2428. DP(BNX2X_MSG_IOV, "VF[%d] STATE: %s\n", vf->abs_vfid,
  2429. vf->state == VF_FREE ? "Free" :
  2430. vf->state == VF_ACQUIRED ? "Acquired" :
  2431. vf->state == VF_ENABLED ? "Enabled" :
  2432. vf->state == VF_RESET ? "Reset" :
  2433. "Unknown");
  2434. switch (vf->state) {
  2435. case VF_ENABLED:
  2436. vfop->rc = bnx2x_vfop_close_cmd(bp, vf, &cmd);
  2437. if (vfop->rc)
  2438. goto op_err;
  2439. return;
  2440. case VF_ACQUIRED:
  2441. DP(BNX2X_MSG_IOV, "about to free resources\n");
  2442. bnx2x_vf_free_resc(bp, vf);
  2443. DP(BNX2X_MSG_IOV, "vfop->rc %d\n", vfop->rc);
  2444. goto op_done;
  2445. case VF_FREE:
  2446. case VF_RESET:
  2447. /* do nothing */
  2448. goto op_done;
  2449. default:
  2450. bnx2x_vfop_default(vf->state);
  2451. }
  2452. op_err:
  2453. BNX2X_ERR("VF[%d] RELEASE error: rc %d\n", vf->abs_vfid, vfop->rc);
  2454. op_done:
  2455. bnx2x_vfop_end(bp, vf, vfop);
  2456. }
  2457. static void bnx2x_vfop_rss(struct bnx2x *bp, struct bnx2x_virtf *vf)
  2458. {
  2459. struct bnx2x_vfop *vfop = bnx2x_vfop_cur(bp, vf);
  2460. enum bnx2x_vfop_rss_state state;
  2461. if (!vfop) {
  2462. BNX2X_ERR("vfop was null\n");
  2463. return;
  2464. }
  2465. state = vfop->state;
  2466. bnx2x_vfop_reset_wq(vf);
  2467. if (vfop->rc < 0)
  2468. goto op_err;
  2469. DP(BNX2X_MSG_IOV, "vf[%d] STATE: %d\n", vf->abs_vfid, state);
  2470. switch (state) {
  2471. case BNX2X_VFOP_RSS_CONFIG:
  2472. /* next state */
  2473. vfop->state = BNX2X_VFOP_RSS_DONE;
  2474. bnx2x_config_rss(bp, &vfop->op_p->rss);
  2475. bnx2x_vfop_finalize(vf, vfop->rc, VFOP_DONE);
  2476. op_err:
  2477. BNX2X_ERR("RSS error: rc %d\n", vfop->rc);
  2478. op_done:
  2479. case BNX2X_VFOP_RSS_DONE:
  2480. bnx2x_vfop_end(bp, vf, vfop);
  2481. return;
  2482. default:
  2483. bnx2x_vfop_default(state);
  2484. }
  2485. op_pending:
  2486. return;
  2487. }
  2488. int bnx2x_vfop_release_cmd(struct bnx2x *bp,
  2489. struct bnx2x_virtf *vf,
  2490. struct bnx2x_vfop_cmd *cmd)
  2491. {
  2492. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  2493. if (vfop) {
  2494. bnx2x_vfop_opset(-1, /* use vf->state */
  2495. bnx2x_vfop_release, cmd->done);
  2496. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_release,
  2497. cmd->block);
  2498. }
  2499. return -ENOMEM;
  2500. }
  2501. int bnx2x_vfop_rss_cmd(struct bnx2x *bp,
  2502. struct bnx2x_virtf *vf,
  2503. struct bnx2x_vfop_cmd *cmd)
  2504. {
  2505. struct bnx2x_vfop *vfop = bnx2x_vfop_add(bp, vf);
  2506. if (vfop) {
  2507. bnx2x_vfop_opset(BNX2X_VFOP_RSS_CONFIG, bnx2x_vfop_rss,
  2508. cmd->done);
  2509. return bnx2x_vfop_transition(bp, vf, bnx2x_vfop_rss,
  2510. cmd->block);
  2511. }
  2512. return -ENOMEM;
  2513. }
  2514. /* VF release ~ VF close + VF release-resources
  2515. * Release is the ultimate SW shutdown and is called whenever an
  2516. * irrecoverable error is encountered.
  2517. */
  2518. void bnx2x_vf_release(struct bnx2x *bp, struct bnx2x_virtf *vf, bool block)
  2519. {
  2520. struct bnx2x_vfop_cmd cmd = {
  2521. .done = NULL,
  2522. .block = block,
  2523. };
  2524. int rc;
  2525. DP(BNX2X_MSG_IOV, "PF releasing vf %d\n", vf->abs_vfid);
  2526. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_RELEASE_VF);
  2527. rc = bnx2x_vfop_release_cmd(bp, vf, &cmd);
  2528. if (rc)
  2529. WARN(rc,
  2530. "VF[%d] Failed to allocate resources for release op- rc=%d\n",
  2531. vf->abs_vfid, rc);
  2532. }
  2533. static inline void bnx2x_vf_get_sbdf(struct bnx2x *bp,
  2534. struct bnx2x_virtf *vf, u32 *sbdf)
  2535. {
  2536. *sbdf = vf->devfn | (vf->bus << 8);
  2537. }
  2538. static inline void bnx2x_vf_get_bars(struct bnx2x *bp, struct bnx2x_virtf *vf,
  2539. struct bnx2x_vf_bar_info *bar_info)
  2540. {
  2541. int n;
  2542. bar_info->nr_bars = bp->vfdb->sriov.nres;
  2543. for (n = 0; n < bar_info->nr_bars; n++)
  2544. bar_info->bars[n] = vf->bars[n];
  2545. }
  2546. void bnx2x_lock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  2547. enum channel_tlvs tlv)
  2548. {
  2549. /* we don't lock the channel for unsupported tlvs */
  2550. if (!bnx2x_tlv_supported(tlv)) {
  2551. BNX2X_ERR("attempting to lock with unsupported tlv. Aborting\n");
  2552. return;
  2553. }
  2554. /* lock the channel */
  2555. mutex_lock(&vf->op_mutex);
  2556. /* record the locking op */
  2557. vf->op_current = tlv;
  2558. /* log the lock */
  2559. DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel locked by %d\n",
  2560. vf->abs_vfid, tlv);
  2561. }
  2562. void bnx2x_unlock_vf_pf_channel(struct bnx2x *bp, struct bnx2x_virtf *vf,
  2563. enum channel_tlvs expected_tlv)
  2564. {
  2565. enum channel_tlvs current_tlv;
  2566. if (!vf) {
  2567. BNX2X_ERR("VF was %p\n", vf);
  2568. return;
  2569. }
  2570. current_tlv = vf->op_current;
  2571. /* we don't unlock the channel for unsupported tlvs */
  2572. if (!bnx2x_tlv_supported(expected_tlv))
  2573. return;
  2574. WARN(expected_tlv != vf->op_current,
  2575. "lock mismatch: expected %d found %d", expected_tlv,
  2576. vf->op_current);
  2577. /* record the locking op */
  2578. vf->op_current = CHANNEL_TLV_NONE;
  2579. /* lock the channel */
  2580. mutex_unlock(&vf->op_mutex);
  2581. /* log the unlock */
  2582. DP(BNX2X_MSG_IOV, "VF[%d]: vf pf channel unlocked by %d\n",
  2583. vf->abs_vfid, vf->op_current);
  2584. }
  2585. int bnx2x_sriov_configure(struct pci_dev *dev, int num_vfs_param)
  2586. {
  2587. struct bnx2x *bp = netdev_priv(pci_get_drvdata(dev));
  2588. DP(BNX2X_MSG_IOV, "bnx2x_sriov_configure called with %d, BNX2X_NR_VIRTFN(bp) was %d\n",
  2589. num_vfs_param, BNX2X_NR_VIRTFN(bp));
  2590. /* HW channel is only operational when PF is up */
  2591. if (bp->state != BNX2X_STATE_OPEN) {
  2592. BNX2X_ERR("VF num configuration via sysfs not supported while PF is down\n");
  2593. return -EINVAL;
  2594. }
  2595. /* we are always bound by the total_vfs in the configuration space */
  2596. if (num_vfs_param > BNX2X_NR_VIRTFN(bp)) {
  2597. BNX2X_ERR("truncating requested number of VFs (%d) down to maximum allowed (%d)\n",
  2598. num_vfs_param, BNX2X_NR_VIRTFN(bp));
  2599. num_vfs_param = BNX2X_NR_VIRTFN(bp);
  2600. }
  2601. bp->requested_nr_virtfn = num_vfs_param;
  2602. if (num_vfs_param == 0) {
  2603. pci_disable_sriov(dev);
  2604. return 0;
  2605. } else {
  2606. return bnx2x_enable_sriov(bp);
  2607. }
  2608. }
  2609. #define IGU_ENTRY_SIZE 4
  2610. int bnx2x_enable_sriov(struct bnx2x *bp)
  2611. {
  2612. int rc = 0, req_vfs = bp->requested_nr_virtfn;
  2613. int vf_idx, sb_idx, vfq_idx, qcount, first_vf;
  2614. u32 igu_entry, address;
  2615. u16 num_vf_queues;
  2616. if (req_vfs == 0)
  2617. return 0;
  2618. first_vf = bp->vfdb->sriov.first_vf_in_pf;
  2619. /* statically distribute vf sb pool between VFs */
  2620. num_vf_queues = min_t(u16, BNX2X_VF_MAX_QUEUES,
  2621. BP_VFDB(bp)->vf_sbs_pool / req_vfs);
  2622. /* zero previous values learned from igu cam */
  2623. for (vf_idx = 0; vf_idx < req_vfs; vf_idx++) {
  2624. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  2625. vf->sb_count = 0;
  2626. vf_sb_count(BP_VF(bp, vf_idx)) = 0;
  2627. }
  2628. bp->vfdb->vf_sbs_pool = 0;
  2629. /* prepare IGU cam */
  2630. sb_idx = BP_VFDB(bp)->first_vf_igu_entry;
  2631. address = IGU_REG_MAPPING_MEMORY + sb_idx * IGU_ENTRY_SIZE;
  2632. for (vf_idx = first_vf; vf_idx < first_vf + req_vfs; vf_idx++) {
  2633. for (vfq_idx = 0; vfq_idx < num_vf_queues; vfq_idx++) {
  2634. igu_entry = vf_idx << IGU_REG_MAPPING_MEMORY_FID_SHIFT |
  2635. vfq_idx << IGU_REG_MAPPING_MEMORY_VECTOR_SHIFT |
  2636. IGU_REG_MAPPING_MEMORY_VALID;
  2637. DP(BNX2X_MSG_IOV, "assigning sb %d to vf %d\n",
  2638. sb_idx, vf_idx);
  2639. REG_WR(bp, address, igu_entry);
  2640. sb_idx++;
  2641. address += IGU_ENTRY_SIZE;
  2642. }
  2643. }
  2644. /* Reinitialize vf database according to igu cam */
  2645. bnx2x_get_vf_igu_cam_info(bp);
  2646. DP(BNX2X_MSG_IOV, "vf_sbs_pool %d, num_vf_queues %d\n",
  2647. BP_VFDB(bp)->vf_sbs_pool, num_vf_queues);
  2648. qcount = 0;
  2649. for_each_vf(bp, vf_idx) {
  2650. struct bnx2x_virtf *vf = BP_VF(bp, vf_idx);
  2651. /* set local queue arrays */
  2652. vf->vfqs = &bp->vfdb->vfqs[qcount];
  2653. qcount += vf_sb_count(vf);
  2654. }
  2655. /* prepare msix vectors in VF configuration space */
  2656. for (vf_idx = first_vf; vf_idx < first_vf + req_vfs; vf_idx++) {
  2657. bnx2x_pretend_func(bp, HW_VF_HANDLE(bp, vf_idx));
  2658. REG_WR(bp, PCICFG_OFFSET + GRC_CONFIG_REG_VF_MSIX_CONTROL,
  2659. num_vf_queues);
  2660. }
  2661. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  2662. /* enable sriov. This will probe all the VFs, and consequentially cause
  2663. * the "acquire" messages to appear on the VF PF channel.
  2664. */
  2665. DP(BNX2X_MSG_IOV, "about to call enable sriov\n");
  2666. pci_disable_sriov(bp->pdev);
  2667. rc = pci_enable_sriov(bp->pdev, req_vfs);
  2668. if (rc) {
  2669. BNX2X_ERR("pci_enable_sriov failed with %d\n", rc);
  2670. return rc;
  2671. }
  2672. DP(BNX2X_MSG_IOV, "sriov enabled (%d vfs)\n", req_vfs);
  2673. return req_vfs;
  2674. }
  2675. void bnx2x_pf_set_vfs_vlan(struct bnx2x *bp)
  2676. {
  2677. int vfidx;
  2678. struct pf_vf_bulletin_content *bulletin;
  2679. DP(BNX2X_MSG_IOV, "configuring vlan for VFs from sp-task\n");
  2680. for_each_vf(bp, vfidx) {
  2681. bulletin = BP_VF_BULLETIN(bp, vfidx);
  2682. if (BP_VF(bp, vfidx)->cfg_flags & VF_CFG_VLAN)
  2683. bnx2x_set_vf_vlan(bp->dev, vfidx, bulletin->vlan, 0);
  2684. }
  2685. }
  2686. void bnx2x_disable_sriov(struct bnx2x *bp)
  2687. {
  2688. pci_disable_sriov(bp->pdev);
  2689. }
  2690. int bnx2x_vf_ndo_prep(struct bnx2x *bp, int vfidx, struct bnx2x_virtf **vf,
  2691. struct pf_vf_bulletin_content **bulletin)
  2692. {
  2693. if (bp->state != BNX2X_STATE_OPEN) {
  2694. BNX2X_ERR("vf ndo called though PF is down\n");
  2695. return -EINVAL;
  2696. }
  2697. if (!IS_SRIOV(bp)) {
  2698. BNX2X_ERR("vf ndo called though sriov is disabled\n");
  2699. return -EINVAL;
  2700. }
  2701. if (vfidx >= BNX2X_NR_VIRTFN(bp)) {
  2702. BNX2X_ERR("vf ndo called for uninitialized VF. vfidx was %d BNX2X_NR_VIRTFN was %d\n",
  2703. vfidx, BNX2X_NR_VIRTFN(bp));
  2704. return -EINVAL;
  2705. }
  2706. /* init members */
  2707. *vf = BP_VF(bp, vfidx);
  2708. *bulletin = BP_VF_BULLETIN(bp, vfidx);
  2709. if (!*vf) {
  2710. BNX2X_ERR("vf ndo called but vf struct is null. vfidx was %d\n",
  2711. vfidx);
  2712. return -EINVAL;
  2713. }
  2714. if (!(*vf)->vfqs) {
  2715. BNX2X_ERR("vf ndo called but vfqs struct is null. Was ndo invoked before dynamically enabling SR-IOV? vfidx was %d\n",
  2716. vfidx);
  2717. return -EINVAL;
  2718. }
  2719. if (!*bulletin) {
  2720. BNX2X_ERR("vf ndo called but Bulletin Board struct is null. vfidx was %d\n",
  2721. vfidx);
  2722. return -EINVAL;
  2723. }
  2724. return 0;
  2725. }
  2726. int bnx2x_get_vf_config(struct net_device *dev, int vfidx,
  2727. struct ifla_vf_info *ivi)
  2728. {
  2729. struct bnx2x *bp = netdev_priv(dev);
  2730. struct bnx2x_virtf *vf = NULL;
  2731. struct pf_vf_bulletin_content *bulletin = NULL;
  2732. struct bnx2x_vlan_mac_obj *mac_obj;
  2733. struct bnx2x_vlan_mac_obj *vlan_obj;
  2734. int rc;
  2735. /* sanity and init */
  2736. rc = bnx2x_vf_ndo_prep(bp, vfidx, &vf, &bulletin);
  2737. if (rc)
  2738. return rc;
  2739. mac_obj = &bnx2x_leading_vfq(vf, mac_obj);
  2740. vlan_obj = &bnx2x_leading_vfq(vf, vlan_obj);
  2741. if (!mac_obj || !vlan_obj) {
  2742. BNX2X_ERR("VF partially initialized\n");
  2743. return -EINVAL;
  2744. }
  2745. ivi->vf = vfidx;
  2746. ivi->qos = 0;
  2747. ivi->tx_rate = 10000; /* always 10G. TBA take from link struct */
  2748. ivi->spoofchk = 1; /*always enabled */
  2749. if (vf->state == VF_ENABLED) {
  2750. /* mac and vlan are in vlan_mac objects */
  2751. if (validate_vlan_mac(bp, &bnx2x_leading_vfq(vf, mac_obj)))
  2752. mac_obj->get_n_elements(bp, mac_obj, 1, (u8 *)&ivi->mac,
  2753. 0, ETH_ALEN);
  2754. if (validate_vlan_mac(bp, &bnx2x_leading_vfq(vf, vlan_obj)))
  2755. vlan_obj->get_n_elements(bp, vlan_obj, 1,
  2756. (u8 *)&ivi->vlan, 0,
  2757. VLAN_HLEN);
  2758. } else {
  2759. /* mac */
  2760. if (bulletin->valid_bitmap & (1 << MAC_ADDR_VALID))
  2761. /* mac configured by ndo so its in bulletin board */
  2762. memcpy(&ivi->mac, bulletin->mac, ETH_ALEN);
  2763. else
  2764. /* function has not been loaded yet. Show mac as 0s */
  2765. memset(&ivi->mac, 0, ETH_ALEN);
  2766. /* vlan */
  2767. if (bulletin->valid_bitmap & (1 << VLAN_VALID))
  2768. /* vlan configured by ndo so its in bulletin board */
  2769. memcpy(&ivi->vlan, &bulletin->vlan, VLAN_HLEN);
  2770. else
  2771. /* function has not been loaded yet. Show vlans as 0s */
  2772. memset(&ivi->vlan, 0, VLAN_HLEN);
  2773. }
  2774. return 0;
  2775. }
  2776. /* New mac for VF. Consider these cases:
  2777. * 1. VF hasn't been acquired yet - save the mac in local bulletin board and
  2778. * supply at acquire.
  2779. * 2. VF has already been acquired but has not yet initialized - store in local
  2780. * bulletin board. mac will be posted on VF bulletin board after VF init. VF
  2781. * will configure this mac when it is ready.
  2782. * 3. VF has already initialized but has not yet setup a queue - post the new
  2783. * mac on VF's bulletin board right now. VF will configure this mac when it
  2784. * is ready.
  2785. * 4. VF has already set a queue - delete any macs already configured for this
  2786. * queue and manually config the new mac.
  2787. * In any event, once this function has been called refuse any attempts by the
  2788. * VF to configure any mac for itself except for this mac. In case of a race
  2789. * where the VF fails to see the new post on its bulletin board before sending a
  2790. * mac configuration request, the PF will simply fail the request and VF can try
  2791. * again after consulting its bulletin board.
  2792. */
  2793. int bnx2x_set_vf_mac(struct net_device *dev, int vfidx, u8 *mac)
  2794. {
  2795. struct bnx2x *bp = netdev_priv(dev);
  2796. int rc, q_logical_state;
  2797. struct bnx2x_virtf *vf = NULL;
  2798. struct pf_vf_bulletin_content *bulletin = NULL;
  2799. /* sanity and init */
  2800. rc = bnx2x_vf_ndo_prep(bp, vfidx, &vf, &bulletin);
  2801. if (rc)
  2802. return rc;
  2803. if (!is_valid_ether_addr(mac)) {
  2804. BNX2X_ERR("mac address invalid\n");
  2805. return -EINVAL;
  2806. }
  2807. /* update PF's copy of the VF's bulletin. Will no longer accept mac
  2808. * configuration requests from vf unless match this mac
  2809. */
  2810. bulletin->valid_bitmap |= 1 << MAC_ADDR_VALID;
  2811. memcpy(bulletin->mac, mac, ETH_ALEN);
  2812. /* Post update on VF's bulletin board */
  2813. rc = bnx2x_post_vf_bulletin(bp, vfidx);
  2814. if (rc) {
  2815. BNX2X_ERR("failed to update VF[%d] bulletin\n", vfidx);
  2816. return rc;
  2817. }
  2818. q_logical_state =
  2819. bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj));
  2820. if (vf->state == VF_ENABLED &&
  2821. q_logical_state == BNX2X_Q_LOGICAL_STATE_ACTIVE) {
  2822. /* configure the mac in device on this vf's queue */
  2823. unsigned long ramrod_flags = 0;
  2824. struct bnx2x_vlan_mac_obj *mac_obj =
  2825. &bnx2x_leading_vfq(vf, mac_obj);
  2826. rc = validate_vlan_mac(bp, &bnx2x_leading_vfq(vf, mac_obj));
  2827. if (rc)
  2828. return rc;
  2829. /* must lock vfpf channel to protect against vf flows */
  2830. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
  2831. /* remove existing eth macs */
  2832. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_ETH_MAC, true);
  2833. if (rc) {
  2834. BNX2X_ERR("failed to delete eth macs\n");
  2835. return -EINVAL;
  2836. }
  2837. /* remove existing uc list macs */
  2838. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, true);
  2839. if (rc) {
  2840. BNX2X_ERR("failed to delete uc_list macs\n");
  2841. return -EINVAL;
  2842. }
  2843. /* configure the new mac to device */
  2844. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  2845. bnx2x_set_mac_one(bp, (u8 *)&bulletin->mac, mac_obj, true,
  2846. BNX2X_ETH_MAC, &ramrod_flags);
  2847. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_MAC);
  2848. }
  2849. return 0;
  2850. }
  2851. int bnx2x_set_vf_vlan(struct net_device *dev, int vfidx, u16 vlan, u8 qos)
  2852. {
  2853. struct bnx2x *bp = netdev_priv(dev);
  2854. int rc, q_logical_state;
  2855. struct bnx2x_virtf *vf = NULL;
  2856. struct pf_vf_bulletin_content *bulletin = NULL;
  2857. /* sanity and init */
  2858. rc = bnx2x_vf_ndo_prep(bp, vfidx, &vf, &bulletin);
  2859. if (rc)
  2860. return rc;
  2861. if (vlan > 4095) {
  2862. BNX2X_ERR("illegal vlan value %d\n", vlan);
  2863. return -EINVAL;
  2864. }
  2865. DP(BNX2X_MSG_IOV, "configuring VF %d with VLAN %d qos %d\n",
  2866. vfidx, vlan, 0);
  2867. /* update PF's copy of the VF's bulletin. No point in posting the vlan
  2868. * to the VF since it doesn't have anything to do with it. But it useful
  2869. * to store it here in case the VF is not up yet and we can only
  2870. * configure the vlan later when it does.
  2871. */
  2872. bulletin->valid_bitmap |= 1 << VLAN_VALID;
  2873. bulletin->vlan = vlan;
  2874. /* is vf initialized and queue set up? */
  2875. q_logical_state =
  2876. bnx2x_get_q_logical_state(bp, &bnx2x_leading_vfq(vf, sp_obj));
  2877. if (vf->state == VF_ENABLED &&
  2878. q_logical_state == BNX2X_Q_LOGICAL_STATE_ACTIVE) {
  2879. /* configure the vlan in device on this vf's queue */
  2880. unsigned long ramrod_flags = 0;
  2881. unsigned long vlan_mac_flags = 0;
  2882. struct bnx2x_vlan_mac_obj *vlan_obj =
  2883. &bnx2x_leading_vfq(vf, vlan_obj);
  2884. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  2885. struct bnx2x_queue_state_params q_params = {NULL};
  2886. struct bnx2x_queue_update_params *update_params;
  2887. rc = validate_vlan_mac(bp, &bnx2x_leading_vfq(vf, mac_obj));
  2888. if (rc)
  2889. return rc;
  2890. memset(&ramrod_param, 0, sizeof(ramrod_param));
  2891. /* must lock vfpf channel to protect against vf flows */
  2892. bnx2x_lock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
  2893. /* remove existing vlans */
  2894. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  2895. rc = vlan_obj->delete_all(bp, vlan_obj, &vlan_mac_flags,
  2896. &ramrod_flags);
  2897. if (rc) {
  2898. BNX2X_ERR("failed to delete vlans\n");
  2899. return -EINVAL;
  2900. }
  2901. /* send queue update ramrod to configure default vlan and silent
  2902. * vlan removal
  2903. */
  2904. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  2905. q_params.cmd = BNX2X_Q_CMD_UPDATE;
  2906. q_params.q_obj = &bnx2x_leading_vfq(vf, sp_obj);
  2907. update_params = &q_params.params.update;
  2908. __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
  2909. &update_params->update_flags);
  2910. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  2911. &update_params->update_flags);
  2912. if (vlan == 0) {
  2913. /* if vlan is 0 then we want to leave the VF traffic
  2914. * untagged, and leave the incoming traffic untouched
  2915. * (i.e. do not remove any vlan tags).
  2916. */
  2917. __clear_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN,
  2918. &update_params->update_flags);
  2919. __clear_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  2920. &update_params->update_flags);
  2921. } else {
  2922. /* configure the new vlan to device */
  2923. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  2924. ramrod_param.vlan_mac_obj = vlan_obj;
  2925. ramrod_param.ramrod_flags = ramrod_flags;
  2926. ramrod_param.user_req.u.vlan.vlan = vlan;
  2927. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  2928. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  2929. if (rc) {
  2930. BNX2X_ERR("failed to configure vlan\n");
  2931. return -EINVAL;
  2932. }
  2933. /* configure default vlan to vf queue and set silent
  2934. * vlan removal (the vf remains unaware of this vlan).
  2935. */
  2936. update_params = &q_params.params.update;
  2937. __set_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN,
  2938. &update_params->update_flags);
  2939. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  2940. &update_params->update_flags);
  2941. update_params->def_vlan = vlan;
  2942. }
  2943. /* Update the Queue state */
  2944. rc = bnx2x_queue_state_change(bp, &q_params);
  2945. if (rc) {
  2946. BNX2X_ERR("Failed to configure default VLAN\n");
  2947. return rc;
  2948. }
  2949. /* clear the flag indicating that this VF needs its vlan
  2950. * (will only be set if the HV configured th Vlan before vf was
  2951. * and we were called because the VF came up later
  2952. */
  2953. vf->cfg_flags &= ~VF_CFG_VLAN;
  2954. bnx2x_unlock_vf_pf_channel(bp, vf, CHANNEL_TLV_PF_SET_VLAN);
  2955. }
  2956. return 0;
  2957. }
  2958. /* crc is the first field in the bulletin board. Compute the crc over the
  2959. * entire bulletin board excluding the crc field itself. Use the length field
  2960. * as the Bulletin Board was posted by a PF with possibly a different version
  2961. * from the vf which will sample it. Therefore, the length is computed by the
  2962. * PF and the used blindly by the VF.
  2963. */
  2964. u32 bnx2x_crc_vf_bulletin(struct bnx2x *bp,
  2965. struct pf_vf_bulletin_content *bulletin)
  2966. {
  2967. return crc32(BULLETIN_CRC_SEED,
  2968. ((u8 *)bulletin) + sizeof(bulletin->crc),
  2969. bulletin->length - sizeof(bulletin->crc));
  2970. }
  2971. /* Check for new posts on the bulletin board */
  2972. enum sample_bulletin_result bnx2x_sample_bulletin(struct bnx2x *bp)
  2973. {
  2974. struct pf_vf_bulletin_content bulletin = bp->pf2vf_bulletin->content;
  2975. int attempts;
  2976. /* bulletin board hasn't changed since last sample */
  2977. if (bp->old_bulletin.version == bulletin.version)
  2978. return PFVF_BULLETIN_UNCHANGED;
  2979. /* validate crc of new bulletin board */
  2980. if (bp->old_bulletin.version != bp->pf2vf_bulletin->content.version) {
  2981. /* sampling structure in mid post may result with corrupted data
  2982. * validate crc to ensure coherency.
  2983. */
  2984. for (attempts = 0; attempts < BULLETIN_ATTEMPTS; attempts++) {
  2985. bulletin = bp->pf2vf_bulletin->content;
  2986. if (bulletin.crc == bnx2x_crc_vf_bulletin(bp,
  2987. &bulletin))
  2988. break;
  2989. BNX2X_ERR("bad crc on bulletin board. Contained %x computed %x\n",
  2990. bulletin.crc,
  2991. bnx2x_crc_vf_bulletin(bp, &bulletin));
  2992. }
  2993. if (attempts >= BULLETIN_ATTEMPTS) {
  2994. BNX2X_ERR("pf to vf bulletin board crc was wrong %d consecutive times. Aborting\n",
  2995. attempts);
  2996. return PFVF_BULLETIN_CRC_ERR;
  2997. }
  2998. }
  2999. /* the mac address in bulletin board is valid and is new */
  3000. if (bulletin.valid_bitmap & 1 << MAC_ADDR_VALID &&
  3001. memcmp(bulletin.mac, bp->old_bulletin.mac, ETH_ALEN)) {
  3002. /* update new mac to net device */
  3003. memcpy(bp->dev->dev_addr, bulletin.mac, ETH_ALEN);
  3004. }
  3005. /* the vlan in bulletin board is valid and is new */
  3006. if (bulletin.valid_bitmap & 1 << VLAN_VALID)
  3007. memcpy(&bulletin.vlan, &bp->old_bulletin.vlan, VLAN_HLEN);
  3008. /* copy new bulletin board to bp */
  3009. bp->old_bulletin = bulletin;
  3010. return PFVF_BULLETIN_UPDATED;
  3011. }
  3012. void bnx2x_timer_sriov(struct bnx2x *bp)
  3013. {
  3014. bnx2x_sample_bulletin(bp);
  3015. /* if channel is down we need to self destruct */
  3016. if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
  3017. smp_mb__before_clear_bit();
  3018. set_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  3019. &bp->sp_rtnl_state);
  3020. smp_mb__after_clear_bit();
  3021. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3022. }
  3023. }
  3024. void __iomem *bnx2x_vf_doorbells(struct bnx2x *bp)
  3025. {
  3026. /* vf doorbells are embedded within the regview */
  3027. return bp->regview + PXP_VF_ADDR_DB_START;
  3028. }
  3029. int bnx2x_vf_pci_alloc(struct bnx2x *bp)
  3030. {
  3031. mutex_init(&bp->vf2pf_mutex);
  3032. /* allocate vf2pf mailbox for vf to pf channel */
  3033. BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping,
  3034. sizeof(struct bnx2x_vf_mbx_msg));
  3035. /* allocate pf 2 vf bulletin board */
  3036. BNX2X_PCI_ALLOC(bp->pf2vf_bulletin, &bp->pf2vf_bulletin_mapping,
  3037. sizeof(union pf_vf_bulletin));
  3038. return 0;
  3039. alloc_mem_err:
  3040. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
  3041. sizeof(struct bnx2x_vf_mbx_msg));
  3042. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->pf2vf_bulletin_mapping,
  3043. sizeof(union pf_vf_bulletin));
  3044. return -ENOMEM;
  3045. }
  3046. int bnx2x_open_epilog(struct bnx2x *bp)
  3047. {
  3048. /* Enable sriov via delayed work. This must be done via delayed work
  3049. * because it causes the probe of the vf devices to be run, which invoke
  3050. * register_netdevice which must have rtnl lock taken. As we are holding
  3051. * the lock right now, that could only work if the probe would not take
  3052. * the lock. However, as the probe of the vf may be called from other
  3053. * contexts as well (such as passthrough to vm fails) it can't assume
  3054. * the lock is being held for it. Using delayed work here allows the
  3055. * probe code to simply take the lock (i.e. wait for it to be released
  3056. * if it is being held). We only want to do this if the number of VFs
  3057. * was set before PF driver was loaded.
  3058. */
  3059. if (IS_SRIOV(bp) && BNX2X_NR_VIRTFN(bp)) {
  3060. smp_mb__before_clear_bit();
  3061. set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
  3062. smp_mb__after_clear_bit();
  3063. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3064. }
  3065. return 0;
  3066. }
  3067. void bnx2x_iov_channel_down(struct bnx2x *bp)
  3068. {
  3069. int vf_idx;
  3070. struct pf_vf_bulletin_content *bulletin;
  3071. if (!IS_SRIOV(bp))
  3072. return;
  3073. for_each_vf(bp, vf_idx) {
  3074. /* locate this VFs bulletin board and update the channel down
  3075. * bit
  3076. */
  3077. bulletin = BP_VF_BULLETIN(bp, vf_idx);
  3078. bulletin->valid_bitmap |= 1 << CHANNEL_DOWN;
  3079. /* update vf bulletin board */
  3080. bnx2x_post_vf_bulletin(bp, vf_idx);
  3081. }
  3082. }