bnx2x_sriov.c 87 KB

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