bnx2x_sriov.c 86 KB

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