bnx2x_sriov.c 95 KB

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