bnx2x_sriov.c 87 KB

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