bnx2x_sriov.c 86 KB

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