bnx2x_sriov.c 86 KB

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